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