1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDeclarative module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #ifndef QDECLARATIVEMETATYPE_P_H
43 #define QDECLARATIVEMETATYPE_P_H
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.
56 #include "qdeclarative.h"
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>
66 class QDeclarativeType;
67 class QDeclarativeCustomParser;
68 class QDeclarativeTypePrivate;
69 class QDeclarativeTypeModule;
71 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeMetaType
74 static QList<QString> qmlTypeNames();
75 static QList<QDeclarativeType*> qmlTypes();
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);
82 static QMetaProperty defaultProperty(const QMetaObject *);
83 static QMetaProperty defaultProperty(QObject *);
84 static QMetaMethod defaultMethod(const QMetaObject *);
85 static QMetaMethod defaultMethod(QObject *);
87 static bool isQObject(int);
88 static QObject *toQObject(const QVariant &, bool *ok = 0);
90 static int listType(int);
91 static int attachedPropertiesFuncId(const QMetaObject *);
92 static QDeclarativeAttachedPropertiesFunc attachedPropertiesFuncById(int);
94 enum TypeCategory { Unknown, Object, List };
95 static TypeCategory typeCategory(int);
97 static bool isInterface(int);
98 static const char *interfaceIId(int);
99 static bool isList(int);
101 typedef QVariant (*StringConverter)(const QString &);
102 static void registerCustomStringConverter(int, StringConverter);
103 static StringConverter customStringConverter(int);
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);
109 static QList<QDeclarativePrivate::AutoParentFunction> parentFunctions();
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);
116 struct ModuleApiInstance {
118 : scriptCallback(0), qobjectCallback(0), qobjectApi(0) {}
120 QJSValue (*scriptCallback)(QDeclarativeEngine *, QJSEngine *);
121 QObject *(*qobjectCallback)(QDeclarativeEngine *, QJSEngine *);
127 inline bool operator==(const ModuleApi &) const;
130 QJSValue (*script)(QDeclarativeEngine *, QJSEngine *);
131 QObject *(*qobject)(QDeclarativeEngine *, QJSEngine *);
133 static ModuleApi moduleApi(const QString &, int, int);
134 static QHash<QString, QList<ModuleApi> > moduleApis();
137 static CompareFunction anchorLineCompareFunction;
140 class QHashedStringRef;
141 class QHashedV8String;
142 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeType
145 QByteArray typeName() const;
146 const QString &qmlTypeName() const;
147 const QString &elementName() const;
149 QString module() const;
150 int majorVersion() const;
151 int minorVersion() const;
153 bool availableInVersion(int vmajor, int vminor) const;
154 bool availableInVersion(const QString &module, int vmajor, int vminor) const;
156 QObject *create() const;
157 void create(QObject **, void **, size_t) const;
159 typedef void (*CreateFunc)(void *);
160 CreateFunc createFunction() const;
161 int createSize() const;
163 QDeclarativeCustomParser *customParser() const;
165 bool isCreatable() const;
166 bool isExtendedType() const;
167 QString noCreationReason() const;
169 bool isInterface() const;
171 int qListTypeId() const;
173 const QMetaObject *metaObject() const;
174 const QMetaObject *baseMetaObject() const;
175 int metaObjectRevision() const;
176 bool containsRevisionedAttributes() const;
178 QDeclarativeAttachedPropertiesFunc attachedPropertiesFunction() const;
179 const QMetaObject *attachedPropertiesType() const;
180 int attachedPropertiesId() const;
182 int parserStatusCast() const;
183 QVariant fromObject(QObject *) const;
184 const char *interfaceIId() const;
185 int propertyValueSourceCast() const;
186 int propertyValueInterceptorCast() const;
190 int enumValue(const QHashedStringRef &) const;
191 int enumValue(const QHashedV8String &) const;
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 &);
202 QDeclarativeTypePrivate *d;
205 class QDeclarativeTypeModulePrivate;
206 class QDeclarativeTypeModule
209 QString module() const;
210 int majorVersion() const;
212 int minimumMinorVersion() const;
213 int maximumMinorVersion() const;
215 QList<QDeclarativeType *> types();
216 QList<QDeclarativeType *> type(const QString &);
218 QDeclarativeType *type(const QHashedStringRef &, int);
219 QDeclarativeType *type(const QHashedV8String &, int);
222 friend int registerType(const QDeclarativePrivate::RegisterType &);
223 QDeclarativeTypeModule();
224 ~QDeclarativeTypeModule();
225 QDeclarativeTypeModulePrivate *d;
228 class QDeclarativeTypeModuleVersion
231 QDeclarativeTypeModuleVersion();
232 QDeclarativeTypeModuleVersion(QDeclarativeTypeModule *, int);
233 QDeclarativeTypeModuleVersion(const QDeclarativeTypeModuleVersion &);
234 QDeclarativeTypeModuleVersion &operator=(const QDeclarativeTypeModuleVersion &);
236 QDeclarativeTypeModule *module() const;
237 int minorVersion() const;
239 QDeclarativeType *type(const QHashedStringRef &) const;
240 QDeclarativeType *type(const QHashedV8String &) const;
243 QDeclarativeTypeModule *m_module;
247 QDeclarativeMetaType::ModuleApi::ModuleApi()
255 bool QDeclarativeMetaType::ModuleApi::operator==(const ModuleApi &other) const
257 return major == other.major && minor == other.minor && script == other.script && qobject == other.qobject;
260 inline uint qHash(const QDeclarativeMetaType::ModuleApi &import)
262 return import.major ^ import.minor ^ quintptr(import.script) ^ quintptr(import.qobject);
267 #endif // QDECLARATIVEMETATYPE_P_H