Merge branch 'master' of git://scm.dev.nokia.troll.no/qt/qtdeclarative
[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 <QtScript/qscriptvalue.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 isModule(const QByteArray &module, int versionMajor, int versionMinor);
108
109     static QList<QDeclarativePrivate::AutoParentFunction> parentFunctions();
110
111     struct ModuleApiInstance {
112         ModuleApiInstance()
113             : scriptCallback(0), qobjectCallback(0), qobjectApi(0) {}
114
115         QScriptValue (*scriptCallback)(QDeclarativeEngine *, QScriptEngine *);
116         QObject *(*qobjectCallback)(QDeclarativeEngine *, QScriptEngine *);
117         QScriptValue scriptApi;
118         QObject *qobjectApi;
119     };
120     struct ModuleApi {
121         inline ModuleApi();
122         inline bool operator==(const ModuleApi &) const;
123         int major;
124         int minor;
125         QScriptValue (*script)(QDeclarativeEngine *, QScriptEngine *);
126         QObject *(*qobject)(QDeclarativeEngine *, QScriptEngine *);
127     };
128     static ModuleApi moduleApi(const QByteArray &, int, int);
129 };
130
131 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeType
132 {
133 public:
134     QByteArray typeName() const;
135     QByteArray qmlTypeName() const;
136
137     QByteArray module() const;
138     int majorVersion() const;
139     int minorVersion() const;
140
141     bool availableInVersion(int vmajor, int vminor) const;
142     bool availableInVersion(const QByteArray &module, int vmajor, int vminor) const;
143
144     QObject *create() const;
145     void create(QObject **, void **, size_t) const;
146
147     typedef void (*CreateFunc)(void *);
148     CreateFunc createFunction() const;
149     int createSize() const;
150
151     QDeclarativeCustomParser *customParser() const;
152
153     bool isCreatable() const;
154     bool isExtendedType() const;
155     QString noCreationReason() const;
156
157     bool isInterface() const;
158     int typeId() const;
159     int qListTypeId() const;
160
161     const QMetaObject *metaObject() const;
162     const QMetaObject *baseMetaObject() const;
163     int metaObjectRevision() const;
164     bool containsRevisionedAttributes() const;
165
166     QDeclarativeAttachedPropertiesFunc attachedPropertiesFunction() const;
167     const QMetaObject *attachedPropertiesType() const;
168     int attachedPropertiesId() const;
169
170     int parserStatusCast() const;
171     QVariant fromObject(QObject *) const;
172     const char *interfaceIId() const;
173     int propertyValueSourceCast() const;
174     int propertyValueInterceptorCast() const;
175
176     int index() const;
177
178 private:
179     QDeclarativeType *superType() const;
180     friend class QDeclarativeTypePrivate;
181     friend struct QDeclarativeMetaTypeData;
182     friend int registerType(const QDeclarativePrivate::RegisterType &);
183     friend int registerInterface(const QDeclarativePrivate::RegisterInterface &);
184     QDeclarativeType(int, const QDeclarativePrivate::RegisterInterface &);
185     QDeclarativeType(int, const QDeclarativePrivate::RegisterType &);
186     ~QDeclarativeType();
187
188     QDeclarativeTypePrivate *d;
189 };
190
191 QDeclarativeMetaType::ModuleApi::ModuleApi()
192 //    : major(0), minor(0), script(0), qobject(0)
193 {
194     major = 0;
195     minor = 0;
196     script = 0;
197     qobject = 0;
198 }
199
200 bool QDeclarativeMetaType::ModuleApi::operator==(const ModuleApi &other) const
201 {
202     return major == other.major && minor == other.minor && script == other.script && qobject == other.qobject;
203 }
204
205 inline uint qHash(const QDeclarativeMetaType::ModuleApi &import)
206 {
207     return import.major ^ import.minor ^ quintptr(import.script) ^ quintptr(import.qobject);
208 }
209
210 QT_END_NAMESPACE
211
212 #endif // QDECLARATIVEMETATYPE_P_H
213