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 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>
63 QT_MODULE(Declarative)
65 typedef QObject *(*QDeclarativeAttachedPropertiesFunc)(QObject *);
67 template <typename TYPE>
68 class QDeclarativeTypeInfo
72 hasAttachedProperties = 0
79 class QDeclarativeEngine;
80 class QDeclarativeCustomParser;
81 namespace QDeclarativePrivate
83 void Q_DECLARATIVE_EXPORT qdeclarativeelement_destructor(QObject *);
85 class QDeclarativeElement : public T
88 virtual ~QDeclarativeElement() {
89 QDeclarativePrivate::qdeclarativeelement_destructor(this);
94 void createInto(void *memory) { new (memory) QDeclarativeElement<T>; }
97 QObject *createParent(QObject *p) { return new T(p); }
99 template<class From, class To, int N>
100 struct StaticCastSelectorClass
102 static inline int cast() { return -1; }
105 template<class From, class To>
106 struct StaticCastSelectorClass<From, To, sizeof(int)>
108 static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; }
111 template<class From, class To>
112 struct StaticCastSelector
114 typedef int yes_type;
115 typedef char no_type;
117 static yes_type check(To *);
118 static no_type check(...);
120 static inline int cast()
122 return StaticCastSelectorClass<From, To, sizeof(check(reinterpret_cast<From *>(0)))>::cast();
126 template <typename T>
127 struct has_attachedPropertiesMember
129 static bool const value = QDeclarativeTypeInfo<T>::hasAttachedProperties;
132 template <typename T, bool hasMember>
133 class has_attachedPropertiesMethod
136 typedef int yes_type;
137 typedef char no_type;
139 template<typename ReturnType>
140 static yes_type check(ReturnType *(*)(QObject *));
141 static no_type check(...);
143 static bool const value = sizeof(check(&T::qmlAttachedProperties)) == sizeof(yes_type);
146 template <typename T>
147 class has_attachedPropertiesMethod<T, false>
150 static bool const value = false;
153 template<typename T, int N>
154 class AttachedPropertySelector
157 static inline QDeclarativeAttachedPropertiesFunc func() { return 0; }
158 static inline const QMetaObject *metaObject() { return 0; }
161 class AttachedPropertySelector<T, 1>
163 static inline QObject *attachedProperties(QObject *obj) {
164 return T::qmlAttachedProperties(obj);
166 template<typename ReturnType>
167 static inline const QMetaObject *attachedPropertiesMetaObject(ReturnType *(*)(QObject *)) {
168 return &ReturnType::staticMetaObject;
171 static inline QDeclarativeAttachedPropertiesFunc func() {
172 return &attachedProperties;
174 static inline const QMetaObject *metaObject() {
175 return attachedPropertiesMetaObject(&T::qmlAttachedProperties);
180 inline QDeclarativeAttachedPropertiesFunc attachedPropertiesFunc()
182 return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::func();
186 inline const QMetaObject *attachedPropertiesMetaObject()
188 return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::metaObject();
191 enum AutoParentResult { Parented, IncompatibleObject, IncompatibleParent };
192 typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent);
194 struct RegisterType {
200 void (*create)(void *);
201 QString noCreationReason;
206 const char *elementName;
207 const QMetaObject *metaObject;
209 QDeclarativeAttachedPropertiesFunc attachedPropertiesFunction;
210 const QMetaObject *attachedPropertiesMetaObject;
212 int parserStatusCast;
214 int valueInterceptorCast;
216 QObject *(*extensionObjectCreate)(QObject *);
217 const QMetaObject *extensionMetaObject;
219 QDeclarativeCustomParser *customParser;
221 // If this is extended ensure "version" is bumped!!!
224 struct RegisterInterface {
233 struct RegisterAutoParent {
236 AutoParentFunction function;
239 struct RegisterModuleApi {
246 QJSValue (*scriptApi)(QDeclarativeEngine *, QJSEngine *);
247 QObject *(*qobjectApi)(QDeclarativeEngine *, QJSEngine *);
250 enum RegistrationType {
251 TypeRegistration = 0,
252 InterfaceRegistration = 1,
253 AutoParentRegistration = 2,
254 ModuleApiRegistration = 3,
257 int Q_DECLARATIVE_EXPORT qmlregister(RegistrationType, void *);
264 #endif // QDECLARATIVEPRIVATE_H