OpenMS  2.5.0
ListEditor.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2020.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: David Wojnar $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 // OpenMS_GUI config
38 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
39 
40 #ifndef Q_MOC_RUN
42 #endif
43 
44 #include <QDialog>
45 #include <QListWidget>
46 #include <QItemDelegate>
47 
48 class QPushButton;
49 
50 namespace OpenMS
51 {
52  namespace Internal
53  {
54  class ListTable;
55  class ListEditorDelegate;
56  }
57 
61  class OPENMS_GUI_DLLAPI ListEditor :
62  public QDialog
63  {
64  Q_OBJECT
65 
66 public:
67  //types of lists
68  enum Type
69  {
70  INT,
74  INPUT_FILE
75  };
76 
78  ListEditor(QWidget * parent = nullptr, QString title = "");
80  StringList getList() const;
82  void setList(const StringList & list, ListEditor::Type type);
84  void setListRestrictions(const String & restrictions);
86  void setTypeName(QString name);
87 
88 private:
96  QPushButton * newRowButton_;
98  QPushButton * removeRowButton_;
100  QPushButton * OkButton_;
102  QPushButton * CancelButton_;
103  };
104 
109  namespace Internal
110  {
111  class OPENMS_GUI_DLLAPI ListTable :
112  public QListWidget
113  {
114  Q_OBJECT
115 
116 public:
117 
118  //Default Constructor
119  ListTable(QWidget * parent = nullptr);
120 
121  //returns a list_
122  StringList getList();
123 
124  //sets new list
125  void setList(const StringList & list, ListEditor::Type type);
126 
127 public slots:
128  void createNewRow();
129  void removeCurrentRow();
130 
131 private:
134  //everything is internally stored as stringlist
136  };
137 
143  class OPENMS_GUI_DLLAPI ListEditorDelegate :
144  public QItemDelegate
145  {
146  Q_OBJECT
147 
148 public:
150  ListEditorDelegate(QObject * parent);
152  QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
154  void setEditorData(QWidget * editor, const QModelIndex & index) const override;
156  void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override;
158  void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
159 
160  //sets Type of List
161  void setType(const ListEditor::Type type);
162  //sets restrictions for listelements
163  void setRestrictions(const String & restrictions);
165  void setTypeName(QString name);
167  void setFileName(QString name);
168 
169 private:
177  QString typeName_;
179  mutable QString file_name_;
180 
181  };
182  }
183 
184 } // namespace OpenMS
OpenMS::ListEditor::type_
ListEditor::Type type_
List type.
Definition: ListEditor.h:90
QObject
OpenMS::ListEditor::removeRowButton_
QPushButton * removeRowButton_
button for removing row
Definition: ListEditor.h:98
OpenMS::ListEditor::CancelButton_
QPushButton * CancelButton_
button clicked if modifications are rejected
Definition: ListEditor.h:102
OpenMS::ListEditor::OkButton_
QPushButton * OkButton_
button clicked if modifications are accepted
Definition: ListEditor.h:100
QListWidget
OpenMS::Internal::ListTable::type_
ListEditor::Type type_
List type.
Definition: ListEditor.h:133
OpenMS::Internal::ListEditorDelegate
Internal delegate class.
Definition: ListEditor.h:143
OpenMS::ListEditor
Editor for editing int, double and string lists (including output and input file lists)
Definition: ListEditor.h:61
OpenMS::ListEditor::INT
Definition: ListEditor.h:70
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::Internal::ListEditorDelegate::typeName_
QString typeName_
type name. used to distinguish output/input from string lists
Definition: ListEditor.h:177
QDialog
QWidget
ListUtils.h
OpenMS::ListEditor::STRING
Definition: ListEditor.h:72
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::ListEditor::FLOAT
Definition: ListEditor.h:71
OpenMS::ListEditor::newRowButton_
QPushButton * newRowButton_
button for new Row
Definition: ListEditor.h:96
OpenMS::Internal::ListEditorDelegate::restrictions_
String restrictions_
restrictions for list elements
Definition: ListEditor.h:175
OpenMS::ListEditor::OUTPUT_FILE
Definition: ListEditor.h:73
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
OpenMS::Internal::ListEditorDelegate::file_name_
QString file_name_
used to set input and output values in setModelData
Definition: ListEditor.h:179
OpenMS::Internal::ListTable
Definition: ListEditor.h:111
OpenMS::Internal::ListTable::list_
StringList list_
Definition: ListEditor.h:135
OpenMS::ListEditor::Type
Type
Definition: ListEditor.h:68
OpenMS::ListEditor::listTable_
Internal::ListTable * listTable_
displays the list
Definition: ListEditor.h:92
QItemDelegate
OpenMS::Internal::ListEditorDelegate::type_
ListEditor::Type type_
List type.
Definition: ListEditor.h:173
OpenMS::ListEditor::listDelegate_
Internal::ListEditorDelegate * listDelegate_
Delegate between view and model.
Definition: ListEditor.h:94