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 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef QDECLARATIVE_H
43 #define QDECLARATIVE_H
45 #include <QtDeclarative/qdeclarativeprivate.h>
46 #include <QtDeclarative/qdeclarativeparserstatus.h>
47 #include <QtDeclarative/qdeclarativepropertyvaluesource.h>
48 #include <QtDeclarative/qdeclarativepropertyvalueinterceptor.h>
49 #include <QtDeclarative/qdeclarativelist.h>
51 #include <QtCore/qbytearray.h>
52 #include <QtCore/qmetaobject.h>
56 #define QML_DECLARE_TYPE(TYPE) \
57 Q_DECLARE_METATYPE(TYPE *) \
58 Q_DECLARE_METATYPE(QDeclarativeListProperty<TYPE>)
60 #define QML_DECLARE_TYPE_HASMETATYPE(TYPE) \
61 Q_DECLARE_METATYPE(QDeclarativeListProperty<TYPE>)
63 #define QML_DECLARE_INTERFACE(INTERFACE) \
64 QML_DECLARE_TYPE(INTERFACE)
66 #define QML_DECLARE_INTERFACE_HASMETATYPE(INTERFACE) \
67 QML_DECLARE_TYPE_HASMETATYPE(INTERFACE)
69 enum { /* TYPEINFO flags */
70 QML_HAS_ATTACHED_PROPERTIES = 0x01
73 #define QML_DECLARE_TYPEINFO(TYPE, FLAGS) \
76 class QDeclarativeTypeInfo<TYPE > \
80 hasAttachedProperties = (((FLAGS) & QML_HAS_ATTACHED_PROPERTIES) == QML_HAS_ATTACHED_PROPERTIES) \
87 QT_MODULE(Declarative)
92 QByteArray name(T::staticMetaObject.className());
94 QByteArray pointerName(name + '*');
95 QByteArray listName("QDeclarativeListProperty<" + name + ">");
97 QDeclarativePrivate::RegisterType type = {
100 qRegisterMetaType<T *>(pointerName.constData()),
101 qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
105 0, 0, 0, 0, &T::staticMetaObject,
107 QDeclarativePrivate::attachedPropertiesFunc<T>(),
108 QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
110 QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(),
111 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(),
112 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(),
120 return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type);
123 int Q_AUTOTEST_EXPORT qmlRegisterTypeNotAvailable(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& message);
126 int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& reason)
128 QByteArray name(T::staticMetaObject.className());
130 QByteArray pointerName(name + '*');
131 QByteArray listName("QDeclarativeListProperty<" + name + ">");
133 QDeclarativePrivate::RegisterType type = {
136 qRegisterMetaType<T *>(pointerName.constData()),
137 qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
141 uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
143 QDeclarativePrivate::attachedPropertiesFunc<T>(),
144 QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
146 QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(),
147 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(),
148 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(),
156 return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type);
160 int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
162 QByteArray name(T::staticMetaObject.className());
164 QByteArray pointerName(name + '*');
165 QByteArray listName("QDeclarativeListProperty<" + name + ">");
167 QDeclarativePrivate::RegisterType type = {
170 qRegisterMetaType<T *>(pointerName.constData()),
171 qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
172 sizeof(T), QDeclarativePrivate::createInto<T>,
175 uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
177 QDeclarativePrivate::attachedPropertiesFunc<T>(),
178 QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
180 QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(),
181 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(),
182 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(),
190 return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type);
193 template<typename T, int metaObjectRevision>
194 int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
196 QByteArray name(T::staticMetaObject.className());
198 QByteArray pointerName(name + '*');
199 QByteArray listName("QDeclarativeListProperty<" + name + ">");
201 QDeclarativePrivate::RegisterType type = {
204 qRegisterMetaType<T *>(pointerName.constData()),
205 qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
206 sizeof(T), QDeclarativePrivate::createInto<T>,
209 uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
211 QDeclarativePrivate::attachedPropertiesFunc<T>(),
212 QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
214 QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(),
215 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(),
216 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(),
224 return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type);
227 template<typename T, int metaObjectRevision>
228 int qmlRegisterRevision(const char *uri, int versionMajor, int versionMinor)
230 QByteArray name(T::staticMetaObject.className());
232 QByteArray pointerName(name + '*');
233 QByteArray listName("QDeclarativeListProperty<" + name + ">");
235 QDeclarativePrivate::RegisterType type = {
238 qRegisterMetaType<T *>(pointerName.constData()),
239 qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
240 sizeof(T), QDeclarativePrivate::createInto<T>,
243 uri, versionMajor, versionMinor, 0, &T::staticMetaObject,
245 QDeclarativePrivate::attachedPropertiesFunc<T>(),
246 QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
248 QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(),
249 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(),
250 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(),
258 return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type);
262 template<typename T, typename E>
263 int qmlRegisterExtendedType()
265 QByteArray name(T::staticMetaObject.className());
267 QByteArray pointerName(name + '*');
268 QByteArray listName("QDeclarativeListProperty<" + name + ">");
270 QDeclarativePrivate::RegisterType type = {
273 qRegisterMetaType<T *>(pointerName.constData()),
274 qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
278 0, 0, 0, 0, &T::staticMetaObject,
280 QDeclarativePrivate::attachedPropertiesFunc<T>(),
281 QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
283 QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(),
284 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(),
285 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(),
287 QDeclarativePrivate::createParent<E>, &E::staticMetaObject,
293 return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type);
296 template<typename T, typename E>
297 int qmlRegisterExtendedType(const char *uri, int versionMajor, int versionMinor,
300 QByteArray name(T::staticMetaObject.className());
302 QByteArray pointerName(name + '*');
303 QByteArray listName("QDeclarativeListProperty<" + name + ">");
305 QDeclarativeAttachedPropertiesFunc attached = QDeclarativePrivate::attachedPropertiesFunc<E>();
306 const QMetaObject * attachedMetaObject = QDeclarativePrivate::attachedPropertiesMetaObject<E>();
308 attached = QDeclarativePrivate::attachedPropertiesFunc<T>();
309 attachedMetaObject = QDeclarativePrivate::attachedPropertiesMetaObject<T>();
312 QDeclarativePrivate::RegisterType type = {
315 qRegisterMetaType<T *>(pointerName.constData()),
316 qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
317 sizeof(T), QDeclarativePrivate::createInto<T>,
320 uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
325 QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(),
326 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(),
327 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(),
329 QDeclarativePrivate::createParent<E>, &E::staticMetaObject,
335 return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type);
339 int qmlRegisterInterface(const char *typeName)
341 QByteArray name(typeName);
343 QByteArray pointerName(name + '*');
344 QByteArray listName("QDeclarativeListProperty<" + name + ">");
346 QDeclarativePrivate::RegisterInterface qmlInterface = {
349 qRegisterMetaType<T *>(pointerName.constData()),
350 qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
352 qobject_interface_iid<T *>()
355 return QDeclarativePrivate::qmlregister(QDeclarativePrivate::InterfaceRegistration, &qmlInterface);
359 int qmlRegisterCustomType(const char *uri, int versionMajor, int versionMinor,
360 const char *qmlName, QDeclarativeCustomParser *parser)
362 QByteArray name(T::staticMetaObject.className());
364 QByteArray pointerName(name + '*');
365 QByteArray listName("QDeclarativeListProperty<" + name + ">");
367 QDeclarativePrivate::RegisterType type = {
370 qRegisterMetaType<T *>(pointerName.constData()),
371 qRegisterMetaType<QDeclarativeListProperty<T> >(listName.constData()),
372 sizeof(T), QDeclarativePrivate::createInto<T>,
375 uri, versionMajor, versionMinor, qmlName, &T::staticMetaObject,
377 QDeclarativePrivate::attachedPropertiesFunc<T>(),
378 QDeclarativePrivate::attachedPropertiesMetaObject<T>(),
380 QDeclarativePrivate::StaticCastSelector<T,QDeclarativeParserStatus>::cast(),
381 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueSource>::cast(),
382 QDeclarativePrivate::StaticCastSelector<T,QDeclarativePropertyValueInterceptor>::cast(),
390 return QDeclarativePrivate::qmlregister(QDeclarativePrivate::TypeRegistration, &type);
393 class QDeclarativeContext;
394 class QDeclarativeEngine;
395 Q_DECLARATIVE_EXPORT void qmlExecuteDeferred(QObject *);
396 Q_DECLARATIVE_EXPORT QDeclarativeContext *qmlContext(const QObject *);
397 Q_DECLARATIVE_EXPORT QDeclarativeEngine *qmlEngine(const QObject *);
398 Q_DECLARATIVE_EXPORT QObject *qmlAttachedPropertiesObjectById(int, const QObject *, bool create = true);
399 Q_DECLARATIVE_EXPORT QObject *qmlAttachedPropertiesObject(int *, const QObject *, const QMetaObject *, bool create);
402 QObject *qmlAttachedPropertiesObject(const QObject *obj, bool create = true)
405 return qmlAttachedPropertiesObject(&idx, obj, &T::staticMetaObject, create);
410 QML_DECLARE_TYPE(QObject)
411 Q_DECLARE_METATYPE(QVariant)
415 #endif // QDECLARATIVE_H