1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the tools applications of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QTPROPERTYBROWSER_H
|
---|
43 | #define QTPROPERTYBROWSER_H
|
---|
44 |
|
---|
45 | #include <QtGui/QWidget>
|
---|
46 | #include <QtCore/QSet>
|
---|
47 |
|
---|
48 | #if QT_VERSION >= 0x040400
|
---|
49 | QT_BEGIN_NAMESPACE
|
---|
50 | #endif
|
---|
51 |
|
---|
52 |
|
---|
53 |
|
---|
54 | class QtAbstractPropertyManager;
|
---|
55 | class QtPropertyPrivate;
|
---|
56 |
|
---|
57 | class QtProperty
|
---|
58 | {
|
---|
59 | public:
|
---|
60 | virtual ~QtProperty();
|
---|
61 |
|
---|
62 | QList<QtProperty *> subProperties() const;
|
---|
63 |
|
---|
64 | QtAbstractPropertyManager *propertyManager() const;
|
---|
65 |
|
---|
66 | QString toolTip() const;
|
---|
67 | QString statusTip() const;
|
---|
68 | QString whatsThis() const;
|
---|
69 | QString propertyName() const;
|
---|
70 | bool isEnabled() const;
|
---|
71 | bool isModified() const;
|
---|
72 |
|
---|
73 | bool hasValue() const;
|
---|
74 | QIcon valueIcon() const;
|
---|
75 | QString valueText() const;
|
---|
76 |
|
---|
77 | void setToolTip(const QString &text);
|
---|
78 | void setStatusTip(const QString &text);
|
---|
79 | void setWhatsThis(const QString &text);
|
---|
80 | void setPropertyName(const QString &text);
|
---|
81 | void setEnabled(bool enable);
|
---|
82 | void setModified(bool modified);
|
---|
83 |
|
---|
84 | void addSubProperty(QtProperty *property);
|
---|
85 | void insertSubProperty(QtProperty *property, QtProperty *afterProperty);
|
---|
86 | void removeSubProperty(QtProperty *property);
|
---|
87 | protected:
|
---|
88 | explicit QtProperty(QtAbstractPropertyManager *manager);
|
---|
89 | void propertyChanged();
|
---|
90 | private:
|
---|
91 | friend class QtAbstractPropertyManager;
|
---|
92 | QtPropertyPrivate *d_ptr;
|
---|
93 | };
|
---|
94 |
|
---|
95 | class QtAbstractPropertyManagerPrivate;
|
---|
96 |
|
---|
97 | class QtAbstractPropertyManager : public QObject
|
---|
98 | {
|
---|
99 | Q_OBJECT
|
---|
100 | public:
|
---|
101 |
|
---|
102 | explicit QtAbstractPropertyManager(QObject *parent = 0);
|
---|
103 | ~QtAbstractPropertyManager();
|
---|
104 |
|
---|
105 | QSet<QtProperty *> properties() const;
|
---|
106 | void clear() const;
|
---|
107 |
|
---|
108 | QtProperty *addProperty(const QString &name = QString());
|
---|
109 | Q_SIGNALS:
|
---|
110 |
|
---|
111 | void propertyInserted(QtProperty *property,
|
---|
112 | QtProperty *parent, QtProperty *after);
|
---|
113 | void propertyChanged(QtProperty *property);
|
---|
114 | void propertyRemoved(QtProperty *property, QtProperty *parent);
|
---|
115 | void propertyDestroyed(QtProperty *property);
|
---|
116 | protected:
|
---|
117 | virtual bool hasValue(const QtProperty *property) const;
|
---|
118 | virtual QIcon valueIcon(const QtProperty *property) const;
|
---|
119 | virtual QString valueText(const QtProperty *property) const;
|
---|
120 | virtual void initializeProperty(QtProperty *property) = 0;
|
---|
121 | virtual void uninitializeProperty(QtProperty *property);
|
---|
122 | virtual QtProperty *createProperty();
|
---|
123 | private:
|
---|
124 | friend class QtProperty;
|
---|
125 | QtAbstractPropertyManagerPrivate *d_ptr;
|
---|
126 | Q_DECLARE_PRIVATE(QtAbstractPropertyManager)
|
---|
127 | Q_DISABLE_COPY(QtAbstractPropertyManager)
|
---|
128 | };
|
---|
129 |
|
---|
130 | class QtAbstractEditorFactoryBase : public QObject
|
---|
131 | {
|
---|
132 | Q_OBJECT
|
---|
133 | public:
|
---|
134 | virtual QWidget *createEditor(QtProperty *property, QWidget *parent) = 0;
|
---|
135 | protected:
|
---|
136 | explicit QtAbstractEditorFactoryBase(QObject *parent = 0)
|
---|
137 | : QObject(parent) {}
|
---|
138 |
|
---|
139 | virtual void breakConnection(QtAbstractPropertyManager *manager) = 0;
|
---|
140 | protected Q_SLOTS:
|
---|
141 | virtual void managerDestroyed(QObject *manager) = 0;
|
---|
142 |
|
---|
143 | friend class QtAbstractPropertyBrowser;
|
---|
144 | };
|
---|
145 |
|
---|
146 | template <class PropertyManager>
|
---|
147 | class QtAbstractEditorFactory : public QtAbstractEditorFactoryBase
|
---|
148 | {
|
---|
149 | public:
|
---|
150 | explicit QtAbstractEditorFactory(QObject *parent) : QtAbstractEditorFactoryBase(parent) {}
|
---|
151 | QWidget *createEditor(QtProperty *property, QWidget *parent)
|
---|
152 | {
|
---|
153 | QSetIterator<PropertyManager *> it(m_managers);
|
---|
154 | while (it.hasNext()) {
|
---|
155 | PropertyManager *manager = it.next();
|
---|
156 | if (manager == property->propertyManager()) {
|
---|
157 | return createEditor(manager, property, parent);
|
---|
158 | }
|
---|
159 | }
|
---|
160 | return 0;
|
---|
161 | }
|
---|
162 | void addPropertyManager(PropertyManager *manager)
|
---|
163 | {
|
---|
164 | if (m_managers.contains(manager))
|
---|
165 | return;
|
---|
166 | m_managers.insert(manager);
|
---|
167 | connectPropertyManager(manager);
|
---|
168 | connect(manager, SIGNAL(destroyed(QObject *)),
|
---|
169 | this, SLOT(managerDestroyed(QObject *)));
|
---|
170 | }
|
---|
171 | void removePropertyManager(PropertyManager *manager)
|
---|
172 | {
|
---|
173 | if (!m_managers.contains(manager))
|
---|
174 | return;
|
---|
175 | disconnect(manager, SIGNAL(destroyed(QObject *)),
|
---|
176 | this, SLOT(managerDestroyed(QObject *)));
|
---|
177 | disconnectPropertyManager(manager);
|
---|
178 | m_managers.remove(manager);
|
---|
179 | }
|
---|
180 | QSet<PropertyManager *> propertyManagers() const
|
---|
181 | {
|
---|
182 | return m_managers;
|
---|
183 | }
|
---|
184 | PropertyManager *propertyManager(QtProperty *property) const
|
---|
185 | {
|
---|
186 | QtAbstractPropertyManager *manager = property->propertyManager();
|
---|
187 | QSetIterator<PropertyManager *> itManager(m_managers);
|
---|
188 | while (itManager.hasNext()) {
|
---|
189 | PropertyManager *m = itManager.next();
|
---|
190 | if (m == manager) {
|
---|
191 | return m;
|
---|
192 | }
|
---|
193 | }
|
---|
194 | return 0;
|
---|
195 | }
|
---|
196 | protected:
|
---|
197 | virtual void connectPropertyManager(PropertyManager *manager) = 0;
|
---|
198 | virtual QWidget *createEditor(PropertyManager *manager, QtProperty *property,
|
---|
199 | QWidget *parent) = 0;
|
---|
200 | virtual void disconnectPropertyManager(PropertyManager *manager) = 0;
|
---|
201 | void managerDestroyed(QObject *manager)
|
---|
202 | {
|
---|
203 | QSetIterator<PropertyManager *> it(m_managers);
|
---|
204 | while (it.hasNext()) {
|
---|
205 | PropertyManager *m = it.next();
|
---|
206 | if (m == manager) {
|
---|
207 | m_managers.remove(m);
|
---|
208 | return;
|
---|
209 | }
|
---|
210 | }
|
---|
211 | }
|
---|
212 | private:
|
---|
213 | void breakConnection(QtAbstractPropertyManager *manager)
|
---|
214 | {
|
---|
215 | QSetIterator<PropertyManager *> it(m_managers);
|
---|
216 | while (it.hasNext()) {
|
---|
217 | PropertyManager *m = it.next();
|
---|
218 | if (m == manager) {
|
---|
219 | removePropertyManager(m);
|
---|
220 | return;
|
---|
221 | }
|
---|
222 | }
|
---|
223 | }
|
---|
224 | private:
|
---|
225 | QSet<PropertyManager *> m_managers;
|
---|
226 | friend class QtAbstractPropertyEditor;
|
---|
227 | };
|
---|
228 |
|
---|
229 | class QtAbstractPropertyBrowser;
|
---|
230 | class QtBrowserItemPrivate;
|
---|
231 |
|
---|
232 | class QtBrowserItem
|
---|
233 | {
|
---|
234 | public:
|
---|
235 | QtProperty *property() const;
|
---|
236 | QtBrowserItem *parent() const;
|
---|
237 | QList<QtBrowserItem *> children() const;
|
---|
238 | QtAbstractPropertyBrowser *browser() const;
|
---|
239 | private:
|
---|
240 | explicit QtBrowserItem(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent);
|
---|
241 | ~QtBrowserItem();
|
---|
242 | QtBrowserItemPrivate *d_ptr;
|
---|
243 | friend class QtAbstractPropertyBrowserPrivate;
|
---|
244 | };
|
---|
245 |
|
---|
246 | class QtAbstractPropertyBrowserPrivate;
|
---|
247 |
|
---|
248 | class QtAbstractPropertyBrowser : public QWidget
|
---|
249 | {
|
---|
250 | Q_OBJECT
|
---|
251 | public:
|
---|
252 |
|
---|
253 | explicit QtAbstractPropertyBrowser(QWidget *parent = 0);
|
---|
254 | ~QtAbstractPropertyBrowser();
|
---|
255 |
|
---|
256 | QList<QtProperty *> properties() const;
|
---|
257 | QList<QtBrowserItem *> items(QtProperty *property) const;
|
---|
258 | QtBrowserItem *topLevelItem(QtProperty *property) const;
|
---|
259 | QList<QtBrowserItem *> topLevelItems() const;
|
---|
260 | void clear();
|
---|
261 |
|
---|
262 | template <class PropertyManager>
|
---|
263 | void setFactoryForManager(PropertyManager *manager,
|
---|
264 | QtAbstractEditorFactory<PropertyManager> *factory) {
|
---|
265 | QtAbstractPropertyManager *abstractManager = manager;
|
---|
266 | QtAbstractEditorFactoryBase *abstractFactory = factory;
|
---|
267 |
|
---|
268 | if (addFactory(abstractManager, abstractFactory))
|
---|
269 | factory->addPropertyManager(manager);
|
---|
270 | }
|
---|
271 |
|
---|
272 | void unsetFactoryForManager(QtAbstractPropertyManager *manager);
|
---|
273 |
|
---|
274 | QtBrowserItem *currentItem() const;
|
---|
275 | void setCurrentItem(QtBrowserItem *);
|
---|
276 |
|
---|
277 | Q_SIGNALS:
|
---|
278 | void currentItemChanged(QtBrowserItem *);
|
---|
279 |
|
---|
280 | public Q_SLOTS:
|
---|
281 |
|
---|
282 | QtBrowserItem *addProperty(QtProperty *property);
|
---|
283 | QtBrowserItem *insertProperty(QtProperty *property, QtProperty *afterProperty);
|
---|
284 | void removeProperty(QtProperty *property);
|
---|
285 |
|
---|
286 | protected:
|
---|
287 |
|
---|
288 | virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem) = 0;
|
---|
289 | virtual void itemRemoved(QtBrowserItem *item) = 0;
|
---|
290 | // can be tooltip, statustip, whatsthis, name, icon, text.
|
---|
291 | virtual void itemChanged(QtBrowserItem *item) = 0;
|
---|
292 |
|
---|
293 | virtual QWidget *createEditor(QtProperty *property, QWidget *parent);
|
---|
294 | private:
|
---|
295 |
|
---|
296 | bool addFactory(QtAbstractPropertyManager *abstractManager,
|
---|
297 | QtAbstractEditorFactoryBase *abstractFactory);
|
---|
298 |
|
---|
299 | QtAbstractPropertyBrowserPrivate *d_ptr;
|
---|
300 | Q_DECLARE_PRIVATE(QtAbstractPropertyBrowser)
|
---|
301 | Q_DISABLE_COPY(QtAbstractPropertyBrowser)
|
---|
302 | Q_PRIVATE_SLOT(d_func(), void slotPropertyInserted(QtProperty *,
|
---|
303 | QtProperty *, QtProperty *))
|
---|
304 | Q_PRIVATE_SLOT(d_func(), void slotPropertyRemoved(QtProperty *,
|
---|
305 | QtProperty *))
|
---|
306 | Q_PRIVATE_SLOT(d_func(), void slotPropertyDestroyed(QtProperty *))
|
---|
307 | Q_PRIVATE_SLOT(d_func(), void slotPropertyDataChanged(QtProperty *))
|
---|
308 |
|
---|
309 | };
|
---|
310 |
|
---|
311 | #if QT_VERSION >= 0x040400
|
---|
312 | QT_END_NAMESPACE
|
---|
313 | #endif
|
---|
314 |
|
---|
315 | #endif // QTPROPERTYBROWSER_H
|
---|