1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | // |
5 | // W A R N I N G |
6 | // ------------- |
7 | // |
8 | // This file is not part of the Qt API. It exists for the convenience |
9 | // of Qt Designer. This header file may change from version to version |
10 | // without notice, or even be removed. |
11 | // |
12 | // We mean it. |
13 | // |
14 | |
15 | #ifndef QTPROPERTYBROWSER_H |
16 | #define QTPROPERTYBROWSER_H |
17 | |
18 | #include <QtWidgets/QWidget> |
19 | #include <QtCore/QSet> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | class QtAbstractPropertyManager; |
24 | class QtPropertyPrivate; |
25 | |
26 | class QtProperty |
27 | { |
28 | public: |
29 | virtual ~QtProperty(); |
30 | |
31 | QList<QtProperty *> subProperties() const; |
32 | QtProperty *parentProperty() const; |
33 | |
34 | QtAbstractPropertyManager *propertyManager() const; |
35 | |
36 | QString toolTip() const { return valueToolTip(); } // Compatibility |
37 | QString valueToolTip() const; |
38 | QString descriptionToolTip() const; |
39 | QString statusTip() const; |
40 | QString whatsThis() const; |
41 | QString propertyName() const; |
42 | bool isEnabled() const; |
43 | bool isModified() const; |
44 | |
45 | bool hasValue() const; |
46 | QIcon valueIcon() const; |
47 | QString valueText() const; |
48 | |
49 | void setToolTip(const QString &text) { setValueToolTip(text); } // Compatibility |
50 | void setValueToolTip(const QString &text); |
51 | void setDescriptionToolTip(const QString &text); |
52 | void setStatusTip(const QString &text); |
53 | void setWhatsThis(const QString &text); |
54 | void setPropertyName(const QString &text); |
55 | void setEnabled(bool enable); |
56 | void setModified(bool modified); |
57 | |
58 | void addSubProperty(QtProperty *property); |
59 | void insertSubProperty(QtProperty *property, QtProperty *afterProperty); |
60 | void removeSubProperty(QtProperty *property); |
61 | protected: |
62 | explicit QtProperty(QtAbstractPropertyManager *manager); |
63 | void propertyChanged(); |
64 | private: |
65 | friend class QtAbstractPropertyManager; |
66 | QScopedPointer<QtPropertyPrivate> d_ptr; |
67 | }; |
68 | |
69 | class QtAbstractPropertyManagerPrivate; |
70 | |
71 | class QtAbstractPropertyManager : public QObject |
72 | { |
73 | Q_OBJECT |
74 | public: |
75 | |
76 | explicit QtAbstractPropertyManager(QObject *parent = 0); |
77 | ~QtAbstractPropertyManager(); |
78 | |
79 | QSet<QtProperty *> properties() const; |
80 | void clear() const; |
81 | |
82 | QtProperty *addProperty(const QString &name = QString()); |
83 | Q_SIGNALS: |
84 | void propertyInserted(QtProperty *property, QtProperty *parent, QtProperty *after); |
85 | void propertyChanged(QtProperty *property); |
86 | void propertyRemoved(QtProperty *property, QtProperty *parent); |
87 | void propertyDestroyed(QtProperty *property); |
88 | protected: |
89 | virtual bool hasValue(const QtProperty *property) const; |
90 | virtual QIcon valueIcon(const QtProperty *property) const; |
91 | virtual QString valueText(const QtProperty *property) const; |
92 | virtual void initializeProperty(QtProperty *property) = 0; |
93 | virtual void uninitializeProperty(QtProperty *property); |
94 | virtual QtProperty *createProperty(); |
95 | private: |
96 | friend class QtProperty; |
97 | QScopedPointer<QtAbstractPropertyManagerPrivate> d_ptr; |
98 | Q_DECLARE_PRIVATE(QtAbstractPropertyManager) |
99 | Q_DISABLE_COPY_MOVE(QtAbstractPropertyManager) |
100 | }; |
101 | |
102 | class QtAbstractEditorFactoryBase : public QObject |
103 | { |
104 | Q_OBJECT |
105 | public: |
106 | virtual QWidget *createEditor(QtProperty *property, QWidget *parent) = 0; |
107 | protected: |
108 | explicit QtAbstractEditorFactoryBase(QObject *parent = 0) |
109 | : QObject(parent) {} |
110 | |
111 | virtual void breakConnection(QtAbstractPropertyManager *manager) = 0; |
112 | protected Q_SLOTS: |
113 | virtual void managerDestroyed(QObject *manager) = 0; |
114 | |
115 | friend class QtAbstractPropertyBrowser; |
116 | }; |
117 | |
118 | template <class PropertyManager> |
119 | class QtAbstractEditorFactory : public QtAbstractEditorFactoryBase |
120 | { |
121 | public: |
122 | explicit QtAbstractEditorFactory(QObject *parent) : QtAbstractEditorFactoryBase(parent) {} |
123 | QWidget *createEditor(QtProperty *property, QWidget *parent) override |
124 | { |
125 | for (PropertyManager *manager : std::as_const(m_managers)) { |
126 | if (manager == property->propertyManager()) { |
127 | return createEditor(manager, property, parent); |
128 | } |
129 | } |
130 | return 0; |
131 | } |
132 | void addPropertyManager(PropertyManager *manager) |
133 | { |
134 | if (m_managers.contains(manager)) |
135 | return; |
136 | m_managers.insert(manager); |
137 | connectPropertyManager(manager); |
138 | connect(manager, &QObject::destroyed, |
139 | this, &QtAbstractEditorFactory<PropertyManager>::managerDestroyed); |
140 | } |
141 | void removePropertyManager(PropertyManager *manager) |
142 | { |
143 | if (!m_managers.contains(manager)) |
144 | return; |
145 | disconnect(manager, &QObject::destroyed, |
146 | this, &QtAbstractEditorFactory<PropertyManager>::managerDestroyed); |
147 | disconnectPropertyManager(manager); |
148 | m_managers.remove(manager); |
149 | } |
150 | QSet<PropertyManager *> propertyManagers() const |
151 | { |
152 | return m_managers; |
153 | } |
154 | PropertyManager *propertyManager(QtProperty *property) const |
155 | { |
156 | QtAbstractPropertyManager *manager = property->propertyManager(); |
157 | for (PropertyManager *m : std::as_const(m_managers)) { |
158 | if (m == manager) { |
159 | return m; |
160 | } |
161 | } |
162 | return 0; |
163 | } |
164 | protected: |
165 | virtual void connectPropertyManager(PropertyManager *manager) = 0; |
166 | virtual QWidget *createEditor(PropertyManager *manager, QtProperty *property, |
167 | QWidget *parent) = 0; |
168 | virtual void disconnectPropertyManager(PropertyManager *manager) = 0; |
169 | void managerDestroyed(QObject *manager) override |
170 | { |
171 | for (PropertyManager *m : std::as_const(m_managers)) { |
172 | if (m == manager) { |
173 | m_managers.remove(m); |
174 | return; |
175 | } |
176 | } |
177 | } |
178 | private: |
179 | void breakConnection(QtAbstractPropertyManager *manager) override |
180 | { |
181 | for (PropertyManager *m : std::as_const(m_managers)) { |
182 | if (m == manager) { |
183 | removePropertyManager(manager: m); |
184 | return; |
185 | } |
186 | } |
187 | } |
188 | private: |
189 | QSet<PropertyManager *> m_managers; |
190 | friend class QtAbstractPropertyEditor; |
191 | }; |
192 | |
193 | class QtAbstractPropertyBrowser; |
194 | class QtBrowserItemPrivate; |
195 | |
196 | class QtBrowserItem |
197 | { |
198 | public: |
199 | QtProperty *property() const; |
200 | QtBrowserItem *parent() const; |
201 | QList<QtBrowserItem *> children() const; |
202 | QtAbstractPropertyBrowser *browser() const; |
203 | private: |
204 | explicit QtBrowserItem(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent); |
205 | ~QtBrowserItem(); |
206 | QScopedPointer<QtBrowserItemPrivate> d_ptr; |
207 | friend class QtAbstractPropertyBrowserPrivate; |
208 | }; |
209 | |
210 | class QtAbstractPropertyBrowserPrivate; |
211 | |
212 | class QtAbstractPropertyBrowser : public QWidget |
213 | { |
214 | Q_OBJECT |
215 | public: |
216 | |
217 | explicit QtAbstractPropertyBrowser(QWidget *parent = 0); |
218 | ~QtAbstractPropertyBrowser(); |
219 | |
220 | QList<QtProperty *> properties() const; |
221 | QList<QtBrowserItem *> items(QtProperty *property) const; |
222 | QtBrowserItem *topLevelItem(QtProperty *property) const; |
223 | QList<QtBrowserItem *> topLevelItems() const; |
224 | void clear(); |
225 | |
226 | template <class PropertyManager> |
227 | void setFactoryForManager(PropertyManager *manager, |
228 | QtAbstractEditorFactory<PropertyManager> *factory) { |
229 | QtAbstractPropertyManager *abstractManager = manager; |
230 | QtAbstractEditorFactoryBase *abstractFactory = factory; |
231 | |
232 | if (addFactory(abstractManager, abstractFactory)) |
233 | factory->addPropertyManager(manager); |
234 | } |
235 | |
236 | void unsetFactoryForManager(QtAbstractPropertyManager *manager); |
237 | |
238 | QtBrowserItem *currentItem() const; |
239 | void setCurrentItem(QtBrowserItem *); |
240 | |
241 | Q_SIGNALS: |
242 | void currentItemChanged(QtBrowserItem *); |
243 | |
244 | public Q_SLOTS: |
245 | |
246 | QtBrowserItem *addProperty(QtProperty *property); |
247 | QtBrowserItem *insertProperty(QtProperty *property, QtProperty *afterProperty); |
248 | void removeProperty(QtProperty *property); |
249 | |
250 | protected: |
251 | |
252 | virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem) = 0; |
253 | virtual void itemRemoved(QtBrowserItem *item) = 0; |
254 | // can be tooltip, statustip, whatsthis, name, icon, text. |
255 | virtual void itemChanged(QtBrowserItem *item) = 0; |
256 | |
257 | virtual QWidget *createEditor(QtProperty *property, QWidget *parent); |
258 | private: |
259 | |
260 | bool addFactory(QtAbstractPropertyManager *abstractManager, |
261 | QtAbstractEditorFactoryBase *abstractFactory); |
262 | |
263 | QScopedPointer<QtAbstractPropertyBrowserPrivate> d_ptr; |
264 | Q_DECLARE_PRIVATE(QtAbstractPropertyBrowser) |
265 | Q_DISABLE_COPY_MOVE(QtAbstractPropertyBrowser) |
266 | }; |
267 | |
268 | QT_END_NAMESPACE |
269 | |
270 | #endif // QTPROPERTYBROWSER_H |
271 |
Definitions
- QtProperty
- toolTip
- setToolTip
- QtAbstractPropertyManager
- QtAbstractPropertyManager
- QtAbstractEditorFactoryBase
- QtAbstractEditorFactoryBase
- QtAbstractEditorFactory
- QtAbstractEditorFactory
- createEditor
- addPropertyManager
- removePropertyManager
- propertyManagers
- propertyManager
- managerDestroyed
- breakConnection
- QtBrowserItem
- QtAbstractPropertyBrowser
- setFactoryForManager
- QtAbstractPropertyBrowser
Learn to use CMake with our Intro Training
Find out more