253
|
1 module qt.core.QMetaObject;
|
|
2
|
|
3 import qt.QGlobal;
|
|
4 import qt.core.QObject;
|
|
5 import qt.QtdObject;
|
|
6
|
288
|
7 import std.algorithm;
|
|
8
|
|
9 class Meta
|
|
10 {
|
|
11 string name;
|
|
12 }
|
|
13
|
|
14 class MetaType : Meta
|
|
15 {
|
|
16 this()
|
|
17 {
|
|
18 }
|
|
19 }
|
|
20
|
|
21 class MetaVariable : Meta
|
|
22 {
|
|
23 MetaType type;
|
|
24 }
|
|
25
|
|
26 class MetaCallable : Meta { }
|
|
27
|
|
28 class MetaMethod : Meta { }
|
|
29
|
|
30 class QMetaArgument : MetaVariable { }
|
|
31
|
|
32 class QMetaMethod : MetaMethod
|
|
33 {
|
|
34 // QMetaArgument[] arguments;
|
|
35 string signature;
|
|
36 int indexOfMethod;
|
|
37
|
|
38 this(string signature_, int indexOfMethod_)
|
|
39 {
|
|
40 signature = signature_;
|
|
41 indexOfMethod = indexOfMethod_;
|
|
42 }
|
|
43 }
|
|
44
|
|
45 class QMetaSignal : QMetaMethod
|
|
46 {
|
|
47 this(string signature_, int indexOfMethod_)
|
|
48 {
|
|
49 super(signature_, indexOfMethod_);
|
|
50 }
|
|
51 }
|
|
52
|
|
53 class QMetaSlot : QMetaMethod
|
|
54 {
|
|
55 this(string signature_, int indexOfMethod_)
|
|
56 {
|
|
57 super(signature_, indexOfMethod_);
|
|
58 }
|
|
59 }
|
|
60
|
|
61 class MetaObject : MetaType
|
|
62 {
|
|
63 MetaObject _base;
|
|
64 }
|
|
65
|
|
66 struct QMetaObjectNative
|
|
67 {
|
|
68 QMetaObjectNative *superdata;
|
|
69 immutable(char) *stringdata;
|
|
70 const(uint) *data;
|
|
71 void *extradata;
|
|
72 }
|
|
73
|
253
|
74 final class QMetaObject
|
|
75 {
|
288
|
76 enum Call
|
|
77 {
|
|
78 InvokeMetaMethod,
|
|
79 ReadProperty,
|
|
80 WriteProperty,
|
|
81 ResetProperty,
|
|
82 QueryPropertyDesignable,
|
|
83 QueryPropertyScriptable,
|
|
84 QueryPropertyStored,
|
|
85 QueryPropertyEditable,
|
|
86 QueryPropertyUser,
|
|
87 CreateInstance
|
|
88 }
|
|
89
|
253
|
90 private
|
|
91 {
|
288
|
92 QMetaObjectNative* _nativeId;
|
253
|
93 QMetaObject _base; // super class
|
|
94 QMetaObject _firstDerived; // head of the linked list of derived classes
|
|
95 QMetaObject _next; // next sibling on this derivation level
|
288
|
96 QMetaMethod[] _methods;
|
253
|
97 ClassInfo _classInfo;
|
|
98
|
|
99 QObject function(void* nativeId) _createWrapper;
|
|
100 }
|
|
101
|
|
102 private void addDerived(QMetaObject mo)
|
|
103 {
|
|
104 mo._next = _firstDerived;
|
|
105 _firstDerived = mo;
|
|
106 }
|
|
107
|
|
108 // NOTE: construction is split between this non-templated constructor and 'construct' function below.
|
288
|
109 this(QMetaObjectNative* nativeId, QMetaObject base)
|
253
|
110 {
|
|
111 _nativeId = nativeId;
|
|
112 if (base)
|
|
113 {
|
|
114 base.addDerived(this);
|
|
115 _base = base;
|
|
116 }
|
|
117 }
|
|
118
|
|
119 // TODO: remove when D acquires templated constructors
|
|
120 void construct(T : QObject, Concrete = T)()
|
|
121 {
|
|
122 _classInfo = T.classinfo;
|
|
123
|
|
124 _createWrapper = function QObject(void* nativeId) {
|
|
125 // COMPILER BUG: cast is should not be needed
|
|
126 auto obj = new Concrete(nativeId, cast(QtdObjectFlags)(QtdObjectFlags.nativeOwnership | QtdObjectFlags.dynamicEntity));
|
|
127 // TODO: Probably this should be a virtual call from T's constructor
|
|
128 T.__createEntity(nativeId, cast(void*)obj);
|
|
129 return obj;
|
|
130 };
|
|
131 }
|
|
132
|
|
133 /++
|
|
134 +/
|
|
135 QMetaObject base()
|
|
136 {
|
|
137 return _base;
|
|
138 }
|
|
139
|
|
140 /++
|
|
141 +/
|
288
|
142 QMetaObjectNative* nativeId()
|
253
|
143 {
|
|
144 return _nativeId;
|
|
145 }
|
|
146
|
|
147 /++
|
|
148 +/
|
|
149 ClassInfo classInfo()
|
|
150 {
|
|
151 return _classInfo;
|
|
152 }
|
|
153
|
288
|
154 const (QMetaMethod[]) methods()
|
|
155 {
|
|
156 return _methods;
|
|
157 }
|
|
158
|
|
159 void addMethod(QMetaMethod method_)
|
|
160 {
|
|
161 _methods ~= method_;
|
|
162 }
|
|
163
|
|
164 int lookUpMethod(string slot)
|
|
165 {
|
|
166 foreach (method; _methods)
|
|
167 if (method.signature == slot)
|
|
168 return method.indexOfMethod;
|
|
169 if (_base)
|
|
170 return _base.lookUpMethod(slot);
|
|
171 else
|
|
172 return -1;
|
|
173 }
|
|
174
|
|
175 int lookUpSignal(string signal)
|
|
176 {
|
|
177 // auto signalBegin = signal[0..$-1];
|
|
178 foreach (method; _methods)
|
|
179 if (method.signature == signal && cast(QMetaSignal)method)
|
|
180 return method.indexOfMethod;
|
|
181 if (_base)
|
|
182 return _base.lookUpSignal(signal);
|
|
183 else
|
|
184 return -1;
|
|
185 }
|
|
186
|
253
|
187 private QMetaObject lookupDerived(void*[] moIds)
|
|
188 {
|
|
189 assert (moIds.length >= 1);
|
|
190
|
|
191 for (auto mo = _firstDerived; mo !is null; mo = mo._next)
|
|
192 {
|
|
193 if (mo._nativeId == moIds[0])
|
|
194 {
|
|
195 if (moIds.length == 1) // exact match found
|
|
196 return mo;
|
|
197 else // look deeper
|
|
198 return mo.lookupDerived(moIds[1..$]);
|
|
199 }
|
|
200 }
|
|
201
|
|
202 // no initialized wrapper that matches the native object.
|
|
203 // use the base class wrapper
|
|
204 return this;
|
|
205 }
|
|
206
|
|
207 QObject getObject(void* nativeObjId)
|
|
208 {
|
|
209 QObject result;
|
|
210
|
|
211 if (nativeObjId)
|
|
212 {
|
|
213 result = cast(QObject)qtd_get_d_qobject(nativeObjId);
|
|
214 if (!result)
|
|
215 {
|
|
216 auto moId = qtd_QObject_metaObject(nativeObjId);
|
|
217 if (_nativeId == moId)
|
|
218 result = _createWrapper(nativeObjId);
|
|
219 else
|
|
220 {
|
|
221 // get native metaobjects for the entire derivation lattice
|
|
222 // up to, but not including, the current metaobject.
|
|
223 size_t moCount = 1;
|
|
224
|
|
225 for (void* tmp = moId;;)
|
|
226 {
|
|
227 tmp = qtd_QMetaObject_superClass(tmp);
|
|
228 assert(tmp);
|
|
229 if (tmp == _nativeId)
|
|
230 break;
|
|
231 moCount++;
|
|
232 }
|
|
233
|
|
234 void*[] moIds = (cast(void**)alloca(moCount * (void*).sizeof))[0..moCount];
|
|
235
|
|
236 moIds[--moCount] = moId;
|
|
237 while (moCount > 0)
|
|
238 moIds[--moCount] = moId = qtd_QMetaObject_superClass(moId);
|
|
239
|
|
240 result = lookupDerived(moIds)._createWrapper(nativeObjId);
|
288
|
241 }
|
253
|
242 }
|
|
243 }
|
|
244
|
|
245 return result;
|
|
246 }
|
288
|
247
|
|
248 static void activate(QObject sender, QMetaObject m, int local_signal_index, void **argv)
|
|
249 {
|
|
250 qtd_QMetaObject_activate_3(sender.__nativeId, m.nativeId, local_signal_index, argv);
|
|
251 }
|
|
252
|
|
253 static void activate(QObject sender, QMetaObject m, int from_local_signal_index, int to_local_signal_index, void **argv)
|
|
254 {
|
|
255 qtd_QMetaObject_activate_4(sender.__nativeId, m.nativeId, from_local_signal_index, to_local_signal_index, argv);
|
|
256 }
|
|
257
|
|
258 static bool connect(const QObject sender, int signal_index,
|
|
259 const QObject receiver, int method_index,
|
|
260 int type = 0, int *types = null)
|
|
261 {
|
|
262 return qtd_QMetaObject_connect(sender.__nativeId, signal_index, receiver.__nativeId, method_index, type, types);
|
|
263 }
|
|
264
|
|
265 int indexOfMethod_Cpp(string method)
|
|
266 {
|
|
267 return qtd_QMetaObject_indexOfMethod(_nativeId, toStringz(method));
|
|
268 }
|
|
269
|
|
270 int methodCount()
|
|
271 {
|
|
272 return qtd_QMetaObject_methodCount(_nativeId);
|
|
273 }
|
|
274
|
253
|
275 }
|
|
276
|
288
|
277 extern(C) void qtd_QMetaObject_activate_3(void* sender, void* m, int local_signal_index, void **argv);
|
|
278 extern(C) void qtd_QMetaObject_activate_4(void *sender, void* m, int from_local_signal_index, int to_local_signal_index, void **argv);
|
|
279 extern(C) bool qtd_QMetaObject_connect(const void* sender, int signal_index,
|
|
280 const void* receiver, int method_index,
|
|
281 int type, int *types);
|
|
282
|
|
283 extern(C) int qtd_QMetaObject_indexOfMethod(void *nativeId, const(char) *method);
|
|
284 extern(C) int qtd_QMetaObject_methodCount(void *nativeId);
|
|
285
|
253
|
286 extern(C) void* qtd_QMetaObject_superClass(void* nativeId); |