Implement strict mode for qmldir modules
[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 ModuleApiInstance {
121         ModuleApiInstance()
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 ModuleApi {
132         inline ModuleApi();
133         inline bool operator==(const ModuleApi &) const;
134         int major;
135         int minor;
136         QObject *(*qobject)(QQmlEngine *, QJSEngine *);
137         const QMetaObject *instanceMetaObject;
138         QJSValue (*script)(QQmlEngine *, QJSEngine *);
139     };
140     static ModuleApi moduleApi(const QString &, int, int);
141     static QHash<QString, QList<ModuleApi> > moduleApis();
142
143     static bool namespaceContainsRegistrations(const QString &);
144
145     static void protectNamespace(const QString &);
146
147     static void setTypeRegistrationNamespace(const QString &);
148     static QStringList typeRegistrationFailures();
149
150     static QReadWriteLock *typeRegistrationLock();
151
152 private:
153     static CompareFunction anchorLineCompareFunction;
154 };
155
156 class QHashedCStringRef;
157 class QHashedV8String;
158 class Q_QML_PRIVATE_EXPORT QQmlType
159 {
160 public:
161     QByteArray typeName() const;
162     const QString &qmlTypeName() const;
163     const QString &elementName() const;
164
165     const QHashedString &module() const;
166     int majorVersion() const;
167     int minorVersion() const;
168
169     bool availableInVersion(int vmajor, int vminor) const;
170     bool availableInVersion(const QHashedStringRef &module, int vmajor, int vminor) const;
171
172     QObject *create() const;
173     void create(QObject **, void **, size_t) const;
174
175     typedef void (*CreateFunc)(void *);
176     CreateFunc createFunction() const;
177     int createSize() const;
178
179     QQmlCustomParser *customParser() const;
180
181     bool isCreatable() const;
182     bool isExtendedType() const;
183     QString noCreationReason() const;
184
185     bool isInterface() const;
186     int typeId() const;
187     int qListTypeId() const;
188
189     const QMetaObject *metaObject() const;
190     const QMetaObject *baseMetaObject() const;
191     int metaObjectRevision() const;
192     bool containsRevisionedAttributes() const;
193
194     QQmlAttachedPropertiesFunc attachedPropertiesFunction() const;
195     const QMetaObject *attachedPropertiesType() const;
196     int attachedPropertiesId() const;
197
198     int parserStatusCast() const;
199     const char *interfaceIId() const;
200     int propertyValueSourceCast() const;
201     int propertyValueInterceptorCast() const;
202
203     int index() const;
204
205     int enumValue(const QHashedStringRef &, bool *ok) const;
206     int enumValue(const QHashedCStringRef &, bool *ok) const;
207     int enumValue(const QHashedV8String &, bool *ok) const;
208 private:
209     QQmlType *superType() const;
210     friend class QQmlTypePrivate;
211     friend struct QQmlMetaTypeData;
212     friend int registerType(const QQmlPrivate::RegisterType &);
213     friend int registerInterface(const QQmlPrivate::RegisterInterface &);
214     QQmlType(int, const QQmlPrivate::RegisterInterface &);
215     QQmlType(int, const QQmlPrivate::RegisterType &);
216     ~QQmlType();
217
218     QQmlTypePrivate *d;
219 };
220
221 class QQmlTypeModulePrivate;
222 class QQmlTypeModule
223 {
224 public:
225     QString module() const;
226     int majorVersion() const;
227
228     int minimumMinorVersion() const;
229     int maximumMinorVersion() const;
230
231     QQmlType *type(const QHashedStringRef &, int);
232     QQmlType *type(const QHashedV8String &, int);
233
234 private:
235     friend int registerType(const QQmlPrivate::RegisterType &);
236     QQmlTypeModule();
237     ~QQmlTypeModule();
238     QQmlTypeModulePrivate *d;
239 };
240
241 class QQmlTypeModuleVersion 
242 {
243 public:
244     QQmlTypeModuleVersion();
245     QQmlTypeModuleVersion(QQmlTypeModule *, int);
246     QQmlTypeModuleVersion(const QQmlTypeModuleVersion &);
247     QQmlTypeModuleVersion &operator=(const QQmlTypeModuleVersion &);
248
249     QQmlTypeModule *module() const;
250     int minorVersion() const;
251
252     QQmlType *type(const QHashedStringRef &) const;
253     QQmlType *type(const QHashedV8String &) const;
254
255 private:
256     QQmlTypeModule *m_module;
257     int m_minor;
258 };
259
260 QQmlMetaType::ModuleApi::ModuleApi()
261 {
262     major = 0;
263     minor = 0;
264     qobject = 0;
265     instanceMetaObject = 0;
266     script = 0;
267 }
268
269 bool QQmlMetaType::ModuleApi::operator==(const ModuleApi &other) const
270 {
271     return major == other.major && minor == other.minor && script == other.script && qobject == other.qobject;
272 }
273
274 inline uint qHash(const QQmlMetaType::ModuleApi &import)
275 {
276     return import.major ^ import.minor ^ quintptr(import.script) ^ quintptr(import.qobject);
277 }
278
279 QT_END_NAMESPACE
280
281 #endif // QQMLMETATYPE_P_H
282