Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / src / declarative / qml / qmetaobjectbuilder_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file.  Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23 **
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QMETAOBJECTBUILDER_H
43 #define QMETAOBJECTBUILDER_H
44
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists for the convenience
50 // of moc.  This header file may change from version to version without notice,
51 // or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include <QtCore/qobject.h>
57 #include <QtCore/qmetaobject.h>
58 #include <QtCore/qdatastream.h>
59 #include <QtCore/qmap.h>
60
61 #include <private/qdeclarativeglobal_p.h>
62
63 QT_BEGIN_NAMESPACE
64
65 class QMetaObjectBuilderPrivate;
66 class QMetaMethodBuilder;
67 class QMetaMethodBuilderPrivate;
68 class QMetaPropertyBuilder;
69 class QMetaPropertyBuilderPrivate;
70 class QMetaEnumBuilder;
71 class QMetaEnumBuilderPrivate;
72
73 class Q_DECLARATIVE_PRIVATE_EXPORT QMetaObjectBuilder
74 {
75 public:
76     enum AddMember
77     {
78         ClassName               = 0x00000001,
79         SuperClass              = 0x00000002,
80         Methods                 = 0x00000004,
81         Signals                 = 0x00000008,
82         Slots                   = 0x00000010,
83         Constructors            = 0x00000020,
84         Properties              = 0x00000040,
85         Enumerators             = 0x00000080,
86         ClassInfos              = 0x00000100,
87         RelatedMetaObjects      = 0x00000200,
88         StaticMetacall          = 0x00000400,
89         PublicMethods           = 0x00000800,
90         ProtectedMethods        = 0x00001000,
91         PrivateMethods          = 0x00002000,
92         AllMembers              = 0x7FFFFFFF,
93         AllPrimaryMembers       = 0x7FFFFBFC
94     };
95     Q_DECLARE_FLAGS(AddMembers, AddMember)
96
97     enum MetaObjectFlag {
98         DynamicMetaObject = 0x01
99     };
100     Q_DECLARE_FLAGS(MetaObjectFlags, MetaObjectFlag)
101
102     QMetaObjectBuilder();
103     explicit QMetaObjectBuilder(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members = AllMembers);
104     virtual ~QMetaObjectBuilder();
105
106     QByteArray className() const;
107     void setClassName(const QByteArray& name);
108
109     const QMetaObject *superClass() const;
110     void setSuperClass(const QMetaObject *meta);
111
112     MetaObjectFlags flags() const;
113     void setFlags(MetaObjectFlags);
114
115     int methodCount() const;
116     int constructorCount() const;
117     int propertyCount() const;
118     int enumeratorCount() const;
119     int classInfoCount() const;
120     int relatedMetaObjectCount() const;
121
122     QMetaMethodBuilder addMethod(const QByteArray& signature);
123     QMetaMethodBuilder addMethod(const QByteArray& signature, const QByteArray& returnType);
124     QMetaMethodBuilder addMethod(const QMetaMethod& prototype);
125
126     QMetaMethodBuilder addSlot(const QByteArray& signature);
127     QMetaMethodBuilder addSignal(const QByteArray& signature);
128
129     QMetaMethodBuilder addConstructor(const QByteArray& signature);
130     QMetaMethodBuilder addConstructor(const QMetaMethod& prototype);
131
132     QMetaPropertyBuilder addProperty(const QByteArray& name, const QByteArray& type, int notifierId=-1);
133     QMetaPropertyBuilder addProperty(const QMetaProperty& prototype);
134
135     QMetaEnumBuilder addEnumerator(const QByteArray& name);
136     QMetaEnumBuilder addEnumerator(const QMetaEnum& prototype);
137
138     int addClassInfo(const QByteArray& name, const QByteArray& value);
139
140 #ifdef Q_NO_DATA_RELOCATION
141     int addRelatedMetaObject(const QMetaObjectAccessor &meta);
142 #else
143     int addRelatedMetaObject(const QMetaObject *meta);
144 #endif
145
146     void addMetaObject(const QMetaObject *prototype, QMetaObjectBuilder::AddMembers members = AllMembers);
147
148     QMetaMethodBuilder method(int index) const;
149     QMetaMethodBuilder constructor(int index) const;
150     QMetaPropertyBuilder property(int index) const;
151     QMetaEnumBuilder enumerator(int index) const;
152     const QMetaObject *relatedMetaObject(int index) const;
153
154     QByteArray classInfoName(int index) const;
155     QByteArray classInfoValue(int index) const;
156
157     void removeMethod(int index);
158     void removeConstructor(int index);
159     void removeProperty(int index);
160     void removeEnumerator(int index);
161     void removeClassInfo(int index);
162     void removeRelatedMetaObject(int index);
163
164     int indexOfMethod(const QByteArray& signature);
165     int indexOfSignal(const QByteArray& signature);
166     int indexOfSlot(const QByteArray& signature);
167     int indexOfConstructor(const QByteArray& signature);
168     int indexOfProperty(const QByteArray& name);
169     int indexOfEnumerator(const QByteArray& name);
170     int indexOfClassInfo(const QByteArray& name);
171
172     typedef QMetaObjectExtraData::StaticMetacallFunction StaticMetacallFunction;
173
174     QMetaObjectBuilder::StaticMetacallFunction staticMetacallFunction() const;
175     void setStaticMetacallFunction(QMetaObjectBuilder::StaticMetacallFunction value);
176
177     QMetaObject *toMetaObject() const;
178     QByteArray toRelocatableData(bool * = 0) const;
179     static void fromRelocatableData(QMetaObject *, const QMetaObject *, const QByteArray &);
180
181 #ifndef QT_NO_DATASTREAM
182     void serialize(QDataStream& stream) const;
183     void deserialize
184         (QDataStream& stream,
185          const QMap<QByteArray, const QMetaObject *>& references);
186 #endif
187
188 private:
189     Q_DISABLE_COPY(QMetaObjectBuilder)
190
191     QMetaObjectBuilderPrivate *d;
192
193     friend class QMetaMethodBuilder;
194     friend class QMetaPropertyBuilder;
195     friend class QMetaEnumBuilder;
196 };
197
198 class Q_DECLARATIVE_PRIVATE_EXPORT QMetaMethodBuilder
199 {
200 public:
201     QMetaMethodBuilder() : _mobj(0), _index(0) {}
202
203     int index() const;
204
205     QMetaMethod::MethodType methodType() const;
206     QByteArray signature() const;
207
208     QByteArray returnType() const;
209     void setReturnType(const QByteArray& value);
210
211     QList<QByteArray> parameterNames() const;
212     void setParameterNames(const QList<QByteArray>& value);
213
214     QByteArray tag() const;
215     void setTag(const QByteArray& value);
216
217     QMetaMethod::Access access() const;
218     void setAccess(QMetaMethod::Access value);
219
220     int attributes() const;
221     void setAttributes(int value);
222
223 private:
224     const QMetaObjectBuilder *_mobj;
225     int _index;
226
227     friend class QMetaObjectBuilder;
228     friend class QMetaPropertyBuilder;
229
230     QMetaMethodBuilder(const QMetaObjectBuilder *mobj, int index)
231         : _mobj(mobj), _index(index) {}
232
233     QMetaMethodBuilderPrivate *d_func() const;
234 };
235
236 class Q_DECLARATIVE_PRIVATE_EXPORT QMetaPropertyBuilder
237 {
238 public:
239     QMetaPropertyBuilder() : _mobj(0), _index(0) {}
240
241     int index() const { return _index; }
242
243     QByteArray name() const;
244     QByteArray type() const;
245
246     bool hasNotifySignal() const;
247     QMetaMethodBuilder notifySignal() const;
248     void setNotifySignal(const QMetaMethodBuilder& value);
249     void removeNotifySignal();
250
251     bool isReadable() const;
252     bool isWritable() const;
253     bool isResettable() const;
254     bool isDesignable() const;
255     bool isScriptable() const;
256     bool isStored() const;
257     bool isEditable() const;
258     bool isUser() const;
259     bool hasStdCppSet() const;
260     bool isEnumOrFlag() const;
261
262     void setReadable(bool value);
263     void setWritable(bool value);
264     void setResettable(bool value);
265     void setDesignable(bool value);
266     void setScriptable(bool value);
267     void setStored(bool value);
268     void setEditable(bool value);
269     void setUser(bool value);
270     void setStdCppSet(bool value);
271     void setEnumOrFlag(bool value);
272
273 private:
274     const QMetaObjectBuilder *_mobj;
275     int _index;
276
277     friend class QMetaObjectBuilder;
278
279     QMetaPropertyBuilder(const QMetaObjectBuilder *mobj, int index)
280         : _mobj(mobj), _index(index) {}
281
282     QMetaPropertyBuilderPrivate *d_func() const;
283 };
284
285 class Q_DECLARATIVE_PRIVATE_EXPORT QMetaEnumBuilder
286 {
287 public:
288     QMetaEnumBuilder() : _mobj(0), _index(0) {}
289
290     int index() const { return _index; }
291
292     QByteArray name() const;
293
294     bool isFlag() const;
295     void setIsFlag(bool value);
296
297     int keyCount() const;
298     QByteArray key(int index) const;
299     int value(int index) const;
300
301     int addKey(const QByteArray& name, int value);
302     void removeKey(int index);
303
304 private:
305     const QMetaObjectBuilder *_mobj;
306     int _index;
307
308     friend class QMetaObjectBuilder;
309
310     QMetaEnumBuilder(const QMetaObjectBuilder *mobj, int index)
311         : _mobj(mobj), _index(index) {}
312
313     QMetaEnumBuilderPrivate *d_func() const;
314 };
315
316 Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaObjectBuilder::AddMembers)
317 Q_DECLARE_OPERATORS_FOR_FLAGS(QMetaObjectBuilder::MetaObjectFlags)
318
319 QT_END_NAMESPACE
320
321 #endif