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 QtCore module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
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 Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QMETAOBJECTBUILDER_P_H |
41 | #define QMETAOBJECTBUILDER_P_H |
42 | |
43 | // |
44 | // W A R N I N G |
45 | // ------------- |
46 | // |
47 | // This file is not part of the Qt API. It exists for the convenience |
48 | // of moc. This header file may change from version to version without notice, |
49 | // or even be removed. |
50 | // |
51 | // We mean it. |
52 | // |
53 | |
54 | #include <QtCore/private/qglobal_p.h> |
55 | #include <QtCore/qobject.h> |
56 | #include <QtCore/qmetaobject.h> |
57 | #include <QtCore/qdatastream.h> |
58 | #include <QtCore/qhash.h> |
59 | #include <QtCore/qmap.h> |
60 | |
61 | |
62 | QT_BEGIN_NAMESPACE |
63 | |
64 | class QMetaObjectBuilderPrivate; |
65 | class QMetaMethodBuilder; |
66 | class QMetaMethodBuilderPrivate; |
67 | class QMetaPropertyBuilder; |
68 | class QMetaPropertyBuilderPrivate; |
69 | class QMetaEnumBuilder; |
70 | class QMetaEnumBuilderPrivate; |
71 | |
72 | class Q_CORE_EXPORT QMetaObjectBuilder |
73 | { |
74 | public: |
75 | enum AddMember |
76 | { |
77 | ClassName = 0x00000001, |
78 | SuperClass = 0x00000002, |
79 | Methods = 0x00000004, |
80 | Signals = 0x00000008, |
81 | Slots = 0x00000010, |
82 | Constructors = 0x00000020, |
83 | Properties = 0x00000040, |
84 | Enumerators = 0x00000080, |
85 | ClassInfos = 0x00000100, |
86 | RelatedMetaObjects = 0x00000200, |
87 | StaticMetacall = 0x00000400, |
88 | PublicMethods = 0x00000800, |
89 | ProtectedMethods = 0x00001000, |
90 | PrivateMethods = 0x00002000, |
91 | AllMembers = 0x7FFFFFFF, |
92 | AllPrimaryMembers = 0x7FFFFBFC |
93 | }; |
94 | Q_DECLARE_FLAGS(AddMembers, AddMember) |
95 | |
96 | // ### TODO Qt6: remove me and use the MetaObjectFlags enum from qmetaobject_p.h |
97 | enum MetaObjectFlag { // keep it in sync with enum MetaObjectFlags from qmetaobject_p.h |
98 | DynamicMetaObject = 0x01, |
99 | RequiresVariantMetaObject = 0x02, |
100 | PropertyAccessInStaticMetaCall = 0x04 // since Qt 5.5, property code is in the static metacall |
101 | }; |
102 | Q_DECLARE_FLAGS(MetaObjectFlags, MetaObjectFlag) |
103 | |
104 | QMetaObjectBuilder(); |
105 | explicit QMetaObjectBuilder(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members = AllMembers); |
106 | virtual ~QMetaObjectBuilder(); |
107 | |
108 | QByteArray className() const; |
109 | void setClassName(const QByteArray& name); |
110 | |
111 | const QMetaObject *superClass() const; |
112 | void setSuperClass(const QMetaObject *meta); |
113 | |
114 | MetaObjectFlags flags() const; |
115 | void setFlags(MetaObjectFlags); |
116 | |
117 | int methodCount() const; |
118 | int constructorCount() const; |
119 | int propertyCount() const; |
120 | int enumeratorCount() const; |
121 | int classInfoCount() const; |
122 | int relatedMetaObjectCount() const; |
123 | |
124 | QMetaMethodBuilder addMethod(const QByteArray& signature); |
125 | QMetaMethodBuilder addMethod(const QByteArray& signature, const QByteArray& returnType); |
126 | QMetaMethodBuilder addMethod(const QMetaMethod& prototype); |
127 | |
128 | QMetaMethodBuilder addSlot(const QByteArray& signature); |
129 | QMetaMethodBuilder addSignal(const QByteArray& signature); |
130 | |
131 | QMetaMethodBuilder addConstructor(const QByteArray& signature); |
132 | QMetaMethodBuilder addConstructor(const QMetaMethod& prototype); |
133 | |
134 | QMetaPropertyBuilder addProperty(const QByteArray& name, const QByteArray& type, int notifierId=-1); |
135 | QMetaPropertyBuilder addProperty(const QMetaProperty& prototype); |
136 | |
137 | QMetaEnumBuilder addEnumerator(const QByteArray& name); |
138 | QMetaEnumBuilder addEnumerator(const QMetaEnum& prototype); |
139 | |
140 | int addClassInfo(const QByteArray& name, const QByteArray& value); |
141 | |
142 | int addRelatedMetaObject(const QMetaObject *meta); |
143 | |
144 | void addMetaObject(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members = AllMembers); |
145 | |
146 | QMetaMethodBuilder method(int index) const; |
147 | QMetaMethodBuilder constructor(int index) const; |
148 | QMetaPropertyBuilder property(int index) const; |
149 | QMetaEnumBuilder enumerator(int index) const; |
150 | const QMetaObject *relatedMetaObject(int index) const; |
151 | |
152 | QByteArray classInfoName(int index) const; |
153 | QByteArray classInfoValue(int index) const; |
154 | |
155 | void removeMethod(int index); |
156 | void removeConstructor(int index); |
157 | void removeProperty(int index); |
158 | void removeEnumerator(int index); |
159 | void removeClassInfo(int index); |
160 | void removeRelatedMetaObject(int index); |
161 | |
162 | int indexOfMethod(const QByteArray& signature); |
163 | int indexOfSignal(const QByteArray& signature); |
164 | int indexOfSlot(const QByteArray& signature); |
165 | int indexOfConstructor(const QByteArray& signature); |
166 | int indexOfProperty(const QByteArray& name); |
167 | int indexOfEnumerator(const QByteArray& name); |
168 | int indexOfClassInfo(const QByteArray& name); |
169 | |
170 | typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **); |
171 | |
172 | QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction() const; |
173 | void setStaticMetacallFunction(QMetaObjectBuilder::StaticMetacallFunction value); |
174 | |
175 | QMetaObject *toMetaObject() const; |
176 | QByteArray toRelocatableData(bool * = nullptr) const; |
177 | static void fromRelocatableData(QMetaObject *, const QMetaObject *, const QByteArray &); |
178 | |
179 | #ifndef QT_NO_DATASTREAM |
180 | void serialize(QDataStream& stream) const; |
181 | void deserialize |
182 | (QDataStream& stream, |
183 | const QMap<QByteArray, const QMetaObject *>& references); |
184 | #endif |
185 | |
186 | private: |
187 | Q_DISABLE_COPY_MOVE(QMetaObjectBuilder) |
188 | |
189 | QMetaObjectBuilderPrivate *d; |
190 | |
191 | friend class QMetaMethodBuilder; |
192 | friend class QMetaPropertyBuilder; |
193 | friend class QMetaEnumBuilder; |
194 | }; |
195 | |
196 | class Q_CORE_EXPORT QMetaMethodBuilder |
197 | { |
198 | public: |
199 | QMetaMethodBuilder() : _mobj(nullptr), _index(0) {} |
200 | |
201 | int index() const; |
202 | |
203 | QMetaMethod::MethodType methodType() const; |
204 | QByteArray signature() const; |
205 | |
206 | QByteArray returnType() const; |
207 | void setReturnType(const QByteArray& value); |
208 | |
209 | QList<QByteArray> parameterTypes() const; |
210 | QList<QByteArray> parameterNames() const; |
211 | void setParameterNames(const QList<QByteArray>& value); |
212 | |
213 | QByteArray tag() const; |
214 | void setTag(const QByteArray& value); |
215 | |
216 | QMetaMethod::Access access() const; |
217 | void setAccess(QMetaMethod::Access value); |
218 | |
219 | int attributes() const; |
220 | void setAttributes(int value); |
221 | |
222 | int revision() const; |
223 | void setRevision(int revision); |
224 | |
225 | private: |
226 | const QMetaObjectBuilder *_mobj; |
227 | int _index; |
228 | |
229 | friend class QMetaObjectBuilder; |
230 | friend class QMetaPropertyBuilder; |
231 | |
232 | QMetaMethodBuilder(const QMetaObjectBuilder *mobj, int index) |
233 | : _mobj(mobj), _index(index) {} |
234 | |
235 | QMetaMethodBuilderPrivate *d_func() const; |
236 | }; |
237 | |
238 | class Q_CORE_EXPORT QMetaPropertyBuilder |
239 | { |
240 | public: |
241 | QMetaPropertyBuilder() : _mobj(nullptr), _index(0) {} |
242 | |
243 | int index() const { return _index; } |
244 | |
245 | QByteArray name() const; |
246 | QByteArray type() const; |
247 | |
248 | bool hasNotifySignal() const; |
249 | QMetaMethodBuilder notifySignal() const; |
250 | void setNotifySignal(const QMetaMethodBuilder& value); |
251 | void removeNotifySignal(); |
252 | |
253 | bool isReadable() const; |
254 | bool isWritable() const; |
255 | bool isResettable() const; |
256 | bool isDesignable() const; |
257 | bool isScriptable() const; |
258 | bool isStored() const; |
259 | bool isEditable() const; |
260 | bool isUser() const; |
261 | bool hasStdCppSet() const; |
262 | bool isEnumOrFlag() const; |
263 | bool isConstant() const; |
264 | bool isFinal() const; |
265 | |
266 | void setReadable(bool value); |
267 | void setWritable(bool value); |
268 | void setResettable(bool value); |
269 | void setDesignable(bool value); |
270 | void setScriptable(bool value); |
271 | void setStored(bool value); |
272 | void setEditable(bool value); |
273 | void setUser(bool value); |
274 | void setStdCppSet(bool value); |
275 | void setEnumOrFlag(bool value); |
276 | void setConstant(bool value); |
277 | void setFinal(bool value); |
278 | |
279 | int revision() const; |
280 | void setRevision(int revision); |
281 | |
282 | private: |
283 | const QMetaObjectBuilder *_mobj; |
284 | int _index; |
285 | |
286 | friend class QMetaObjectBuilder; |
287 | |
288 | QMetaPropertyBuilder(const QMetaObjectBuilder *mobj, int index) |
289 | : _mobj(mobj), _index(index) {} |
290 | |
291 | QMetaPropertyBuilderPrivate *d_func() const; |
292 | }; |
293 | |
294 | class Q_CORE_EXPORT QMetaEnumBuilder |
295 | { |
296 | public: |
297 | QMetaEnumBuilder() : _mobj(nullptr), _index(0) {} |
298 | |
299 | int index() const { return _index; } |
300 | |
301 | QByteArray name() const; |
302 | |
303 | QByteArray enumName() const; |
304 | void setEnumName(const QByteArray &alias); |
305 | |
306 | bool isFlag() const; |
307 | void setIsFlag(bool value); |
308 | |
309 | bool isScoped() const; |
310 | void setIsScoped(bool value); |
311 | |
312 | int keyCount() const; |
313 | QByteArray key(int index) const; |
314 | int value(int index) const; |
315 | |
316 | int addKey(const QByteArray& name, int value); |
317 | void removeKey(int index); |
318 | |
319 | private: |
320 | const QMetaObjectBuilder *_mobj; |
321 | int _index; |
322 | |
323 | friend class QMetaObjectBuilder; |
324 | |
325 | QMetaEnumBuilder(const QMetaObjectBuilder *mobj, int index) |
326 | : _mobj(mobj), _index(index) {} |
327 | |
328 | QMetaEnumBuilderPrivate *d_func() const; |
329 | }; |
330 | |
331 | class Q_CORE_EXPORT QMetaStringTable |
332 | { |
333 | public: |
334 | explicit QMetaStringTable(const QByteArray &className); |
335 | |
336 | int enter(const QByteArray &value); |
337 | |
338 | static int preferredAlignment(); |
339 | int blobSize() const; |
340 | void writeBlob(char *out) const; |
341 | |
342 | private: |
343 | typedef QHash<QByteArray, int> Entries; // string --> index mapping |
344 | Entries m_entries; |
345 | int m_index; |
346 | QByteArray m_className; |
347 | }; |
348 | |
349 | Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaObjectBuilder::AddMembers) |
350 | Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaObjectBuilder::MetaObjectFlags) |
351 | |
352 | QT_END_NAMESPACE |
353 | |
354 | #endif |
355 | |