Remove "All rights reserved" line from license headers.
[profile/ivi/qtdeclarative.git] / src / declarative / qml / qdeclarativemetatype_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 QtDeclarative 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 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 QList<QString> qmlTypeNames();
75     static QList<QDeclarativeType*> qmlTypes();
76
77     static QDeclarativeType *qmlType(const QString &, int, int);
78     static QDeclarativeType *qmlType(const QMetaObject *);
79     static QDeclarativeType *qmlType(const QMetaObject *metaObject, const QString &module, int version_major, int version_minor);
80     static QDeclarativeType *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 QDeclarativeAttachedPropertiesFunc 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 QDeclarativeTypeModule *typeModule(const QString &uri, int majorVersion);
108
109     static QList<QDeclarativePrivate::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)(QDeclarativeEngine *, QJSEngine *);
121         QObject *(*qobjectCallback)(QDeclarativeEngine *, 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)(QDeclarativeEngine *, QJSEngine *);
131         QObject *(*qobject)(QDeclarativeEngine *, 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_DECLARATIVE_PRIVATE_EXPORT QDeclarativeType
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     QDeclarativeCustomParser *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     QDeclarativeAttachedPropertiesFunc 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     QDeclarativeType *superType() const;
194     friend class QDeclarativeTypePrivate;
195     friend struct QDeclarativeMetaTypeData;
196     friend int registerType(const QDeclarativePrivate::RegisterType &);
197     friend int registerInterface(const QDeclarativePrivate::RegisterInterface &);
198     QDeclarativeType(int, const QDeclarativePrivate::RegisterInterface &);
199     QDeclarativeType(int, const QDeclarativePrivate::RegisterType &);
200     ~QDeclarativeType();
201
202     QDeclarativeTypePrivate *d;
203 };
204
205 class QDeclarativeTypeModulePrivate;
206 class QDeclarativeTypeModule
207 {
208 public:
209     QString module() const;
210     int majorVersion() const;
211
212     int minimumMinorVersion() const;
213     int maximumMinorVersion() const;
214
215     QList<QDeclarativeType *> types();
216     QList<QDeclarativeType *> type(const QString &);
217
218     QDeclarativeType *type(const QHashedStringRef &, int);
219     QDeclarativeType *type(const QHashedV8String &, int);
220
221 private:
222     friend int registerType(const QDeclarativePrivate::RegisterType &);
223     QDeclarativeTypeModule();
224     ~QDeclarativeTypeModule();
225     QDeclarativeTypeModulePrivate *d;
226 };
227
228 class QDeclarativeTypeModuleVersion 
229 {
230 public:
231     QDeclarativeTypeModuleVersion();
232     QDeclarativeTypeModuleVersion(QDeclarativeTypeModule *, int);
233     QDeclarativeTypeModuleVersion(const QDeclarativeTypeModuleVersion &);
234     QDeclarativeTypeModuleVersion &operator=(const QDeclarativeTypeModuleVersion &);
235
236     QDeclarativeTypeModule *module() const;
237     int minorVersion() const;
238
239     QDeclarativeType *type(const QHashedStringRef &) const;
240     QDeclarativeType *type(const QHashedV8String &) const;
241
242 private:
243     QDeclarativeTypeModule *m_module;
244     int m_minor;
245 };
246
247 QDeclarativeMetaType::ModuleApi::ModuleApi()
248 {
249     major = 0;
250     minor = 0;
251     script = 0;
252     qobject = 0;
253 }
254
255 bool QDeclarativeMetaType::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 QDeclarativeMetaType::ModuleApi &import)
261 {
262     return import.major ^ import.minor ^ quintptr(import.script) ^ quintptr(import.qobject);
263 }
264
265 QT_END_NAMESPACE
266
267 #endif // QDECLARATIVEMETATYPE_P_H
268