Computer Assited Medical Intervention Tool Kit  version 4.0
qtpropertybrowser.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 **
6 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 **
8 ** This file is part of a Qt Solutions component.
9 **
10 ** You may use this file under the terms of the BSD license as follows:
11 **
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
14 ** met:
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
20 ** distribution.
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
24 ** permission.
25 **
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
37 **
38 ****************************************************************************/
39 
40 
41 #ifndef QTPROPERTYBROWSER_H
42 #define QTPROPERTYBROWSER_H
43 
44 #include <QtWidgets/QWidget>
45 #include <QSet>
46 #include <QtWidgets/QLineEdit>
47 
48 #if QT_VERSION >= 0x040400
49 QT_BEGIN_NAMESPACE
50 #endif
51 
52 #if defined(_WIN32)
53 # if defined(COMPILE_QTPROPERTYBROWSER)
54 # define QT_QTPROPERTYBROWSER_EXPORT __declspec(dllexport)
55 # else
56 # define QT_QTPROPERTYBROWSER_EXPORT __declspec(dllimport)
57 # endif
58 #else
59 #define QT_QTPROPERTYBROWSER_EXPORT
60 #endif
61 
63 
65 class QtPropertyPrivate;
66 
75 public:
76  virtual ~QtProperty();
77 
78  QList<QtProperty *> subProperties() const;
79 
80  QtAbstractPropertyManager *propertyManager() const;
81 
82  QString toolTip() const;
83  QString statusTip() const;
84  QString whatsThis() const;
85  QString propertyName() const;
86  bool isEnabled() const;
87  bool isModified() const;
88 
89  bool hasValue() const;
90  QIcon valueIcon() const;
91  QString valueText() const;
92  QString displayText() const;
93 
94  void setToolTip(const QString &text);
95  void setStatusTip(const QString &text);
96  void setWhatsThis(const QString &text);
97  void setPropertyName(const QString &text);
98  void setEnabled(bool enable);
99  void setModified(bool modified);
100 
101  void addSubProperty(QtProperty *property);
102  void insertSubProperty(QtProperty *property, QtProperty *afterProperty);
103  void removeSubProperty(QtProperty *property);
104 protected:
105  explicit QtProperty(QtAbstractPropertyManager *manager);
106  void propertyChanged();
107 private:
110 };
111 
113 
115  Q_OBJECT
116 public:
117 
118  explicit QtAbstractPropertyManager(QObject *parent = 0);
120 
121  QSet<QtProperty *> properties() const;
122  void clear() const;
123 
124  QtProperty *addProperty(const QString &name = QString());
125 Q_SIGNALS:
126 
127  void propertyInserted(QtProperty *property,
128  QtProperty *parent, QtProperty *after);
129  void propertyChanged(QtProperty *property);
130  void propertyRemoved(QtProperty *property, QtProperty *parent);
131  void propertyDestroyed(QtProperty *property);
132 protected:
133  virtual bool hasValue(const QtProperty *property) const;
134  virtual QIcon valueIcon(const QtProperty *property) const;
135  virtual QString valueText(const QtProperty *property) const;
136  virtual QString displayText(const QtProperty *property) const;
137  virtual EchoMode echoMode(const QtProperty *) const;
138  virtual void initializeProperty(QtProperty *property) = 0;
139  virtual void uninitializeProperty(QtProperty *property);
140  virtual QtProperty *createProperty();
141 private:
142  friend class QtProperty;
144  Q_DECLARE_PRIVATE(QtAbstractPropertyManager)
145  Q_DISABLE_COPY(QtAbstractPropertyManager)
146 };
147 
149  Q_OBJECT
150 public:
151  virtual QWidget *createEditor(QtProperty *property, QWidget *parent) = 0;
152 protected:
153  explicit QtAbstractEditorFactoryBase(QObject *parent = 0)
154  : QObject(parent) {}
155 
156  virtual void breakConnection(QtAbstractPropertyManager *manager) = 0;
157 protected Q_SLOTS:
158  virtual void managerDestroyed(QObject *manager) = 0;
159 
161 };
162 
163 template <class PropertyManager>
165 public:
166  explicit QtAbstractEditorFactory(QObject *parent) : QtAbstractEditorFactoryBase(parent) {}
167  QWidget *createEditor(QtProperty *property, QWidget *parent) {
168  QSetIterator<PropertyManager *> it(m_managers);
169  while (it.hasNext()) {
170  PropertyManager *manager = it.next();
171  if (manager == property->propertyManager()) {
172  return createEditor(manager, property, parent);
173  }
174  }
175  return 0;
176  }
177  void addPropertyManager(PropertyManager *manager) {
178  if (m_managers.contains(manager))
179  return;
180  m_managers.insert(manager);
181  connectPropertyManager(manager);
182  connect(manager, SIGNAL(destroyed(QObject *)),
183  this, SLOT(managerDestroyed(QObject *)));
184  }
185  void removePropertyManager(PropertyManager *manager) {
186  if (!m_managers.contains(manager))
187  return;
188  disconnect(manager, SIGNAL(destroyed(QObject *)),
189  this, SLOT(managerDestroyed(QObject *)));
190  disconnectPropertyManager(manager);
191  m_managers.remove(manager);
192  }
193  QSet<PropertyManager *> propertyManagers() const {
194  return m_managers;
195  }
196  PropertyManager *propertyManager(QtProperty *property) const {
197  QtAbstractPropertyManager *manager = property->propertyManager();
198  QSetIterator<PropertyManager *> itManager(m_managers);
199  while (itManager.hasNext()) {
200  PropertyManager *m = itManager.next();
201  if (m == manager) {
202  return m;
203  }
204  }
205  return 0;
206  }
207 protected:
208  virtual void connectPropertyManager(PropertyManager *manager) = 0;
209  virtual QWidget *createEditor(PropertyManager *manager, QtProperty *property,
210  QWidget *parent) = 0;
211  virtual void disconnectPropertyManager(PropertyManager *manager) = 0;
212  void managerDestroyed(QObject *manager) {
213  QSetIterator<PropertyManager *> it(m_managers);
214  while (it.hasNext()) {
215  PropertyManager *m = it.next();
216  if (m == manager) {
217  m_managers.remove(m);
218  return;
219  }
220  }
221  }
222 private:
224  QSetIterator<PropertyManager *> it(m_managers);
225  while (it.hasNext()) {
226  PropertyManager *m = it.next();
227  if (m == manager) {
228  removePropertyManager(m);
229  return;
230  }
231  }
232  }
233 private:
234  QSet<PropertyManager *> m_managers;
235  friend class QtAbstractPropertyEditor;
236 };
237 
240 
242 public:
243  QtProperty *property() const;
244  QtBrowserItem *parent() const;
245  QList<QtBrowserItem *> children() const;
246  QtAbstractPropertyBrowser *browser() const;
247 private:
248  explicit QtBrowserItem(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent);
249  ~QtBrowserItem();
252 };
253 
255 
257  Q_OBJECT
258 public:
259 
260  explicit QtAbstractPropertyBrowser(QWidget *parent = 0);
262 
263  QList<QtProperty *> properties() const;
264  QList<QtBrowserItem *> items(QtProperty *property) const;
265  QtBrowserItem *topLevelItem(QtProperty *property) const;
266  QList<QtBrowserItem *> topLevelItems() const;
267  void clear();
268 
269  template <class PropertyManager>
270  void setFactoryForManager(PropertyManager *manager,
272  QtAbstractPropertyManager *abstractManager = manager;
273  QtAbstractEditorFactoryBase *abstractFactory = factory;
274 
275  if (addFactory(abstractManager, abstractFactory))
276  factory->addPropertyManager(manager);
277  }
278 
279  void unsetFactoryForManager(QtAbstractPropertyManager *manager);
280 
281  QtBrowserItem *currentItem() const;
282  void setCurrentItem(QtBrowserItem *);
283 
284 Q_SIGNALS:
285  void currentItemChanged(QtBrowserItem *);
286 
287 public Q_SLOTS:
288 
289  QtBrowserItem *addProperty(QtProperty *property);
290  QtBrowserItem *insertProperty(QtProperty *property, QtProperty *afterProperty);
291  void removeProperty(QtProperty *property);
292 
293 protected:
294 
295  virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem) = 0;
296  virtual void itemRemoved(QtBrowserItem *item) = 0;
297  // can be tooltip, statustip, whatsthis, name, icon, text.
298  virtual void itemChanged(QtBrowserItem *item) = 0;
299 
300  virtual QWidget *createEditor(QtProperty *property, QWidget *parent);
301 private:
302 
303  bool addFactory(QtAbstractPropertyManager *abstractManager,
304  QtAbstractEditorFactoryBase *abstractFactory);
305 
307  Q_DECLARE_PRIVATE(QtAbstractPropertyBrowser)
308  Q_DISABLE_COPY(QtAbstractPropertyBrowser)
309  Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *,
310  QtProperty *, QtProperty *))
311  Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty *,
312  QtProperty *))
313  Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *))
314  Q_PRIVATE_SLOT(d_func(), void slotPropertyDataChanged(QtProperty *))
315 
316 };
317 
318 #if QT_VERSION >= 0x040400
319 QT_END_NAMESPACE
320 #endif
321 
322 #endif // QTPROPERTYBROWSER_H
QtAbstractEditorFactoryBase(QObject *parent=0)
Definition: qtpropertybrowser.h:153
Definition: qtpropertybrowser.cpp:55
QtAbstractPropertyBrowser provides a base class for implementing property browsers.
Definition: qtpropertybrowser.h:256
QtAbstractPropertyManagerPrivate * d_ptr
Definition: qtpropertybrowser.h:143
The QtBrowserItem class represents a property in a property browser instance.
Definition: qtpropertybrowser.h:241
Definition: qtpropertybrowser.cpp:76
The QtAbstractPropertyManager provides an interface for property managers.
Definition: qtpropertybrowser.h:114
Definition: qtpropertybrowser.cpp:1060
void addPropertyManager(PropertyManager *manager)
Definition: qtpropertybrowser.h:177
void breakConnection(QtAbstractPropertyManager *manager)
Definition: qtpropertybrowser.h:223
QtAbstractPropertyBrowserPrivate * d_ptr
Definition: qtpropertybrowser.h:306
QtAbstractPropertyManager * propertyManager() const
Definition: qtpropertybrowser.cpp:196
The QtAbstractEditorFactory is the base template class for editor factories.
Definition: qtpropertybrowser.h:164
QtAbstractEditorFactory(QObject *parent)
Definition: qtpropertybrowser.h:166
QtPropertyPrivate * d_ptr
Definition: qtpropertybrowser.h:109
void setFactoryForManager(PropertyManager *manager, QtAbstractEditorFactory< PropertyManager > *factory)
Definition: qtpropertybrowser.h:270
void managerDestroyed(QObject *manager)
Definition: qtpropertybrowser.h:212
#define QT_QTPROPERTYBROWSER_EXPORT
Definition: qtpropertybrowser.h:59
QSet< PropertyManager * > propertyManagers() const
Definition: qtpropertybrowser.h:193
PropertyManager * propertyManager(QtProperty *property) const
Definition: qtpropertybrowser.h:196
QWidget * createEditor(QtProperty *property, QWidget *parent)
Definition: qtpropertybrowser.h:167
The description of this class will come soon !
Definition: qtpropertybrowser.h:74
void removePropertyManager(PropertyManager *manager)
Definition: qtpropertybrowser.h:185
QLineEdit::EchoMode EchoMode
Definition: qtpropertybrowser.h:62
QSet< PropertyManager * > m_managers
Definition: qtpropertybrowser.h:234
Definition: qtpropertybrowser.cpp:1179
The QtAbstractEditorFactoryBase provides an interface for editor factories.
Definition: qtpropertybrowser.h:148
QtBrowserItemPrivate * d_ptr
Definition: qtpropertybrowser.h:250