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 ****************************************************************************/
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 <QtQml/qtqmlglobal.h>
58 #include <QtCore/qglobal.h>
59 #include <QtCore/qvariant.h>
66 typedef QObject *(*QQmlAttachedPropertiesFunc)(QObject *);
68 template <typename TYPE>
73 hasAttachedProperties = 0
81 class QQmlCustomParser;
84 void Q_QML_EXPORT qdeclarativeelement_destructor(QObject *);
86 class QQmlElement : public T
89 virtual ~QQmlElement() {
90 QQmlPrivate::qdeclarativeelement_destructor(this);
95 void createInto(void *memory) { new (memory) QQmlElement<T>; }
98 QObject *createParent(QObject *p) { return new T(p); }
100 template<class From, class To, int N>
101 struct StaticCastSelectorClass
103 static inline int cast() { return -1; }
106 template<class From, class To>
107 struct StaticCastSelectorClass<From, To, sizeof(int)>
109 static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; }
112 template<class From, class To>
113 struct StaticCastSelector
115 typedef int yes_type;
116 typedef char no_type;
118 static yes_type check(To *);
119 static no_type check(...);
121 static inline int cast()
123 return StaticCastSelectorClass<From, To, sizeof(check(reinterpret_cast<From *>(0)))>::cast();
127 template <typename T>
128 struct has_attachedPropertiesMember
130 static bool const value = QQmlTypeInfo<T>::hasAttachedProperties;
133 template <typename T, bool hasMember>
134 class has_attachedPropertiesMethod
137 typedef int yes_type;
138 typedef char no_type;
140 template<typename ReturnType>
141 static yes_type check(ReturnType *(*)(QObject *));
142 static no_type check(...);
144 static bool const value = sizeof(check(&T::qmlAttachedProperties)) == sizeof(yes_type);
147 template <typename T>
148 class has_attachedPropertiesMethod<T, false>
151 static bool const value = false;
154 template<typename T, int N>
155 class AttachedPropertySelector
158 static inline QQmlAttachedPropertiesFunc func() { return 0; }
159 static inline const QMetaObject *metaObject() { return 0; }
162 class AttachedPropertySelector<T, 1>
164 static inline QObject *attachedProperties(QObject *obj) {
165 return T::qmlAttachedProperties(obj);
167 template<typename ReturnType>
168 static inline const QMetaObject *attachedPropertiesMetaObject(ReturnType *(*)(QObject *)) {
169 return &ReturnType::staticMetaObject;
172 static inline QQmlAttachedPropertiesFunc func() {
173 return &attachedProperties;
175 static inline const QMetaObject *metaObject() {
176 return attachedPropertiesMetaObject(&T::qmlAttachedProperties);
181 inline QQmlAttachedPropertiesFunc attachedPropertiesFunc()
183 return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::func();
187 inline const QMetaObject *attachedPropertiesMetaObject()
189 return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::metaObject();
192 enum AutoParentResult { Parented, IncompatibleObject, IncompatibleParent };
193 typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent);
195 struct RegisterType {
201 void (*create)(void *);
202 QString noCreationReason;
207 const char *elementName;
208 const QMetaObject *metaObject;
210 QQmlAttachedPropertiesFunc attachedPropertiesFunction;
211 const QMetaObject *attachedPropertiesMetaObject;
213 int parserStatusCast;
215 int valueInterceptorCast;
217 QObject *(*extensionObjectCreate)(QObject *);
218 const QMetaObject *extensionMetaObject;
220 QQmlCustomParser *customParser;
222 // If this is extended ensure "version" is bumped!!!
225 struct RegisterInterface {
234 struct RegisterAutoParent {
237 AutoParentFunction function;
240 struct RegisterModuleApi {
247 QJSValue (*scriptApi)(QQmlEngine *, QJSEngine *);
248 QObject *(*qobjectApi)(QQmlEngine *, QJSEngine *);
251 enum RegistrationType {
252 TypeRegistration = 0,
253 InterfaceRegistration = 1,
254 AutoParentRegistration = 2,
255 ModuleApiRegistration = 3
258 int Q_QML_EXPORT qmlregister(RegistrationType, void *);
265 #endif // QQMLPRIVATE_H