1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtQml module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 RegisterSingletonType {
246 const char *typeName;
248 QJSValue (*scriptApi)(QQmlEngine *, QJSEngine *);
249 QObject *(*qobjectApi)(QQmlEngine *, QJSEngine *);
250 const QMetaObject *instanceMetaObject; // new in version 1
251 int typeId; // new in version 2
252 int revision; // new in version 2
253 // If this is extended ensure "version" is bumped!!!
256 enum RegistrationType {
257 TypeRegistration = 0,
258 InterfaceRegistration = 1,
259 AutoParentRegistration = 2,
260 SingletonRegistration = 3
263 int Q_QML_EXPORT qmlregister(RegistrationType, void *);
270 #endif // QQMLPRIVATE_H