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>
68 class QQmlCustomParser;
69 class QQmlTypePrivate;
72 class QHashedStringRef;
75 class Q_QML_PRIVATE_EXPORT QQmlMetaType
78 static QList<QString> qmlTypeNames();
79 static QList<QQmlType*> qmlTypes();
80 static QList<QQmlType*> qmlSingletonTypes();
82 static QQmlType *qmlType(const QString &qualifiedName, int, int);
83 static QQmlType *qmlType(const QHashedStringRef &name, const QHashedStringRef &module, int, int);
84 static QQmlType *qmlType(const QMetaObject *);
85 static QQmlType *qmlType(const QMetaObject *metaObject, const QHashedStringRef &module, int version_major, int version_minor);
86 static QQmlType *qmlType(int);
88 static QMetaProperty defaultProperty(const QMetaObject *);
89 static QMetaProperty defaultProperty(QObject *);
90 static QMetaMethod defaultMethod(const QMetaObject *);
91 static QMetaMethod defaultMethod(QObject *);
93 static bool isQObject(int);
94 static QObject *toQObject(const QVariant &, bool *ok = 0);
96 static int listType(int);
97 static int attachedPropertiesFuncId(const QMetaObject *);
98 static QQmlAttachedPropertiesFunc attachedPropertiesFuncById(int);
100 enum TypeCategory { Unknown, Object, List };
101 static TypeCategory typeCategory(int);
103 static bool isInterface(int);
104 static const char *interfaceIId(int);
105 static bool isList(int);
107 typedef QVariant (*StringConverter)(const QString &);
108 static void registerCustomStringConverter(int, StringConverter);
109 static StringConverter customStringConverter(int);
111 static bool isAnyModule(const QString &uri);
112 static bool isModule(const QString &module, int versionMajor, int versionMinor);
113 static QQmlTypeModule *typeModule(const QString &uri, int majorVersion);
115 static QList<QQmlPrivate::AutoParentFunction> parentFunctions();
117 static int QQuickAnchorLineMetaTypeId();
118 typedef bool (*CompareFunction)(const void *, const void *);
119 static void setQQuickAnchorLineCompareFunction(CompareFunction);
120 static bool QQuickAnchorLineCompare(const void *p1, const void *p2);
122 static bool namespaceContainsRegistrations(const QString &);
124 static void protectNamespace(const QString &);
126 static void setTypeRegistrationNamespace(const QString &);
127 static QStringList typeRegistrationFailures();
129 static QReadWriteLock *typeRegistrationLock();
132 static CompareFunction anchorLineCompareFunction;
135 struct QQmlMetaTypeData;
136 class QHashedCStringRef;
137 class QHashedV8String;
138 class Q_QML_PRIVATE_EXPORT QQmlType
141 QByteArray typeName() const;
142 const QString &qmlTypeName() const;
143 const QString &elementName() const;
145 const QHashedString &module() const;
146 int majorVersion() const;
147 int minorVersion() const;
149 bool availableInVersion(int vmajor, int vminor) const;
150 bool availableInVersion(const QHashedStringRef &module, int vmajor, int vminor) const;
152 QObject *create() const;
153 void create(QObject **, void **, size_t) const;
155 typedef void (*CreateFunc)(void *);
156 CreateFunc createFunction() const;
157 int createSize() const;
159 QQmlCustomParser *customParser() const;
161 bool isCreatable() const;
162 bool isExtendedType() const;
163 QString noCreationReason() const;
165 bool isSingleton() const;
166 bool isInterface() const;
168 int qListTypeId() const;
170 const QMetaObject *metaObject() const;
171 const QMetaObject *baseMetaObject() const;
172 int metaObjectRevision() const;
173 bool containsRevisionedAttributes() const;
175 QQmlAttachedPropertiesFunc attachedPropertiesFunction() const;
176 const QMetaObject *attachedPropertiesType() const;
177 int attachedPropertiesId() const;
179 int parserStatusCast() const;
180 const char *interfaceIId() const;
181 int propertyValueSourceCast() const;
182 int propertyValueInterceptorCast() const;
186 class Q_QML_PRIVATE_EXPORT SingletonInstanceInfo
189 SingletonInstanceInfo()
190 : scriptCallback(0), qobjectCallback(0), instanceMetaObject(0) {}
192 QJSValue (*scriptCallback)(QQmlEngine *, QJSEngine *);
193 QObject *(*qobjectCallback)(QQmlEngine *, QJSEngine *);
194 const QMetaObject *instanceMetaObject;
197 void setQObjectApi(QQmlEngine *, QObject *);
198 QObject *qobjectApi(QQmlEngine *) const;
199 void setScriptApi(QQmlEngine *, QJSValue);
200 QJSValue scriptApi(QQmlEngine *) const;
202 void init(QQmlEngine *);
203 void destroy(QQmlEngine *);
205 QHash<QQmlEngine *, QJSValue> scriptApis;
206 QHash<QQmlEngine *, QObject *> qobjectApis;
208 SingletonInstanceInfo *singletonInstanceInfo() const;
210 int enumValue(const QHashedStringRef &, bool *ok) const;
211 int enumValue(const QHashedCStringRef &, bool *ok) const;
212 int enumValue(const QHashedV8String &, bool *ok) const;
214 QQmlType *superType() const;
215 friend class QQmlTypePrivate;
216 friend struct QQmlMetaTypeData;
218 enum RegistrationType {
221 // In the future, we should register all types via QQmlType, including Composite types.
223 friend QString registrationTypeString(RegistrationType);
224 friend bool checkRegistration(RegistrationType, QQmlMetaTypeData *, const char *, const QString &);
225 friend int registerType(const QQmlPrivate::RegisterType &);
226 friend int registerSingletonType(const QQmlPrivate::RegisterSingletonType &);
227 friend int registerInterface(const QQmlPrivate::RegisterInterface &);
228 QQmlType(int, const QQmlPrivate::RegisterInterface &);
229 QQmlType(int, const QString &, const QQmlPrivate::RegisterSingletonType &);
230 QQmlType(int, const QString &, const QQmlPrivate::RegisterType &);
236 class QQmlTypeModulePrivate;
240 QString module() const;
241 int majorVersion() const;
243 int minimumMinorVersion() const;
244 int maximumMinorVersion() const;
246 QQmlType *type(const QHashedStringRef &, int);
247 QQmlType *type(const QHashedV8String &, int);
249 QList<QQmlType*> singletonTypes(int) const;
252 friend int registerType(const QQmlPrivate::RegisterType &);
253 friend int registerSingletonType(const QQmlPrivate::RegisterSingletonType &);
254 friend struct QQmlMetaTypeData;
258 QQmlTypeModulePrivate *d;
261 class QQmlTypeModuleVersion
264 QQmlTypeModuleVersion();
265 QQmlTypeModuleVersion(QQmlTypeModule *, int);
266 QQmlTypeModuleVersion(const QQmlTypeModuleVersion &);
267 QQmlTypeModuleVersion &operator=(const QQmlTypeModuleVersion &);
269 QQmlTypeModule *module() const;
270 int minorVersion() const;
272 QQmlType *type(const QHashedStringRef &) const;
273 QQmlType *type(const QHashedV8String &) const;
276 QQmlTypeModule *m_module;
282 #endif // QQMLMETATYPE_P_H