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 SingletonInstance {
122 : scriptCallback(0), qobjectCallback(0), qobjectApi(0), instanceMetaObject(0) {}
124 QJSValue (*scriptCallback)(QQmlEngine *, QJSEngine *);
125 QObject *(*qobjectCallback)(QQmlEngine *, QJSEngine *);
127 const QMetaObject *instanceMetaObject;
131 struct SingletonType {
132 inline SingletonType();
133 inline bool operator==(const SingletonType &) const;
137 QObject *(*qobject)(QQmlEngine *, QJSEngine *);
138 const QMetaObject *instanceMetaObject;
139 QJSValue (*script)(QQmlEngine *, QJSEngine *);
141 static SingletonType singletonType(const QString &, int, int);
142 static QHash<QString, QList<SingletonType> > singletonTypes();
144 static bool namespaceContainsRegistrations(const QString &);
146 static void protectNamespace(const QString &);
148 static void setTypeRegistrationNamespace(const QString &);
149 static QStringList typeRegistrationFailures();
151 static QReadWriteLock *typeRegistrationLock();
154 static CompareFunction anchorLineCompareFunction;
157 class QHashedCStringRef;
158 class QHashedV8String;
159 class Q_QML_PRIVATE_EXPORT QQmlType
162 QByteArray typeName() const;
163 const QString &qmlTypeName() const;
164 const QString &elementName() const;
166 const QHashedString &module() const;
167 int majorVersion() const;
168 int minorVersion() const;
170 bool availableInVersion(int vmajor, int vminor) const;
171 bool availableInVersion(const QHashedStringRef &module, int vmajor, int vminor) const;
173 QObject *create() const;
174 void create(QObject **, void **, size_t) const;
176 typedef void (*CreateFunc)(void *);
177 CreateFunc createFunction() const;
178 int createSize() const;
180 QQmlCustomParser *customParser() const;
182 bool isCreatable() const;
183 bool isExtendedType() const;
184 QString noCreationReason() const;
186 bool isInterface() const;
188 int qListTypeId() const;
190 const QMetaObject *metaObject() const;
191 const QMetaObject *baseMetaObject() const;
192 int metaObjectRevision() const;
193 bool containsRevisionedAttributes() const;
195 QQmlAttachedPropertiesFunc attachedPropertiesFunction() const;
196 const QMetaObject *attachedPropertiesType() const;
197 int attachedPropertiesId() const;
199 int parserStatusCast() const;
200 const char *interfaceIId() const;
201 int propertyValueSourceCast() const;
202 int propertyValueInterceptorCast() const;
206 int enumValue(const QHashedStringRef &, bool *ok) const;
207 int enumValue(const QHashedCStringRef &, bool *ok) const;
208 int enumValue(const QHashedV8String &, bool *ok) const;
210 QQmlType *superType() const;
211 friend class QQmlTypePrivate;
212 friend struct QQmlMetaTypeData;
213 friend int registerType(const QQmlPrivate::RegisterType &);
214 friend int registerInterface(const QQmlPrivate::RegisterInterface &);
215 QQmlType(int, const QQmlPrivate::RegisterInterface &);
216 QQmlType(int, const QQmlPrivate::RegisterType &);
222 class QQmlTypeModulePrivate;
226 QString module() const;
227 int majorVersion() const;
229 int minimumMinorVersion() const;
230 int maximumMinorVersion() const;
232 QQmlType *type(const QHashedStringRef &, int);
233 QQmlType *type(const QHashedV8String &, int);
236 QQmlType *typeNoLock(const QString &name, int minor);
238 friend int registerType(const QQmlPrivate::RegisterType &);
239 friend struct QQmlMetaTypeData;
243 QQmlTypeModulePrivate *d;
246 class QQmlTypeModuleVersion
249 QQmlTypeModuleVersion();
250 QQmlTypeModuleVersion(QQmlTypeModule *, int);
251 QQmlTypeModuleVersion(const QQmlTypeModuleVersion &);
252 QQmlTypeModuleVersion &operator=(const QQmlTypeModuleVersion &);
254 QQmlTypeModule *module() const;
255 int minorVersion() const;
257 QQmlType *type(const QHashedStringRef &) const;
258 QQmlType *type(const QHashedV8String &) const;
261 QQmlTypeModule *m_module;
265 QQmlMetaType::SingletonType::SingletonType()
270 instanceMetaObject = 0;
274 bool QQmlMetaType::SingletonType::operator==(const SingletonType &other) const
276 return major == other.major && minor == other.minor && script == other.script && qobject == other.qobject;
279 inline uint qHash(const QQmlMetaType::SingletonType &import)
281 return import.major ^ import.minor ^ quintptr(import.script) ^ quintptr(import.qobject);
286 #endif // QQMLMETATYPE_P_H