Computer Assited Medical Intervention Tool Kit  version 4.0
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-2016 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 <QWidget>
35 #include <QPushButton>
36 #include <QVBoxLayout>
37 #include <QScrollArea>
38 #include <QMetaEnum>
39 #include <signal.h>
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 {
175  BUTTON
176  };
177 
179  ObjectController ( QWidget *parent = 0, ViewMode viewMode = TREE );
180 
182  ~ObjectController();
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
QtAbstractPropertyBrowser provides a base class for implementing property browsers.
Definition: qtpropertybrowser.h:256
The QtVariantPropertyManager class provides and manages QVariant based properties.
Definition: qtvariantproperty.h:83
QtVariantPropertyManager * m_readOnlyManager
the property manager for the read only property
Definition: ObjectController.h:296
QMap< QtProperty *, bool > m_propertyToExpanded
TODO doc.
Definition: ObjectController.h:281
Definition: ObjectController.h:240
Definition: Action.cpp:40
Definition: objectcontroller.cpp:50
QtVariantPropertyManager * m_manager
the main property manager (does not include the read only property)
Definition: ObjectController.h:293
QVBoxLayout * layout
layout which will contains the propertybrowser and, in view mode GROUPBOX and BUTTON, the scroll
Definition: ObjectController.h:233
QObject * m_object
the currently edited object
Definition: ObjectController.h:264
The property browser can be shown like a QListView.
Definition: ObjectController.h:173
#define CAMITK_API
Definition: CamiTKAPI.h:49
QMap< QtProperty *, int > m_dynamicPropertyToIndex
map from the dynamic property to the idx in the dynamic property
Definition: ObjectController.h:278
QMap< QString, QtProperty * > groupProperties
map of all the QtProperty that are top-level groups
Definition: ObjectController.h:303
QScrollArea * scroll
scroll add to navigate in the property browser
Definition: ObjectController.h:236
QList< QtProperty * > m_topLevelProperties
TODO doc.
Definition: ObjectController.h:284
It is like the TREE but with a delimitation to indicate the arborescence of the property type...
Definition: ObjectController.h:174
ObjectControllerPrivate * d_ptr
private object controller wich contains pointer about object, browser and more
Definition: ObjectController.h:216
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
The description of this class will come soon !
Definition: qtvariantproperty.h:64
QMap< QtProperty *, int > m_classPropertyToIndex
map from the class property to the index in the meta object
Definition: ObjectController.h:271
QtAbstractPropertyBrowser * m_browser
the browser where all properties are shown to the user
Definition: ObjectController.h:290
The description of this class will come soon !
Definition: qtpropertybrowser.h:74
ViewMode
The property browser can be shown in different view mode.
Definition: ObjectController.h:172
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
The object controller class.
Definition: ObjectController.h:162
QMap< int, QtVariantProperty * > m_indexToDynamicProperty
map from idx of the dynamic property to the property
Definition: ObjectController.h:276
ObjectController * q_ptr
Definition: ObjectController.h:241