OpenMS  2.8.0
ParamEditor.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: Marc Sturm, Chris Bielow $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 // OpenMS_GUI config
38 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
39 
40 #include <OpenMS/CONCEPT/Types.h>
41 
42 #include <QtWidgets/QLineEdit>
43 #include <QtWidgets/QItemDelegate>
44 #include <QtWidgets/QTreeWidget>
45 
46 class QModelIndex;
47 class QStyleOptionViewItem;
48 class QAbstractItemModel;
49 class QStringList;
50 class QString;
51 
52 namespace Ui
53 {
54  class ParamEditorTemplate;
55 }
56 
57 namespace OpenMS
58 {
59  class String;
60  class Param;
61  class ParamEditor;
66  namespace Internal
67  {
68 
73  class OPENMS_GUI_DLLAPI OpenMSLineEdit
74  : public QLineEdit
75  {
76  Q_OBJECT
77  public:
79  :QLineEdit(w)
80  {}
81 
82 signals:
84  void lostFocus();
85 
86 
87  protected:
88  void focusOutEvent ( QFocusEvent * e ) override;
89  void focusInEvent ( QFocusEvent * e ) override;
90  };
96  class OPENMS_GUI_DLLAPI ParamEditorDelegate :
97  public QItemDelegate
98  {
99  Q_OBJECT
100 
101 public:
105  QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
107  void setEditorData(QWidget * editor, const QModelIndex & index) const override;
109  void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override;
111  void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
112 
114  bool hasUncommittedData() const;
115 signals:
117  void modified(bool) const;
118 
119 protected:
121  bool eventFilter(QObject* editor, QEvent* event) override;
122 
124  bool exists_(QString name, QModelIndex index) const;
125 
126 private slots:
130  void closeEditor_();
133 
134 private:
138  mutable QString fileName_;
140  mutable bool has_uncommited_data_;
141  };
142 
144  class OPENMS_GUI_DLLAPI ParamTree :
145  public QTreeWidget
146  {
147  Q_OBJECT
148 
149 public:
151  ParamTree(QWidget * parent);
153  bool edit(const QModelIndex & index, EditTrigger trigger, QEvent * event) override;
154 
155 signals:
157  void selected(const QModelIndex & index);
158 
159 protected slots:
161  void selectionChanged(const QItemSelection & selected, const QItemSelection &) override;
162  };
163 
164  }
165 
166 
178  class OPENMS_GUI_DLLAPI ParamEditor :
179  public QWidget
180  {
181  Q_OBJECT
182 
183 public:
185  enum
186  {
189  ADVANCED_ITEM
190  };
191 
193  ParamEditor(QWidget* parent = nullptr);
195  ~ParamEditor() override;
196 
198  void load(Param& param);
200  void store();
202  bool isModified() const;
204  void clear();
205 
206 public slots:
209  void setModified(bool is_modified);
210 
211 signals:
213  void modified(bool);
214 
215 protected slots:
217  void toggleAdvancedMode(bool advanced);
219  void showDocumentation(const QModelIndex & index);
220 
221 protected:
223  void storeRecursive_(QTreeWidgetItem * child, String path, std::map<String, String> & section_descriptions);
224 
230  bool modified_;
233 
234 private:
235  Ui::ParamEditorTemplate* ui_;
236  };
237 
238 
239 } // namespace OpenMS
240 
Custom QLineEdit which emits a signal when losing focus (such that we can commit its data)
Definition: ParamEditor.h:75
void focusInEvent(QFocusEvent *e) override
void lostFocus()
emitted on focusOutEvent
void focusOutEvent(QFocusEvent *e) override
OpenMSLineEdit(QWidget *w)
Definition: ParamEditor.h:78
Internal delegate class for QTreeWidget.
Definition: ParamEditor.h:98
bool exists_(QString name, QModelIndex index) const
Checks if a name is valid for the entry corresponding to index (checks if it would be duplicate)
ParamEditorDelegate(QObject *parent)
Constructor.
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 closeEditor_()
if cancel in any editor is clicked, the Dialog is closed and changes are rejected
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
Returns the widget(combobox or QLineEdit) used to edit the item specified by index for editing....
bool hasUncommittedData() const
true if the underlying tree has an open QLineEdit which has uncommitted data
bool has_uncommited_data_
true if a QLineEdit is still open and has not committed its data yet (so storing the current param is...
Definition: ParamEditor.h:140
void commitAndCloseEditor_()
For closing any editor and updating ParamEditor.
QString fileName_
used to modify value of output and input files( not for output and input lists)
Definition: ParamEditor.h:138
void commitAndCloseLineEdit_()
... a bit special, because reset uncommited data
void modified(bool) const
signal for showing ParamEditor if the Model data changed
bool eventFilter(QObject *editor, QEvent *event) override
a shortcut to calling commit(), which calls setModelData(); useful for embedded editors,...
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.
QTreeWidget that emits a signal whenever a new row is selected.
Definition: ParamEditor.h:146
void selected(const QModelIndex &index)
Signal that is emitted when a new item is selected.
ParamTree(QWidget *parent)
Constructor.
bool edit(const QModelIndex &index, EditTrigger trigger, QEvent *event) override
Overloaded edit method to activate F2 use.
void selectionChanged(const QItemSelection &selected, const QItemSelection &) override
Reimplemented virtual slot.
A GUI for editing or viewing a Param object.
Definition: ParamEditor.h:180
Internal::ParamTree * tree_
Pointer to the tree widget.
Definition: ParamEditor.h:226
bool advanced_mode_
Indicates if normal mode or advanced mode is activated.
Definition: ParamEditor.h:232
void storeRecursive_(QTreeWidgetItem *child, String path, std::map< String, String > &section_descriptions)
recursive helper method for method storeRecursive()
void showDocumentation(const QModelIndex &index)
Shows the documentation of an item in doc_.
void load(Param &param)
load method for Param object
bool isModified() const
Indicates if the data changed since last save.
bool modified_
Indicates that the data was modified since last store/load operation.
Definition: ParamEditor.h:230
Ui::ParamEditorTemplate * ui_
Definition: ParamEditor.h:235
void setModified(bool is_modified)
void toggleAdvancedMode(bool advanced)
Switches between normal and advanced mode.
void modified(bool)
item was edited
Param * param_
The data to edit.
Definition: ParamEditor.h:228
ParamEditor(QWidget *parent=nullptr)
constructor
void clear()
Clears all parameters.
~ParamEditor() override
destructor
void store()
store edited data in Param object
@ NODE
Section.
Definition: ParamEditor.h:187
@ NORMAL_ITEM
Item that is always shown.
Definition: ParamEditor.h:188
Management and storage of parameters / INI files.
Definition: Param.h:70
A more convenient string class.
Definition: String.h:60
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Definition: SwathWizardBase.h:63
@TODO loop over all runs