OpenMS
ParamEditor.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Timo Sachsenberg $
6 // $Authors: Marc Sturm, Chris Bielow $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 // OpenMS_GUI config
12 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
13 
14 #include <OpenMS/CONCEPT/Types.h>
15 
16 #include <QtWidgets/QLineEdit>
17 #include <QtWidgets/QItemDelegate>
18 #include <QtWidgets/QTreeWidget>
19 
20 class QModelIndex;
21 class QStyleOptionViewItem;
22 class QAbstractItemModel;
23 class QStringList;
24 class QString;
25 
26 namespace Ui
27 {
28  class ParamEditorTemplate;
29 }
30 
31 namespace OpenMS
32 {
33  class String;
34  class Param;
35  class ParamEditor;
40  namespace Internal
41  {
42 
47  class OPENMS_GUI_DLLAPI OpenMSLineEdit
48  : public QLineEdit
49  {
50  Q_OBJECT
51  public:
53  :QLineEdit(w)
54  {}
55 
56 signals:
58  void lostFocus();
59 
60 
61  protected:
62  void focusOutEvent ( QFocusEvent * e ) override;
63  void focusInEvent ( QFocusEvent * e ) override;
64  };
70  class OPENMS_GUI_DLLAPI ParamEditorDelegate :
71  public QItemDelegate
72  {
73  Q_OBJECT
74 
75 public:
79  QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
81  void setEditorData(QWidget * editor, const QModelIndex & index) const override;
83  void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override;
85  void updateEditorGeometry(QWidget * editor, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
86 
88  bool hasUncommittedData() const;
89 signals:
91  void modified(bool) const;
92 
93 protected:
95  bool eventFilter(QObject* editor, QEvent* event) override;
96 
98  bool exists_(const QString& name, QModelIndex index) const;
99 
100 private slots:
104  void closeEditor_();
107 
108 private:
112  mutable QString fileName_;
114  mutable QString dirName_;
116  mutable bool has_uncommited_data_;
117  };
118 
120  class OPENMS_GUI_DLLAPI ParamTree :
121  public QTreeWidget
122  {
123  Q_OBJECT
124 
125 public:
127  ParamTree(QWidget * parent);
129  bool edit(const QModelIndex & index, EditTrigger trigger, QEvent * event) override;
130 
131 signals:
133  void selected(const QModelIndex & index);
134 
135 protected slots:
137  void selectionChanged(const QItemSelection & selected, const QItemSelection &) override;
138  };
139 
140  }
141 
142 
154  class OPENMS_GUI_DLLAPI ParamEditor :
155  public QWidget
156  {
157  Q_OBJECT
158 
159 public:
161  enum
162  {
165  ADVANCED_ITEM
166  };
167 
169  ParamEditor(QWidget* parent = nullptr);
171  ~ParamEditor() override;
172 
174  void load(Param& param);
176  void store();
178  bool isModified() const;
180  void clear();
181 
182 public slots:
185  void setModified(bool is_modified);
186 
187 signals:
189  void modified(bool);
190 
191 protected slots:
193  void toggleAdvancedMode(bool advanced);
195  void showDocumentation(const QModelIndex & index);
196 
197 protected:
199  void storeRecursive_(QTreeWidgetItem * child, String path, std::map<String, String> & section_descriptions);
200 
206  bool modified_;
209 
210 private:
211  Ui::ParamEditorTemplate* ui_;
212  };
213 
214 
215 } // namespace OpenMS
216 
Custom QLineEdit which emits a signal when losing focus (such that we can commit its data)
Definition: ParamEditor.h:49
void focusInEvent(QFocusEvent *e) override
void lostFocus()
emitted on focusOutEvent
void focusOutEvent(QFocusEvent *e) override
OpenMSLineEdit(QWidget *w)
Definition: ParamEditor.h:52
Internal delegate class for QTreeWidget.
Definition: ParamEditor.h:72
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:116
bool exists_(const QString &name, QModelIndex index) const
Checks if a name is valid for the entry corresponding to index (checks if it would be duplicate)
void commitAndCloseEditor_()
For closing any editor and updating ParamEditor.
QString dirName_
holds a directory name (for output directories)
Definition: ParamEditor.h:114
QString fileName_
used to modify value of output and input files( not for output and input lists)
Definition: ParamEditor.h:112
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:122
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:156
Internal::ParamTree * tree_
Pointer to the tree widget.
Definition: ParamEditor.h:202
bool advanced_mode_
Indicates if normal mode or advanced mode is activated.
Definition: ParamEditor.h:208
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:206
Ui::ParamEditorTemplate * ui_
Definition: ParamEditor.h:211
@ NODE
Section.
Definition: ParamEditor.h:163
@ NORMAL_ITEM
Item that is always shown.
Definition: ParamEditor.h:164
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:204
ParamEditor(QWidget *parent=nullptr)
constructor
void clear()
Clears all parameters.
~ParamEditor() override
destructor
void store()
store edited data in Param object
Management and storage of parameters / INI files.
Definition: Param.h:44
A more convenient string class.
Definition: String.h:34
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Definition: FLASHDeconvWizardBase.h:37