itom  4.1.0
paramEditorWidget.h
1 /* ********************************************************************
2 itom measurement system
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5 Universitaet Stuttgart, Germany
6 
7 This file is part of itom.
8 
9 itom is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 itom is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 #ifndef PARAMEDITORWIDGET_H
24 #define PARAMEDITORWIDGET_H
25 
26 
27 #include "commonWidgets.h"
28 
29 #include "common/sharedStructuresQt.h"
30 #include "common/param.h"
31 
32 #include <qwidget.h>
33 #include <qscopedpointer.h>
34 #include <qpointer.h>
35 #include <qvector.h>
36 
37 class ParamEditorModel;
39 class QtProperty;
40 class QtBrowserItem;
41 class QTimerEvent;
42 
43 namespace ito {
44  class AddInBase; //forward declaration
45 };
46 
47 class ITOMWIDGETS_EXPORT ParamEditorWidget : public QWidget
48 {
49  Q_OBJECT
50 
51  Q_PROPERTY(QPointer<ito::AddInBase> plugin READ plugin WRITE setPlugin)
52  Q_PROPERTY(int indentation READ indentation WRITE setIndentation)
53  Q_PROPERTY(bool rootIsDecorated READ rootIsDecorated WRITE setRootIsDecorated)
54  Q_PROPERTY(bool alternatingRowColors READ alternatingRowColors WRITE setAlternatingRowColors)
55  Q_PROPERTY(bool headerVisible READ isHeaderVisible WRITE setHeaderVisible)
56  Q_PROPERTY(ResizeMode resizeMode READ resizeMode WRITE setResizeMode)
57  Q_PROPERTY(int splitterPosition READ splitterPosition WRITE setSplitterPosition)
58  Q_PROPERTY(bool propertiesWithoutValueMarked READ propertiesWithoutValueMarked WRITE setPropertiesWithoutValueMarked)
59  Q_PROPERTY(bool readonly READ readonly WRITE setReadonly)
60  Q_PROPERTY(bool showDescriptions READ showDescriptions WRITE setShowDescriptions)
61  Q_PROPERTY(QStringList filteredCategories READ filteredCategories WRITE setFilteredCategories)
62  Q_PROPERTY(bool immediatelyModifyPluginParamsAfterChange READ immediatelyModifyPluginParamsAfterChange WRITE setImmediatelyModifyPluginParamsAfterChange)
63  Q_PROPERTY(int numChangedParameters READ numberOfChangedParameters)
64  Q_PROPERTY(bool collapsed READ collapsed WRITE setCollapsed)
65  Q_PROPERTY(bool popupSlider READ popupSlider WRITE setPopupSlider);
66 
67  Q_CLASSINFO("prop://plugin", "Actuator or dataIO instance whose parameters are observed and set by this widget.")
68  Q_CLASSINFO("prop://indentation", "Indentation level of child items in the tree.")
69  Q_CLASSINFO("prop://rootIsDecorated", "Slightly changes the visualization of root and child elements.")
70  Q_CLASSINFO("prop://alternatingRowColors", "En- or disables alternating row colors.")
71  Q_CLASSINFO("prop://headerVisible", "Indicates if the header line (property, value) is visible.")
72  Q_CLASSINFO("prop://resizeMode", "Sets the mode how the columns can be resized.")
73  Q_CLASSINFO("prop://splitterPosition", "Width of the first column (not possible if resizeMode is set to Stretch).")
74  Q_CLASSINFO("prop://propertiesWithoutValueMarked", "If True, category values are marked with a dark gray background.")
75  Q_CLASSINFO("prop://readonly", "Indicates if widget is readonly or if values can be changed.")
76  Q_CLASSINFO("prop://showDescriptions", "If True, a text box is visible below the properties to show an information text about the currently set entry.")
77  Q_CLASSINFO("prop://filteredCategories", "If empty, all categories are shown. Else pass a list of category names to only show these categories.")
78  Q_CLASSINFO("prop://immediatelyModifyPluginParamsAfterChange", "If true (default), changed values in the widget will be immediately sent to the connected plugin, calling its 'setParam' method. Else, changed values will be stored in a temporary list and can be sent later (using applyChangedParameters).")
79  Q_CLASSINFO("prop://numChangedParameters", "Number of changed parameters, that have not been applied to the plugin yet.")
80  Q_CLASSINFO("prop://collapsed", "If true, collapse all items in the tree or load new items collapsed, else expand the full tree. (default: false)")
81  Q_CLASSINFO("prop://popupSlider", "If a slider widget (slider + spinbox) is used for corresponding floating point number parameters, the slider is displayed as popup window when hovering the spinbox. If false, the slider is always displayed left to the spinbox.")
82 
83 public:
84  enum ResizeMode
85  {
86  Interactive,
87  Stretch,
88  Fixed,
89  ResizeToContents
90  };
91 
92  //Q_ENUM exposes a meta object to the enumeration types, such that the key names for the enumeration
93  //values are always accessible.
94  Q_ENUM(ResizeMode)
95 
96 
102  ParamEditorWidget(QWidget* parent = 0);
103 
105  virtual ~ParamEditorWidget();
106 
107  QPointer<ito::AddInBase> plugin() const;
108  void setPlugin(QPointer<ito::AddInBase> plugin);
109 
110  void refresh();
111 
112  int indentation() const;
113  void setIndentation(int i);
114 
115  bool collapsed() const;
116  void setCollapsed(bool c);
117 
118  bool popupSlider() const;
119  void setPopupSlider(bool popup);
120 
121  bool rootIsDecorated() const;
122  void setRootIsDecorated(bool show);
123 
124  bool alternatingRowColors() const;
125  void setAlternatingRowColors(bool enable);
126 
127  bool readonly() const;
128  void setReadonly(bool enable);
129 
130  bool isHeaderVisible() const;
131  void setHeaderVisible(bool visible);
132 
133  ResizeMode resizeMode() const;
134  void setResizeMode(ResizeMode mode);
135 
136  int splitterPosition() const;
137  void setSplitterPosition(int position);
138 
139  void setPropertiesWithoutValueMarked(bool mark);
140  bool propertiesWithoutValueMarked() const;
141 
142  void setShowDescriptions(bool show);
143  bool showDescriptions() const;
144 
145  void setFilteredCategories(const QStringList &filteredCategories);
146  QStringList filteredCategories() const;
147 
148  void setImmediatelyModifyPluginParamsAfterChange(bool immediateChange);
149  bool immediatelyModifyPluginParamsAfterChange() const;
150 
151  int numberOfChangedParameters() const;
152 
153  QVector<QSharedPointer<ito::ParamBase> > getAndResetChangedParameters();
154 
155 protected:
161  {
162  msgLevelNo = 0,
163  msgLevelErrorOnly = 1,
164  msgLevelWarningOnly = 2,
165  msgLevelWarningAndError = msgLevelErrorOnly | msgLevelWarningOnly
166  };
167 
168  ito::RetVal setPluginParameter(QSharedPointer<ito::ParamBase> param, MessageLevel msgLevel = msgLevelWarningAndError) const;
169  ito::RetVal setPluginParameters(const QVector<QSharedPointer<ito::ParamBase> > params, MessageLevel msgLevel = msgLevelWarningAndError) const;
170  ito::RetVal observeInvocation(ItomSharedSemaphore *waitCond, MessageLevel msgLevel) const;
171 
172  ito::RetVal addParam(const ito::Param &param);
173  ito::RetVal addParamInt(const ito::Param &param, QtProperty *groupProperty);
174  ito::RetVal addParamChar(const ito::Param &param, QtProperty *groupProperty);
175  ito::RetVal addParamDouble(const ito::Param &param, QtProperty *groupProperty);
176  ito::RetVal addParamString(const ito::Param &param, QtProperty *groupProperty);
177  ito::RetVal addParamOthers(const ito::Param &param, QtProperty *groupProperty);
178  ito::RetVal addParamInterval(const ito::Param &param, QtProperty *groupProperty);
179  ito::RetVal addParamRect(const ito::Param &param, QtProperty *groupProperty);
180  ito::RetVal addParamIntArray(const ito::Param &param, QtProperty *groupProperty);
181  ito::RetVal addParamCharArray(const ito::Param &param, QtProperty *groupProperty);
182  ito::RetVal addParamDoubleArray(const ito::Param &param, QtProperty *groupProperty);
183 
184  ito::RetVal loadPlugin(QPointer<ito::AddInBase> plugin);
185 
186 protected:
187  void timerEvent(QTimerEvent *event);
188 
189 private:
190  QScopedPointer<ParamEditorWidgetPrivate> d_ptr;
191 
192  Q_DECLARE_PRIVATE(ParamEditorWidget);
193  Q_DISABLE_COPY(ParamEditorWidget);
194 
195 private slots:
196  void valueChanged(QtProperty* prop, int value);
197  void valueChanged(QtProperty* prop, char value);
198  void valueChanged(QtProperty* prop, double value);
199  void valueChanged(QtProperty* prop, int num, const char* values);
200  void valueChanged(QtProperty* prop, int num, const int* values);
201  void valueChanged(QtProperty* prop, int num, const double* values);
202  void valueChanged(QtProperty* prop, const QByteArray &value);
203  void valueChanged(QtProperty* prop, int min, int max);
204  void valueChanged(QtProperty* prop, int left, int top, int width, int height);
205 
206  void currentItemChanged(QtBrowserItem *);
207 
208  void parametersChanged(QMap<QString, ito::Param> parameters);
209 
210 public slots:
211  ito::RetVal applyChangedParameters();
212 
213 };
214 
215 #endif
Definition: paramEditorWidget.cpp:43
MessageLevel
Definition: paramEditorWidget.h:160
Class for managing status values (like errors or warning)
Definition: retVal.h:54
class for parameter handling e.g. to pass paramters to plugins
Definition: param.h:283
Definition: paramEditorWidget.h:47
Definition: apiFunctionsGraph.cpp:39
semaphore which can be used for asychronous thread communication. By using this class it is possible ...
Definition: sharedStructuresQt.h:57
The QtBrowserItem class represents a property in a property browser instance.
Definition: qtpropertybrowser.h:238
The QtProperty class encapsulates an instance of a property.
Definition: qtpropertybrowser.h:60