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