Rename QDeclarative symbols to QQuick and QQml
[profile/ivi/qtdeclarative.git] / src / qml / qml / qqmlmetatype_p.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQml module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQMLMETATYPE_P_H
43 #define QQMLMETATYPE_P_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 purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55
56 #include "qqml.h"
57 #include <private/qtqmlglobal_p.h>
58
59 #include <QtCore/qglobal.h>
60 #include <QtCore/qvariant.h>
61 #include <QtCore/qbitarray.h>
62 #include <QtQml/qjsvalue.h>
63
64 QT_BEGIN_NAMESPACE
65
66 class QQmlType;
67 class QQmlCustomParser;
68 class QQmlTypePrivate;
69 class QQmlTypeModule;
70
71 class Q_QML_PRIVATE_EXPORT QQmlMetaType
72 {
73 public:
74     static QList<QString> qmlTypeNames();
75     static QList<QQmlType*> qmlTypes();
76
77     static QQmlType *qmlType(const QString &, int, int);
78     static QQmlType *qmlType(const QMetaObject *);
79     static QQmlType *qmlType(const QMetaObject *metaObject, const QString &module, int version_major, int version_minor);
80     static QQmlType *qmlType(int);
81
82     static QMetaProperty defaultProperty(const QMetaObject *);
83     static QMetaProperty defaultProperty(QObject *);
84     static QMetaMethod defaultMethod(const QMetaObject *);
85     static QMetaMethod defaultMethod(QObject *);
86
87     static bool isQObject(int);
88     static QObject *toQObject(const QVariant &, bool *ok = 0);
89
90     static int listType(int);
91     static int attachedPropertiesFuncId(const QMetaObject *);
92     static QQmlAttachedPropertiesFunc attachedPropertiesFuncById(int);
93
94     enum TypeCategory { Unknown, Object, List };
95     static TypeCategory typeCategory(int);
96         
97     static bool isInterface(int);
98     static const char *interfaceIId(int);
99     static bool isList(int);
100
101     typedef QVariant (*StringConverter)(const QString &);
102     static void registerCustomStringConverter(int, StringConverter);
103     static StringConverter customStringConverter(int);
104
105     static bool isAnyModule(const QString &uri);
106     static bool isModule(const QString &module, int versionMajor, int versionMinor);
107     static QQmlTypeModule *typeModule(const QString &uri, int majorVersion);
108
109     static QList<QQmlPrivate::AutoParentFunction> parentFunctions();
110
111     static int QQuickAnchorLineMetaTypeId();
112     typedef bool (*CompareFunction)(const void *, const void *);
113     static void setQQuickAnchorLineCompareFunction(CompareFunction);
114     static bool QQuickAnchorLineCompare(const void *p1, const void *p2);
115
116     struct ModuleApiInstance {
117         ModuleApiInstance()
118             : scriptCallback(0), qobjectCallback(0), qobjectApi(0) {}
119
120         QJSValue (*scriptCallback)(QQmlEngine *, QJSEngine *);
121         QObject *(*qobjectCallback)(QQmlEngine *, QJSEngine *);
122         QJSValue scriptApi;
123         QObject *qobjectApi;
124     };
125     struct ModuleApi {
126         inline ModuleApi();
127         inline bool operator==(const ModuleApi &) const;
128         int major;
129         int minor;
130         QJSValue (*script)(QQmlEngine *, QJSEngine *);
131         QObject *(*qobject)(QQmlEngine *, QJSEngine *);
132     };
133     static ModuleApi moduleApi(const QString &, int, int);
134     static QHash<QString, QList<ModuleApi> > moduleApis();
135
136 private:
137     static CompareFunction anchorLineCompareFunction;
138 };
139
140 class QHashedStringRef;
141 class QHashedV8String;
142 class Q_QML_PRIVATE_EXPORT QQmlType
143 {
144 public:
145     QByteArray typeName() const;
146     const QString &qmlTypeName() const;
147     const QString &elementName() const;
148
149     QString module() const;
150     int majorVersion() const;
151     int minorVersion() const;
152
153     bool availableInVersion(int vmajor, int vminor) const;
154     bool availableInVersion(const QString &module, int vmajor, int vminor) const;
155
156     QObject *create() const;
157     void create(QObject **, void **, size_t) const;
158
159     typedef void (*CreateFunc)(void *);
160     CreateFunc createFunction() const;
161     int createSize() const;
162
163     QQmlCustomParser *customParser() const;
164
165     bool isCreatable() const;
166     bool isExtendedType() const;
167     QString noCreationReason() const;
168
169     bool isInterface() const;
170     int typeId() const;
171     int qListTypeId() const;
172
173     const QMetaObject *metaObject() const;
174     const QMetaObject *baseMetaObject() const;
175     int metaObjectRevision() const;
176     bool containsRevisionedAttributes() const;
177
178     QQmlAttachedPropertiesFunc attachedPropertiesFunction() const;
179     const QMetaObject *attachedPropertiesType() const;
180     int attachedPropertiesId() const;
181
182     int parserStatusCast() const;
183     QVariant fromObject(QObject *) const;
184     const char *interfaceIId() const;
185     int propertyValueSourceCast() const;
186     int propertyValueInterceptorCast() const;
187
188     int index() const;
189
190     int enumValue(const QHashedStringRef &) const;
191     int enumValue(const QHashedV8String &) const;
192 private:
193     QQmlType *superType() const;
194     friend class QQmlTypePrivate;
195     friend struct QQmlMetaTypeData;
196     friend int registerType(const QQmlPrivate::RegisterType &);
197     friend int registerInterface(const QQmlPrivate::RegisterInterface &);
198     QQmlType(int, const QQmlPrivate::RegisterInterface &);
199     QQmlType(int, const QQmlPrivate::RegisterType &);
200     ~QQmlType();
201
202     QQmlTypePrivate *d;
203 };
204
205 class QQmlTypeModulePrivate;
206 class QQmlTypeModule
207 {
208 public:
209     QString module() const;
210     int majorVersion() const;
211
212     int minimumMinorVersion() const;
213     int maximumMinorVersion() const;
214
215     QList<QQmlType *> types();
216     QList<QQmlType *> type(const QString &);
217
218     QQmlType *type(const QHashedStringRef &, int);
219     QQmlType *type(const QHashedV8String &, int);
220
221 private:
222     friend int registerType(const QQmlPrivate::RegisterType &);
223     QQmlTypeModule();
224     ~QQmlTypeModule();
225     QQmlTypeModulePrivate *d;
226 };
227
228 class QQmlTypeModuleVersion 
229 {
230 public:
231     QQmlTypeModuleVersion();
232     QQmlTypeModuleVersion(QQmlTypeModule *, int);
233     QQmlTypeModuleVersion(const QQmlTypeModuleVersion &);
234     QQmlTypeModuleVersion &operator=(const QQmlTypeModuleVersion &);
235
236     QQmlTypeModule *module() const;
237     int minorVersion() const;
238
239     QQmlType *type(const QHashedStringRef &) const;
240     QQmlType *type(const QHashedV8String &) const;
241
242 private:
243     QQmlTypeModule *m_module;
244     int m_minor;
245 };
246
247 QQmlMetaType::ModuleApi::ModuleApi()
248 {
249     major = 0;
250     minor = 0;
251     script = 0;
252     qobject = 0;
253 }
254
255 bool QQmlMetaType::ModuleApi::operator==(const ModuleApi &other) const
256 {
257     return major == other.major && minor == other.minor && script == other.script && qobject == other.qobject;
258 }
259
260 inline uint qHash(const QQmlMetaType::ModuleApi &import)
261 {
262     return import.major ^ import.minor ^ quintptr(import.script) ^ quintptr(import.qobject);
263 }
264
265 QT_END_NAMESPACE
266
267 #endif // QQMLMETATYPE_P_H
268