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 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
77 class QDeclarativeCustomParser;
78 namespace QDeclarativePrivate
80 void Q_DECLARATIVE_EXPORT qdeclarativeelement_destructor(QObject *);
82 class QDeclarativeElement : public T
85 virtual ~QDeclarativeElement() {
86 QDeclarativePrivate::qdeclarativeelement_destructor(this);
91 void createInto(void *memory) { new (memory) QDeclarativeElement<T>; }
94 QObject *createParent(QObject *p) { return new T(p); }
96 template<class From, class To, int N>
97 struct StaticCastSelectorClass
99 static inline int cast() { return -1; }
102 template<class From, class To>
103 struct StaticCastSelectorClass<From, To, sizeof(int)>
105 static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; }
108 template<class From, class To>
109 struct StaticCastSelector
111 typedef int yes_type;
112 typedef char no_type;
114 static yes_type check(To *);
115 static no_type check(...);
117 static inline int cast()
119 return StaticCastSelectorClass<From, To, sizeof(check(reinterpret_cast<From *>(0)))>::cast();
123 template <typename T>
124 struct has_attachedPropertiesMember
126 static bool const value = QDeclarativeTypeInfo<T>::hasAttachedProperties;
129 template <typename T, bool hasMember>
130 class has_attachedPropertiesMethod
133 typedef int yes_type;
134 typedef char no_type;
136 template<typename ReturnType>
137 static yes_type check(ReturnType *(*)(QObject *));
138 static no_type check(...);
140 static bool const value = sizeof(check(&T::qmlAttachedProperties)) == sizeof(yes_type);
143 template <typename T>
144 class has_attachedPropertiesMethod<T, false>
147 static bool const value = false;
150 template<typename T, int N>
151 class AttachedPropertySelector
154 static inline QDeclarativeAttachedPropertiesFunc func() { return 0; }
155 static inline const QMetaObject *metaObject() { return 0; }
158 class AttachedPropertySelector<T, 1>
160 static inline QObject *attachedProperties(QObject *obj) {
161 return T::qmlAttachedProperties(obj);
163 template<typename ReturnType>
164 static inline const QMetaObject *attachedPropertiesMetaObject(ReturnType *(*)(QObject *)) {
165 return &ReturnType::staticMetaObject;
168 static inline QDeclarativeAttachedPropertiesFunc func() {
169 return &attachedProperties;
171 static inline const QMetaObject *metaObject() {
172 return attachedPropertiesMetaObject(&T::qmlAttachedProperties);
177 inline QDeclarativeAttachedPropertiesFunc attachedPropertiesFunc()
179 return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::func();
183 inline const QMetaObject *attachedPropertiesMetaObject()
185 return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::metaObject();
188 enum AutoParentResult { Parented, IncompatibleObject, IncompatibleParent };
189 typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent);
191 struct RegisterType {
197 void (*create)(void *);
198 QString noCreationReason;
203 const char *elementName;
204 const QMetaObject *metaObject;
206 QDeclarativeAttachedPropertiesFunc attachedPropertiesFunction;
207 const QMetaObject *attachedPropertiesMetaObject;
209 int parserStatusCast;
211 int valueInterceptorCast;
213 QObject *(*extensionObjectCreate)(QObject *);
214 const QMetaObject *extensionMetaObject;
216 QDeclarativeCustomParser *customParser;
218 // If this is extended ensure "version" is bumped!!!
221 struct RegisterInterface {
230 struct RegisterAutoParent {
233 AutoParentFunction function;
236 enum RegistrationType {
237 TypeRegistration = 0,
238 InterfaceRegistration = 1,
239 AutoParentRegistration = 2
242 int Q_DECLARATIVE_EXPORT qmlregister(RegistrationType, void *);
249 #endif // QDECLARATIVEPRIVATE_H