itom
Loading...
Searching...
No Matches
qtpropertybrowser.h
1/****************************************************************************
2**
3** Copyright (C) 2012 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#ifndef QTPROPERTYBROWSER_H
43#define QTPROPERTYBROWSER_H
44
45#include <QWidget>
46#include <QtCore/QSet>
47#include <QLineEdit>
48
49#include "../commonWidgets.h"
50
51#if QT_VERSION >= 0x040400
52QT_BEGIN_NAMESPACE
53#endif
54
55typedef QLineEdit::EchoMode EchoMode;
56
59
60class ITOMWIDGETS_EXPORT QtProperty
61{
62public:
63 virtual ~QtProperty();
64
65 QList<QtProperty *> subProperties() const;
66
67 QtAbstractPropertyManager *propertyManager() const;
68
69 QString toolTip() const;
70 QString statusTip() const;
71 QString whatsThis() const;
72 QString propertyName() const;
73 bool isEnabled() const;
74 bool isModified() const;
75
76 bool hasValue() const;
77 QIcon valueIcon() const;
78 QString valueText() const;
79 QString displayText() const;
80
81 void setToolTip(const QString &text);
82 void setStatusTip(const QString &text);
83 void setWhatsThis(const QString &text);
84 void setPropertyName(const QString &text);
85 void setEnabled(bool enable);
86 void setModified(bool modified);
87
88 void addSubProperty(QtProperty *property);
89 void insertSubProperty(QtProperty *property, QtProperty *afterProperty);
90 void removeSubProperty(QtProperty *property);
91protected:
92 explicit QtProperty(QtAbstractPropertyManager *manager);
93 void propertyChanged();
94private:
95 friend class QtAbstractPropertyManager;
96 QtPropertyPrivate *d_ptr;
97};
98
100
101class ITOMWIDGETS_EXPORT QtAbstractPropertyManager : public QObject
102{
103 Q_OBJECT
104public:
105
106 explicit QtAbstractPropertyManager(QObject *parent = 0);
108
109 QSet<QtProperty *> properties() const;
110 void clear() const;
111
112 QtProperty *addProperty(const QString &name = QString());
113Q_SIGNALS:
114
116 QtProperty *parent, QtProperty *after);
118 void propertyRemoved(QtProperty *property, QtProperty *parent);
120protected:
121 virtual bool hasValue(const QtProperty *property) const;
122 virtual QIcon valueIcon(const QtProperty *property) const;
123 virtual QString valueText(const QtProperty *property) const;
124 virtual QString displayText(const QtProperty *property) const;
125 virtual EchoMode echoMode(const QtProperty *) const;
126 virtual void initializeProperty(QtProperty *property) = 0;
127 virtual void uninitializeProperty(QtProperty *property);
128 virtual QtProperty *createProperty();
129private:
130 friend class QtProperty;
132 Q_DECLARE_PRIVATE(QtAbstractPropertyManager)
133 Q_DISABLE_COPY(QtAbstractPropertyManager)
134};
135
136class ITOMWIDGETS_EXPORT QtAbstractEditorFactoryBase : public QObject
137{
138 Q_OBJECT
139public:
140 virtual QWidget *createEditor(QtProperty *property, QWidget *parent) = 0;
141protected:
142 explicit QtAbstractEditorFactoryBase(QObject *parent = 0)
143 : QObject(parent) {}
144
145 virtual void breakConnection(QtAbstractPropertyManager *manager) = 0;
146protected Q_SLOTS:
147 virtual void managerDestroyed(QObject *manager) = 0;
148
149 friend class QtAbstractPropertyBrowser;
150};
151
152template <class PropertyManager>
154{
155public:
156 explicit QtAbstractEditorFactory(QObject *parent) : QtAbstractEditorFactoryBase(parent) {}
157 QWidget *createEditor(QtProperty *property, QWidget *parent)
158 {
159 QSetIterator<PropertyManager *> it(m_managers);
160 while (it.hasNext()) {
161 PropertyManager *manager = it.next();
162 if (manager == property->propertyManager()) {
163 return createEditor(manager, property, parent);
164 }
165 }
166 return 0;
167 }
168 void addPropertyManager(PropertyManager *manager)
169 {
170 if (m_managers.contains(manager))
171 return;
172 m_managers.insert(manager);
173 connectPropertyManager(manager);
174 connect(manager, SIGNAL(destroyed(QObject *)),
175 this, SLOT(managerDestroyed(QObject *)));
176 }
177 void removePropertyManager(PropertyManager *manager)
178 {
179 if (!m_managers.contains(manager))
180 return;
181 disconnect(manager, SIGNAL(destroyed(QObject *)),
182 this, SLOT(managerDestroyed(QObject *)));
184 m_managers.remove(manager);
185 }
186 QSet<PropertyManager *> propertyManagers() const
187 {
188 return m_managers;
189 }
190 PropertyManager *propertyManager(QtProperty *property) const
191 {
192 QtAbstractPropertyManager *manager = property->propertyManager();
193 QSetIterator<PropertyManager *> itManager(m_managers);
194 while (itManager.hasNext()) {
195 PropertyManager *m = itManager.next();
196 if (m == manager) {
197 return m;
198 }
199 }
200 return 0;
201 }
202protected:
203 virtual void connectPropertyManager(PropertyManager *manager) = 0;
204 virtual QWidget *createEditor(PropertyManager *manager, QtProperty *property,
205 QWidget *parent) = 0;
206 virtual void disconnectPropertyManager(PropertyManager *manager) = 0;
207 void managerDestroyed(QObject *manager)
208 {
209 QSetIterator<PropertyManager *> it(m_managers);
210 while (it.hasNext()) {
211 PropertyManager *m = it.next();
212 if (m == manager) {
213 m_managers.remove(m);
214 return;
215 }
216 }
217 }
218private:
219 void breakConnection(QtAbstractPropertyManager *manager)
220 {
221 QSetIterator<PropertyManager *> it(m_managers);
222 while (it.hasNext()) {
223 PropertyManager *m = it.next();
224 if (m == manager) {
226 return;
227 }
228 }
229 }
230private:
231 QSet<PropertyManager *> m_managers;
232 friend class QtAbstractPropertyEditor;
233};
234
237
238class ITOMWIDGETS_EXPORT QtBrowserItem
239{
240public:
241 QtProperty *property() const;
242 QtBrowserItem *parent() const;
243 QList<QtBrowserItem *> children() const;
244 QtAbstractPropertyBrowser *browser() const;
245private:
246 explicit QtBrowserItem(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent);
250};
251
253
254class ITOMWIDGETS_EXPORT QtAbstractPropertyBrowser : public QWidget
255{
256 Q_OBJECT
257public:
258
259 explicit QtAbstractPropertyBrowser(QWidget *parent = 0);
261
262 QList<QtProperty *> properties() const;
263 QList<QtBrowserItem *> items(QtProperty *property) const;
264 QtBrowserItem *topLevelItem(QtProperty *property) const;
265 QList<QtBrowserItem *> topLevelItems() const;
266 void clear();
267
268 template <class PropertyManager>
269 void setFactoryForManager(PropertyManager *manager,
271 QtAbstractPropertyManager *abstractManager = manager;
272 QtAbstractEditorFactoryBase *abstractFactory = factory;
273
274 if (addFactory(abstractManager, abstractFactory))
275 factory->addPropertyManager(manager);
276 }
277
278 void unsetFactoryForManager(QtAbstractPropertyManager *manager);
279
280 QtBrowserItem *currentItem() const;
281 void setCurrentItem(QtBrowserItem *);
282
283Q_SIGNALS:
285
286public Q_SLOTS:
287
288 QtBrowserItem *addProperty(QtProperty *property);
289 QtBrowserItem *insertProperty(QtProperty *property, QtProperty *afterProperty);
290 void removeProperty(QtProperty *property);
291
292protected:
293
294 virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem) = 0;
295 virtual void itemRemoved(QtBrowserItem *item) = 0;
296 // can be tooltip, statustip, whatsthis, name, icon, text.
297 virtual void itemChanged(QtBrowserItem *item) = 0;
298
299 virtual QWidget *createEditor(QtProperty *property, QWidget *parent);
300private:
301
302 bool addFactory(QtAbstractPropertyManager *abstractManager,
303 QtAbstractEditorFactoryBase *abstractFactory);
304
306 Q_DECLARE_PRIVATE(QtAbstractPropertyBrowser)
307 Q_DISABLE_COPY(QtAbstractPropertyBrowser)
308 Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *,
310 Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty *,
311 QtProperty *))
312 Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *))
313 Q_PRIVATE_SLOT(d_func(), void slotPropertyDataChanged(QtProperty *))
314
315};
316
317#if QT_VERSION >= 0x040400
318QT_END_NAMESPACE
319#endif
320
321#endif // QTPROPERTYBROWSER_H
The QtAbstractEditorFactoryBase provides an interface for editor factories.
Definition qtpropertybrowser.h:137
virtual QWidget * createEditor(QtProperty *property, QWidget *parent)=0
QtAbstractEditorFactoryBase(QObject *parent=0)
Definition qtpropertybrowser.h:142
The QtAbstractEditorFactory is the base template class for editor factories.
Definition qtpropertybrowser.h:154
void removePropertyManager(PropertyManager *manager)
Definition qtpropertybrowser.h:177
QtAbstractEditorFactory(QObject *parent)
Definition qtpropertybrowser.h:156
QWidget * createEditor(QtProperty *property, QWidget *parent)
Definition qtpropertybrowser.h:157
virtual void disconnectPropertyManager(PropertyManager *manager)=0
PropertyManager * propertyManager(QtProperty *property) const
Definition qtpropertybrowser.h:190
QSet< PropertyManager * > propertyManagers() const
Definition qtpropertybrowser.h:186
virtual QWidget * createEditor(PropertyManager *manager, QtProperty *property, QWidget *parent)=0
void addPropertyManager(PropertyManager *manager)
Definition qtpropertybrowser.h:168
virtual void connectPropertyManager(PropertyManager *manager)=0
QtAbstractPropertyBrowser provides a base class for implementing property browsers.
Definition qtpropertybrowser.h:255
virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem)=0
void currentItemChanged(QtBrowserItem *)
void setFactoryForManager(PropertyManager *manager, QtAbstractEditorFactory< PropertyManager > *factory)
Definition qtpropertybrowser.h:269
virtual void itemRemoved(QtBrowserItem *item)=0
virtual void itemChanged(QtBrowserItem *item)=0
Definition qtpropertybrowser.cpp:1232
The QtAbstractPropertyManager provides an interface for property managers.
Definition qtpropertybrowser.h:102
virtual void initializeProperty(QtProperty *property)=0
void propertyDestroyed(QtProperty *property)
void propertyInserted(QtProperty *property, QtProperty *parent, QtProperty *after)
void propertyChanged(QtProperty *property)
void propertyRemoved(QtProperty *property, QtProperty *parent)
Definition qtpropertybrowser.cpp:79
The QtBrowserItem class represents a property in a property browser instance.
Definition qtpropertybrowser.h:239
Definition qtpropertybrowser.cpp:1104
The QtProperty class encapsulates an instance of a property.
Definition qtpropertybrowser.h:61
QtAbstractPropertyManager * propertyManager() const
Definition qtpropertybrowser.cpp:202
Definition qtpropertybrowser.cpp:57