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 QtDeclarative 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 QDECLARATIVEPRIVATE_H
43 #define QDECLARATIVEPRIVATE_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 <QtCore/qglobal.h>
57 #include <QtCore/qvariant.h>
64 typedef QObject *(*QDeclarativeAttachedPropertiesFunc)(QObject *);
66 template <typename TYPE>
67 class QDeclarativeTypeInfo
71 hasAttachedProperties = 0
78 class QDeclarativeEngine;
79 class QDeclarativeCustomParser;
80 namespace QDeclarativePrivate
82 void Q_DECLARATIVE_EXPORT qdeclarativeelement_destructor(QObject *);
84 class QDeclarativeElement : public T
87 virtual ~QDeclarativeElement() {
88 QDeclarativePrivate::qdeclarativeelement_destructor(this);
93 void createInto(void *memory) { new (memory) QDeclarativeElement<T>; }
96 QObject *createParent(QObject *p) { return new T(p); }
98 template<class From, class To, int N>
99 struct StaticCastSelectorClass
101 static inline int cast() { return -1; }
104 template<class From, class To>
105 struct StaticCastSelectorClass<From, To, sizeof(int)>
107 static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; }
110 template<class From, class To>
111 struct StaticCastSelector
113 typedef int yes_type;
114 typedef char no_type;
116 static yes_type check(To *);
117 static no_type check(...);
119 static inline int cast()
121 return StaticCastSelectorClass<From, To, sizeof(check(reinterpret_cast<From *>(0)))>::cast();
125 template <typename T>
126 struct has_attachedPropertiesMember
128 static bool const value = QDeclarativeTypeInfo<T>::hasAttachedProperties;
131 template <typename T, bool hasMember>
132 class has_attachedPropertiesMethod
135 typedef int yes_type;
136 typedef char no_type;
138 template<typename ReturnType>
139 static yes_type check(ReturnType *(*)(QObject *));
140 static no_type check(...);
142 static bool const value = sizeof(check(&T::qmlAttachedProperties)) == sizeof(yes_type);
145 template <typename T>
146 class has_attachedPropertiesMethod<T, false>
149 static bool const value = false;
152 template<typename T, int N>
153 class AttachedPropertySelector
156 static inline QDeclarativeAttachedPropertiesFunc func() { return 0; }
157 static inline const QMetaObject *metaObject() { return 0; }
160 class AttachedPropertySelector<T, 1>
162 static inline QObject *attachedProperties(QObject *obj) {
163 return T::qmlAttachedProperties(obj);
165 template<typename ReturnType>
166 static inline const QMetaObject *attachedPropertiesMetaObject(ReturnType *(*)(QObject *)) {
167 return &ReturnType::staticMetaObject;
170 static inline QDeclarativeAttachedPropertiesFunc func() {
171 return &attachedProperties;
173 static inline const QMetaObject *metaObject() {
174 return attachedPropertiesMetaObject(&T::qmlAttachedProperties);
179 inline QDeclarativeAttachedPropertiesFunc attachedPropertiesFunc()
181 return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::func();
185 inline const QMetaObject *attachedPropertiesMetaObject()
187 return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::metaObject();
190 enum AutoParentResult { Parented, IncompatibleObject, IncompatibleParent };
191 typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent);
193 struct RegisterType {
199 void (*create)(void *);
200 QString noCreationReason;
205 const char *elementName;
206 const QMetaObject *metaObject;
208 QDeclarativeAttachedPropertiesFunc attachedPropertiesFunction;
209 const QMetaObject *attachedPropertiesMetaObject;
211 int parserStatusCast;
213 int valueInterceptorCast;
215 QObject *(*extensionObjectCreate)(QObject *);
216 const QMetaObject *extensionMetaObject;
218 QDeclarativeCustomParser *customParser;
220 // If this is extended ensure "version" is bumped!!!
223 struct RegisterInterface {
232 struct RegisterAutoParent {
235 AutoParentFunction function;
238 struct RegisterModuleApi {
245 QJSValue (*scriptApi)(QDeclarativeEngine *, QJSEngine *);
246 QObject *(*qobjectApi)(QDeclarativeEngine *, QJSEngine *);
249 enum RegistrationType {
250 TypeRegistration = 0,
251 InterfaceRegistration = 1,
252 AutoParentRegistration = 2,
253 ModuleApiRegistration = 3
256 int Q_DECLARATIVE_EXPORT qmlregister(RegistrationType, void *);
263 #endif // QDECLARATIVEPRIVATE_H