Computer Assited Medical Intervention Tool Kit
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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-2013 UJF-Grenoble 1, 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 // -- Core stuff
30 #include "CamiTKAPI.h"
31 
32 // -- QT stuff
33 #include <QtGui/QWidget>
34 #include <QtVariantProperty>
35 #include <QPushButton>
36 #include <QVBoxLayout>
37 #include <QScrollArea>
38 #include <QMetaEnum>
39 #include <signal.h>
40 
41 
42 namespace camitk
43 {
44 class ObjectControllerPrivate;
45 
46 
138 class CAMITK_API ObjectController : public QWidget {
139  Q_OBJECT
140  Q_ENUMS(ViewMode) // so that it can be used in property editor
141 
142 public:
143  // [CAMITK ADDED]
148  enum ViewMode {
149  TREE,
150  GROUPBOX,
151  BUTTON
152  };
153 
155  ObjectController ( QWidget *parent = 0, ViewMode viewMode = TREE );
156 
158  ~ObjectController();
159 
161  void setObject ( QObject *object );
162 
164  QObject *object() const;
165 
167  void setAutoUpdateProperty(bool);
168 
169  // [CAMITK ADDED]
171  void setViewMode ( ViewMode viewMode );
172 
173  // [CAMITK ADDED]
175  ViewMode getViewMode() const;
176 
177  // [CAMITK ADDED]
179  bool isModified ();
180 
181 public slots:
182  // [CAMITK ADDED]
184  void apply();
185 
186  // [CAMITK ADDED]
188  void revert();
189 
190 private:
193  Q_DECLARE_PRIVATE ( ObjectController )
194  Q_DISABLE_COPY ( ObjectController )
195 
196  // [CAMITK CHANGED]
197  Q_PRIVATE_SLOT ( d_func(), void saveChange ( QtProperty *, const QVariant & ) )
198  Q_PRIVATE_SLOT ( d_func(), void valueChanged ( QtProperty *, const QVariant & ) )
199 
200  // [CAMITK ADDED]
202  ViewMode currentViewMode;
203 
204  // [CAMITK ADDED]
206  void initViewMode();
207 
209  QVBoxLayout *layout;
210 
212  QScrollArea *scroll;
213 
214 };
215 
218  Q_DECLARE_PUBLIC ( ObjectController )
219 public:
220 
221  void addClassProperties ( const QMetaObject *metaObject );
222  void addDynamicProperties ( const QObject *edited );
223  void updateClassProperties ( const QMetaObject *metaObject, bool recursive );
224  void updateDynamicProperties ( const QObject * edited);
225  void saveExpandedState();
226  void restoreExpandedState();
227  void valueChanged ( QtProperty *property, const QVariant value );
228  //CAMITK ADDED
229  void saveChange ( QtProperty *property, const QVariant &value );
230  void applyChange();
231  //
232  int enumToInt ( const QMetaEnum &metaEnum, int enumValue ) const;
233  int intToEnum ( const QMetaEnum &metaEnum, int intValue ) const;
234  int flagToInt ( const QMetaEnum &metaEnum, int flagValue ) const;
235  int intToFlag ( const QMetaEnum &metaEnum, int intValue ) const;
236  bool isSubValue ( int value, int subValue ) const;
237  bool isPowerOf2 ( int value ) const;
238 
240  QObject *m_object;
241 
242  /* [CAMITK REMOVED]
243  QMap<const QMetaObject *, QtProperty *> m_classToProperty;
244  QMap<QtProperty *, const QMetaObject *> m_propertyToClass;
245  */
247  QMap<QtProperty *, int> m_classPropertyToIndex;
249  QMap<const QMetaObject *, QMap<int, QtVariantProperty *> > m_classToIndexToProperty;
250 
252  QMap<int, QtVariantProperty *> m_indexToDynamicProperty;
254  QMap<QtProperty *, int> m_dynamicPropertyToIndex;
255 
257  QMap<QtProperty *, bool> m_propertyToExpanded;
258 
260  QList<QtProperty *> m_topLevelProperties;
261 
263  QMap<QtProperty *, QVariant> saveChangeValue;
264 
266  QtAbstractPropertyBrowser *m_browser;
267 
269  QtVariantPropertyManager *m_manager;
270 
272  QtVariantPropertyManager *m_readOnlyManager;
273 
274  // [CAMITK ADDED]
276  QtVariantProperty * buildQtVariantProperty(QString name, QMetaType::Type type, QVariant value, bool isReadable, bool isWritable, bool isEnumType, bool isFlagType, bool isDesignable, QMetaEnum * metaEnum = NULL);
277 };
278 
279 }
280 
281 #endif