OpenMS  2.8.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-2021.
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 = "");
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_
123 
124  //sets new list
125  void setList(const StringList & list, ListEditor::Type type);
126 
127 public slots:
128  void createNewRow();
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:
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
Internal delegate class.
Definition: ListEditor.h:145
void setTypeName(QString name)
set name of type
void setFileName(QString name)
sets the fileName
void setRestrictions(const String &restrictions)
ListEditorDelegate(QObject *parent)
Constructor.
void setType(const ListEditor::Type type)
ListEditor::Type type_
List type.
Definition: ListEditor.h:173
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Updates the editor for the item specified by index according to the style option given.
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Sets the data for the specified model and item index from that supplied by the editor....
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
not reimplemented
QString file_name_
used to set input and output values in setModelData
Definition: ListEditor.h:179
String restrictions_
restrictions for list elements
Definition: ListEditor.h:175
QString typeName_
type name. used to distinguish output/input from string lists
Definition: ListEditor.h:177
void setEditorData(QWidget *editor, const QModelIndex &index) const override
Sets the data to be displayed and edited by the editor for the item specified by index.
ListEditorDelegate()
Not implemented => private.
Definition: ListEditor.h:113
void setList(const StringList &list, ListEditor::Type type)
ListEditor::Type type_
List type.
Definition: ListEditor.h:133
ListTable(QWidget *parent=nullptr)
StringList list_
Definition: ListEditor.h:135
Editor for editing int, double and string lists (including output and input file lists)
Definition: ListEditor.h:63
void setTypeName(QString name)
set name of type
QPushButton * CancelButton_
button clicked if modifications are rejected
Definition: ListEditor.h:102
void setList(const StringList &list, ListEditor::Type type)
sets list (and its type)that will be modified by user
Type
Definition: ListEditor.h:69
@ OUTPUT_FILE
Definition: ListEditor.h:73
@ FLOAT
Definition: ListEditor.h:71
@ STRING
Definition: ListEditor.h:72
@ INT
Definition: ListEditor.h:70
ListEditor::Type type_
List type.
Definition: ListEditor.h:90
void setListRestrictions(const String &restrictions)
set restrictions for list elements
QPushButton * removeRowButton_
button for removing row
Definition: ListEditor.h:98
QPushButton * newRowButton_
button for new Row
Definition: ListEditor.h:96
ListEditor(QWidget *parent=nullptr, QString title="")
Constructor.
QPushButton * OkButton_
button clicked if modifications are accepted
Definition: ListEditor.h:100
StringList getList() const
returns modified list
Internal::ListTable * listTable_
displays the list
Definition: ListEditor.h:92
Internal::ListEditorDelegate * listDelegate_
Delegate between view and model.
Definition: ListEditor.h:94
A more convenient string class.
Definition: String.h:60
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47