1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Designer of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | // |
30 | // W A R N I N G |
31 | // ------------- |
32 | // |
33 | // This file is not part of the Qt API. It exists for the convenience |
34 | // of Qt Designer. This header |
35 | // file may change from version to version without notice, or even be removed. |
36 | // |
37 | // We mean it. |
38 | // |
39 | |
40 | #ifndef QDESIGNER_PROPERTYSHEET_H |
41 | #define QDESIGNER_PROPERTYSHEET_H |
42 | |
43 | #include "shared_global_p.h" |
44 | #include "dynamicpropertysheet.h" |
45 | #include <QtDesigner/propertysheet.h> |
46 | #include <QtDesigner/default_extensionfactory.h> |
47 | #include <QtDesigner/qextensionmanager.h> |
48 | |
49 | #include <QtCore/qvariant.h> |
50 | #include <QtCore/qpair.h> |
51 | |
52 | #include <QtCore/qpointer.h> |
53 | |
54 | QT_BEGIN_NAMESPACE |
55 | |
56 | class QLayout; |
57 | class QDesignerFormEditorInterface; |
58 | class QDesignerPropertySheetPrivate; |
59 | |
60 | namespace qdesigner_internal |
61 | { |
62 | class DesignerPixmapCache; |
63 | class DesignerIconCache; |
64 | class FormWindowBase; |
65 | } |
66 | |
67 | class QDESIGNER_SHARED_EXPORT QDesignerPropertySheet: public QObject, public QDesignerPropertySheetExtension, public QDesignerDynamicPropertySheetExtension |
68 | { |
69 | Q_OBJECT |
70 | Q_INTERFACES(QDesignerPropertySheetExtension QDesignerDynamicPropertySheetExtension) |
71 | public: |
72 | explicit QDesignerPropertySheet(QObject *object, QObject *parent = nullptr); |
73 | ~QDesignerPropertySheet() override; |
74 | |
75 | int indexOf(const QString &name) const override; |
76 | |
77 | int count() const override; |
78 | QString propertyName(int index) const override; |
79 | |
80 | QString propertyGroup(int index) const override; |
81 | void setPropertyGroup(int index, const QString &group) override; |
82 | |
83 | bool hasReset(int index) const override; |
84 | bool reset(int index) override; |
85 | |
86 | bool isAttribute(int index) const override; |
87 | void setAttribute(int index, bool b) override; |
88 | |
89 | bool isVisible(int index) const override; |
90 | void setVisible(int index, bool b) override; |
91 | |
92 | QVariant property(int index) const override; |
93 | void setProperty(int index, const QVariant &value) override; |
94 | |
95 | bool isChanged(int index) const override; |
96 | |
97 | void setChanged(int index, bool changed) override; |
98 | |
99 | bool dynamicPropertiesAllowed() const override; |
100 | int addDynamicProperty(const QString &propertyName, const QVariant &value) override; |
101 | bool removeDynamicProperty(int index) override; |
102 | bool isDynamicProperty(int index) const override; |
103 | bool canAddDynamicProperty(const QString &propertyName) const override; |
104 | |
105 | bool isDefaultDynamicProperty(int index) const; |
106 | |
107 | bool isResourceProperty(int index) const; |
108 | QVariant defaultResourceProperty(int index) const; |
109 | |
110 | qdesigner_internal::DesignerPixmapCache *pixmapCache() const; |
111 | void setPixmapCache(qdesigner_internal::DesignerPixmapCache *cache); |
112 | qdesigner_internal::DesignerIconCache *iconCache() const; |
113 | void setIconCache(qdesigner_internal::DesignerIconCache *cache); |
114 | int createFakeProperty(const QString &propertyName, const QVariant &value = QVariant()); |
115 | |
116 | bool isEnabled(int index) const override; |
117 | QObject *object() const; |
118 | |
119 | static bool internalDynamicPropertiesEnabled(); |
120 | static void setInternalDynamicPropertiesEnabled(bool v); |
121 | |
122 | protected: |
123 | bool isAdditionalProperty(int index) const; |
124 | bool isFakeProperty(int index) const; |
125 | QVariant resolvePropertyValue(int index, const QVariant &value) const; |
126 | QVariant metaProperty(int index) const; |
127 | void setFakeProperty(int index, const QVariant &value); |
128 | void clearFakeProperties(); |
129 | |
130 | bool isFakeLayoutProperty(int index) const; |
131 | bool isDynamic(int index) const; |
132 | qdesigner_internal::FormWindowBase *formWindowBase() const; |
133 | QDesignerFormEditorInterface *core() const; |
134 | |
135 | public: |
136 | enum PropertyType { PropertyNone, |
137 | PropertyLayoutObjectName, |
138 | PropertyLayoutLeftMargin, |
139 | PropertyLayoutTopMargin, |
140 | PropertyLayoutRightMargin, |
141 | PropertyLayoutBottomMargin, |
142 | PropertyLayoutSpacing, |
143 | PropertyLayoutHorizontalSpacing, |
144 | PropertyLayoutVerticalSpacing, |
145 | PropertyLayoutSizeConstraint, |
146 | PropertyLayoutFieldGrowthPolicy, |
147 | PropertyLayoutRowWrapPolicy, |
148 | PropertyLayoutLabelAlignment, |
149 | PropertyLayoutFormAlignment, |
150 | PropertyLayoutBoxStretch, |
151 | PropertyLayoutGridRowStretch, |
152 | PropertyLayoutGridColumnStretch, |
153 | PropertyLayoutGridRowMinimumHeight, |
154 | PropertyLayoutGridColumnMinimumWidth, |
155 | PropertyBuddy, |
156 | PropertyAccessibility, |
157 | PropertyGeometry, |
158 | PropertyChecked, |
159 | PropertyCheckable, |
160 | PropertyVisible, |
161 | PropertyWindowTitle, |
162 | PropertyWindowIcon, |
163 | PropertyWindowFilePath, |
164 | PropertyWindowOpacity, |
165 | PropertyWindowIconText, |
166 | PropertyWindowModality, |
167 | PropertyWindowModified, |
168 | PropertyStyleSheet, |
169 | PropertyText |
170 | }; |
171 | |
172 | enum ObjectType { ObjectNone, ObjectLabel, ObjectLayout, ObjectLayoutWidget }; |
173 | enum ObjectFlag |
174 | { |
175 | CheckableProperty = 0x1 // Has a "checked" property depending on "checkable" |
176 | }; |
177 | Q_DECLARE_FLAGS(ObjectFlags, ObjectFlag) |
178 | |
179 | static ObjectType objectTypeFromObject(const QObject *o); |
180 | static ObjectFlags objectFlagsFromObject(const QObject *o); |
181 | static PropertyType propertyTypeFromName(const QString &name); |
182 | |
183 | protected: |
184 | PropertyType propertyType(int index) const; |
185 | ObjectType objectType() const; |
186 | |
187 | private: |
188 | QDesignerPropertySheetPrivate *d; |
189 | }; |
190 | |
191 | /* Abstract base class for factories that register a property sheet that implements |
192 | * both QDesignerPropertySheetExtension and QDesignerDynamicPropertySheetExtension |
193 | * by multiple inheritance. The factory maintains ownership of |
194 | * the extension and returns it for both id's. */ |
195 | |
196 | class QDESIGNER_SHARED_EXPORT QDesignerAbstractPropertySheetFactory: public QExtensionFactory |
197 | { |
198 | Q_OBJECT |
199 | Q_INTERFACES(QAbstractExtensionFactory) |
200 | public: |
201 | explicit QDesignerAbstractPropertySheetFactory(QExtensionManager *parent = nullptr); |
202 | ~QDesignerAbstractPropertySheetFactory() override; |
203 | |
204 | QObject *extension(QObject *object, const QString &iid) const override; |
205 | |
206 | private slots: |
207 | void objectDestroyed(QObject *object); |
208 | |
209 | private: |
210 | virtual QObject *createPropertySheet(QObject *qObject, QObject *parent) const = 0; |
211 | |
212 | struct PropertySheetFactoryPrivate; |
213 | PropertySheetFactoryPrivate *m_impl; |
214 | }; |
215 | |
216 | /* Convenience factory template for property sheets that implement |
217 | * QDesignerPropertySheetExtension and QDesignerDynamicPropertySheetExtension |
218 | * by multiple inheritance. */ |
219 | |
220 | template <class Object, class PropertySheet> |
221 | class QDesignerPropertySheetFactory : public QDesignerAbstractPropertySheetFactory { |
222 | public: |
223 | explicit QDesignerPropertySheetFactory(QExtensionManager *parent = nullptr); |
224 | |
225 | static void registerExtension(QExtensionManager *mgr); |
226 | |
227 | private: |
228 | // Does a qobject_cast on the object. |
229 | QObject *createPropertySheet(QObject *qObject, QObject *parent) const override; |
230 | }; |
231 | |
232 | template <class Object, class PropertySheet> |
233 | QDesignerPropertySheetFactory<Object, PropertySheet>::QDesignerPropertySheetFactory(QExtensionManager *parent) : |
234 | QDesignerAbstractPropertySheetFactory(parent) |
235 | { |
236 | } |
237 | |
238 | template <class Object, class PropertySheet> |
239 | QObject *QDesignerPropertySheetFactory<Object, PropertySheet>::createPropertySheet(QObject *qObject, QObject *parent) const |
240 | { |
241 | Object *object = qobject_cast<Object *>(qObject); |
242 | if (!object) |
243 | return nullptr; |
244 | return new PropertySheet(object, parent); |
245 | } |
246 | |
247 | template <class Object, class PropertySheet> |
248 | void QDesignerPropertySheetFactory<Object, PropertySheet>::registerExtension(QExtensionManager *mgr) |
249 | { |
250 | QDesignerPropertySheetFactory *factory = new QDesignerPropertySheetFactory(mgr); |
251 | mgr->registerExtensions(factory, Q_TYPEID(QDesignerPropertySheetExtension)); |
252 | mgr->registerExtensions(factory, Q_TYPEID(QDesignerDynamicPropertySheetExtension)); |
253 | } |
254 | |
255 | |
256 | // Standard property sheet |
257 | typedef QDesignerPropertySheetFactory<QObject, QDesignerPropertySheet> QDesignerDefaultPropertySheetFactory; |
258 | |
259 | Q_DECLARE_OPERATORS_FOR_FLAGS(QDesignerPropertySheet::ObjectFlags) |
260 | |
261 | QT_END_NAMESPACE |
262 | |
263 | #endif // QDESIGNER_PROPERTYSHEET_H |
264 | |