Computer Assited Medical Intervention Tool Kit  version 4.1
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-2018 Univ. Grenoble Alpes, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
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  Q_ENUMS(ViewMode); // so that it can be used in property editor
165 
166 public:
167  // [CAMITK ADDED]
172  enum ViewMode {
173  TREE,
174  GROUPBOX,
175  BUTTON
176  };
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 
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 
284  QList<QtProperty*> m_topLevelProperties;
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 // to use this enum as a CamiTK property
309 Q_DECLARE_METATYPE(camitk::ObjectController::ViewMode)
310 
311 #endif
camitk::ObjectControllerPrivate::q_ptr
ObjectController * q_ptr
Definition: ObjectController.h:262
ObjectControllerPrivate::m_object
QObject * m_object
Definition: objectcontroller.cpp:102
camitk::ObjectControllerPrivate::enumToInt
int enumToInt(const QMetaEnum &metaEnum, int enumValue) const
Definition: ObjectController.cpp:68
camitk::ObjectControllerPrivate::m_indexToDynamicProperty
QMap< int, QtVariantProperty * > m_indexToDynamicProperty
map from idx of the dynamic property to the property
Definition: ObjectController.h:297
camitk::ObjectControllerPrivate::groupProperties
QMap< QString, QtProperty * > groupProperties
map of all the QtProperty that are top-level groups
Definition: ObjectController.h:324
QtProperty::setStatusTip
void setStatusTip(const QString &text)
Definition: qtpropertybrowser.cpp:317
camitk::ObjectControllerPrivate
Definition: ObjectController.h:261
camitk::ObjectControllerPrivate::valueChanged
void valueChanged(QtProperty *property, const QVariant value)
Definition: ObjectController.cpp:493
camitk::ObjectControllerPrivate::addClassProperties
void addClassProperties(const QMetaObject *metaObject)
Definition: ObjectController.cpp:313
camitk::Property::getEnumIcons
QMap< int, QIcon > getEnumIcons() const
get the enum icons
Definition: Property.cpp:147
camitk::ObjectController::initViewMode
void initViewMode()
initialize the view mode depending on currentViewMode
Definition: ObjectController.cpp:651
camitk::ObjectControllerPrivate::m_dynamicPropertyToIndex
QMap< QtProperty *, int > m_dynamicPropertyToIndex
map from the dynamic property to the idx in the dynamic property
Definition: ObjectController.h:299
camitk::ObjectControllerPrivate::saveChangeValue
QMap< QtProperty *, QVariant > saveChangeValue
when a property is modified by the user, the change is stored here (until applyChange is called)
Definition: ObjectController.h:308
QtTreePropertyBrowser
The description of this class will come soon !
Definition: qttreepropertybrowser.h:59
ObjectControllerPrivate::m_propertyToExpanded
QMap< QtProperty *, bool > m_propertyToExpanded
Definition: objectcontroller.cpp:109
ObjectController
Definition: objectcontroller.h:46
ObjectControllerPrivate::slotValueChanged
void slotValueChanged(QtProperty *property, const QVariant &value)
Definition: objectcontroller.cpp:312
ObjectControllerPrivate::m_manager
QtVariantPropertyManager * m_manager
Definition: objectcontroller.cpp:114
camitk::Property::getGroupName
QString getGroupName() const
get this property subgroup's name
Definition: Property.cpp:157
camitk::ObjectControllerPrivate::saveExpandedState
void saveExpandedState()
Definition: ObjectController.cpp:485
camitk::ObjectController::~ObjectController
~ObjectController() override
destructor of object controller
Definition: ObjectController.cpp:572
CamiTKAPI.h
camitk::ObjectControllerPrivate::m_manager
QtVariantPropertyManager * m_manager
the main property manager (does not include the read only property)
Definition: ObjectController.h:314
qtbuttonpropertybrowser.h
QtTreePropertyBrowser::setRootIsDecorated
void setRootIsDecorated(bool show)
Definition: qttreepropertybrowser.cpp:792
QtAbstractPropertyBrowser
QtAbstractPropertyBrowser provides a base class for implementing property browsers.
Definition: qtpropertybrowser.h:296
camitk::ObjectControllerPrivate::m_classToIndexToProperty
QMap< const QMetaObject *, QMap< int, QtVariantProperty * > > m_classToIndexToProperty
Each meta object have a map to get the property by its index.
Definition: ObjectController.h:294
QtProperty::setEnabled
void setEnabled(bool enable)
Definition: qtpropertybrowser.cpp:361
ObjectControllerPrivate::updateClassProperties
void updateClassProperties(const QMetaObject *metaObject, bool recursive)
Definition: objectcontroller.cpp:185
ObjectControllerPrivate::m_classToIndexToProperty
QMap< const QMetaObject *, QMap< int, QtVariantProperty * > > m_classToIndexToProperty
Definition: objectcontroller.cpp:107
ObjectController::d_ptr
ObjectControllerPrivate * d_ptr
Definition: objectcontroller.h:56
ObjectControllerPrivate::m_classToProperty
QMap< const QMetaObject *, QtProperty * > m_classToProperty
Definition: objectcontroller.cpp:104
camitk::ObjectControllerPrivate::isSubValue
bool isSubValue(int value, int subValue) const
Definition: ObjectController.cpp:107
QtVariantPropertyManager::enumTypeId
static int enumTypeId()
Definition: qtvariantproperty.cpp:90
camitk::ObjectController::TREE
The property browser can be shown like a QListView.
Definition: ObjectController.h:194
QtAbstractPropertyBrowser::addProperty
QtBrowserItem * addProperty(QtProperty *property)
Definition: qtpropertybrowser.cpp:1782
camitk::ObjectController::ViewMode
ViewMode
Definition: ObjectController.h:193
camitk::ObjectController::apply
void apply()
slot to apply change made by the user in the property editor
Definition: ObjectController.cpp:681
camitk::ObjectControllerPrivate::saveChange
void saveChange(QtProperty *property, const QVariant &value)
Definition: ObjectController.cpp:528
QtVariantPropertyManager
The QtVariantPropertyManager class provides and manages QVariant based properties.
Definition: qtvariantproperty.h:116
camitk::ObjectControllerPrivate::intToFlag
int intToFlag(const QMetaEnum &metaEnum, int intValue) const
Definition: ObjectController.cpp:164
QtProperty
The QtProperty class encapsulates an instance of a property.
Definition: qtpropertybrowser.h:112
camitk::ObjectControllerPrivate::m_readOnlyManager
QtVariantPropertyManager * m_readOnlyManager
the property manager for the read only property
Definition: ObjectController.h:317
camitk::ObjectController::layout
QVBoxLayout * layout
layout which will contains the propertybrowser and, in view mode GROUPBOX and BUTTON,...
Definition: ObjectController.h:254
QtVariantPropertyManager::flagTypeId
static int flagTypeId()
Definition: qtvariantproperty.cpp:103
ObjectControllerPrivate::addClassProperties
void addClassProperties(const QMetaObject *metaObject)
Definition: objectcontroller.cpp:220
ObjectControllerPrivate::m_propertyToIndex
QMap< QtProperty *, int > m_propertyToIndex
Definition: objectcontroller.cpp:106
qtpropertybrowser.h
ObjectController::setObject
void setObject(QObject *object)
Definition: objectcontroller.cpp:374
camitk::Property
This class describes a property that can be used in components and actions or any class that needs to...
Definition: Property.h:312
QtVariantPropertyManager::addProperty
virtual QtVariantProperty * addProperty(int propertyType, const QString &name=QString())
Definition: qtvariantproperty.cpp:1321
camitk::ObjectControllerPrivate::m_browser
QtAbstractPropertyBrowser * m_browser
the browser where all properties are shown to the user
Definition: ObjectController.h:311
QtAbstractPropertyBrowser::setFactoryForManager
void setFactoryForManager(PropertyManager *manager, QtAbstractEditorFactory< PropertyManager > *factory)
Definition: qtpropertybrowser.h:310
camitk::ObjectControllerPrivate::isPowerOf2
bool isPowerOf2(int value) const
Definition: ObjectController.cpp:128
QtProperty::setWhatsThis
void setWhatsThis(const QString &text)
Definition: qtpropertybrowser.cpp:331
ObjectControllerPrivate::saveExpandedState
void saveExpandedState()
Definition: objectcontroller.cpp:304
camitk::ObjectControllerPrivate::applyChange
void applyChange()
Definition: ObjectController.cpp:532
camitk::ObjectControllerPrivate::m_object
QObject * m_object
the currently edited object
Definition: ObjectController.h:285
ObjectControllerPrivate::q_ptr
ObjectController * q_ptr
Definition: objectcontroller.cpp:86
QtVariantProperty
The QtVariantProperty class is a convenience class handling QVariant based properties.
Definition: qtvariantproperty.h:94
ObjectControllerPrivate::restoreExpandedState
void restoreExpandedState()
Definition: objectcontroller.cpp:308
camitk::ObjectControllerPrivate::flagToInt
int flagToInt(const QMetaEnum &metaEnum, int flagValue) const
Definition: ObjectController.cpp:140
camitk::ObjectController::setObject
void setObject(QObject *object)
mutatorMethod of the object at unroll in the property browser
Definition: ObjectController.cpp:576
QtButtonPropertyBrowser
The description of this class will come soon !
Definition: qtbuttonpropertybrowser.h:58
camitk::ObjectController
The object controller class.
Definition: ObjectController.h:183
Property.h
camitk::ObjectController::valueChanged
void valueChanged(QtProperty *, const QVariant &)) ViewMode currentViewMode
variable to choose the type of property browser
QtGroupBoxPropertyBrowser
The description of this class will come soon !
Definition: qtgroupboxpropertybrowser.h:58
camitk::ObjectController::object
QObject * object() const
accessorMethod of the object contains in the property browser
Definition: ObjectController.cpp:610
camitk::Property::getReadOnly
bool getReadOnly() const
Definition: Property.cpp:86
QtProperty::setToolTip
void setToolTip(const QString &text)
Definition: qtpropertybrowser.cpp:303
ObjectControllerPrivate::m_readOnlyManager
QtVariantPropertyManager * m_readOnlyManager
Definition: objectcontroller.cpp:115
camitk::ObjectController::scroll
QScrollArea * scroll
scroll add to navigate in the property browser
Definition: ObjectController.h:257
qtvariantproperty.h
camitk::ObjectController::isModified
bool isModified()
call this to check if a modification was done
Definition: ObjectController.cpp:677
description
const char * description
Definition: applications/cepgenerator/main.cpp:37
ObjectControllerPrivate::intToFlag
int intToFlag(const QMetaEnum &metaEnum, int intValue) const
Definition: objectcontroller.cpp:159
camitk::ObjectControllerPrivate::updateDynamicProperties
void updateDynamicProperties(const QObject *edited)
Definition: ObjectController.cpp:361
qtgroupboxpropertybrowser.h
ObjectController::ObjectController
ObjectController(QWidget *parent=0)
Definition: objectcontroller.cpp:338
camitk::Property::getAttributeList
QStringList getAttributeList()
returns the list of attribute names that are specific to this property
Definition: Property.cpp:177
camitk::ObjectControllerPrivate::m_propertyToExpanded
QMap< QtProperty *, bool > m_propertyToExpanded
TODO doc.
Definition: ObjectController.h:302
QtVariantEditorFactory
The QtVariantEditorFactory class provides widgets for properties created by QtVariantPropertyManager ...
Definition: qtvariantproperty.h:205
QtAbstractPropertyBrowser::removeProperty
void removeProperty(QtProperty *property)
Definition: qtpropertybrowser.cpp:1849
camitk::ObjectController::setAutoUpdateProperty
void setAutoUpdateProperty(bool)
if set, the properties are immediatly updated in the managed object (default false)
Definition: ObjectController.cpp:615
camitk::Property::getEnumTypeName
QString getEnumTypeName() const
Definition: Property.cpp:102
ObjectControllerPrivate::m_browser
QtAbstractPropertyBrowser * m_browser
Definition: objectcontroller.cpp:113
ObjectController.h
camitk::ObjectControllerPrivate::addDynamicProperties
void addDynamicProperties(QObject *edited)
Definition: ObjectController.cpp:384
QtTreePropertyBrowser::Interactive
Definition: qttreepropertybrowser.h:72
camitk::ObjectController::getViewMode
ViewMode getViewMode() const
accessorMethod of the view mode
Definition: ObjectController.cpp:673
camitk::ObjectControllerPrivate::m_topLevelProperties
QList< QtProperty * > m_topLevelProperties
TODO doc.
Definition: ObjectController.h:305
camitk::Q_ENUMS
Q_ENUMS(ControlMode CameraOrientation)
RendererWidget implements all support methods to use camiTK with Qt interface.
ObjectControllerPrivate::enumToInt
int enumToInt(const QMetaEnum &metaEnum, int enumValue) const
Definition: objectcontroller.cpp:82
ObjectControllerPrivate
Definition: objectcontroller.cpp:49
camitk::ObjectControllerPrivate::m_classPropertyToIndex
QMap< QtProperty *, int > m_classPropertyToIndex
map from the class property to the index in the meta object
Definition: ObjectController.h:292
camitk::ObjectController::BUTTON
It is like the GROUPBOX but the buttons allow the user to control the comput display of arborescence.
Definition: ObjectController.h:196
QtVariantProperty::setValue
void setValue(const QVariant &value)
Definition: qtvariantproperty.cpp:263
ObjectController::object
QObject * object() const
Definition: objectcontroller.cpp:399
camitk::Property::getAttribute
QVariant getAttribute(QString attName)
get the current value of a given attribute, see setAttribute() if the attribute attName was never set...
Definition: Property.cpp:167
qttreepropertybrowser.h
camitk::ObjectController::setViewMode
void setViewMode(ViewMode viewMode)
mutator Method of the view mode
Definition: ObjectController.cpp:626
camitk::ObjectController::d_ptr
ObjectControllerPrivate * d_ptr
private object controller wich contains pointer about object, browser and more
Definition: ObjectController.h:237
ObjectController::~ObjectController
~ObjectController()
Definition: objectcontroller.cpp:370
camitk::ObjectController::ObjectController
ObjectController(QWidget *parent=nullptr, ViewMode viewMode=TREE)
constructor of object controller with in parameters the parent widget and the view mode (default : TR...
Definition: ObjectController.cpp:543
camitk::ObjectController::revert
void revert()
slot to revert the values of all properties (revert to values in memory)
Definition: ObjectController.cpp:685
ObjectControllerPrivate::m_topLevelProperties
QList< QtProperty * > m_topLevelProperties
Definition: objectcontroller.cpp:111
camitk::ObjectController::GROUPBOX
It is like the TREE but with a delimitation to indicate the arborescence of the property type.
Definition: ObjectController.h:195
camitk::Property::getDescription
const QString & getDescription() const
get the description
Definition: Property.cpp:96
camitk::ObjectControllerPrivate::intToEnum
int intToEnum(const QMetaEnum &metaEnum, int intValue) const
Definition: ObjectController.cpp:87
objectcontroller.h
QtVariantProperty::setAttribute
void setAttribute(const QString &attribute, const QVariant &value)
Definition: qtvariantproperty.cpp:276
ObjectControllerPrivate::intToEnum
int intToEnum(const QMetaEnum &metaEnum, int intValue) const
Definition: objectcontroller.cpp:97
QtVariantPropertyManager::isPropertyTypeSupported
virtual bool isPropertyTypeSupported(int propertyType) const
Definition: qtvariantproperty.cpp:1300
ObjectControllerPrivate::flagToInt
int flagToInt(const QMetaEnum &metaEnum, int flagValue) const
Definition: objectcontroller.cpp:140
camitk::ObjectControllerPrivate::updateClassProperties
void updateClassProperties(const QMetaObject *metaObject, bool recursive)
Definition: ObjectController.cpp:197
QtProperty::addSubProperty
void addSubProperty(QtProperty *property)
Definition: qtpropertybrowser.cpp:392
QtVariantProperty::value
QVariant value() const
Definition: qtvariantproperty.cpp:213
QtVariantPropertyManager::groupTypeId
static int groupTypeId()
Definition: qtvariantproperty.cpp:116
camitk::ObjectControllerPrivate::restoreExpandedState
void restoreExpandedState()
Definition: ObjectController.cpp:489
ObjectControllerPrivate::isPowerOf2
bool isPowerOf2(int value) const
Definition: objectcontroller.cpp:130
ObjectControllerPrivate::isSubValue
bool isSubValue(int value, int subValue) const
Definition: objectcontroller.cpp:113
ObjectControllerPrivate::m_propertyToClass
QMap< QtProperty *, const QMetaObject * > m_propertyToClass
Definition: objectcontroller.cpp:105
camitk::ObjectControllerPrivate::buildQtVariantProperty
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:229
CAMITK_API
#define CAMITK_API
Definition: CamiTKAPI.h:48
camitk
Definition: Action.cpp:36
qtpropertymanager.h