|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtDeclarative module of the Qt Toolkit. |
|
8 ** |
|
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 |
|
14 ** this package. |
|
15 ** |
|
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. |
|
23 ** |
|
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. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QDECLARATIVEPRIVATE_H |
|
43 #define QDECLARATIVEPRIVATE_H |
|
44 |
|
45 #include <QtCore/qglobal.h> |
|
46 #include <QtCore/qvariant.h> |
|
47 #ifndef Q_OS_WIN |
|
48 #include <stdint.h> |
|
49 #endif |
|
50 |
|
51 QT_BEGIN_HEADER |
|
52 |
|
53 QT_BEGIN_NAMESPACE |
|
54 |
|
55 QT_MODULE(Declarative) |
|
56 |
|
57 typedef QObject *(*QDeclarativeAttachedPropertiesFunc)(QObject *); |
|
58 |
|
59 template <typename TYPE> |
|
60 class QDeclarativeTypeInfo |
|
61 { |
|
62 public: |
|
63 enum { |
|
64 hasAttachedProperties = 0 |
|
65 }; |
|
66 }; |
|
67 |
|
68 |
|
69 class QDeclarativeCustomParser; |
|
70 namespace QDeclarativePrivate |
|
71 { |
|
72 void Q_DECLARATIVE_EXPORT qdeclarativeelement_destructor(QObject *); |
|
73 template<typename T> |
|
74 class QDeclarativeElement : public T |
|
75 { |
|
76 public: |
|
77 virtual ~QDeclarativeElement() { |
|
78 QDeclarativePrivate::qdeclarativeelement_destructor(this); |
|
79 } |
|
80 }; |
|
81 |
|
82 template<typename T> |
|
83 void createInto(void *memory) { new (memory) QDeclarativeElement<T>; } |
|
84 |
|
85 template<typename T> |
|
86 QObject *createParent(QObject *p) { return new T(p); } |
|
87 |
|
88 template<class From, class To, int N> |
|
89 struct StaticCastSelectorClass |
|
90 { |
|
91 static inline int cast() { return -1; } |
|
92 }; |
|
93 |
|
94 template<class From, class To> |
|
95 struct StaticCastSelectorClass<From, To, sizeof(int)> |
|
96 { |
|
97 static inline int cast() { return (int)((intptr_t)static_cast<To *>((From *)0x10000000)) - 0x10000000; } |
|
98 }; |
|
99 |
|
100 template<class From, class To> |
|
101 struct StaticCastSelector |
|
102 { |
|
103 typedef int yes_type; |
|
104 typedef char no_type; |
|
105 |
|
106 static yes_type check(To *); |
|
107 static no_type check(...); |
|
108 |
|
109 static inline int cast() |
|
110 { |
|
111 return StaticCastSelectorClass<From, To, sizeof(check((From *)0))>::cast(); |
|
112 } |
|
113 }; |
|
114 |
|
115 template <typename T> |
|
116 struct has_attachedPropertiesMember |
|
117 { |
|
118 static bool const value = QDeclarativeTypeInfo<T>::hasAttachedProperties; |
|
119 }; |
|
120 |
|
121 template <typename T, bool hasMember> |
|
122 class has_attachedPropertiesMethod |
|
123 { |
|
124 typedef int yes_type; |
|
125 typedef char no_type; |
|
126 |
|
127 template<typename ReturnType> |
|
128 static yes_type check(ReturnType *(*)(QObject *)); |
|
129 static no_type check(...); |
|
130 |
|
131 public: |
|
132 static bool const value = sizeof(check(&T::qmlAttachedProperties)) == sizeof(yes_type); |
|
133 }; |
|
134 |
|
135 template <typename T> |
|
136 class has_attachedPropertiesMethod<T, false> |
|
137 { |
|
138 public: |
|
139 static bool const value = false; |
|
140 }; |
|
141 |
|
142 template<typename T, int N> |
|
143 class AttachedPropertySelector |
|
144 { |
|
145 public: |
|
146 static inline QDeclarativeAttachedPropertiesFunc func() { return 0; } |
|
147 static inline const QMetaObject *metaObject() { return 0; } |
|
148 }; |
|
149 template<typename T> |
|
150 class AttachedPropertySelector<T, 1> |
|
151 { |
|
152 static inline QObject *attachedProperties(QObject *obj) { |
|
153 return T::qmlAttachedProperties(obj); |
|
154 } |
|
155 template<typename ReturnType> |
|
156 static inline const QMetaObject *attachedPropertiesMetaObject(ReturnType *(*)(QObject *)) { |
|
157 return &ReturnType::staticMetaObject; |
|
158 } |
|
159 public: |
|
160 static inline QDeclarativeAttachedPropertiesFunc func() { |
|
161 return &attachedProperties; |
|
162 } |
|
163 static inline const QMetaObject *metaObject() { |
|
164 return attachedPropertiesMetaObject(&T::qmlAttachedProperties); |
|
165 } |
|
166 }; |
|
167 |
|
168 template<typename T> |
|
169 inline QDeclarativeAttachedPropertiesFunc attachedPropertiesFunc() |
|
170 { |
|
171 return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::func(); |
|
172 } |
|
173 |
|
174 template<typename T> |
|
175 inline const QMetaObject *attachedPropertiesMetaObject() |
|
176 { |
|
177 return AttachedPropertySelector<T, has_attachedPropertiesMethod<T, has_attachedPropertiesMember<T>::value>::value>::metaObject(); |
|
178 } |
|
179 |
|
180 struct RegisterType { |
|
181 int version; |
|
182 |
|
183 int typeId; |
|
184 int listId; |
|
185 int objectSize; |
|
186 void (*create)(void *); |
|
187 QString noCreationReason; |
|
188 |
|
189 const char *uri; |
|
190 int versionMajor; |
|
191 int versionMinor; |
|
192 const char *elementName; |
|
193 const QMetaObject *metaObject; |
|
194 |
|
195 QDeclarativeAttachedPropertiesFunc attachedPropertiesFunction; |
|
196 const QMetaObject *attachedPropertiesMetaObject; |
|
197 |
|
198 int parserStatusCast; |
|
199 int valueSourceCast; |
|
200 int valueInterceptorCast; |
|
201 |
|
202 QObject *(*extensionObjectCreate)(QObject *); |
|
203 const QMetaObject *extensionMetaObject; |
|
204 |
|
205 QDeclarativeCustomParser *customParser; |
|
206 }; |
|
207 |
|
208 struct RegisterInterface { |
|
209 int version; |
|
210 |
|
211 int typeId; |
|
212 int listId; |
|
213 |
|
214 const char *iid; |
|
215 }; |
|
216 |
|
217 int Q_DECLARATIVE_EXPORT registerType(const RegisterType &); |
|
218 int Q_DECLARATIVE_EXPORT registerType(const RegisterInterface &); |
|
219 |
|
220 } |
|
221 |
|
222 QT_END_NAMESPACE |
|
223 |
|
224 QT_END_HEADER |
|
225 |
|
226 #endif // QDECLARATIVEPRIVATE_H |