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 #pragma GCC system_header
41 
42 #ifndef QTPROPERTYBROWSER_H
43 #define QTPROPERTYBROWSER_H
44 
45 #include <QtGui/QWidget>
46 #include <QtCore/QSet>
47 #include <QtGui/QLineEdit>
48 #include <QtCore/QMap>
49 
50 #if QT_VERSION >= 0x040400
51 QT_BEGIN_NAMESPACE
52 #endif
53 
54 #if defined(Q_WS_WIN)
55 # if !defined(QT_QTPROPERTYBROWSER_EXPORT) && \
56 !defined(QT_QTPROPERTYBROWSER_IMPORT)
57 # define QT_QTPROPERTYBROWSER_EXPORT
58 # elif defined(QT_QTPROPERTYBROWSER_IMPORT)
59 # if defined(QT_QTPROPERTYBROWSER_EXPORT)
60 # undef QT_QTPROPERTYBROWSER_EXPORT
61 # endif
62 # define QT_QTPROPERTYBROWSER_EXPORT __declspec(dllimport)
63 # elif defined(QT_QTPROPERTYBROWSER_EXPORT)
64 # undef QT_QTPROPERTYBROWSER_EXPORT
65 # define QT_QTPROPERTYBROWSER_EXPORT __declspec(dllexport)
66 # endif
67 #else
68 # define QT_QTPROPERTYBROWSER_EXPORT
69 #endif
70 
72 
74 class QtPropertyPrivate;
75 
76 
78 {
79  public:
80  virtual ~QtProperty();
81 
82  QList<QtProperty *> subProperties() const;
83 
84  QtAbstractPropertyManager *propertyManager() const;
85 
86  QString toolTip() const;
87  QString statusTip() const;
88  QString whatsThis() const;
89  QString propertyName() const;
90  bool isEnabled() const;
91  bool isModified() const;
92 
93  bool hasValue() const;
94  QIcon valueIcon() const;
95  QString valueText() const;
96  QString displayText() const;
97 
98  void setToolTip(const QString &text);
99  void setStatusTip(const QString &text);
100  void setWhatsThis(const QString &text);
101  void setPropertyName(const QString &text);
102  void setEnabled(bool enable);
103  void setModified(bool modified);
104 
105  void addSubProperty(QtProperty *property);
106  void insertSubProperty(QtProperty *property, QtProperty *afterProperty);
107  void removeSubProperty(QtProperty *property);
108  protected:
109  explicit QtProperty(QtAbstractPropertyManager *manager);
110  void propertyChanged();
111  private:
113  QtPropertyPrivate *d_ptr;
114 };
115 
117 {
118  public:
120  : q_ptr(NULL),
121  m_enabled(true),
122  m_modified(false),
123  m_manager(manager) {}
125 
126  QSet<QtProperty *> m_parentItems;
127  QList<QtProperty *> m_subItems;
128 
129  QString m_toolTip;
130  QString m_statusTip;
131  QString m_whatsThis;
132  QString m_name;
133  bool m_enabled;
135 
137 };
138 
140 
142 {
143  Q_OBJECT
144  public:
145 
146  explicit QtAbstractPropertyManager(QObject *parent = 0);
148 
149  QSet<QtProperty *> properties() const;
150  void clear() const;
151 
152  QtProperty *addProperty(const QString &name = QString());
153  Q_SIGNALS:
154 
155  void propertyInserted(QtProperty *property,
156  QtProperty *parent, QtProperty *after);
157  void propertyChanged(QtProperty *property);
158  void propertyRemoved(QtProperty *property, QtProperty *parent);
159  void propertyDestroyed(QtProperty *property);
160  protected:
161  virtual bool hasValue(const QtProperty *property) const;
162  virtual QIcon valueIcon(const QtProperty *property) const;
163  virtual QString valueText(const QtProperty *property) const;
164  virtual QString displayText(const QtProperty *property) const;
165  virtual EchoMode echoMode(const QtProperty *) const;
166  virtual void initializeProperty(QtProperty *property) = 0;
167  virtual void uninitializeProperty(QtProperty *property);
168  virtual QtProperty *createProperty();
169  private:
170  friend class QtProperty;
172  Q_DECLARE_PRIVATE(QtAbstractPropertyManager)
173  Q_DISABLE_COPY(QtAbstractPropertyManager)
174 };
175 
177 {
178  QtAbstractPropertyManager *q_ptr;
179  Q_DECLARE_PUBLIC(QtAbstractPropertyManager)
180  public:
181  QtAbstractPropertyManagerPrivate() : q_ptr(NULL) {}
182  void propertyDestroyed(QtProperty *property);
183  void propertyChanged(QtProperty *property) const;
184  void propertyRemoved(QtProperty *property,
185  QtProperty *parentProperty) const;
186  void propertyInserted(QtProperty *property, QtProperty *parentProperty,
187  QtProperty *afterProperty) const;
188 
189  QSet<QtProperty *> m_properties;
190 };
191 
193 {
194  Q_OBJECT
195  public:
196  virtual QWidget *createEditor(QtProperty *property, QWidget *parent) = 0;
197  protected:
198  explicit QtAbstractEditorFactoryBase(QObject *parent = 0)
199  : QObject(parent) {}
200 
201  virtual void breakConnection(QtAbstractPropertyManager *manager) = 0;
202  protected Q_SLOTS:
203  virtual void managerDestroyed(QObject *manager) = 0;
204 
206 };
207 
208 template <class PropertyManager>
210 {
211  public:
213  QObject *parent) : QtAbstractEditorFactoryBase(parent) {}
214  QWidget *createEditor(QtProperty *property, QWidget *parent)
215 
216  {
217  QSetIterator<PropertyManager *> it(m_managers);
218  while (it.hasNext())
219  {
220  PropertyManager *manager = it.next();
221  if (manager == property->propertyManager())
222  {
223  return createEditor(manager, property, parent);
224  }
225  }
226  return 0;
227  }
228  void addPropertyManager(PropertyManager *manager)
229 
230  {
231  if (m_managers.contains(manager))
232  return;
233  m_managers.insert(manager);
234  connectPropertyManager(manager);
235  connect(manager, SIGNAL(destroyed(QObject *)),
236  this, SLOT(managerDestroyed(QObject *)));
237  }
238  void removePropertyManager(PropertyManager *manager)
239 
240  {
241  if (!m_managers.contains(manager))
242  return;
243  disconnect(manager, SIGNAL(destroyed(QObject *)),
244  this, SLOT(managerDestroyed(QObject *)));
245  disconnectPropertyManager(manager);
246  m_managers.remove(manager);
247  }
248  QSet<PropertyManager *> propertyManagers() const
249 
250  {
251  return m_managers;
252  }
253  PropertyManager *propertyManager(QtProperty *property) const
254 
255  {
256  QtAbstractPropertyManager *manager = property->propertyManager();
257  QSetIterator<PropertyManager *> itManager(m_managers);
258  while (itManager.hasNext())
259  {
260  PropertyManager *m = itManager.next();
261  if (m == manager)
262  {
263  return m;
264  }
265  }
266  return 0;
267  }
268  protected:
269  virtual void connectPropertyManager(PropertyManager *manager) = 0;
270  virtual QWidget *createEditor(PropertyManager *manager,
271  QtProperty *property,
272  QWidget *parent) = 0;
273  virtual void disconnectPropertyManager(PropertyManager *manager) = 0;
274  void managerDestroyed(QObject *manager)
275 
276  {
277  QSetIterator<PropertyManager *> it(m_managers);
278  while (it.hasNext())
279  {
280  PropertyManager *m = it.next();
281  if (m == manager)
282  {
283  m_managers.remove(m);
284  return;
285  }
286  }
287  }
288  private:
289  void breakConnection(QtAbstractPropertyManager *manager)
290 
291  {
292  QSetIterator<PropertyManager *> it(m_managers);
293  while (it.hasNext())
294  {
295  PropertyManager *m = it.next();
296  if (m == manager)
297  {
298  removePropertyManager(m);
299  return;
300  }
301  }
302  }
303  private:
304  QSet<PropertyManager *> m_managers;
305  friend class QtAbstractPropertyEditor;
306 };
307 
310 
312 {
313  public:
314  QtProperty *property() const;
315  QtBrowserItem *parent() const;
316  QList<QtBrowserItem *> children() const;
317  QtAbstractPropertyBrowser *browser() const;
318  private:
319  explicit QtBrowserItem(QtAbstractPropertyBrowser *browser,
320  QtProperty *property, QtBrowserItem *parent);
321  ~QtBrowserItem();
322  QtBrowserItemPrivate *d_ptr;
324 };
325 
327 {
328  public:
330  QtProperty *property, QtBrowserItem *parent)
331  : m_browser(browser), m_property(property), m_parent(parent), q_ptr(0) {}
332 
333  void addChild(QtBrowserItem *index, QtBrowserItem *after);
334  void removeChild(QtBrowserItem *index);
335 
339 
341 
342  QList<QtBrowserItem *> m_children;
343 };
344 
346 {
348  Q_DECLARE_PUBLIC(QtAbstractPropertyBrowser)
349  public:
351 
352  void insertSubTree(QtProperty *property,
353  QtProperty *parentProperty);
354  void removeSubTree(QtProperty *property,
355  QtProperty *parentProperty);
356  void createBrowserIndexes(QtProperty *property, QtProperty *parentProperty,
357  QtProperty *afterProperty);
358  void removeBrowserIndexes(QtProperty *property, QtProperty *parentProperty);
359  QtBrowserItem *createBrowserIndex(QtProperty *property,
360  QtBrowserItem *parentIndex, QtBrowserItem *afterIndex);
361  void removeBrowserIndex(QtBrowserItem *index);
362  void clearIndex(QtBrowserItem *index);
363 
364  void slotPropertyInserted(QtProperty *property,
365  QtProperty *parentProperty, QtProperty *afterProperty);
366  void slotPropertyRemoved(QtProperty *property, QtProperty *parentProperty);
367  void slotPropertyDestroyed(QtProperty *property);
368  void slotPropertyDataChanged(QtProperty *property);
369 
370  QList<QtProperty *> m_subItems;
372  QList<QtProperty *> > m_managerToProperties;
373  QMap<QtProperty *, QList<QtProperty *> > m_propertyToParents;
374 
375  QMap<QtProperty *, QtBrowserItem *> m_topLevelPropertyToIndex;
376  QList<QtBrowserItem *> m_topLevelIndexes;
377  QMap<QtProperty *, QList<QtBrowserItem *> > m_propertyToIndexes;
378 
379  QtBrowserItem *m_currentItem;
380 };
381 
382 
383 
385 {
386  Q_OBJECT
387  public:
388 
389  explicit QtAbstractPropertyBrowser(QWidget *parent = 0);
391 
392  QList<QtProperty *> properties() const;
393  QList<QtBrowserItem *> items(QtProperty *property) const;
394  QtBrowserItem *topLevelItem(QtProperty *property) const;
395  QList<QtBrowserItem *> topLevelItems() const;
396  void clear();
397 
398  template <class PropertyManager>
399  void setFactoryForManager(PropertyManager *manager,
401 
402  {
403  QtAbstractPropertyManager *abstractManager = manager;
404  QtAbstractEditorFactoryBase *abstractFactory = factory;
405 
406  if (addFactory(abstractManager, abstractFactory))
407  factory->addPropertyManager(manager);
408  }
409 
410  void unsetFactoryForManager(QtAbstractPropertyManager *manager);
411 
412  QtBrowserItem *currentItem() const;
413  void setCurrentItem(QtBrowserItem *e);
414 
415  Q_SIGNALS:
416  void currentItemChanged(QtBrowserItem *e);
417 
418  public Q_SLOTS:
419 
420  QtBrowserItem *addProperty(QtProperty *property);
421  QtBrowserItem *insertProperty(QtProperty *property,
422  QtProperty *afterProperty);
423  void removeProperty(QtProperty *property);
424 
425  protected:
426 
427  virtual void itemInserted(QtBrowserItem *item,
428  QtBrowserItem *afterItem) = 0;
429  virtual void itemRemoved(QtBrowserItem *item) = 0;
430  // can be tooltip, statustip, whatsthis, name, icon, text.
431  virtual void itemChanged(QtBrowserItem *item) = 0;
432 
433  virtual QWidget *createEditor(QtProperty *property, QWidget *parent);
434  private:
435 
436  bool addFactory(QtAbstractPropertyManager *abstractManager,
437  QtAbstractEditorFactoryBase *abstractFactory);
438 
440  Q_DECLARE_PRIVATE(QtAbstractPropertyBrowser)
441  Q_DISABLE_COPY(QtAbstractPropertyBrowser)
442  Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *,
443  QtProperty *, QtProperty *))
444  Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty *,
445  QtProperty *))
446  Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *))
447  Q_PRIVATE_SLOT(d_func(), void slotPropertyDataChanged(QtProperty *))
448 };
449 
450 #if QT_VERSION >= 0x040400
451 QT_END_NAMESPACE
452 #endif
453 
454 #endif // QTPROPERTYBROWSER_H
QtAbstractEditorFactoryBase(QObject *parent=0)
Definition: qtpropertybrowser.h:198
Definition: qtpropertybrowser.h:116
QtAbstractPropertyBrowser *const m_browser
Definition: qtpropertybrowser.h:336
Definition: qtpropertybrowser.h:384
Definition: qtpropertybrowser.h:311
Definition: qtpropertybrowser.h:176
QList< QtProperty * > m_subItems
Definition: qtpropertybrowser.h:127
Definition: qtpropertybrowser.h:141
Definition: qtpropertybrowser.h:326
QtBrowserItem * q_ptr
Definition: qtpropertybrowser.h:340
void propertyChanged()
void addPropertyManager(PropertyManager *manager)
Definition: qtpropertybrowser.h:228
QString m_statusTip
Definition: qtpropertybrowser.h:130
QtAbstractPropertyManager * propertyManager() const
QtBrowserItem * m_parent
Definition: qtpropertybrowser.h:338
Definition: qtpropertybrowser.h:209
QtAbstractEditorFactory(QObject *parent)
Definition: qtpropertybrowser.h:212
QSet< QtProperty * > m_parentItems
Definition: qtpropertybrowser.h:126
GAZEBO_VISIBLE void enable()
Enable sensors.
QWidget * createEditor(QtProperty *property, QWidget *parent)
Definition: qtpropertybrowser.h:214
bool m_modified
Definition: qtpropertybrowser.h:134
void setFactoryForManager(PropertyManager *manager, QtAbstractEditorFactory< PropertyManager > *factory)
Definition: qtpropertybrowser.h:399
QList< QtBrowserItem * > m_children
Definition: qtpropertybrowser.h:342
void managerDestroyed(QObject *manager)
Definition: qtpropertybrowser.h:274
QtBrowserItemPrivate(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent)
Definition: qtpropertybrowser.h:329
#define NULL
Definition: CommonTypes.hh:30
void setEnabled(bool _enabled)
Definition: SkyX.h:355
#define QT_QTPROPERTYBROWSER_EXPORT
Definition: qtpropertybrowser.h:68
QtProperty * m_property
Definition: qtpropertybrowser.h:337
Definition: qtpropertybrowser.h:77
QString m_toolTip
Definition: qtpropertybrowser.h:129
void removePropertyManager(PropertyManager *manager)
Definition: qtpropertybrowser.h:238
QString m_whatsThis
Definition: qtpropertybrowser.h:131
QString m_name
Definition: qtpropertybrowser.h:132
PropertyManager * propertyManager(QtProperty *property) const
Definition: qtpropertybrowser.h:253
QLineEdit::EchoMode EchoMode
Definition: qtpropertybrowser.h:71
QtProperty * q_ptr
Definition: qtpropertybrowser.h:124
Definition: qtpropertybrowser.h:345
Definition: qtpropertybrowser.h:192
QSet< PropertyManager * > propertyManagers() const
Definition: qtpropertybrowser.h:248
QtPropertyPrivate(QtAbstractPropertyManager *manager)
Definition: qtpropertybrowser.h:119
bool m_enabled
Definition: qtpropertybrowser.h:133
QtAbstractPropertyManager *const m_manager
Definition: qtpropertybrowser.h:136