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