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 
296  QtVariantPropertyManager *m_readOnlyManager;
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
Definition: ObjectController.h:240
Definition: Action.cpp:40
Definition: objectcontroller.cpp:50
The property browser can be shown like a QListView.
Definition: ObjectController.h:173
#define CAMITK_API
Definition: CamiTKAPI.h:49
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
The description of this class will come soon !
Definition: qtvariantproperty.h:64
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
The object controller class.
Definition: ObjectController.h:162
ObjectController * q_ptr
Definition: ObjectController.h:241