Computer Assisted Medical Intervention Tool Kit  version 5.2
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:
148  QtPropertyPrivate* d_ptr;
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 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
185  Q_DISABLE_COPY_MOVE(QtAbstractPropertyManager)
186 #else
187  Q_DISABLE_COPY(QtAbstractPropertyManager)
188 #endif
189 };
190 
192  Q_OBJECT
193 public:
194  virtual QWidget* createEditor(QtProperty* property, QWidget* parent) = 0;
195 protected:
196  explicit QtAbstractEditorFactoryBase(QObject* parent = nullptr)
197  : QObject(parent) {}
198 
199  virtual void breakConnection(QtAbstractPropertyManager* manager) = 0;
200 protected Q_SLOTS:
201  virtual void managerDestroyed(QObject* manager) = 0;
202 
204 };
205 
206 template <class PropertyManager>
208 public:
209  explicit QtAbstractEditorFactory(QObject* parent) : QtAbstractEditorFactoryBase(parent) {}
210  QWidget* createEditor(QtProperty* property, QWidget* parent) override {
211  QSetIterator<PropertyManager*> it(m_managers);
212  while (it.hasNext()) {
213  PropertyManager* manager = it.next();
214  if (manager == property->propertyManager()) {
215  return createEditor(manager, property, parent);
216  }
217  }
218  return nullptr;
219  }
220  void addPropertyManager(PropertyManager* manager) {
221  if (m_managers.contains(manager)) {
222  return;
223  }
224  m_managers.insert(manager);
225  connectPropertyManager(manager);
226  connect(manager, SIGNAL(destroyed(QObject*)),
227  this, SLOT(managerDestroyed(QObject*)));
228  }
229  void removePropertyManager(PropertyManager* manager) {
230  if (!m_managers.contains(manager)) {
231  return;
232  }
233  disconnect(manager, SIGNAL(destroyed(QObject*)),
234  this, SLOT(managerDestroyed(QObject*)));
235  disconnectPropertyManager(manager);
236  m_managers.remove(manager);
237  }
238  QSet<PropertyManager*> propertyManagers() const {
239  return m_managers;
240  }
241  PropertyManager* propertyManager(QtProperty* property) const {
242  QtAbstractPropertyManager* manager = property->propertyManager();
243  QSetIterator<PropertyManager*> itManager(m_managers);
244  while (itManager.hasNext()) {
245  PropertyManager* m = itManager.next();
246  if (m == manager) {
247  return m;
248  }
249  }
250  return 0;
251  }
252 protected:
253  virtual void connectPropertyManager(PropertyManager* manager) = 0;
254  virtual QWidget* createEditor(PropertyManager* manager, QtProperty* property,
255  QWidget* parent) = 0;
256  virtual void disconnectPropertyManager(PropertyManager* manager) = 0;
257  void managerDestroyed(QObject* manager) override {
258  QSetIterator<PropertyManager*> it(m_managers);
259  while (it.hasNext()) {
260  PropertyManager* m = it.next();
261  if (m == manager) {
262  m_managers.remove(m);
263  return;
264  }
265  }
266  }
267 private:
268  void breakConnection(QtAbstractPropertyManager* manager) override {
269  QSetIterator<PropertyManager*> it(m_managers);
270  while (it.hasNext()) {
271  PropertyManager* m = it.next();
272  if (m == manager) {
274  return;
275  }
276  }
277  }
278 private:
279  QSet<PropertyManager*> m_managers;
281 };
282 
285 
287 public:
288  QtProperty* property() const;
289  QtBrowserItem* parent() const;
290  QList<QtBrowserItem*> children() const;
291  QtAbstractPropertyBrowser* browser() const;
292 private:
293  explicit QtBrowserItem(QtAbstractPropertyBrowser* browser, QtProperty* property, QtBrowserItem* parent);
294  ~QtBrowserItem();
295  QtBrowserItemPrivate* d_ptr;
297 };
298 
300 
302  Q_OBJECT
303 public:
304 
305  explicit QtAbstractPropertyBrowser(QWidget* parent = nullptr);
306  ~QtAbstractPropertyBrowser() override;
307 
308  QList<QtProperty*> properties() const;
309  QList<QtBrowserItem*> items(QtProperty* property) const;
310  QtBrowserItem* topLevelItem(QtProperty* property) const;
311  QList<QtBrowserItem*> topLevelItems() const;
312  void clear();
313 
314  template <class PropertyManager>
315  void setFactoryForManager(PropertyManager* manager,
317  QtAbstractPropertyManager* abstractManager = manager;
318  QtAbstractEditorFactoryBase* abstractFactory = factory;
319 
320  if (addFactory(abstractManager, abstractFactory)) {
321  factory->addPropertyManager(manager);
322  }
323  }
324 
325  void unsetFactoryForManager(QtAbstractPropertyManager* manager);
326 
327  QtBrowserItem* currentItem() const;
328  void setCurrentItem(QtBrowserItem*);
329 
330 Q_SIGNALS:
332 
333 public Q_SLOTS:
334 
335  QtBrowserItem* addProperty(QtProperty* property);
336  QtBrowserItem* insertProperty(QtProperty* property, QtProperty* afterProperty);
337  void removeProperty(QtProperty* property);
338 
339 protected:
340 
341  virtual void itemInserted(QtBrowserItem* item, QtBrowserItem* afterItem) = 0;
342  virtual void itemRemoved(QtBrowserItem* item) = 0;
343  // can be tooltip, statustip, whatsthis, name, icon, text.
344  virtual void itemChanged(QtBrowserItem* item) = 0;
345 
346  virtual QWidget* createEditor(QtProperty* property, QWidget* parent);
347 private:
348 
349  bool addFactory(QtAbstractPropertyManager* abstractManager,
350  QtAbstractEditorFactoryBase* abstractFactory);
351 
353  Q_DECLARE_PRIVATE(QtAbstractPropertyBrowser)
354 #if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
355  Q_DISABLE_COPY_MOVE(QtAbstractPropertyBrowser)
356 #else
357  Q_DISABLE_COPY(QtAbstractPropertyBrowser)
358 #endif
359  Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty*,
361  Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty*,
362  QtProperty*))
363  Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty*))
364  Q_PRIVATE_SLOT(d_func(), void slotPropertyDataChanged(QtProperty*))
365 
366 };
367 
368 #if QT_VERSION >= 0x040400
369 QT_END_NAMESPACE
370 #endif
371 
372 #endif // QTPROPERTYBROWSER_H
The QtAbstractEditorFactoryBase provides an interface for editor factories.
Definition: qtpropertybrowser.h:191
virtual void breakConnection(QtAbstractPropertyManager *manager)=0
virtual void managerDestroyed(QObject *manager)=0
QtAbstractEditorFactoryBase(QObject *parent=nullptr)
Definition: qtpropertybrowser.h:196
virtual QWidget * createEditor(QtProperty *property, QWidget *parent)=0
The QtAbstractEditorFactory is the base template class for editor factories.
Definition: qtpropertybrowser.h:207
void removePropertyManager(PropertyManager *manager)
Definition: qtpropertybrowser.h:229
virtual QWidget * createEditor(PropertyManager *manager, QtProperty *property, QWidget *parent)=0
QtAbstractEditorFactory(QObject *parent)
Definition: qtpropertybrowser.h:209
virtual void disconnectPropertyManager(PropertyManager *manager)=0
QWidget * createEditor(QtProperty *property, QWidget *parent) override
Definition: qtpropertybrowser.h:210
friend class QtAbstractPropertyEditor
Definition: qtpropertybrowser.h:280
PropertyManager * propertyManager(QtProperty *property) const
Definition: qtpropertybrowser.h:241
virtual void connectPropertyManager(PropertyManager *manager)=0
QSet< PropertyManager * > propertyManagers() const
Definition: qtpropertybrowser.h:238
void managerDestroyed(QObject *manager) override
Definition: qtpropertybrowser.h:257
void addPropertyManager(PropertyManager *manager)
Definition: qtpropertybrowser.h:220
Definition: qtpropertybrowser.cpp:1193
QtAbstractPropertyBrowser provides a base class for implementing property browsers.
Definition: qtpropertybrowser.h:301
virtual void itemChanged(QtBrowserItem *item)=0
virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem)=0
void currentItemChanged(QtBrowserItem *)
void setFactoryForManager(PropertyManager *manager, QtAbstractEditorFactory< PropertyManager > *factory)
Definition: qtpropertybrowser.h:315
virtual void itemRemoved(QtBrowserItem *item)=0
Definition: qtpropertybrowser.cpp:76
The QtAbstractPropertyManager provides an interface for property managers.
Definition: qtpropertybrowser.h:153
void propertyDestroyed(QtProperty *property)
void propertyInserted(QtProperty *property, QtProperty *parent, QtProperty *after)
void propertyChanged(QtProperty *property)
virtual void initializeProperty(QtProperty *property)=0
void propertyRemoved(QtProperty *property, QtProperty *parent)
Definition: qtpropertybrowser.cpp:1073
The QtBrowserItem class represents a property in a property browser instance.
Definition: qtpropertybrowser.h:286
Definition: qtpropertybrowser.cpp:55
The QtProperty class encapsulates an instance of a property.
Definition: qtpropertybrowser.h:113
QtAbstractPropertyManager * propertyManager() const
Definition: qtpropertybrowser.cpp:196
#define QT_QTPROPERTYBROWSER_EXPORT
Definition: qtpropertybrowser.h:59
QLineEdit::EchoMode EchoMode
Definition: qtpropertybrowser.h:62