311
|
1 module qt.core.QMetaObject;
|
|
2
|
|
3 import
|
|
4 qt.Core,
|
|
5 qt.core.QObject,
|
|
6 qt.QtdObject;
|
|
7
|
|
8 /++
|
|
9 Meta-object for QObject classes.
|
|
10 +/
|
|
11 final class QMetaObject : QtdMetaObjectBase
|
|
12 {
|
|
13 alias typeof(this) This;
|
|
14
|
|
15 this(void* nativeId, QtdMetaObjectBase base, CreateWrapper createWrapper)
|
|
16 {
|
|
17 super(nativeId, base, createWrapper);
|
|
18 }
|
|
19
|
|
20 private QMetaObject lookupDerived(void*[] moIds)
|
|
21 {
|
|
22 assert (moIds.length >= 1);
|
|
23
|
|
24 for (auto mo = static_cast!(This)(firstDerived); mo !is null; mo = static_cast!(This)(mo.next))
|
|
25 {
|
|
26 if (mo.nativeId == moIds[0])
|
|
27 {
|
|
28 if (moIds.length == 1) // exact match found
|
|
29 return mo;
|
|
30 else // look deeper
|
|
31 return mo.lookupDerived(moIds[1..$]);
|
|
32 }
|
|
33 }
|
|
34
|
|
35 // no initialized wrapper that matches the native object.
|
|
36 // use the base class wrapper
|
|
37 return this;
|
|
38 }
|
|
39
|
|
40 QObject wrap(void* nativeObjId, QtdObjectFlags flags = QtdObjectFlags.none)
|
|
41 {
|
|
42 QObject result;
|
|
43
|
|
44 if (nativeObjId)
|
|
45 {
|
|
46 result = cast(QObject)qtd_get_d_qobject(nativeObjId);
|
|
47 if (!result)
|
|
48 {
|
|
49 auto moId = qtd_QObject_typeId(nativeObjId);
|
|
50 if (nativeId == moId)
|
|
51 result = static_cast!(QObject)(_createWrapper(nativeObjId, flags));
|
|
52 else
|
|
53 {
|
|
54 // get native metaobjects for the entire derivation lattice
|
|
55 // up to, but not including, the current metaobject.
|
|
56 size_t moCount = 1;
|
|
57
|
|
58 for (void* tmp = moId;;)
|
|
59 {
|
|
60 tmp = qtd_QMetaObject_superClass(tmp);
|
|
61 if (!tmp)
|
|
62 return null;
|
|
63
|
|
64 if (tmp == nativeId)
|
|
65 break;
|
|
66 moCount++;
|
|
67 }
|
|
68
|
|
69 void*[] moIds = (cast(void**)alloca(moCount * (void*).sizeof))[0..moCount];
|
|
70
|
|
71 moIds[--moCount] = moId;
|
|
72 while (moCount > 0)
|
|
73 moIds[--moCount] = moId = qtd_QMetaObject_superClass(moId);
|
|
74
|
|
75 auto mo = lookupDerived(moIds);
|
|
76 result = static_cast!(QObject)(mo._createWrapper(nativeObjId, flags));
|
|
77 }
|
|
78 }
|
|
79 }
|
|
80
|
|
81 return result;
|
|
82 }
|
|
83 }
|
|
84
|
|
85 extern(C) void* qtd_QMetaObject_superClass(void* nativeId); |