Mercurial > projects > qtd
comparison d2/qt/core/QMetaObject.d @ 365:958e8b9a89bd
Changeset a084e2df3776 is broken. Backing out.
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Fri, 11 Jun 2010 20:09:25 +0300 |
parents | a084e2df3776 |
children | da4235301224 |
comparison
equal
deleted
inserted
replaced
364:a084e2df3776 | 365:958e8b9a89bd |
---|---|
11 qtd.MOC, | 11 qtd.MOC, |
12 std.string, | 12 std.string, |
13 std.typetuple, | 13 std.typetuple, |
14 std.c.stdlib; | 14 std.c.stdlib; |
15 | 15 |
16 class QMetaArgument : MetaBase | 16 class QMetaArgument : Meta |
17 { | 17 { |
18 } | 18 } |
19 | 19 |
20 class QMetaMethod : MetaBase | 20 class QMetaMethod : Meta |
21 { | 21 { |
22 alias typeof(this) This; | 22 alias typeof(this) This; |
23 | 23 |
24 // QMetaArgument[] arguments; | 24 // QMetaArgument[] arguments; |
25 string signature; | 25 string signature; |
82 { | 82 { |
83 return typeof(super).create!(method, This)(index); | 83 return typeof(super).create!(method, This)(index); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 /** | 87 class MetaObject : MetaType |
88 Base class for QtD meta-classes. | 88 { |
89 */ | 89 MetaObject _base; |
90 abstract class QtdMetaClass : MetaClass | |
91 { | |
92 private: | |
93 void* nativeId_; | |
94 | |
95 this() {} | |
96 | |
97 public: | |
98 | |
99 /** | |
100 */ | |
101 @property | |
102 void* nativeId() | |
103 { | |
104 return nativeId_; | |
105 } | |
106 | |
107 /* internal */ void construct(T)() | |
108 { | |
109 super.construct!T(); | |
110 nativeId_ = T.qtd_nativeMetaObject; | |
111 } | |
112 } | 90 } |
113 | 91 |
114 struct QMetaObjectNative | 92 struct QMetaObjectNative |
115 { | 93 { |
116 QMetaObjectNative *superdata; | 94 QMetaObjectNative *superdata; |
119 void *extradata; | 97 void *extradata; |
120 } | 98 } |
121 | 99 |
122 class QMetaException : Exception { this(string msg) { super(msg); } } | 100 class QMetaException : Exception { this(string msg) { super(msg); } } |
123 | 101 |
124 final class QMetaObject : QtdMetaClass | 102 final class QMetaObject |
125 { | 103 { |
126 alias typeof(this) This; | 104 alias typeof(this) This; |
105 | |
106 private this() {} | |
127 | 107 |
128 enum Call | 108 enum Call |
129 { | 109 { |
130 InvokeMetaMethod, | 110 InvokeMetaMethod, |
131 ReadProperty, | 111 ReadProperty, |
139 CreateInstance | 119 CreateInstance |
140 } | 120 } |
141 | 121 |
142 private | 122 private |
143 { | 123 { |
124 QMetaObjectNative* _nativeId; | |
125 QMetaObject _base; // super class | |
126 QMetaObject _firstDerived; // head of the linked list of derived classes | |
127 QMetaObject _next; // next sibling on this derivation level | |
144 QMetaMethod[] _methods; | 128 QMetaMethod[] _methods; |
129 ClassInfo _classInfo; | |
130 | |
145 QObject function(void* nativeId) _createWrapper; | 131 QObject function(void* nativeId) _createWrapper; |
146 } | 132 } |
147 | 133 |
148 void construct(T : QObject)() | 134 private void addDerived(QMetaObject mo) |
149 { | 135 { |
150 super.construct!T(); | 136 mo._next = _firstDerived; |
137 _firstDerived = mo; | |
138 } | |
139 | |
140 // ctor | |
141 void construct(T : QObject)(void* nativeId) | |
142 { | |
143 alias BaseClassesTuple!(T)[0] Base; | |
144 This base; | |
145 static if (is(Base : QObject)) | |
146 base = Base.staticMetaObject; | |
147 | |
148 _nativeId = cast(QMetaObjectNative*)nativeId; | |
149 T.setStaticMetaObject(this); | |
150 | |
151 if (base) | |
152 { | |
153 base.addDerived(this); | |
154 _base = base; | |
155 } | |
156 _classInfo = T.classinfo; | |
157 | |
151 | 158 |
152 static if (isQtType!T) | 159 static if (isQtType!T) |
153 { | 160 { |
154 static if (is(T.ConcreteType)) | 161 static if (is(T.ConcreteType)) |
155 alias T.ConcreteType Concrete; | 162 alias T.ConcreteType Concrete; |
162 return obj; | 169 return obj; |
163 }; | 170 }; |
164 | 171 |
165 T._populateMetaInfo; | 172 T._populateMetaInfo; |
166 } | 173 } |
167 | |
168 // create run time meta-objects for user-defined signals and slots | 174 // create run time meta-objects for user-defined signals and slots |
169 else static if (is(typeof(T.methods))) | 175 else static if (is(typeof(T.methods))) |
170 { | 176 { |
171 alias BaseClassesTuple!(T)[0] Base; | |
172 int index = Base.staticMetaObject().methodCount(); | 177 int index = Base.staticMetaObject().methodCount(); |
173 | 178 |
174 static if (T.signals.length) | 179 static if (T.signals.length) |
175 { | 180 { |
176 foreach (signal; T.signals) | 181 foreach (signal; T.signals) |
189 } | 194 } |
190 } | 195 } |
191 } | 196 } |
192 } | 197 } |
193 | 198 |
194 /* internal */ alias createImpl!This create; | 199 // new |
195 | 200 static This create(T : QObject)(void* nativeId) |
196 /** | 201 { |
197 */ | 202 auto m = new This(); |
198 @property | 203 m.construct!T(nativeId); |
199 override This base() | 204 return m; |
200 { | 205 } |
201 return super.base; | 206 |
202 } | 207 /++ |
203 | 208 +/ |
204 /** | 209 QMetaObject base() |
205 */ | 210 { |
206 @property | 211 return _base; |
207 override This firstDerived() | 212 } |
208 { | 213 |
209 return super.firstDerived; | 214 /++ |
210 } | 215 +/ |
211 | 216 QMetaObjectNative* nativeId() |
212 /** | 217 { |
213 */ | 218 return _nativeId; |
214 @property | 219 } |
215 override This next() | 220 |
216 { | 221 /++ |
217 return super.next; | 222 +/ |
218 } | 223 ClassInfo classInfo() |
219 | 224 { |
220 /** | 225 return _classInfo; |
221 */ | 226 } |
222 @property | 227 |
223 override QMetaObjectNative* nativeId() | |
224 { | |
225 return cast(QMetaObjectNative*)super.nativeId; | |
226 } | |
227 | |
228 @property | |
229 const (QMetaMethod[]) methods() | 228 const (QMetaMethod[]) methods() |
230 { | 229 { |
231 return _methods; | 230 return _methods; |
232 } | 231 } |
233 | 232 |
239 QMetaMethod lookUpMethod(string slot) | 238 QMetaMethod lookUpMethod(string slot) |
240 { | 239 { |
241 foreach (method; _methods) | 240 foreach (method; _methods) |
242 if (method.signature == slot) | 241 if (method.signature == slot) |
243 return method; | 242 return method; |
244 if (base) | 243 if (_base) |
245 return base.lookUpMethod(slot); | 244 return _base.lookUpMethod(slot); |
246 else | 245 else |
247 return null; | 246 return null; |
248 } | 247 } |
249 | 248 |
250 QMetaSignal lookUpSignal(string signal) | 249 QMetaSignal lookUpSignal(string signal) |
251 { | 250 { |
252 foreach (method; _methods) | 251 foreach (method; _methods) |
253 if (method.signature == signal && cast(QMetaSignal)method) | 252 if (method.signature == signal && cast(QMetaSignal)method) |
254 return cast(QMetaSignal)method; | 253 return cast(QMetaSignal)method; |
255 if (base) | 254 if (_base) |
256 return base.lookUpSignal(signal); | 255 return _base.lookUpSignal(signal); |
257 else | 256 else |
258 return null; | 257 return null; |
259 } | 258 } |
260 | 259 |
261 QMetaMethod[] lookUpMethodOverloads(string methodName) | 260 QMetaMethod[] lookUpMethodOverloads(string methodName) |
262 { | 261 { |
263 typeof(return) result; | 262 typeof(return) result; |
264 foreach (method; _methods) | 263 foreach (method; _methods) |
265 if (method.name == methodName) | 264 if (method.name == methodName) |
266 result ~= method; | 265 result ~= method; |
267 if (base) | 266 if (_base) |
268 result ~= base.lookUpMethodOverloads(methodName); | 267 result ~= _base.lookUpMethodOverloads(methodName); |
269 return result; | 268 return result; |
270 } | 269 } |
271 | 270 |
272 QMetaSignal[] lookUpSignalOverloads(string signalName) | 271 QMetaSignal[] lookUpSignalOverloads(string signalName) |
273 { | 272 { |
274 typeof(return) result; | 273 typeof(return) result; |
275 foreach (method; _methods) | 274 foreach (method; _methods) |
276 if (method.name == signalName && cast(QMetaSignal)method) | 275 if (method.name == signalName && cast(QMetaSignal)method) |
277 result ~= cast(QMetaSignal)method; | 276 result ~= cast(QMetaSignal)method; |
278 if (base) | 277 if (_base) |
279 result ~= base.lookUpSignalOverloads(signalName); | 278 result ~= _base.lookUpSignalOverloads(signalName); |
280 return result; | 279 return result; |
281 } | 280 } |
282 | 281 |
283 private QMetaObject lookupDerived(void*[] moIds) | 282 private QMetaObject lookupDerived(void*[] moIds) |
284 { | 283 { |
285 assert (moIds.length >= 1); | 284 assert (moIds.length >= 1); |
286 | 285 |
287 for (auto mo = firstDerived; mo !is null; mo = mo.next) | 286 for (auto mo = _firstDerived; mo !is null; mo = mo._next) |
288 { | 287 { |
289 if (mo.nativeId == moIds[0]) | 288 if (mo._nativeId == moIds[0]) |
290 { | 289 { |
291 if (moIds.length == 1) // exact match found | 290 if (moIds.length == 1) // exact match found |
292 return mo; | 291 return mo; |
293 else // look deeper | 292 else // look deeper |
294 return mo.lookupDerived(moIds[1..$]); | 293 return mo.lookupDerived(moIds[1..$]); |
307 if (nativeObjId) | 306 if (nativeObjId) |
308 { | 307 { |
309 result = cast(QObject)qtd_get_d_qobject(nativeObjId); | 308 result = cast(QObject)qtd_get_d_qobject(nativeObjId); |
310 if (!result) | 309 if (!result) |
311 { | 310 { |
312 auto nId = nativeId; | |
313 auto moId = qtd_QObject_metaObject(nativeObjId); | 311 auto moId = qtd_QObject_metaObject(nativeObjId); |
314 if (nId == moId) | 312 if (_nativeId == moId) |
315 result = _createWrapper(nativeObjId); | 313 result = _createWrapper(nativeObjId); |
316 else | 314 else |
317 { | 315 { |
318 // get native metaobjects for the entire derivation lattice | 316 // get native metaobjects for the entire derivation lattice |
319 // up to, but not including, the current metaobject. | 317 // up to, but not including, the current metaobject. |
321 | 319 |
322 for (void* tmp = moId;;) | 320 for (void* tmp = moId;;) |
323 { | 321 { |
324 tmp = qtd_QMetaObject_superClass(tmp); | 322 tmp = qtd_QMetaObject_superClass(tmp); |
325 assert(tmp); | 323 assert(tmp); |
326 if (tmp == nId) | 324 if (tmp == _nativeId) |
327 break; | 325 break; |
328 moCount++; | 326 moCount++; |
329 } | 327 } |
330 | 328 |
331 void*[] moIds = (cast(void**)alloca(moCount * (void*).sizeof))[0..moCount]; | 329 void*[] moIds = (cast(void**)alloca(moCount * (void*).sizeof))[0..moCount]; |
359 return qtd_QMetaObject_connect(sender.__nativeId, signal_index, receiver.__nativeId, method_index, type, types); | 357 return qtd_QMetaObject_connect(sender.__nativeId, signal_index, receiver.__nativeId, method_index, type, types); |
360 } | 358 } |
361 | 359 |
362 int indexOfMethod_Cpp(string method) | 360 int indexOfMethod_Cpp(string method) |
363 { | 361 { |
364 return qtd_QMetaObject_indexOfMethod(nativeId, toStringz(method)); | 362 return qtd_QMetaObject_indexOfMethod(_nativeId, toStringz(method)); |
365 } | 363 } |
366 | 364 |
367 int methodCount() | 365 int methodCount() |
368 { | 366 { |
369 return qtd_QMetaObject_methodCount(nativeId); | 367 return qtd_QMetaObject_methodCount(_nativeId); |
370 } | 368 } |
371 | 369 |
372 static void connectImpl(QObject sender, string signalString, QObject receiver, string methodString, int type) | 370 static void connectImpl(QObject sender, string signalString, QObject receiver, string methodString, int type) |
373 { | 371 { |
374 QMetaSignal[] signals; | 372 QMetaSignal[] signals; |