Add missing QT_{BEGIN,END}_NAMESPACE
[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 class QHashedString;
71 class QHashedStringRef;
72 class QReadWriteLock;
73
74 class Q_QML_PRIVATE_EXPORT QQmlMetaType
75 {
76 public:
77     static QList<QString> qmlTypeNames();
78     static QList<QQmlType*> qmlTypes();
79
80     static QQmlType *qmlType(const QString &qualifiedName, int, int);
81     static QQmlType *qmlType(const QHashedStringRef &name, const QHashedStringRef &module, int, int);
82     static QQmlType *qmlType(const QMetaObject *);
83     static QQmlType *qmlType(const QMetaObject *metaObject, const QHashedStringRef &module, int version_major, int version_minor);
84     static QQmlType *qmlType(int);
85
86     static QMetaProperty defaultProperty(const QMetaObject *);
87     static QMetaProperty defaultProperty(QObject *);
88     static QMetaMethod defaultMethod(const QMetaObject *);
89     static QMetaMethod defaultMethod(QObject *);
90
91     static bool isQObject(int);
92     static QObject *toQObject(const QVariant &, bool *ok = 0);
93
94     static int listType(int);
95     static int attachedPropertiesFuncId(const QMetaObject *);
96     static QQmlAttachedPropertiesFunc attachedPropertiesFuncById(int);
97
98     enum TypeCategory { Unknown, Object, List };
99     static TypeCategory typeCategory(int);
100         
101     static bool isInterface(int);
102     static const char *interfaceIId(int);
103     static bool isList(int);
104
105     typedef QVariant (*StringConverter)(const QString &);
106     static void registerCustomStringConverter(int, StringConverter);
107     static StringConverter customStringConverter(int);
108
109     static bool isAnyModule(const QString &uri);
110     static bool isModule(const QString &module, int versionMajor, int versionMinor);
111     static QQmlTypeModule *typeModule(const QString &uri, int majorVersion);
112
113     static QList<QQmlPrivate::AutoParentFunction> parentFunctions();
114
115     static int QQuickAnchorLineMetaTypeId();
116     typedef bool (*CompareFunction)(const void *, const void *);
117     static void setQQuickAnchorLineCompareFunction(CompareFunction);
118     static bool QQuickAnchorLineCompare(const void *p1, const void *p2);
119
120     struct SingletonInstance {
121         SingletonInstance()
122             : scriptCallback(0), qobjectCallback(0), qobjectApi(0), instanceMetaObject(0) {}
123
124         QJSValue (*scriptCallback)(QQmlEngine *, QJSEngine *);
125         QObject *(*qobjectCallback)(QQmlEngine *, QJSEngine *);
126         QObject *qobjectApi;
127         const QMetaObject *instanceMetaObject;
128         QJSValue scriptApi;
129
130     };
131     struct SingletonType {
132         inline SingletonType();
133         inline bool operator==(const SingletonType &) const;
134         int major;
135         int minor;
136         QString typeName;
137         QObject *(*qobject)(QQmlEngine *, QJSEngine *);
138         const QMetaObject *instanceMetaObject;
139         QJSValue (*script)(QQmlEngine *, QJSEngine *);
140     };
141     static SingletonType singletonType(const QString &, int, int);
142     static QHash<QString, QList<SingletonType> > singletonTypes();
143
144     static bool namespaceContainsRegistrations(const QString &);
145
146     static void protectNamespace(const QString &);
147
148     static void setTypeRegistrationNamespace(const QString &);
149     static QStringList typeRegistrationFailures();
150
151     static QReadWriteLock *typeRegistrationLock();
152
153 private:
154     static CompareFunction anchorLineCompareFunction;
155 };
156
157 class QHashedCStringRef;
158 class QHashedV8String;
159 class Q_QML_PRIVATE_EXPORT QQmlType
160 {
161 public:
162     QByteArray typeName() const;
163     const QString &qmlTypeName() const;
164     const QString &elementName() const;
165
166     const QHashedString &module() const;
167     int majorVersion() const;
168     int minorVersion() const;
169
170     bool availableInVersion(int vmajor, int vminor) const;
171     bool availableInVersion(const QHashedStringRef &module, int vmajor, int vminor) const;
172
173     QObject *create() const;
174     void create(QObject **, void **, size_t) const;
175
176     typedef void (*CreateFunc)(void *);
177     CreateFunc createFunction() const;
178     int createSize() const;
179
180     QQmlCustomParser *customParser() const;
181
182     bool isCreatable() const;
183     bool isExtendedType() const;
184     QString noCreationReason() const;
185
186     bool isInterface() const;
187     int typeId() const;
188     int qListTypeId() const;
189
190     const QMetaObject *metaObject() const;
191     const QMetaObject *baseMetaObject() const;
192     int metaObjectRevision() const;
193     bool containsRevisionedAttributes() const;
194
195     QQmlAttachedPropertiesFunc attachedPropertiesFunction() const;
196     const QMetaObject *attachedPropertiesType() const;
197     int attachedPropertiesId() const;
198
199     int parserStatusCast() const;
200     const char *interfaceIId() const;
201     int propertyValueSourceCast() const;
202     int propertyValueInterceptorCast() const;
203
204     int index() const;
205
206     int enumValue(const QHashedStringRef &, bool *ok) const;
207     int enumValue(const QHashedCStringRef &, bool *ok) const;
208     int enumValue(const QHashedV8String &, bool *ok) const;
209 private:
210     QQmlType *superType() const;
211     friend class QQmlTypePrivate;
212     friend struct QQmlMetaTypeData;
213     friend int registerType(const QQmlPrivate::RegisterType &);
214     friend int registerInterface(const QQmlPrivate::RegisterInterface &);
215     QQmlType(int, const QQmlPrivate::RegisterInterface &);
216     QQmlType(int, const QQmlPrivate::RegisterType &);
217     ~QQmlType();
218
219     QQmlTypePrivate *d;
220 };
221
222 class QQmlTypeModulePrivate;
223 class QQmlTypeModule
224 {
225 public:
226     QString module() const;
227     int majorVersion() const;
228
229     int minimumMinorVersion() const;
230     int maximumMinorVersion() const;
231
232     QQmlType *type(const QHashedStringRef &, int);
233     QQmlType *type(const QHashedV8String &, int);
234
235 private:
236     QQmlType *typeNoLock(const QString &name, int minor);
237
238     friend int registerType(const QQmlPrivate::RegisterType &);
239     friend struct QQmlMetaTypeData;
240
241     QQmlTypeModule();
242     ~QQmlTypeModule();
243     QQmlTypeModulePrivate *d;
244 };
245
246 class QQmlTypeModuleVersion 
247 {
248 public:
249     QQmlTypeModuleVersion();
250     QQmlTypeModuleVersion(QQmlTypeModule *, int);
251     QQmlTypeModuleVersion(const QQmlTypeModuleVersion &);
252     QQmlTypeModuleVersion &operator=(const QQmlTypeModuleVersion &);
253
254     QQmlTypeModule *module() const;
255     int minorVersion() const;
256
257     QQmlType *type(const QHashedStringRef &) const;
258     QQmlType *type(const QHashedV8String &) const;
259
260 private:
261     QQmlTypeModule *m_module;
262     int m_minor;
263 };
264
265 QQmlMetaType::SingletonType::SingletonType()
266 {
267     major = 0;
268     minor = 0;
269     qobject = 0;
270     instanceMetaObject = 0;
271     script = 0;
272 }
273
274 bool QQmlMetaType::SingletonType::operator==(const SingletonType &other) const
275 {
276     return major == other.major && minor == other.minor && script == other.script && qobject == other.qobject;
277 }
278
279 inline uint qHash(const QQmlMetaType::SingletonType &import)
280 {
281     return import.major ^ import.minor ^ quintptr(import.script) ^ quintptr(import.qobject);
282 }
283
284 QT_END_NAMESPACE
285
286 #endif // QQMLMETATYPE_P_H
287