OpenMS  3.0.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-2022.
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:
103  ParamEditorDelegate(QObject * parent);
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:
128  void commitAndCloseEditor_();
130  void closeEditor_();
132  void commitAndCloseLineEdit_();
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 
QObject
OpenMS::Internal::OpenMSLineEdit::OpenMSLineEdit
OpenMSLineEdit(QWidget *w)
Definition: ParamEditor.h:78
Param
@TODO loop over all runs
Definition: BayesianProteinInferenceAlgorithm.h:98
Types.h
OpenMS::ParamEditor::modified_
bool modified_
Indicates that the data was modified since last store/load operation.
Definition: ParamEditor.h:230
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::ParamEditor::NODE
Section.
Definition: ParamEditor.h:187
OpenMS::Internal::ParamTree
QTreeWidget that emits a signal whenever a new row is selected.
Definition: ParamEditor.h:144
OpenMS::Internal::ParamEditorDelegate::has_uncommited_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
OpenMS::ParamEditor::tree_
Internal::ParamTree * tree_
Pointer to the tree widget.
Definition: ParamEditor.h:226
OpenMS::ParamEditor::ui_
Ui::ParamEditorTemplate * ui_
Definition: ParamEditor.h:235
QWidget
OpenMS::ParamEditor::param_
Param * param_
The data to edit.
Definition: ParamEditor.h:228
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Ui
Definition: SwathWizardBase.h:62
OpenMS::Internal::ParamEditorDelegate::fileName_
QString fileName_
used to modify value of output and input files( not for output and input lists)
Definition: ParamEditor.h:138
OpenMS::Internal::ParamEditorDelegate
Internal delegate class for QTreeWidget.
Definition: ParamEditor.h:96
ParamEditor
OpenMS::ParamEditor ParamEditor
Definition: SwathTabWidget.h:145
OpenMS::Internal::OpenMSLineEdit
Custom QLineEdit which emits a signal when losing focus (such that we can commit its data)
Definition: ParamEditor.h:73
OpenMS::ParamEditor
A GUI for editing or viewing a Param object.
Definition: ParamEditor.h:178
OpenMS::Param
Management and storage of parameters / INI files.
Definition: Param.h:69
OpenMS::ParamEditor::NORMAL_ITEM
Item that is always shown.
Definition: ParamEditor.h:188
QTreeWidget
OpenMS::ParamEditor::advanced_mode_
bool advanced_mode_
Indicates if normal mode or advanced mode is activated.
Definition: ParamEditor.h:232
QLineEdit
QItemDelegate