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 Q_QML_PRIVATE_EXPORT QQmlMetaType
74 static QList<QString> qmlTypeNames();
75 static QList<QQmlType*> qmlTypes();
77 static QQmlType *qmlType(const QString &, int, int);
78 static QQmlType *qmlType(const QMetaObject *);
79 static QQmlType *qmlType(const QMetaObject *metaObject, const QString &module, int version_major, int version_minor);
80 static QQmlType *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 QQmlAttachedPropertiesFunc 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 QQmlTypeModule *typeModule(const QString &uri, int majorVersion);
109 static QList<QQmlPrivate::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)(QQmlEngine *, QJSEngine *);
121 QObject *(*qobjectCallback)(QQmlEngine *, QJSEngine *);
127 inline bool operator==(const ModuleApi &) const;
130 QJSValue (*script)(QQmlEngine *, QJSEngine *);
131 QObject *(*qobject)(QQmlEngine *, 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_QML_PRIVATE_EXPORT QQmlType
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 QQmlCustomParser *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 QQmlAttachedPropertiesFunc 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 QQmlType *superType() const;
194 friend class QQmlTypePrivate;
195 friend struct QQmlMetaTypeData;
196 friend int registerType(const QQmlPrivate::RegisterType &);
197 friend int registerInterface(const QQmlPrivate::RegisterInterface &);
198 QQmlType(int, const QQmlPrivate::RegisterInterface &);
199 QQmlType(int, const QQmlPrivate::RegisterType &);
205 class QQmlTypeModulePrivate;
209 QString module() const;
210 int majorVersion() const;
212 int minimumMinorVersion() const;
213 int maximumMinorVersion() const;
215 QList<QQmlType *> types();
216 QList<QQmlType *> type(const QString &);
218 QQmlType *type(const QHashedStringRef &, int);
219 QQmlType *type(const QHashedV8String &, int);
222 friend int registerType(const QQmlPrivate::RegisterType &);
225 QQmlTypeModulePrivate *d;
228 class QQmlTypeModuleVersion
231 QQmlTypeModuleVersion();
232 QQmlTypeModuleVersion(QQmlTypeModule *, int);
233 QQmlTypeModuleVersion(const QQmlTypeModuleVersion &);
234 QQmlTypeModuleVersion &operator=(const QQmlTypeModuleVersion &);
236 QQmlTypeModule *module() const;
237 int minorVersion() const;
239 QQmlType *type(const QHashedStringRef &) const;
240 QQmlType *type(const QHashedV8String &) const;
243 QQmlTypeModule *m_module;
247 QQmlMetaType::ModuleApi::ModuleApi()
255 bool QQmlMetaType::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 QQmlMetaType::ModuleApi &import)
262 return import.major ^ import.minor ^ quintptr(import.script) ^ quintptr(import.qobject);
267 #endif // QQMLMETATYPE_P_H