1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDeclarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** 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 <QtScript/qscriptvalue.h>
66 class QDeclarativeType;
67 class QDeclarativeCustomParser;
68 class QDeclarativeTypePrivate;
70 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeMetaType
73 static bool canCopy(int type);
74 static bool copy(int type, void *data, const void *copy = 0);
76 static QList<QByteArray> qmlTypeNames();
77 static QList<QDeclarativeType*> qmlTypes();
79 static QDeclarativeType *qmlType(const QByteArray &, int, int);
80 static QDeclarativeType *qmlType(const QMetaObject *);
81 static QDeclarativeType *qmlType(const QMetaObject *metaObject, const QByteArray &module, int version_major, int version_minor);
82 static QDeclarativeType *qmlType(int);
84 static QMetaProperty defaultProperty(const QMetaObject *);
85 static QMetaProperty defaultProperty(QObject *);
86 static QMetaMethod defaultMethod(const QMetaObject *);
87 static QMetaMethod defaultMethod(QObject *);
89 static bool isQObject(int);
90 static QObject *toQObject(const QVariant &, bool *ok = 0);
92 static int listType(int);
93 static int attachedPropertiesFuncId(const QMetaObject *);
94 static QDeclarativeAttachedPropertiesFunc attachedPropertiesFuncById(int);
96 enum TypeCategory { Unknown, Object, List };
97 static TypeCategory typeCategory(int);
99 static bool isInterface(int);
100 static const char *interfaceIId(int);
101 static bool isList(int);
103 typedef QVariant (*StringConverter)(const QString &);
104 static void registerCustomStringConverter(int, StringConverter);
105 static StringConverter customStringConverter(int);
107 static bool isModule(const QByteArray &module, int versionMajor, int versionMinor);
109 static QList<QDeclarativePrivate::AutoParentFunction> parentFunctions();
111 struct ModuleApiInstance {
113 : scriptCallback(0), qobjectCallback(0), qobjectApi(0) {}
115 QScriptValue (*scriptCallback)(QDeclarativeEngine *, QScriptEngine *);
116 QObject *(*qobjectCallback)(QDeclarativeEngine *, QScriptEngine *);
117 QScriptValue scriptApi;
122 inline bool operator==(const ModuleApi &) const;
125 QScriptValue (*script)(QDeclarativeEngine *, QScriptEngine *);
126 QObject *(*qobject)(QDeclarativeEngine *, QScriptEngine *);
128 static ModuleApi moduleApi(const QByteArray &, int, int);
131 class Q_DECLARATIVE_PRIVATE_EXPORT QDeclarativeType
134 QByteArray typeName() const;
135 QByteArray qmlTypeName() const;
137 QByteArray module() const;
138 int majorVersion() const;
139 int minorVersion() const;
141 bool availableInVersion(int vmajor, int vminor) const;
142 bool availableInVersion(const QByteArray &module, int vmajor, int vminor) const;
144 QObject *create() const;
145 void create(QObject **, void **, size_t) const;
147 typedef void (*CreateFunc)(void *);
148 CreateFunc createFunction() const;
149 int createSize() const;
151 QDeclarativeCustomParser *customParser() const;
153 bool isCreatable() const;
154 bool isExtendedType() const;
155 QString noCreationReason() const;
157 bool isInterface() const;
159 int qListTypeId() const;
161 const QMetaObject *metaObject() const;
162 const QMetaObject *baseMetaObject() const;
163 int metaObjectRevision() const;
164 bool containsRevisionedAttributes() const;
166 QDeclarativeAttachedPropertiesFunc attachedPropertiesFunction() const;
167 const QMetaObject *attachedPropertiesType() const;
168 int attachedPropertiesId() const;
170 int parserStatusCast() const;
171 QVariant fromObject(QObject *) const;
172 const char *interfaceIId() const;
173 int propertyValueSourceCast() const;
174 int propertyValueInterceptorCast() const;
179 QDeclarativeType *superType() const;
180 friend class QDeclarativeTypePrivate;
181 friend struct QDeclarativeMetaTypeData;
182 friend int registerType(const QDeclarativePrivate::RegisterType &);
183 friend int registerInterface(const QDeclarativePrivate::RegisterInterface &);
184 QDeclarativeType(int, const QDeclarativePrivate::RegisterInterface &);
185 QDeclarativeType(int, const QDeclarativePrivate::RegisterType &);
188 QDeclarativeTypePrivate *d;
191 QDeclarativeMetaType::ModuleApi::ModuleApi()
192 // : major(0), minor(0), script(0), qobject(0)
200 bool QDeclarativeMetaType::ModuleApi::operator==(const ModuleApi &other) const
202 return major == other.major && minor == other.minor && script == other.script && qobject == other.qobject;
205 inline uint qHash(const QDeclarativeMetaType::ModuleApi &import)
207 return import.major ^ import.minor ^ quintptr(import.script) ^ quintptr(import.qobject);
212 #endif // QDECLARATIVEMETATYPE_P_H