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 | |
33 | QtAbstractPropertyManager *propertyManager() const; |
34 | |
35 | QString toolTip() const { return valueToolTip(); } // Compatibility |
36 | QString valueToolTip() const; |
37 | QString descriptionToolTip() const; |
38 | QString statusTip() const; |
39 | QString whatsThis() const; |
40 | QString propertyName() const; |
41 | bool isEnabled() const; |
42 | bool isModified() const; |
43 | |
44 | bool hasValue() const; |
45 | QIcon valueIcon() const; |
46 | QString valueText() const; |
47 | |
48 | void setToolTip(const QString &text) { setValueToolTip(text); } // Compatibility |
49 | void setValueToolTip(const QString &text); |
50 | void setDescriptionToolTip(const QString &text); |
51 | void setStatusTip(const QString &text); |
52 | void setWhatsThis(const QString &text); |
53 | void setPropertyName(const QString &text); |
54 | void setEnabled(bool enable); |
55 | void setModified(bool modified); |
56 | |
57 | void addSubProperty(QtProperty *property); |
58 | void insertSubProperty(QtProperty *property, QtProperty *afterProperty); |
59 | void removeSubProperty(QtProperty *property); |
60 | protected: |
61 | explicit QtProperty(QtAbstractPropertyManager *manager); |
62 | void propertyChanged(); |
63 | private: |
64 | friend class QtAbstractPropertyManager; |
65 | QScopedPointer<QtPropertyPrivate> d_ptr; |
66 | }; |
67 | |
68 | class QtAbstractPropertyManagerPrivate; |
69 | |
70 | class QtAbstractPropertyManager : public QObject |
71 | { |
72 | Q_OBJECT |
73 | public: |
74 | |
75 | explicit QtAbstractPropertyManager(QObject *parent = 0); |
76 | ~QtAbstractPropertyManager(); |
77 | |
78 | QSet<QtProperty *> properties() const; |
79 | void clear() const; |
80 | |
81 | QtProperty *addProperty(const QString &name = QString()); |
82 | Q_SIGNALS: |
83 | void propertyInserted(QtProperty *property, QtProperty *parent, QtProperty *after); |
84 | void propertyChanged(QtProperty *property); |
85 | void propertyRemoved(QtProperty *property, QtProperty *parent); |
86 | void propertyDestroyed(QtProperty *property); |
87 | protected: |
88 | virtual bool hasValue(const QtProperty *property) const; |
89 | virtual QIcon valueIcon(const QtProperty *property) const; |
90 | virtual QString valueText(const QtProperty *property) const; |
91 | virtual void initializeProperty(QtProperty *property) = 0; |
92 | virtual void uninitializeProperty(QtProperty *property); |
93 | virtual QtProperty *createProperty(); |
94 | private: |
95 | friend class QtProperty; |
96 | QScopedPointer<QtAbstractPropertyManagerPrivate> d_ptr; |
97 | Q_DECLARE_PRIVATE(QtAbstractPropertyManager) |
98 | Q_DISABLE_COPY_MOVE(QtAbstractPropertyManager) |
99 | }; |
100 | |
101 | class QtAbstractEditorFactoryBase : public QObject |
102 | { |
103 | Q_OBJECT |
104 | public: |
105 | virtual QWidget *createEditor(QtProperty *property, QWidget *parent) = 0; |
106 | protected: |
107 | explicit QtAbstractEditorFactoryBase(QObject *parent = 0) |
108 | : QObject(parent) {} |
109 | |
110 | virtual void breakConnection(QtAbstractPropertyManager *manager) = 0; |
111 | protected Q_SLOTS: |
112 | virtual void managerDestroyed(QObject *manager) = 0; |
113 | |
114 | friend class QtAbstractPropertyBrowser; |
115 | }; |
116 | |
117 | template <class PropertyManager> |
118 | class QtAbstractEditorFactory : public QtAbstractEditorFactoryBase |
119 | { |
120 | public: |
121 | explicit QtAbstractEditorFactory(QObject *parent) : QtAbstractEditorFactoryBase(parent) {} |
122 | QWidget *createEditor(QtProperty *property, QWidget *parent) override |
123 | { |
124 | for (PropertyManager *manager : std::as_const(m_managers)) { |
125 | if (manager == property->propertyManager()) { |
126 | return createEditor(manager, property, parent); |
127 | } |
128 | } |
129 | return 0; |
130 | } |
131 | void addPropertyManager(PropertyManager *manager) |
132 | { |
133 | if (m_managers.contains(manager)) |
134 | return; |
135 | m_managers.insert(manager); |
136 | connectPropertyManager(manager); |
137 | connect(manager, &QObject::destroyed, |
138 | this, &QtAbstractEditorFactory<PropertyManager>::managerDestroyed); |
139 | } |
140 | void removePropertyManager(PropertyManager *manager) |
141 | { |
142 | if (!m_managers.contains(manager)) |
143 | return; |
144 | disconnect(manager, &QObject::destroyed, |
145 | this, &QtAbstractEditorFactory<PropertyManager>::managerDestroyed); |
146 | disconnectPropertyManager(manager); |
147 | m_managers.remove(manager); |
148 | } |
149 | QSet<PropertyManager *> propertyManagers() const |
150 | { |
151 | return m_managers; |
152 | } |
153 | PropertyManager *propertyManager(QtProperty *property) const |
154 | { |
155 | QtAbstractPropertyManager *manager = property->propertyManager(); |
156 | for (PropertyManager *m : std::as_const(m_managers)) { |
157 | if (m == manager) { |
158 | return m; |
159 | } |
160 | } |
161 | return 0; |
162 | } |
163 | protected: |
164 | virtual void connectPropertyManager(PropertyManager *manager) = 0; |
165 | virtual QWidget *createEditor(PropertyManager *manager, QtProperty *property, |
166 | QWidget *parent) = 0; |
167 | virtual void disconnectPropertyManager(PropertyManager *manager) = 0; |
168 | void managerDestroyed(QObject *manager) override |
169 | { |
170 | for (PropertyManager *m : std::as_const(m_managers)) { |
171 | if (m == manager) { |
172 | m_managers.remove(m); |
173 | return; |
174 | } |
175 | } |
176 | } |
177 | private: |
178 | void breakConnection(QtAbstractPropertyManager *manager) override |
179 | { |
180 | for (PropertyManager *m : std::as_const(m_managers)) { |
181 | if (m == manager) { |
182 | removePropertyManager(manager: m); |
183 | return; |
184 | } |
185 | } |
186 | } |
187 | private: |
188 | QSet<PropertyManager *> m_managers; |
189 | friend class QtAbstractPropertyEditor; |
190 | }; |
191 | |
192 | class QtAbstractPropertyBrowser; |
193 | class QtBrowserItemPrivate; |
194 | |
195 | class QtBrowserItem |
196 | { |
197 | public: |
198 | QtProperty *property() const; |
199 | QtBrowserItem *parent() const; |
200 | QList<QtBrowserItem *> children() const; |
201 | QtAbstractPropertyBrowser *browser() const; |
202 | private: |
203 | explicit QtBrowserItem(QtAbstractPropertyBrowser *browser, QtProperty *property, QtBrowserItem *parent); |
204 | ~QtBrowserItem(); |
205 | QScopedPointer<QtBrowserItemPrivate> d_ptr; |
206 | friend class QtAbstractPropertyBrowserPrivate; |
207 | }; |
208 | |
209 | class QtAbstractPropertyBrowserPrivate; |
210 | |
211 | class QtAbstractPropertyBrowser : public QWidget |
212 | { |
213 | Q_OBJECT |
214 | public: |
215 | |
216 | explicit QtAbstractPropertyBrowser(QWidget *parent = 0); |
217 | ~QtAbstractPropertyBrowser(); |
218 | |
219 | QList<QtProperty *> properties() const; |
220 | QList<QtBrowserItem *> items(QtProperty *property) const; |
221 | QtBrowserItem *topLevelItem(QtProperty *property) const; |
222 | QList<QtBrowserItem *> topLevelItems() const; |
223 | void clear(); |
224 | |
225 | template <class PropertyManager> |
226 | void setFactoryForManager(PropertyManager *manager, |
227 | QtAbstractEditorFactory<PropertyManager> *factory) { |
228 | QtAbstractPropertyManager *abstractManager = manager; |
229 | QtAbstractEditorFactoryBase *abstractFactory = factory; |
230 | |
231 | if (addFactory(abstractManager, abstractFactory)) |
232 | factory->addPropertyManager(manager); |
233 | } |
234 | |
235 | void unsetFactoryForManager(QtAbstractPropertyManager *manager); |
236 | |
237 | QtBrowserItem *currentItem() const; |
238 | void setCurrentItem(QtBrowserItem *); |
239 | |
240 | Q_SIGNALS: |
241 | void currentItemChanged(QtBrowserItem *); |
242 | |
243 | public Q_SLOTS: |
244 | |
245 | QtBrowserItem *addProperty(QtProperty *property); |
246 | QtBrowserItem *insertProperty(QtProperty *property, QtProperty *afterProperty); |
247 | void removeProperty(QtProperty *property); |
248 | |
249 | protected: |
250 | |
251 | virtual void itemInserted(QtBrowserItem *item, QtBrowserItem *afterItem) = 0; |
252 | virtual void itemRemoved(QtBrowserItem *item) = 0; |
253 | // can be tooltip, statustip, whatsthis, name, icon, text. |
254 | virtual void itemChanged(QtBrowserItem *item) = 0; |
255 | |
256 | virtual QWidget *createEditor(QtProperty *property, QWidget *parent); |
257 | private: |
258 | |
259 | bool addFactory(QtAbstractPropertyManager *abstractManager, |
260 | QtAbstractEditorFactoryBase *abstractFactory); |
261 | |
262 | QScopedPointer<QtAbstractPropertyBrowserPrivate> d_ptr; |
263 | Q_DECLARE_PRIVATE(QtAbstractPropertyBrowser) |
264 | Q_DISABLE_COPY_MOVE(QtAbstractPropertyBrowser) |
265 | }; |
266 | |
267 | QT_END_NAMESPACE |
268 | |
269 | #endif // QTPROPERTYBROWSER_H |
270 |
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