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 QtQml 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 QQMLMETATYPE_P_H
43 #define QQMLMETATYPE_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.
57 #include <private/qtqmlglobal_p.h>
59 #include <QtCore/qglobal.h>
60 #include <QtCore/qvariant.h>
61 #include <QtCore/qbitarray.h>
62 #include <QtQml/qjsvalue.h>
67 class QQmlCustomParser;
68 class QQmlTypePrivate;
71 class QHashedStringRef;
74 class Q_QML_PRIVATE_EXPORT QQmlMetaType
77 static QList<QString> qmlTypeNames();
78 static QList<QQmlType*> qmlTypes();
80 static QQmlType *qmlType(const QString &qualifiedName, int, int);
81 static QQmlType *qmlType(const QHashedStringRef &name, const QHashedStringRef &module, int, int);
82 static QQmlType *qmlType(const QMetaObject *);
83 static QQmlType *qmlType(const QMetaObject *metaObject, const QHashedStringRef &module, int version_major, int version_minor);
84 static QQmlType *qmlType(int);
86 static QMetaProperty defaultProperty(const QMetaObject *);
87 static QMetaProperty defaultProperty(QObject *);
88 static QMetaMethod defaultMethod(const QMetaObject *);
89 static QMetaMethod defaultMethod(QObject *);
91 static bool isQObject(int);
92 static QObject *toQObject(const QVariant &, bool *ok = 0);
94 static int listType(int);
95 static int attachedPropertiesFuncId(const QMetaObject *);
96 static QQmlAttachedPropertiesFunc attachedPropertiesFuncById(int);
98 enum TypeCategory { Unknown, Object, List };
99 static TypeCategory typeCategory(int);
101 static bool isInterface(int);
102 static const char *interfaceIId(int);
103 static bool isList(int);
105 typedef QVariant (*StringConverter)(const QString &);
106 static void registerCustomStringConverter(int, StringConverter);
107 static StringConverter customStringConverter(int);
109 static bool isAnyModule(const QString &uri);
110 static bool isModule(const QString &module, int versionMajor, int versionMinor);
111 static QQmlTypeModule *typeModule(const QString &uri, int majorVersion);
113 static QList<QQmlPrivate::AutoParentFunction> parentFunctions();
115 static int QQuickAnchorLineMetaTypeId();
116 typedef bool (*CompareFunction)(const void *, const void *);
117 static void setQQuickAnchorLineCompareFunction(CompareFunction);
118 static bool QQuickAnchorLineCompare(const void *p1, const void *p2);
120 struct ModuleApiInstance {
122 : scriptCallback(0), qobjectCallback(0), qobjectApi(0), instanceMetaObject(0) {}
124 QJSValue (*scriptCallback)(QQmlEngine *, QJSEngine *);
125 QObject *(*qobjectCallback)(QQmlEngine *, QJSEngine *);
127 const QMetaObject *instanceMetaObject;
133 inline bool operator==(const ModuleApi &) const;
136 QObject *(*qobject)(QQmlEngine *, QJSEngine *);
137 const QMetaObject *instanceMetaObject;
138 QJSValue (*script)(QQmlEngine *, QJSEngine *);
140 static ModuleApi moduleApi(const QString &, int, int);
141 static QHash<QString, QList<ModuleApi> > moduleApis();
143 static bool namespaceContainsRegistrations(const QString &);
145 static void protectNamespace(const QString &);
147 static void setTypeRegistrationNamespace(const QString &);
148 static QStringList typeRegistrationFailures();
150 static QReadWriteLock *typeRegistrationLock();
153 static CompareFunction anchorLineCompareFunction;
156 class QHashedCStringRef;
157 class QHashedV8String;
158 class Q_QML_PRIVATE_EXPORT QQmlType
161 QByteArray typeName() const;
162 const QString &qmlTypeName() const;
163 const QString &elementName() const;
165 const QHashedString &module() const;
166 int majorVersion() const;
167 int minorVersion() const;
169 bool availableInVersion(int vmajor, int vminor) const;
170 bool availableInVersion(const QHashedStringRef &module, int vmajor, int vminor) const;
172 QObject *create() const;
173 void create(QObject **, void **, size_t) const;
175 typedef void (*CreateFunc)(void *);
176 CreateFunc createFunction() const;
177 int createSize() const;
179 QQmlCustomParser *customParser() const;
181 bool isCreatable() const;
182 bool isExtendedType() const;
183 QString noCreationReason() const;
185 bool isInterface() const;
187 int qListTypeId() const;
189 const QMetaObject *metaObject() const;
190 const QMetaObject *baseMetaObject() const;
191 int metaObjectRevision() const;
192 bool containsRevisionedAttributes() const;
194 QQmlAttachedPropertiesFunc attachedPropertiesFunction() const;
195 const QMetaObject *attachedPropertiesType() const;
196 int attachedPropertiesId() const;
198 int parserStatusCast() const;
199 const char *interfaceIId() const;
200 int propertyValueSourceCast() const;
201 int propertyValueInterceptorCast() const;
205 int enumValue(const QHashedStringRef &, bool *ok) const;
206 int enumValue(const QHashedCStringRef &, bool *ok) const;
207 int enumValue(const QHashedV8String &, bool *ok) const;
209 QQmlType *superType() const;
210 friend class QQmlTypePrivate;
211 friend struct QQmlMetaTypeData;
212 friend int registerType(const QQmlPrivate::RegisterType &);
213 friend int registerInterface(const QQmlPrivate::RegisterInterface &);
214 QQmlType(int, const QQmlPrivate::RegisterInterface &);
215 QQmlType(int, const QQmlPrivate::RegisterType &);
221 class QQmlTypeModulePrivate;
225 QString module() const;
226 int majorVersion() const;
228 int minimumMinorVersion() const;
229 int maximumMinorVersion() const;
231 QQmlType *type(const QHashedStringRef &, int);
232 QQmlType *type(const QHashedV8String &, int);
235 friend int registerType(const QQmlPrivate::RegisterType &);
238 QQmlTypeModulePrivate *d;
241 class QQmlTypeModuleVersion
244 QQmlTypeModuleVersion();
245 QQmlTypeModuleVersion(QQmlTypeModule *, int);
246 QQmlTypeModuleVersion(const QQmlTypeModuleVersion &);
247 QQmlTypeModuleVersion &operator=(const QQmlTypeModuleVersion &);
249 QQmlTypeModule *module() const;
250 int minorVersion() const;
252 QQmlType *type(const QHashedStringRef &) const;
253 QQmlType *type(const QHashedV8String &) const;
256 QQmlTypeModule *m_module;
260 QQmlMetaType::ModuleApi::ModuleApi()
265 instanceMetaObject = 0;
269 bool QQmlMetaType::ModuleApi::operator==(const ModuleApi &other) const
271 return major == other.major && minor == other.minor && script == other.script && qobject == other.qobject;
274 inline uint qHash(const QQmlMetaType::ModuleApi &import)
276 return import.major ^ import.minor ^ quintptr(import.script) ^ quintptr(import.qobject);
281 #endif // QQMLMETATYPE_P_H