Computer Assited Medical Intervention Tool Kit  version 4.1
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 
114 public:
115  virtual ~QtProperty();
116 
117  QList<QtProperty*> subProperties() const;
118 
119  QtAbstractPropertyManager* propertyManager() const;
120 
121  QString toolTip() const;
122  QString statusTip() const;
123  QString whatsThis() const;
124  QString propertyName() const;
125  bool isEnabled() const;
126  bool isModified() const;
127 
128  bool hasValue() const;
129  QIcon valueIcon() const;
130  QString valueText() const;
131  QString displayText() const;
132 
133  void setToolTip(const QString& text);
134  void setStatusTip(const QString& text);
135  void setWhatsThis(const QString& text);
136  void setPropertyName(const QString& text);
137  void setEnabled(bool enable);
138  void setModified(bool modified);
139 
140  void addSubProperty(QtProperty* property);
141  void insertSubProperty(QtProperty* property, QtProperty* afterProperty);
142  void removeSubProperty(QtProperty* property);
143 protected:
144  explicit QtProperty(QtAbstractPropertyManager* manager);
145  void propertyChanged();
146 private:
149 };
150 
152 
154  Q_OBJECT
155 public:
156 
157  explicit QtAbstractPropertyManager(QObject* parent = nullptr);
158  ~QtAbstractPropertyManager() override;
159 
160  QSet<QtProperty*> properties() const;
161  void clear() const;
162 
163  QtProperty* addProperty(const QString& name = QString());
164 Q_SIGNALS:
165 
166  void propertyInserted(QtProperty* property,
167  QtProperty* parent, QtProperty* after);
168  void propertyChanged(QtProperty* property);
169  void propertyRemoved(QtProperty* property, QtProperty* parent);
170  void propertyDestroyed(QtProperty* property);
171 protected:
172  virtual bool hasValue(const QtProperty* property) const;
173  virtual QIcon valueIcon(const QtProperty* property) const;
174  virtual QString valueText(const QtProperty* property) const;
175  virtual QString displayText(const QtProperty* property) const;
176  virtual EchoMode echoMode(const QtProperty*) const;
177  virtual void initializeProperty(QtProperty* property) = 0;
178  virtual void uninitializeProperty(QtProperty* property);
179  virtual QtProperty* createProperty();
180 private:
181  friend class QtProperty;
183  Q_DECLARE_PRIVATE(QtAbstractPropertyManager)
184  Q_DISABLE_COPY(QtAbstractPropertyManager)
185 };
186 
188  Q_OBJECT
189 public:
190  virtual QWidget* createEditor(QtProperty* property, QWidget* parent) = 0;
191 protected:
192  explicit QtAbstractEditorFactoryBase(QObject* parent = nullptr)
193  : QObject(parent) {}
194 
195  virtual void breakConnection(QtAbstractPropertyManager* manager) = 0;
196 protected Q_SLOTS:
197  virtual void managerDestroyed(QObject* manager) = 0;
198 
200 };
201 
202 template <class PropertyManager>
204 public:
205  explicit QtAbstractEditorFactory(QObject* parent) : QtAbstractEditorFactoryBase(parent) {}
206  QWidget* createEditor(QtProperty* property, QWidget* parent) {
207  QSetIterator<PropertyManager*> it(m_managers);
208  while (it.hasNext()) {
209  PropertyManager* manager = it.next();
210  if (manager == property->propertyManager()) {
211  return createEditor(manager, property, parent);
212  }
213  }
214  return nullptr;
215  }
216  void addPropertyManager(PropertyManager* manager) {
217  if (m_managers.contains(manager)) {
218  return;
219  }
220  m_managers.insert(manager);
221  connectPropertyManager(manager);
222  connect(manager, SIGNAL(destroyed(QObject*)),
223  this, SLOT(managerDestroyed(QObject*)));
224  }
225  void removePropertyManager(PropertyManager* manager) {
226  if (!m_managers.contains(manager)) {
227  return;
228  }
229  disconnect(manager, SIGNAL(destroyed(QObject*)),
230  this, SLOT(managerDestroyed(QObject*)));
231  disconnectPropertyManager(manager);
232  m_managers.remove(manager);
233  }
234  QSet<PropertyManager*> propertyManagers() const {
235  return m_managers;
236  }
237  PropertyManager* propertyManager(QtProperty* property) const {
238  QtAbstractPropertyManager* manager = property->propertyManager();
239  QSetIterator<PropertyManager*> itManager(m_managers);
240  while (itManager.hasNext()) {
241  PropertyManager* m = itManager.next();
242  if (m == manager) {
243  return m;
244  }
245  }
246  return 0;
247  }
248 protected:
249  virtual void connectPropertyManager(PropertyManager* manager) = 0;
250  virtual QWidget* createEditor(PropertyManager* manager, QtProperty* property,
251  QWidget* parent) = 0;
252  virtual void disconnectPropertyManager(PropertyManager* manager) = 0;
253  void managerDestroyed(QObject* manager) {
254  QSetIterator<PropertyManager*> it(m_managers);
255  while (it.hasNext()) {
256  PropertyManager* m = it.next();
257  if (m == manager) {
258  m_managers.remove(m);
259  return;
260  }
261  }
262  }
263 private:
265  QSetIterator<PropertyManager*> it(m_managers);
266  while (it.hasNext()) {
267  PropertyManager* m = it.next();
268  if (m == manager) {
269  removePropertyManager(m);
270  return;
271  }
272  }
273  }
274 private:
275  QSet<PropertyManager*> m_managers;
276  friend class QtAbstractPropertyEditor;
277 };
278 
281 
283 public:
284  QtProperty* property() const;
285  QtBrowserItem* parent() const;
286  QList<QtBrowserItem*> children() const;
287  QtAbstractPropertyBrowser* browser() const;
288 private:
289  explicit QtBrowserItem(QtAbstractPropertyBrowser* browser, QtProperty* property, QtBrowserItem* parent);
290  ~QtBrowserItem();
293 };
294 
296 
298  Q_OBJECT
299 public:
300 
301  explicit QtAbstractPropertyBrowser(QWidget* parent = nullptr);
302  ~QtAbstractPropertyBrowser() override;
303 
304  QList<QtProperty*> properties() const;
305  QList<QtBrowserItem*> items(QtProperty* property) const;
306  QtBrowserItem* topLevelItem(QtProperty* property) const;
307  QList<QtBrowserItem*> topLevelItems() const;
308  void clear();
309 
310  template <class PropertyManager>
311  void setFactoryForManager(PropertyManager* manager,
313  QtAbstractPropertyManager* abstractManager = manager;
314  QtAbstractEditorFactoryBase* abstractFactory = factory;
315 
316  if (addFactory(abstractManager, abstractFactory)) {
317  factory->addPropertyManager(manager);
318  }
319  }
320 
321  void unsetFactoryForManager(QtAbstractPropertyManager* manager);
322 
323  QtBrowserItem* currentItem() const;
324  void setCurrentItem(QtBrowserItem*);
325 
326 Q_SIGNALS:
327  void currentItemChanged(QtBrowserItem*);
328 
329 public Q_SLOTS:
330 
331  QtBrowserItem* addProperty(QtProperty* property);
332  QtBrowserItem* insertProperty(QtProperty* property, QtProperty* afterProperty);
333  void removeProperty(QtProperty* property);
334 
335 protected:
336 
337  virtual void itemInserted(QtBrowserItem* item, QtBrowserItem* afterItem) = 0;
338  virtual void itemRemoved(QtBrowserItem* item) = 0;
339  // can be tooltip, statustip, whatsthis, name, icon, text.
340  virtual void itemChanged(QtBrowserItem* item) = 0;
341 
342  virtual QWidget* createEditor(QtProperty* property, QWidget* parent);
343 private:
344 
345  bool addFactory(QtAbstractPropertyManager* abstractManager,
346  QtAbstractEditorFactoryBase* abstractFactory);
347 
349  Q_DECLARE_PRIVATE(QtAbstractPropertyBrowser)
350  Q_DISABLE_COPY(QtAbstractPropertyBrowser)
351  Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty*,
353  Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty*,
354  QtProperty*))
355  Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty*))
356  Q_PRIVATE_SLOT(d_func(), void slotPropertyDataChanged(QtProperty*))
357 
358 };
359 
360 #if QT_VERSION >= 0x040400
361 QT_END_NAMESPACE
362 #endif
363 
364 #endif // QTPROPERTYBROWSER_H
QSet< PropertyManager * > m_managers
Definition: qtpropertybrowser.h:275
Definition: qtpropertybrowser.cpp:55
QtAbstractPropertyBrowser provides a base class for implementing property browsers.
Definition: qtpropertybrowser.h:297
QtAbstractPropertyManagerPrivate * d_ptr
Definition: qtpropertybrowser.h:182
The QtBrowserItem class represents a property in a property browser instance.
Definition: qtpropertybrowser.h:282
Definition: qtpropertybrowser.cpp:76
The QtAbstractPropertyManager provides an interface for property managers.
Definition: qtpropertybrowser.h:153
Definition: qtpropertybrowser.cpp:1073
void addPropertyManager(PropertyManager *manager)
Definition: qtpropertybrowser.h:216
void breakConnection(QtAbstractPropertyManager *manager)
Definition: qtpropertybrowser.h:264
QtAbstractPropertyBrowserPrivate * d_ptr
Definition: qtpropertybrowser.h:348
QtAbstractPropertyManager * propertyManager() const
Definition: qtpropertybrowser.cpp:196
The QtAbstractEditorFactory is the base template class for editor factories.
Definition: qtpropertybrowser.h:203
QtAbstractEditorFactory(QObject *parent)
Definition: qtpropertybrowser.h:205
QtPropertyPrivate * d_ptr
Definition: qtpropertybrowser.h:148
void setFactoryForManager(PropertyManager *manager, QtAbstractEditorFactory< PropertyManager > *factory)
Definition: qtpropertybrowser.h:311
void managerDestroyed(QObject *manager)
Definition: qtpropertybrowser.h:253
QtAbstractEditorFactoryBase(QObject *parent=nullptr)
Definition: qtpropertybrowser.h:192
#define QT_QTPROPERTYBROWSER_EXPORT
Definition: qtpropertybrowser.h:59
QSet< PropertyManager * > propertyManagers() const
Definition: qtpropertybrowser.h:234
PropertyManager * propertyManager(QtProperty *property) const
Definition: qtpropertybrowser.h:237
QWidget * createEditor(QtProperty *property, QWidget *parent)
Definition: qtpropertybrowser.h:206
The QtProperty class encapsulates an instance of a property.
Definition: qtpropertybrowser.h:113
void removePropertyManager(PropertyManager *manager)
Definition: qtpropertybrowser.h:225
QLineEdit::EchoMode EchoMode
Definition: qtpropertybrowser.h:62
Definition: qtpropertybrowser.cpp:1193
The QtAbstractEditorFactoryBase provides an interface for editor factories.
Definition: qtpropertybrowser.h:187
QtBrowserItemPrivate * d_ptr
Definition: qtpropertybrowser.h:291