Computer Assisted Medical Intervention Tool Kit  version 5.2
ObjectController.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * $CAMITK_LICENCE_BEGIN$
3  *
4  * CamiTK - Computer Assisted Medical Intervention ToolKit
5  * (c) 2001-2024 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, TIMC, 38000 Grenoble, France
6  *
7  * Visit http://camitk.imag.fr for more information
8  *
9  * This file is part of CamiTK.
10  *
11  * CamiTK is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * CamiTK is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Lesser General Public License version 3 for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public License
21  * version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
22  *
23  * $CAMITK_LICENCE_END$
24  ****************************************************************************/
25 
26 #ifndef OBJECTCONTROLLER_H
27 #define OBJECTCONTROLLER_H
28 
29 // -- CamiTK includes
30 #include "CamiTKAPI.h"
31 #include <QtVariantProperty>
32 
33 // -- QT stuff
34 #include <QMetaEnum>
35 #include <QPushButton>
36 #include <QScrollArea>
37 #include <QVBoxLayout>
38 #include <QWidget>
39 #include <csignal>
40 
41 
42 namespace camitk {
44 
45 
162 class CAMITK_API ObjectController : public QWidget {
163  Q_OBJECT
164 
165 public:
166  // [CAMITK ADDED]
171  enum ViewMode {
174  BUTTON
175  };
176  Q_ENUM(ViewMode); // so that it can be used in property editor
177 
179  ObjectController(QWidget* parent = nullptr, ViewMode viewMode = TREE);
180 
182  ~ObjectController() override;
183 
185  void setObject(QObject* object);
186 
188  QObject* object() const;
189 
191  void setAutoUpdateProperty(bool);
192 
193  // [CAMITK ADDED]
195  void setViewMode(ViewMode viewMode);
196 
197  // [CAMITK ADDED]
199  ViewMode getViewMode() const;
200 
201  // [CAMITK ADDED]
203  bool isModified();
204 
205 public slots:
206  // [CAMITK ADDED]
208  void apply();
209 
210  // [CAMITK ADDED]
212  void revert();
213 
214 private:
217  Q_DECLARE_PRIVATE(ObjectController)
218  Q_DISABLE_COPY(ObjectController)
219 
220  // [CAMITK CHANGED]
221  Q_PRIVATE_SLOT(d_func(), void saveChange(QtProperty*, const QVariant&))
222  Q_PRIVATE_SLOT(d_func(), void valueChanged(QtProperty*, const QVariant&))
223 
224  // [CAMITK ADDED]
226  ViewMode currentViewMode;
227 
228  // [CAMITK ADDED]
230  void initViewMode();
231 
233  QVBoxLayout* layout;
234 
236  QScrollArea* scroll;
237 
238 };
239 
241  ObjectController* q_ptr;
242  Q_DECLARE_PUBLIC(ObjectController)
243 public:
244 
245  void addClassProperties(const QMetaObject* metaObject);
246  void addDynamicProperties(QObject* edited);
247  void updateClassProperties(const QMetaObject* metaObject, bool recursive);
248  void updateDynamicProperties(const QObject* edited);
249  void saveExpandedState();
250  void restoreExpandedState();
251  void valueChanged(QtProperty* property, const QVariant value);
252  //CAMITK ADDED
253  void saveChange(QtProperty* property, const QVariant& value);
254  void applyChange();
255  //
256  int enumToInt(const QMetaEnum& metaEnum, int enumValue) const;
257  int intToEnum(const QMetaEnum& metaEnum, int intValue) const;
258  int flagToInt(const QMetaEnum& metaEnum, int flagValue) const;
259  int intToFlag(const QMetaEnum& metaEnum, int intValue) const;
260  bool isSubValue(int value, int subValue) const;
261  bool isPowerOf2(int value) const;
262 
264  QObject* m_object;
265 
266  /* [CAMITK REMOVED]
267  QMap<const QMetaObject *, QtProperty *> m_classToProperty;
268  QMap<QtProperty *, const QMetaObject *> m_propertyToClass;
269  */
271  QMap<QtProperty*, int> m_classPropertyToIndex;
273  QMap<const QMetaObject*, QMap<int, QtVariantProperty*> > m_classToIndexToProperty;
274 
276  QMap<int, QtVariantProperty*> m_indexToDynamicProperty;
278  QMap<QtProperty*, int> m_dynamicPropertyToIndex;
279 
281  QMap<QtProperty*, bool> m_propertyToExpanded;
282 
285 
287  QMap<QtProperty*, QVariant> saveChangeValue;
288 
291 
294 
297 
298  // [CAMITK ADDED]
300  QtVariantProperty* buildQtVariantProperty(QString name, QMetaType::Type type, QVariant value, bool isReadable, bool isWritable, bool isEnumType, bool isFlagType, bool isDesignable, QMetaEnum* metaEnum = NULL);
301 
303  QMap<QString, QtProperty*> groupProperties;
304 };
305 
306 }
307 
308 #endif
#define CAMITK_API
Definition: CamiTKAPI.h:49
Definition: objectcontroller.cpp:50
QtAbstractPropertyBrowser provides a base class for implementing property browsers.
Definition: qtpropertybrowser.h:301
The QtProperty class encapsulates an instance of a property.
Definition: qtpropertybrowser.h:113
The QtVariantPropertyManager class provides and manages QVariant based properties.
Definition: qtvariantproperty.h:119
The QtVariantProperty class is a convenience class handling QVariant based properties.
Definition: qtvariantproperty.h:97
Definition: ObjectController.h:240
QMap< const QMetaObject *, QMap< int, QtVariantProperty * > > m_classToIndexToProperty
Each meta object have a map to get the property by its index.
Definition: ObjectController.h:273
int flagToInt(const QMetaEnum &metaEnum, int flagValue) const
Definition: ObjectController.cpp:118
void addDynamicProperties(QObject *edited)
Definition: ObjectController.cpp:361
QMap< QtProperty *, QVariant > saveChangeValue
when a property is modified by the user, the change is stored here (until applyChange is called)
Definition: ObjectController.h:287
void updateClassProperties(const QMetaObject *metaObject, bool recursive)
Definition: ObjectController.cpp:175
int intToEnum(const QMetaEnum &metaEnum, int intValue) const
Definition: ObjectController.cpp:65
QMap< QtProperty *, int > m_dynamicPropertyToIndex
map from the dynamic property to the idx in the dynamic property
Definition: ObjectController.h:278
QMap< QtProperty *, bool > m_propertyToExpanded
TODO doc.
Definition: ObjectController.h:281
QMap< QString, QtProperty * > groupProperties
map of all the QtProperty that are top-level groups
Definition: ObjectController.h:303
QMap< QtProperty *, int > m_classPropertyToIndex
map from the class property to the index in the meta object
Definition: ObjectController.h:271
int enumToInt(const QMetaEnum &metaEnum, int enumValue) const
Definition: ObjectController.cpp:46
void valueChanged(QtProperty *property, const QVariant value)
Definition: ObjectController.cpp:459
QtVariantProperty * buildQtVariantProperty(QString name, QMetaType::Type type, QVariant value, bool isReadable, bool isWritable, bool isEnumType, bool isFlagType, bool isDesignable, QMetaEnum *metaEnum=NULL)
build a QtVariantProperty from name, type, property...etc...
Definition: ObjectController.cpp:207
void restoreExpandedState()
Definition: ObjectController.cpp:455
QMap< int, QtVariantProperty * > m_indexToDynamicProperty
map from idx of the dynamic property to the property
Definition: ObjectController.h:276
QtAbstractPropertyBrowser * m_browser
the browser where all properties are shown to the user
Definition: ObjectController.h:290
void updateDynamicProperties(const QObject *edited)
Definition: ObjectController.cpp:339
void saveExpandedState()
Definition: ObjectController.cpp:451
bool isSubValue(int value, int subValue) const
Definition: ObjectController.cpp:85
QList< QtProperty * > m_topLevelProperties
TODO doc.
Definition: ObjectController.h:284
QObject * m_object
the currently edited object
Definition: ObjectController.h:264
void addClassProperties(const QMetaObject *metaObject)
Definition: ObjectController.cpp:291
QtVariantPropertyManager * m_readOnlyManager
the property manager for the read only property
Definition: ObjectController.h:296
void saveChange(QtProperty *property, const QVariant &value)
Definition: ObjectController.cpp:494
QtVariantPropertyManager * m_manager
the main property manager (does not include the read only property)
Definition: ObjectController.h:293
int intToFlag(const QMetaEnum &metaEnum, int intValue) const
Definition: ObjectController.cpp:142
void applyChange()
Definition: ObjectController.cpp:498
bool isPowerOf2(int value) const
Definition: ObjectController.cpp:106
The object controller class.
Definition: ObjectController.h:162
ViewMode
The property browser can be shown in different view mode.
Definition: ObjectController.h:171
@ GROUPBOX
It is like the TREE but with a delimitation to indicate the arborescence of the property type.
Definition: ObjectController.h:173
@ TREE
The property browser can be shown like a QListView.
Definition: ObjectController.h:172
Definition: Action.cpp:36