Improve QJSValueIterator implementation.
[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
70 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeMetaType
71 {
72 public:
73     static bool canCopy(int type);
74     static bool copy(int type, void *data, const void *copy = 0);
75
76     static QList<QByteArray> qmlTypeNames();
77     static QList<QDeclarativeType*> qmlTypes();
78
79     static QDeclarativeType *qmlType(const QByteArray &, int, int);
80     static QDeclarativeType *qmlType(const QMetaObject *);
81     static QDeclarativeType *qmlType(const QMetaObject *metaObject, const QByteArray &module, int version_major, int version_minor);
82     static QDeclarativeType *qmlType(int);
83
84     static QMetaProperty defaultProperty(const QMetaObject *);
85     static QMetaProperty defaultProperty(QObject *);
86     static QMetaMethod defaultMethod(const QMetaObject *);
87     static QMetaMethod defaultMethod(QObject *);
88
89     static bool isQObject(int);
90     static QObject *toQObject(const QVariant &, bool *ok = 0);
91
92     static int listType(int);
93     static int attachedPropertiesFuncId(const QMetaObject *);
94     static QDeclarativeAttachedPropertiesFunc attachedPropertiesFuncById(int);
95
96     enum TypeCategory { Unknown, Object, List };
97     static TypeCategory typeCategory(int);
98         
99     static bool isInterface(int);
100     static const char *interfaceIId(int);
101     static bool isList(int);
102
103     typedef QVariant (*StringConverter)(const QString &);
104     static void registerCustomStringConverter(int, StringConverter);
105     static StringConverter customStringConverter(int);
106
107     static bool isAnyModule(const QByteArray &module);
108     static bool isModule(const QByteArray &module, int versionMajor, int versionMinor);
109
110     static QList<QDeclarativePrivate::AutoParentFunction> parentFunctions();
111
112     struct ModuleApiInstance {
113         ModuleApiInstance()
114             : scriptCallback(0), qobjectCallback(0), qobjectApi(0) {}
115
116         QJSValue (*scriptCallback)(QDeclarativeEngine *, QJSEngine *);
117         QObject *(*qobjectCallback)(QDeclarativeEngine *, QJSEngine *);
118         QJSValue scriptApi;
119         QObject *qobjectApi;
120     };
121     struct ModuleApi {
122         inline ModuleApi();
123         inline bool operator==(const ModuleApi &) const;
124         int major;
125         int minor;
126         QJSValue (*script)(QDeclarativeEngine *, QJSEngine *);
127         QObject *(*qobject)(QDeclarativeEngine *, QJSEngine *);
128     };
129     static ModuleApi moduleApi(const QByteArray &, int, int);
130 };
131
132 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeType
133 {
134 public:
135     QByteArray typeName() const;
136     QByteArray qmlTypeName() const;
137
138     QByteArray module() const;
139     int majorVersion() const;
140     int minorVersion() const;
141
142     bool availableInVersion(int vmajor, int vminor) const;
143     bool availableInVersion(const QByteArray &module, int vmajor, int vminor) const;
144
145     QObject *create() const;
146     void create(QObject **, void **, size_t) const;
147
148     typedef void (*CreateFunc)(void *);
149     CreateFunc createFunction() const;
150     int createSize() const;
151
152     QDeclarativeCustomParser *customParser() const;
153
154     bool isCreatable() const;
155     bool isExtendedType() const;
156     QString noCreationReason() const;
157
158     bool isInterface() const;
159     int typeId() const;
160     int qListTypeId() const;
161
162     const QMetaObject *metaObject() const;
163     const QMetaObject *baseMetaObject() const;
164     int metaObjectRevision() const;
165     bool containsRevisionedAttributes() const;
166
167     QDeclarativeAttachedPropertiesFunc attachedPropertiesFunction() const;
168     const QMetaObject *attachedPropertiesType() const;
169     int attachedPropertiesId() const;
170
171     int parserStatusCast() const;
172     QVariant fromObject(QObject *) const;
173     const char *interfaceIId() const;
174     int propertyValueSourceCast() const;
175     int propertyValueInterceptorCast() const;
176
177     int index() const;
178
179 private:
180     QDeclarativeType *superType() const;
181     friend class QDeclarativeTypePrivate;
182     friend struct QDeclarativeMetaTypeData;
183     friend int registerType(const QDeclarativePrivate::RegisterType &);
184     friend int registerInterface(const QDeclarativePrivate::RegisterInterface &);
185     QDeclarativeType(int, const QDeclarativePrivate::RegisterInterface &);
186     QDeclarativeType(int, const QDeclarativePrivate::RegisterType &);
187     ~QDeclarativeType();
188
189     QDeclarativeTypePrivate *d;
190 };
191
192 QDeclarativeMetaType::ModuleApi::ModuleApi()
193 //    : major(0), minor(0), script(0), qobject(0)
194 {
195     major = 0;
196     minor = 0;
197     script = 0;
198     qobject = 0;
199 }
200
201 bool QDeclarativeMetaType::ModuleApi::operator==(const ModuleApi &other) const
202 {
203     return major == other.major && minor == other.minor && script == other.script && qobject == other.qobject;
204 }
205
206 inline uint qHash(const QDeclarativeMetaType::ModuleApi &import)
207 {
208     return import.major ^ import.minor ^ quintptr(import.script) ^ quintptr(import.qobject);
209 }
210
211 QT_END_NAMESPACE
212
213 #endif // QDECLARATIVEMETATYPE_P_H
214