author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 17 Sep 2010 08:34:18 +0300 | |
changeset 36 | ef0373b55136 |
parent 33 | 3e2da88830cd |
child 37 | 758a864f9613 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtCore 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 |
#include "qmetaobject.h" |
|
43 |
#include "qmetatype.h" |
|
44 |
#include "qobject.h" |
|
45 |
||
46 |
#include <qcoreapplication.h> |
|
47 |
#include <qcoreevent.h> |
|
48 |
#include <qdatastream.h> |
|
49 |
#include <qstringlist.h> |
|
50 |
#include <qthread.h> |
|
51 |
#include <qvarlengtharray.h> |
|
52 |
#include <qvariant.h> |
|
53 |
#include <qhash.h> |
|
54 |
#include <qdebug.h> |
|
55 |
#include <qsemaphore.h> |
|
56 |
||
57 |
#include "private/qobject_p.h" |
|
58 |
#include "private/qmetaobject_p.h" |
|
59 |
||
60 |
#include <ctype.h> |
|
61 |
||
62 |
QT_BEGIN_NAMESPACE |
|
63 |
||
64 |
/*! |
|
65 |
\class QMetaObject |
|
66 |
||
67 |
\brief The QMetaObject class contains meta-information about Qt |
|
68 |
objects. |
|
69 |
||
70 |
\ingroup objectmodel |
|
71 |
||
72 |
The Qt \l{Meta-Object System} in Qt is responsible for the |
|
73 |
signals and slots inter-object communication mechanism, runtime |
|
74 |
type information, and the Qt property system. A single |
|
75 |
QMetaObject instance is created for each QObject subclass that is |
|
76 |
used in an application, and this instance stores all the |
|
77 |
meta-information for the QObject subclass. This object is |
|
78 |
available as QObject::metaObject(). |
|
79 |
||
80 |
This class is not normally required for application programming, |
|
81 |
but it is useful if you write meta-applications, such as scripting |
|
82 |
engines or GUI builders. |
|
83 |
||
84 |
The functions you are most likely to find useful are these: |
|
85 |
\list |
|
86 |
\o className() returns the name of a class. |
|
87 |
\o superClass() returns the superclass's meta-object. |
|
88 |
\o method() and methodCount() provide information |
|
89 |
about a class's meta-methods (signals, slots and other |
|
90 |
\l{Q_INVOKABLE}{invokable} member functions). |
|
91 |
\o enumerator() and enumeratorCount() and provide information about |
|
92 |
a class's enumerators. |
|
93 |
\o propertyCount() and property() provide information about a |
|
94 |
class's properties. |
|
95 |
\o constructor() and constructorCount() provide information |
|
96 |
about a class's meta-constructors. |
|
97 |
\endlist |
|
98 |
||
99 |
The index functions indexOfConstructor(), indexOfMethod(), |
|
100 |
indexOfEnumerator(), and indexOfProperty() map names of constructors, |
|
101 |
member functions, enumerators, or properties to indexes in the |
|
102 |
meta-object. For example, Qt uses indexOfMethod() internally when you |
|
103 |
connect a signal to a slot. |
|
104 |
||
105 |
Classes can also have a list of \e{name}--\e{value} pairs of |
|
106 |
additional class information, stored in QMetaClassInfo objects. |
|
107 |
The number of pairs is returned by classInfoCount(), single pairs |
|
108 |
are returned by classInfo(), and you can search for pairs with |
|
109 |
indexOfClassInfo(). |
|
110 |
||
111 |
\sa QMetaClassInfo, QMetaEnum, QMetaMethod, QMetaProperty, QMetaType, |
|
112 |
{Meta-Object System} |
|
113 |
*/ |
|
114 |
||
115 |
/*! |
|
116 |
\enum QMetaObject::Call |
|
117 |
||
118 |
\internal |
|
119 |
||
120 |
\value InvokeSlot |
|
121 |
\value EmitSignal |
|
122 |
\value ReadProperty |
|
123 |
\value WriteProperty |
|
124 |
\value ResetProperty |
|
125 |
\value QueryPropertyDesignable |
|
126 |
\value QueryPropertyScriptable |
|
127 |
\value QueryPropertyStored |
|
128 |
\value QueryPropertyEditable |
|
129 |
\value QueryPropertyUser |
|
130 |
\value CreateInstance |
|
131 |
*/ |
|
132 |
||
133 |
/*! |
|
134 |
\enum QMetaMethod::Access |
|
135 |
||
136 |
This enum describes the access level of a method, following the conventions used in C++. |
|
137 |
||
138 |
\value Private |
|
139 |
\value Protected |
|
140 |
\value Public |
|
141 |
*/ |
|
142 |
||
143 |
static inline const QMetaObjectPrivate *priv(const uint* data) |
|
144 |
{ return reinterpret_cast<const QMetaObjectPrivate*>(data); } |
|
145 |
||
146 |
||
147 |
/*! |
|
148 |
\since 4.5 |
|
149 |
||
150 |
Constructs a new instance of this class. You can pass up to ten arguments |
|
151 |
(\a val0, \a val1, \a val2, \a val3, \a val4, \a val5, \a val6, \a val7, |
|
152 |
\a val8, and \a val9) to the constructor. Returns the new object, or 0 if |
|
153 |
no suitable constructor is available. |
|
154 |
||
155 |
Note that only constructors that are declared with the Q_INVOKABLE |
|
156 |
modifier are made available through the meta-object system. |
|
157 |
||
158 |
\sa Q_ARG(), constructor() |
|
159 |
*/ |
|
160 |
QObject *QMetaObject::newInstance(QGenericArgument val0, |
|
161 |
QGenericArgument val1, |
|
162 |
QGenericArgument val2, |
|
163 |
QGenericArgument val3, |
|
164 |
QGenericArgument val4, |
|
165 |
QGenericArgument val5, |
|
166 |
QGenericArgument val6, |
|
167 |
QGenericArgument val7, |
|
168 |
QGenericArgument val8, |
|
169 |
QGenericArgument val9) const |
|
170 |
{ |
|
171 |
QByteArray constructorName = className(); |
|
172 |
{ |
|
173 |
int idx = constructorName.lastIndexOf(':'); |
|
174 |
if (idx != -1) |
|
175 |
constructorName.remove(0, idx+1); // remove qualified part |
|
176 |
} |
|
177 |
QVarLengthArray<char, 512> sig; |
|
178 |
sig.append(constructorName.constData(), constructorName.length()); |
|
179 |
sig.append('('); |
|
180 |
||
181 |
enum { MaximumParamCount = 10 }; |
|
182 |
const char *typeNames[] = {val0.name(), val1.name(), val2.name(), val3.name(), val4.name(), |
|
183 |
val5.name(), val6.name(), val7.name(), val8.name(), val9.name()}; |
|
184 |
||
185 |
int paramCount; |
|
186 |
for (paramCount = 0; paramCount < MaximumParamCount; ++paramCount) { |
|
187 |
int len = qstrlen(typeNames[paramCount]); |
|
188 |
if (len <= 0) |
|
189 |
break; |
|
190 |
sig.append(typeNames[paramCount], len); |
|
191 |
sig.append(','); |
|
192 |
} |
|
193 |
if (paramCount == 0) |
|
194 |
sig.append(')'); // no parameters |
|
195 |
else |
|
196 |
sig[sig.size() - 1] = ')'; |
|
197 |
sig.append('\0'); |
|
198 |
||
199 |
int idx = indexOfConstructor(sig.constData()); |
|
200 |
if (idx < 0) { |
|
201 |
QByteArray norm = QMetaObject::normalizedSignature(sig.constData()); |
|
202 |
idx = indexOfConstructor(norm.constData()); |
|
203 |
} |
|
204 |
if (idx < 0) |
|
205 |
return 0; |
|
206 |
||
207 |
QVariant ret(QMetaType::QObjectStar, (void*)0); |
|
208 |
void *param[] = {ret.data(), val0.data(), val1.data(), val2.data(), val3.data(), val4.data(), |
|
209 |
val5.data(), val6.data(), val7.data(), val8.data(), val9.data()}; |
|
210 |
||
211 |
if (static_metacall(CreateInstance, idx, param) >= 0) |
|
212 |
return 0; |
|
213 |
return *reinterpret_cast<QObject**>(param[0]); |
|
214 |
} |
|
215 |
||
216 |
/*! |
|
217 |
\internal |
|
218 |
*/ |
|
219 |
int QMetaObject::static_metacall(Call cl, int idx, void **argv) const |
|
220 |
{ |
|
221 |
if (priv(d.data)->revision < 2) |
|
222 |
return 0; |
|
223 |
const QMetaObjectExtraData *extra = (const QMetaObjectExtraData*)(d.extradata); |
|
224 |
if (!extra || !extra->static_metacall) |
|
225 |
return 0; |
|
226 |
return extra->static_metacall(cl, idx, argv); |
|
227 |
} |
|
228 |
||
229 |
/*! |
|
230 |
\internal |
|
231 |
*/ |
|
232 |
int QMetaObject::metacall(QObject *object, Call cl, int idx, void **argv) |
|
233 |
{ |
|
234 |
if (QMetaObject *mo = object->d_ptr->metaObject) |
|
235 |
return static_cast<QAbstractDynamicMetaObject*>(mo)->metaCall(cl, idx, argv); |
|
236 |
else |
|
237 |
return object->qt_metacall(cl, idx, argv); |
|
238 |
} |
|
239 |
||
240 |
/*! |
|
241 |
\fn const char *QMetaObject::className() const |
|
242 |
||
243 |
Returns the class name. |
|
244 |
||
245 |
\sa superClass() |
|
246 |
*/ |
|
247 |
||
248 |
/*! |
|
249 |
\fn QMetaObject *QMetaObject::superClass() const |
|
250 |
||
251 |
Returns the meta-object of the superclass, or 0 if there is no |
|
252 |
such object. |
|
253 |
||
254 |
\sa className() |
|
255 |
*/ |
|
256 |
||
257 |
/*! |
|
258 |
\internal |
|
259 |
||
260 |
Returns \a obj if object \a obj inherits from this |
|
261 |
meta-object; otherwise returns 0. |
|
262 |
*/ |
|
263 |
QObject *QMetaObject::cast(QObject *obj) const |
|
264 |
{ |
|
265 |
if (obj) { |
|
266 |
const QMetaObject *m = obj->metaObject(); |
|
267 |
do { |
|
268 |
if (m == this) |
|
269 |
return const_cast<QObject*>(obj); |
|
270 |
} while ((m = m->d.superdata)); |
|
271 |
} |
|
272 |
return 0; |
|
273 |
} |
|
274 |
||
275 |
#ifndef QT_NO_TRANSLATION |
|
276 |
/*! |
|
277 |
\internal |
|
278 |
*/ |
|
279 |
QString QMetaObject::tr(const char *s, const char *c) const |
|
280 |
{ |
|
281 |
return QCoreApplication::translate(d.stringdata, s, c, QCoreApplication::CodecForTr); |
|
282 |
} |
|
283 |
||
284 |
/*! |
|
285 |
\internal |
|
286 |
*/ |
|
287 |
QString QMetaObject::tr(const char *s, const char *c, int n) const |
|
288 |
{ |
|
289 |
return QCoreApplication::translate(d.stringdata, s, c, QCoreApplication::CodecForTr, n); |
|
290 |
} |
|
291 |
||
292 |
/*! |
|
293 |
\internal |
|
294 |
*/ |
|
295 |
QString QMetaObject::trUtf8(const char *s, const char *c) const |
|
296 |
{ |
|
297 |
return QCoreApplication::translate(d.stringdata, s, c, QCoreApplication::UnicodeUTF8); |
|
298 |
} |
|
299 |
||
300 |
/*! |
|
301 |
\internal |
|
302 |
*/ |
|
303 |
QString QMetaObject::trUtf8(const char *s, const char *c, int n) const |
|
304 |
{ |
|
305 |
return QCoreApplication::translate(d.stringdata, s, c, QCoreApplication::UnicodeUTF8, n); |
|
306 |
} |
|
307 |
#endif // QT_NO_TRANSLATION |
|
308 |
||
309 |
/*! |
|
310 |
Returns the method offset for this class; i.e. the index position |
|
311 |
of this class's first member function. |
|
312 |
||
313 |
The offset is the sum of all the methods in the class's |
|
314 |
superclasses (which is always positive since QObject has the |
|
315 |
deleteLater() slot and a destroyed() signal). |
|
316 |
||
317 |
\sa method(), methodCount(), indexOfMethod() |
|
318 |
*/ |
|
319 |
int QMetaObject::methodOffset() const |
|
320 |
{ |
|
321 |
int offset = 0; |
|
322 |
const QMetaObject *m = d.superdata; |
|
323 |
while (m) { |
|
324 |
offset += priv(m->d.data)->methodCount; |
|
325 |
m = m->d.superdata; |
|
326 |
} |
|
327 |
return offset; |
|
328 |
} |
|
329 |
||
330 |
||
331 |
/*! |
|
332 |
Returns the enumerator offset for this class; i.e. the index |
|
333 |
position of this class's first enumerator. |
|
334 |
||
335 |
If the class has no superclasses with enumerators, the offset is |
|
336 |
0; otherwise the offset is the sum of all the enumerators in the |
|
337 |
class's superclasses. |
|
338 |
||
339 |
\sa enumerator(), enumeratorCount(), indexOfEnumerator() |
|
340 |
*/ |
|
341 |
int QMetaObject::enumeratorOffset() const |
|
342 |
{ |
|
343 |
int offset = 0; |
|
344 |
const QMetaObject *m = d.superdata; |
|
345 |
while (m) { |
|
346 |
offset += priv(m->d.data)->enumeratorCount; |
|
347 |
m = m->d.superdata; |
|
348 |
} |
|
349 |
return offset; |
|
350 |
} |
|
351 |
||
352 |
/*! |
|
353 |
Returns the property offset for this class; i.e. the index |
|
354 |
position of this class's first property. |
|
355 |
||
356 |
The offset is the sum of all the properties in the class's |
|
357 |
superclasses (which is always positive since QObject has the |
|
358 |
name() property). |
|
359 |
||
360 |
\sa property(), propertyCount(), indexOfProperty() |
|
361 |
*/ |
|
362 |
int QMetaObject::propertyOffset() const |
|
363 |
{ |
|
364 |
int offset = 0; |
|
365 |
const QMetaObject *m = d.superdata; |
|
366 |
while (m) { |
|
367 |
offset += priv(m->d.data)->propertyCount; |
|
368 |
m = m->d.superdata; |
|
369 |
} |
|
370 |
return offset; |
|
371 |
} |
|
372 |
||
373 |
/*! |
|
374 |
Returns the class information offset for this class; i.e. the |
|
375 |
index position of this class's first class information item. |
|
376 |
||
377 |
If the class has no superclasses with class information, the |
|
378 |
offset is 0; otherwise the offset is the sum of all the class |
|
379 |
information items in the class's superclasses. |
|
380 |
||
381 |
\sa classInfo(), classInfoCount(), indexOfClassInfo() |
|
382 |
*/ |
|
383 |
int QMetaObject::classInfoOffset() const |
|
384 |
{ |
|
385 |
int offset = 0; |
|
386 |
const QMetaObject *m = d.superdata; |
|
387 |
while (m) { |
|
388 |
offset += priv(m->d.data)->classInfoCount; |
|
389 |
m = m->d.superdata; |
|
390 |
} |
|
391 |
return offset; |
|
392 |
} |
|
393 |
||
394 |
/*! |
|
395 |
\since 4.5 |
|
396 |
||
397 |
Returns the number of constructors in this class. |
|
398 |
||
399 |
\sa constructor(), indexOfConstructor() |
|
400 |
*/ |
|
401 |
int QMetaObject::constructorCount() const |
|
402 |
{ |
|
403 |
if (priv(d.data)->revision < 2) |
|
404 |
return 0; |
|
405 |
return priv(d.data)->constructorCount; |
|
406 |
} |
|
407 |
||
408 |
/*! |
|
409 |
Returns the number of methods in this class, including the number of |
|
410 |
properties provided by each base class. These include signals and slots |
|
411 |
as well as normal member functions. |
|
412 |
||
413 |
Use code like the following to obtain a QStringList containing the methods |
|
414 |
specific to a given class: |
|
415 |
||
416 |
\snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp methodCount |
|
417 |
||
418 |
\sa method(), methodOffset(), indexOfMethod() |
|
419 |
*/ |
|
420 |
int QMetaObject::methodCount() const |
|
421 |
{ |
|
422 |
int n = priv(d.data)->methodCount; |
|
423 |
const QMetaObject *m = d.superdata; |
|
424 |
while (m) { |
|
425 |
n += priv(m->d.data)->methodCount; |
|
426 |
m = m->d.superdata; |
|
427 |
} |
|
428 |
return n; |
|
429 |
} |
|
430 |
||
431 |
/*! |
|
432 |
Returns the number of enumerators in this class. |
|
433 |
||
434 |
\sa enumerator(), enumeratorOffset(), indexOfEnumerator() |
|
435 |
*/ |
|
436 |
int QMetaObject::enumeratorCount() const |
|
437 |
{ |
|
438 |
int n = priv(d.data)->enumeratorCount; |
|
439 |
const QMetaObject *m = d.superdata; |
|
440 |
while (m) { |
|
441 |
n += priv(m->d.data)->enumeratorCount; |
|
442 |
m = m->d.superdata; |
|
443 |
} |
|
444 |
return n; |
|
445 |
} |
|
446 |
||
447 |
/*! |
|
448 |
Returns the number of properties in this class, including the number of |
|
449 |
properties provided by each base class. |
|
450 |
||
451 |
Use code like the following to obtain a QStringList containing the properties |
|
452 |
specific to a given class: |
|
453 |
||
454 |
\snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp propertyCount |
|
455 |
||
456 |
\sa property(), propertyOffset(), indexOfProperty() |
|
457 |
*/ |
|
458 |
int QMetaObject::propertyCount() const |
|
459 |
{ |
|
460 |
int n = priv(d.data)->propertyCount; |
|
461 |
const QMetaObject *m = d.superdata; |
|
462 |
while (m) { |
|
463 |
n += priv(m->d.data)->propertyCount; |
|
464 |
m = m->d.superdata; |
|
465 |
} |
|
466 |
return n; |
|
467 |
} |
|
468 |
||
469 |
/*! |
|
470 |
Returns the number of items of class information in this class. |
|
471 |
||
472 |
\sa classInfo(), classInfoOffset(), indexOfClassInfo() |
|
473 |
*/ |
|
474 |
int QMetaObject::classInfoCount() const |
|
475 |
{ |
|
476 |
int n = priv(d.data)->classInfoCount; |
|
477 |
const QMetaObject *m = d.superdata; |
|
478 |
while (m) { |
|
479 |
n += priv(m->d.data)->classInfoCount; |
|
480 |
m = m->d.superdata; |
|
481 |
} |
|
482 |
return n; |
|
483 |
} |
|
484 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
485 |
/** \internal |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
486 |
* helper function for indexOf{Method,Slot,Signal}, returns the relative index of the method within |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
487 |
* the baseObject |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
488 |
* \a MethodType might be MethodSignal or MethodSlot, or 0 to match everything. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
489 |
* \a normalizeStringData set to true if we should do a second pass for old moc generated files normalizing all the symbols. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
490 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
491 |
template<int MethodType> |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
492 |
static inline int indexOfMethodRelative(const QMetaObject **baseObject, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
493 |
const char *method, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
494 |
bool normalizeStringData) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
495 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
496 |
for (const QMetaObject *m = *baseObject; m; m = m->d.superdata) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
497 |
int i = (MethodType == MethodSignal && priv(m->d.data)->revision >= 4) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
498 |
? (priv(m->d.data)->signalCount - 1) : (priv(m->d.data)->methodCount - 1); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
499 |
const int end = (MethodType == MethodSlot && priv(m->d.data)->revision >= 4) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
500 |
? (priv(m->d.data)->signalCount) : 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
501 |
if (!normalizeStringData) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
502 |
for (; i >= end; --i) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
503 |
const char *stringdata = m->d.stringdata + m->d.data[priv(m->d.data)->methodData + 5*i]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
504 |
if (method[0] == stringdata[0] && strcmp(method + 1, stringdata + 1) == 0) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
505 |
*baseObject = m; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
506 |
return i; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
507 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
508 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
509 |
} else if (priv(m->d.data)->revision < 5) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
510 |
for (; i >= end; --i) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
511 |
const char *stringdata = (m->d.stringdata + m->d.data[priv(m->d.data)->methodData + 5 * i]); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
512 |
const QByteArray normalizedSignature = QMetaObject::normalizedSignature(stringdata); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
513 |
if (normalizedSignature == method) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
514 |
*baseObject = m; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
515 |
return i; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
516 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
517 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
518 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
519 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
520 |
return -1; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
521 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
522 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
523 |
|
0 | 524 |
/*! |
525 |
\since 4.5 |
|
526 |
||
527 |
Finds \a constructor and returns its index; otherwise returns -1. |
|
528 |
||
529 |
Note that the \a constructor has to be in normalized form, as returned |
|
530 |
by normalizedSignature(). |
|
531 |
||
532 |
\sa constructor(), constructorCount(), normalizedSignature() |
|
533 |
*/ |
|
534 |
int QMetaObject::indexOfConstructor(const char *constructor) const |
|
535 |
{ |
|
536 |
if (priv(d.data)->revision < 2) |
|
537 |
return -1; |
|
538 |
for (int i = priv(d.data)->constructorCount-1; i >= 0; --i) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
539 |
const char *data = d.stringdata + d.data[priv(d.data)->constructorData + 5*i]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
540 |
if (data[0] == constructor[0] && strcmp(constructor + 1, data + 1) == 0) { |
0 | 541 |
return i; |
542 |
} |
|
543 |
} |
|
544 |
return -1; |
|
545 |
} |
|
546 |
||
547 |
/*! |
|
548 |
Finds \a method and returns its index; otherwise returns -1. |
|
549 |
||
550 |
Note that the \a method has to be in normalized form, as returned |
|
551 |
by normalizedSignature(). |
|
552 |
||
553 |
\sa method(), methodCount(), methodOffset(), normalizedSignature() |
|
554 |
*/ |
|
555 |
int QMetaObject::indexOfMethod(const char *method) const |
|
556 |
{ |
|
557 |
const QMetaObject *m = this; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
558 |
int i = indexOfMethodRelative<0>(&m, method, false); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
559 |
if (i < 0) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
560 |
m = this; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
561 |
i = indexOfMethodRelative<0>(&m, method, true); |
0 | 562 |
} |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
563 |
if (i >= 0) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
564 |
i += m->methodOffset(); |
0 | 565 |
return i; |
566 |
} |
|
567 |
||
568 |
/*! |
|
569 |
Finds \a signal and returns its index; otherwise returns -1. |
|
570 |
||
571 |
This is the same as indexOfMethod(), except that it will return |
|
572 |
-1 if the method exists but isn't a signal. |
|
573 |
||
574 |
Note that the \a signal has to be in normalized form, as returned |
|
575 |
by normalizedSignature(). |
|
576 |
||
577 |
\sa indexOfMethod(), normalizedSignature(), method(), methodCount(), methodOffset() |
|
578 |
*/ |
|
579 |
int QMetaObject::indexOfSignal(const char *signal) const |
|
580 |
{ |
|
581 |
const QMetaObject *m = this; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
582 |
int i = QMetaObjectPrivate::indexOfSignalRelative(&m, signal, false); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
583 |
if (i < 0) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
584 |
m = this; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
585 |
i = QMetaObjectPrivate::indexOfSignalRelative(&m, signal, true); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
586 |
} |
0 | 587 |
if (i >= 0) |
588 |
i += m->methodOffset(); |
|
589 |
return i; |
|
590 |
} |
|
591 |
||
592 |
/*! \internal |
|
593 |
Same as QMetaObject::indexOfSignal, but the result is the local offset to the base object. |
|
594 |
||
595 |
\a baseObject will be adjusted to the enclosing QMetaObject, or 0 if the signal is not found |
|
596 |
*/ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
597 |
int QMetaObjectPrivate::indexOfSignalRelative(const QMetaObject **baseObject, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
598 |
const char *signal, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
599 |
bool normalizeStringData) |
0 | 600 |
{ |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
601 |
int i = indexOfMethodRelative<MethodSignal>(baseObject, signal, normalizeStringData); |
0 | 602 |
#ifndef QT_NO_DEBUG |
603 |
const QMetaObject *m = *baseObject; |
|
604 |
if (i >= 0 && m && m->d.superdata) { |
|
605 |
int conflict = m->d.superdata->indexOfMethod(signal); |
|
606 |
if (conflict >= 0) |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
607 |
qWarning("QMetaObject::indexOfSignal: signal %s from %s redefined in %s", |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
608 |
signal, m->d.superdata->d.stringdata, m->d.stringdata); |
0 | 609 |
} |
610 |
#endif |
|
611 |
return i; |
|
612 |
} |
|
613 |
||
614 |
/*! |
|
615 |
Finds \a slot and returns its index; otherwise returns -1. |
|
616 |
||
617 |
This is the same as indexOfMethod(), except that it will return |
|
618 |
-1 if the method exists but isn't a slot. |
|
619 |
||
620 |
\sa indexOfMethod(), method(), methodCount(), methodOffset() |
|
621 |
*/ |
|
622 |
int QMetaObject::indexOfSlot(const char *slot) const |
|
623 |
{ |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
624 |
int i = QMetaObjectPrivate::indexOfSlot(this, slot, false); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
625 |
if (i < 0) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
626 |
i = QMetaObjectPrivate::indexOfSlot(this, slot, true); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
627 |
return i; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
628 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
629 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
630 |
int QMetaObjectPrivate::indexOfSlot(const QMetaObject *m, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
631 |
const char *slot, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
632 |
bool normalizeStringData) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
633 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
634 |
int i = indexOfMethodRelative<MethodSlot>(&m, slot, normalizeStringData); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
635 |
if (i >= 0) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
636 |
i += m->methodOffset(); |
0 | 637 |
return i; |
638 |
} |
|
639 |
||
640 |
static const QMetaObject *QMetaObject_findMetaObject(const QMetaObject *self, const char *name) |
|
641 |
{ |
|
642 |
while (self) { |
|
643 |
if (strcmp(self->d.stringdata, name) == 0) |
|
644 |
return self; |
|
645 |
if (self->d.extradata) { |
|
646 |
#ifdef Q_NO_DATA_RELOCATION |
|
647 |
const QMetaObjectAccessor *e; |
|
648 |
Q_ASSERT(priv(self->d.data)->revision >= 2); |
|
649 |
#else |
|
650 |
const QMetaObject **e; |
|
651 |
if (priv(self->d.data)->revision < 2) { |
|
652 |
e = (const QMetaObject**)(self->d.extradata); |
|
653 |
} else |
|
654 |
#endif |
|
655 |
{ |
|
656 |
const QMetaObjectExtraData *extra = (const QMetaObjectExtraData*)(self->d.extradata); |
|
657 |
e = extra->objects; |
|
658 |
} |
|
659 |
if (e) { |
|
660 |
while (*e) { |
|
661 |
#ifdef Q_NO_DATA_RELOCATION |
|
662 |
if (const QMetaObject *m =QMetaObject_findMetaObject(&((*e)()), name)) |
|
663 |
#else |
|
664 |
if (const QMetaObject *m =QMetaObject_findMetaObject((*e), name)) |
|
665 |
#endif |
|
666 |
return m; |
|
667 |
++e; |
|
668 |
} |
|
669 |
} |
|
670 |
} |
|
671 |
self = self->d.superdata; |
|
672 |
} |
|
673 |
return self; |
|
674 |
} |
|
675 |
||
676 |
/*! |
|
677 |
Finds enumerator \a name and returns its index; otherwise returns |
|
678 |
-1. |
|
679 |
||
680 |
\sa enumerator(), enumeratorCount(), enumeratorOffset() |
|
681 |
*/ |
|
682 |
int QMetaObject::indexOfEnumerator(const char *name) const |
|
683 |
{ |
|
684 |
const QMetaObject *m = this; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
685 |
while (m) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
686 |
const QMetaObjectPrivate *d = priv(m->d.data); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
687 |
for (int i = d->enumeratorCount - 1; i >= 0; --i) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
688 |
const char *prop = m->d.stringdata + m->d.data[d->enumeratorData + 4*i]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
689 |
if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) { |
0 | 690 |
i += m->enumeratorOffset(); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
691 |
return i; |
0 | 692 |
} |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
693 |
} |
0 | 694 |
m = m->d.superdata; |
695 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
696 |
return -1; |
0 | 697 |
} |
698 |
||
699 |
/*! |
|
700 |
Finds property \a name and returns its index; otherwise returns |
|
701 |
-1. |
|
702 |
||
703 |
\sa property(), propertyCount(), propertyOffset() |
|
704 |
*/ |
|
705 |
int QMetaObject::indexOfProperty(const char *name) const |
|
706 |
{ |
|
707 |
const QMetaObject *m = this; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
708 |
while (m) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
709 |
const QMetaObjectPrivate *d = priv(m->d.data); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
710 |
for (int i = d->propertyCount-1; i >= 0; --i) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
711 |
const char *prop = m->d.stringdata + m->d.data[d->propertyData + 3*i]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
712 |
if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) { |
0 | 713 |
i += m->propertyOffset(); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
714 |
return i; |
0 | 715 |
} |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
716 |
} |
0 | 717 |
m = m->d.superdata; |
718 |
} |
|
719 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
720 |
if (priv(this->d.data)->revision >= 3 && (priv(this->d.data)->flags & DynamicMetaObject)) { |
0 | 721 |
QAbstractDynamicMetaObject *me = |
722 |
const_cast<QAbstractDynamicMetaObject *>(static_cast<const QAbstractDynamicMetaObject *>(this)); |
|
723 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
724 |
return me->createProperty(name, 0); |
0 | 725 |
} |
726 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
727 |
return -1; |
0 | 728 |
} |
729 |
||
730 |
/*! |
|
731 |
Finds class information item \a name and returns its index; |
|
732 |
otherwise returns -1. |
|
733 |
||
734 |
\sa classInfo(), classInfoCount(), classInfoOffset() |
|
735 |
*/ |
|
736 |
int QMetaObject::indexOfClassInfo(const char *name) const |
|
737 |
{ |
|
738 |
int i = -1; |
|
739 |
const QMetaObject *m = this; |
|
740 |
while (m && i < 0) { |
|
741 |
for (i = priv(m->d.data)->classInfoCount-1; i >= 0; --i) |
|
742 |
if (strcmp(name, m->d.stringdata |
|
743 |
+ m->d.data[priv(m->d.data)->classInfoData + 2*i]) == 0) { |
|
744 |
i += m->classInfoOffset(); |
|
745 |
break; |
|
746 |
} |
|
747 |
m = m->d.superdata; |
|
748 |
} |
|
749 |
return i; |
|
750 |
} |
|
751 |
||
752 |
/*! |
|
753 |
\since 4.5 |
|
754 |
||
755 |
Returns the meta-data for the constructor with the given \a index. |
|
756 |
||
757 |
\sa constructorCount(), newInstance() |
|
758 |
*/ |
|
759 |
QMetaMethod QMetaObject::constructor(int index) const |
|
760 |
{ |
|
761 |
int i = index; |
|
762 |
QMetaMethod result; |
|
763 |
if (priv(d.data)->revision >= 2 && i >= 0 && i < priv(d.data)->constructorCount) { |
|
764 |
result.mobj = this; |
|
765 |
result.handle = priv(d.data)->constructorData + 5*i; |
|
766 |
} |
|
767 |
return result; |
|
768 |
} |
|
769 |
||
770 |
/*! |
|
771 |
Returns the meta-data for the method with the given \a index. |
|
772 |
||
773 |
\sa methodCount(), methodOffset(), indexOfMethod() |
|
774 |
*/ |
|
775 |
QMetaMethod QMetaObject::method(int index) const |
|
776 |
{ |
|
777 |
int i = index; |
|
778 |
i -= methodOffset(); |
|
779 |
if (i < 0 && d.superdata) |
|
780 |
return d.superdata->method(index); |
|
781 |
||
782 |
QMetaMethod result; |
|
783 |
if (i >= 0 && i < priv(d.data)->methodCount) { |
|
784 |
result.mobj = this; |
|
785 |
result.handle = priv(d.data)->methodData + 5*i; |
|
786 |
} |
|
787 |
return result; |
|
788 |
} |
|
789 |
||
790 |
/*! |
|
791 |
Returns the meta-data for the enumerator with the given \a index. |
|
792 |
||
793 |
\sa enumeratorCount(), enumeratorOffset(), indexOfEnumerator() |
|
794 |
*/ |
|
795 |
QMetaEnum QMetaObject::enumerator(int index) const |
|
796 |
{ |
|
797 |
int i = index; |
|
798 |
i -= enumeratorOffset(); |
|
799 |
if (i < 0 && d.superdata) |
|
800 |
return d.superdata->enumerator(index); |
|
801 |
||
802 |
QMetaEnum result; |
|
803 |
if (i >= 0 && i < priv(d.data)->enumeratorCount) { |
|
804 |
result.mobj = this; |
|
805 |
result.handle = priv(d.data)->enumeratorData + 4*i; |
|
806 |
} |
|
807 |
return result; |
|
808 |
} |
|
809 |
||
810 |
/*! |
|
811 |
Returns the meta-data for the property with the given \a index. |
|
812 |
If no such property exists, a null QMetaProperty is returned. |
|
813 |
||
814 |
\sa propertyCount(), propertyOffset(), indexOfProperty() |
|
815 |
*/ |
|
816 |
QMetaProperty QMetaObject::property(int index) const |
|
817 |
{ |
|
818 |
int i = index; |
|
819 |
i -= propertyOffset(); |
|
820 |
if (i < 0 && d.superdata) |
|
821 |
return d.superdata->property(index); |
|
822 |
||
823 |
QMetaProperty result; |
|
824 |
if (i >= 0 && i < priv(d.data)->propertyCount) { |
|
825 |
int handle = priv(d.data)->propertyData + 3*i; |
|
826 |
int flags = d.data[handle + 2]; |
|
827 |
const char *type = d.stringdata + d.data[handle + 1]; |
|
828 |
result.mobj = this; |
|
829 |
result.handle = handle; |
|
830 |
result.idx = i; |
|
831 |
||
832 |
if (flags & EnumOrFlag) { |
|
833 |
result.menum = enumerator(indexOfEnumerator(type)); |
|
834 |
if (!result.menum.isValid()) { |
|
835 |
QByteArray enum_name = type; |
|
836 |
QByteArray scope_name = d.stringdata; |
|
837 |
int s = enum_name.lastIndexOf("::"); |
|
838 |
if (s > 0) { |
|
839 |
scope_name = enum_name.left(s); |
|
840 |
enum_name = enum_name.mid(s + 2); |
|
841 |
} |
|
842 |
const QMetaObject *scope = 0; |
|
843 |
if (scope_name == "Qt") |
|
844 |
scope = &QObject::staticQtMetaObject; |
|
845 |
else |
|
846 |
scope = QMetaObject_findMetaObject(this, scope_name); |
|
847 |
if (scope) |
|
848 |
result.menum = scope->enumerator(scope->indexOfEnumerator(enum_name)); |
|
849 |
} |
|
850 |
} |
|
851 |
} |
|
852 |
return result; |
|
853 |
} |
|
854 |
||
855 |
/*! |
|
856 |
\since 4.2 |
|
857 |
||
858 |
Returns the property that has the \c USER flag set to true. |
|
859 |
||
860 |
\sa QMetaProperty::isUser() |
|
861 |
*/ |
|
862 |
QMetaProperty QMetaObject::userProperty() const |
|
863 |
{ |
|
864 |
const int propCount = propertyCount(); |
|
865 |
for (int i = propCount - 1; i >= 0; --i) { |
|
866 |
const QMetaProperty prop = property(i); |
|
867 |
if (prop.isUser()) |
|
868 |
return prop; |
|
869 |
} |
|
870 |
return QMetaProperty(); |
|
871 |
} |
|
872 |
||
873 |
/*! |
|
874 |
Returns the meta-data for the item of class information with the |
|
875 |
given \a index. |
|
876 |
||
877 |
Example: |
|
878 |
||
879 |
\snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 0 |
|
880 |
||
881 |
\sa classInfoCount(), classInfoOffset(), indexOfClassInfo() |
|
882 |
*/ |
|
883 |
QMetaClassInfo QMetaObject::classInfo(int index) const |
|
884 |
{ |
|
885 |
int i = index; |
|
886 |
i -= classInfoOffset(); |
|
887 |
if (i < 0 && d.superdata) |
|
888 |
return d.superdata->classInfo(index); |
|
889 |
||
890 |
QMetaClassInfo result; |
|
891 |
if (i >= 0 && i < priv(d.data)->classInfoCount) { |
|
892 |
result.mobj = this; |
|
893 |
result.handle = priv(d.data)->classInfoData + 2*i; |
|
894 |
} |
|
895 |
return result; |
|
896 |
} |
|
897 |
||
898 |
/*! |
|
899 |
Returns true if the \a signal and \a method arguments are |
|
900 |
compatible; otherwise returns false. |
|
901 |
||
902 |
Both \a signal and \a method are expected to be normalized. |
|
903 |
||
904 |
\sa normalizedSignature() |
|
905 |
*/ |
|
906 |
bool QMetaObject::checkConnectArgs(const char *signal, const char *method) |
|
907 |
{ |
|
908 |
const char *s1 = signal; |
|
909 |
const char *s2 = method; |
|
910 |
while (*s1++ != '(') { } // scan to first '(' |
|
911 |
while (*s2++ != '(') { } |
|
912 |
if (*s2 == ')' || qstrcmp(s1,s2) == 0) // method has no args or |
|
913 |
return true; // exact match |
|
914 |
int s1len = qstrlen(s1); |
|
915 |
int s2len = qstrlen(s2); |
|
916 |
if (s2len < s1len && strncmp(s1,s2,s2len-1)==0 && s1[s2len-1]==',') |
|
917 |
return true; // method has less args |
|
918 |
return false; |
|
919 |
} |
|
920 |
||
921 |
static void qRemoveWhitespace(const char *s, char *d) |
|
922 |
{ |
|
923 |
char last = 0; |
|
924 |
while (*s && is_space(*s)) |
|
925 |
s++; |
|
926 |
while (*s) { |
|
927 |
while (*s && !is_space(*s)) |
|
928 |
last = *d++ = *s++; |
|
929 |
while (*s && is_space(*s)) |
|
930 |
s++; |
|
931 |
if (*s && ((is_ident_char(*s) && is_ident_char(last)) |
|
932 |
|| ((*s == ':') && (last == '<')))) { |
|
933 |
last = *d++ = ' '; |
|
934 |
} |
|
935 |
} |
|
936 |
*d = '\0'; |
|
937 |
} |
|
938 |
||
939 |
static char *qNormalizeType(char *d, int &templdepth, QByteArray &result) |
|
940 |
{ |
|
941 |
const char *t = d; |
|
942 |
while (*d && (templdepth |
|
943 |
|| (*d != ',' && *d != ')'))) { |
|
944 |
if (*d == '<') |
|
945 |
++templdepth; |
|
946 |
if (*d == '>') |
|
947 |
--templdepth; |
|
948 |
++d; |
|
949 |
} |
|
950 |
if (strncmp("void", t, d - t) != 0) |
|
951 |
result += normalizeTypeInternal(t, d); |
|
952 |
||
953 |
return d; |
|
954 |
} |
|
955 |
||
956 |
||
957 |
/*! |
|
958 |
\since 4.2 |
|
959 |
||
960 |
Normalizes a \a type. |
|
961 |
||
962 |
See QMetaObject::normalizedSignature() for a description on how |
|
963 |
Qt normalizes. |
|
964 |
||
965 |
Example: |
|
966 |
||
967 |
\snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 1 |
|
968 |
||
969 |
\sa normalizedSignature() |
|
970 |
*/ |
|
971 |
QByteArray QMetaObject::normalizedType(const char *type) |
|
972 |
{ |
|
973 |
QByteArray result; |
|
974 |
||
975 |
if (!type || !*type) |
|
976 |
return result; |
|
977 |
||
19
fcece45ef507
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
978 |
QVarLengthArray<char> stackbuf(qstrlen(type) + 1); |
0 | 979 |
qRemoveWhitespace(type, stackbuf.data()); |
980 |
int templdepth = 0; |
|
981 |
qNormalizeType(stackbuf.data(), templdepth, result); |
|
982 |
||
983 |
return result; |
|
984 |
} |
|
985 |
||
986 |
/*! |
|
987 |
Normalizes the signature of the given \a method. |
|
988 |
||
989 |
Qt uses normalized signatures to decide whether two given signals |
|
990 |
and slots are compatible. Normalization reduces whitespace to a |
|
991 |
minimum, moves 'const' to the front where appropriate, removes |
|
992 |
'const' from value types and replaces const references with |
|
993 |
values. |
|
994 |
||
995 |
\sa checkConnectArgs(), normalizedType() |
|
996 |
*/ |
|
997 |
QByteArray QMetaObject::normalizedSignature(const char *method) |
|
998 |
{ |
|
999 |
QByteArray result; |
|
1000 |
if (!method || !*method) |
|
1001 |
return result; |
|
1002 |
int len = int(strlen(method)); |
|
1003 |
QVarLengthArray<char> stackbuf(len + 1); |
|
1004 |
char *d = stackbuf.data(); |
|
1005 |
qRemoveWhitespace(method, d); |
|
1006 |
||
1007 |
result.reserve(len); |
|
1008 |
||
1009 |
int argdepth = 0; |
|
1010 |
int templdepth = 0; |
|
1011 |
while (*d) { |
|
1012 |
if (argdepth == 1) |
|
1013 |
d = qNormalizeType(d, templdepth, result); |
|
1014 |
if (*d == '(') |
|
1015 |
++argdepth; |
|
1016 |
if (*d == ')') |
|
1017 |
--argdepth; |
|
1018 |
result += *d++; |
|
1019 |
} |
|
1020 |
||
1021 |
return result; |
|
1022 |
} |
|
1023 |
||
1024 |
enum { MaximumParamCount = 11 }; // up to 10 arguments + 1 return value |
|
1025 |
||
1026 |
/*! |
|
1027 |
Invokes the \a member (a signal or a slot name) on the object \a |
|
1028 |
obj. Returns true if the member could be invoked. Returns false |
|
1029 |
if there is no such member or the parameters did not match. |
|
1030 |
||
1031 |
The invocation can be either synchronous or asynchronous, |
|
1032 |
depending on \a type: |
|
1033 |
||
1034 |
\list |
|
1035 |
\o If \a type is Qt::DirectConnection, the member will be invoked immediately. |
|
1036 |
||
1037 |
\o If \a type is Qt::QueuedConnection, |
|
1038 |
a QEvent will be sent and the member is invoked as soon as the application |
|
1039 |
enters the main event loop. |
|
1040 |
||
1041 |
\o If \a type is Qt::BlockingQueuedConnection, the method will be invoked in |
|
1042 |
the same way as for Qt::QueuedConnection, except that the current thread |
|
1043 |
will block until the event is delivered. Using this connection type to |
|
1044 |
communicate between objects in the same thread will lead to deadlocks. |
|
1045 |
||
1046 |
\o If \a type is Qt::AutoConnection, the member is invoked |
|
1047 |
synchronously if \a obj lives in the same thread as the |
|
1048 |
caller; otherwise it will invoke the member asynchronously. |
|
1049 |
\endlist |
|
1050 |
||
1051 |
The return value of the \a member function call is placed in \a |
|
1052 |
ret. If the invocation is asynchronous, the return value cannot |
|
1053 |
be evaluated. You can pass up to ten arguments (\a val0, \a val1, |
|
1054 |
\a val2, \a val3, \a val4, \a val5, \a val6, \a val7, \a val8, |
|
1055 |
and \a val9) to the \a member function. |
|
1056 |
||
1057 |
QGenericArgument and QGenericReturnArgument are internal |
|
1058 |
helper classes. Because signals and slots can be dynamically |
|
1059 |
invoked, you must enclose the arguments using the Q_ARG() and |
|
1060 |
Q_RETURN_ARG() macros. Q_ARG() takes a type name and a |
|
1061 |
const reference of that type; Q_RETURN_ARG() takes a type name |
|
1062 |
and a non-const reference. |
|
1063 |
||
1064 |
You only need to pass the name of the signal or slot to this function, |
|
1065 |
not the entire signature. For example, to asynchronously invoke |
|
1066 |
the \l{QPushButton::animateClick()}{animateClick()} slot on a |
|
1067 |
QPushButton, use the following code: |
|
1068 |
||
1069 |
\snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 2 |
|
1070 |
||
1071 |
With asynchronous method invocations, the parameters must be of |
|
1072 |
types that are known to Qt's meta-object system, because Qt needs |
|
1073 |
to copy the arguments to store them in an event behind the |
|
1074 |
scenes. If you try to use a queued connection and get the error |
|
1075 |
message |
|
1076 |
||
1077 |
\snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 3 |
|
1078 |
||
1079 |
call qRegisterMetaType() to register the data type before you |
|
1080 |
call invokeMethod(). |
|
1081 |
||
1082 |
To synchronously invoke the \c compute(QString, int, double) slot on |
|
1083 |
some arbitrary object \c obj retrieve its return value: |
|
1084 |
||
1085 |
\snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 4 |
|
1086 |
||
1087 |
If the "compute" slot does not take exactly one QString, one int |
|
1088 |
and one double in the specified order, the call will fail. |
|
1089 |
||
1090 |
\sa Q_ARG(), Q_RETURN_ARG(), qRegisterMetaType(), QMetaMethod::invoke() |
|
1091 |
*/ |
|
1092 |
bool QMetaObject::invokeMethod(QObject *obj, |
|
1093 |
const char *member, |
|
1094 |
Qt::ConnectionType type, |
|
1095 |
QGenericReturnArgument ret, |
|
1096 |
QGenericArgument val0, |
|
1097 |
QGenericArgument val1, |
|
1098 |
QGenericArgument val2, |
|
1099 |
QGenericArgument val3, |
|
1100 |
QGenericArgument val4, |
|
1101 |
QGenericArgument val5, |
|
1102 |
QGenericArgument val6, |
|
1103 |
QGenericArgument val7, |
|
1104 |
QGenericArgument val8, |
|
1105 |
QGenericArgument val9) |
|
1106 |
{ |
|
1107 |
if (!obj) |
|
1108 |
return false; |
|
1109 |
||
1110 |
QVarLengthArray<char, 512> sig; |
|
1111 |
int len = qstrlen(member); |
|
1112 |
if (len <= 0) |
|
1113 |
return false; |
|
1114 |
sig.append(member, len); |
|
1115 |
sig.append('('); |
|
1116 |
||
1117 |
const char *typeNames[] = {ret.name(), val0.name(), val1.name(), val2.name(), val3.name(), |
|
1118 |
val4.name(), val5.name(), val6.name(), val7.name(), val8.name(), |
|
1119 |
val9.name()}; |
|
1120 |
||
1121 |
int paramCount; |
|
1122 |
for (paramCount = 1; paramCount < MaximumParamCount; ++paramCount) { |
|
1123 |
len = qstrlen(typeNames[paramCount]); |
|
1124 |
if (len <= 0) |
|
1125 |
break; |
|
1126 |
sig.append(typeNames[paramCount], len); |
|
1127 |
sig.append(','); |
|
1128 |
} |
|
1129 |
if (paramCount == 1) |
|
1130 |
sig.append(')'); // no parameters |
|
1131 |
else |
|
1132 |
sig[sig.size() - 1] = ')'; |
|
1133 |
sig.append('\0'); |
|
1134 |
||
1135 |
int idx = obj->metaObject()->indexOfMethod(sig.constData()); |
|
1136 |
if (idx < 0) { |
|
1137 |
QByteArray norm = QMetaObject::normalizedSignature(sig.constData()); |
|
1138 |
idx = obj->metaObject()->indexOfMethod(norm.constData()); |
|
1139 |
} |
|
1140 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1141 |
if (idx < 0 || idx >= obj->metaObject()->methodCount()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1142 |
qWarning("QMetaObject::invokeMethod: No such method %s::%s", |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1143 |
obj->metaObject()->className(), sig.constData()); |
0 | 1144 |
return false; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
19
diff
changeset
|
1145 |
} |
0 | 1146 |
QMetaMethod method = obj->metaObject()->method(idx); |
1147 |
return method.invoke(obj, type, ret, |
|
1148 |
val0, val1, val2, val3, val4, val5, val6, val7, val8, val9); |
|
1149 |
} |
|
1150 |
||
1151 |
/*! \fn bool QMetaObject::invokeMethod(QObject *obj, const char *member, |
|
1152 |
QGenericReturnArgument ret, |
|
1153 |
QGenericArgument val0 = QGenericArgument(0), |
|
1154 |
QGenericArgument val1 = QGenericArgument(), |
|
1155 |
QGenericArgument val2 = QGenericArgument(), |
|
1156 |
QGenericArgument val3 = QGenericArgument(), |
|
1157 |
QGenericArgument val4 = QGenericArgument(), |
|
1158 |
QGenericArgument val5 = QGenericArgument(), |
|
1159 |
QGenericArgument val6 = QGenericArgument(), |
|
1160 |
QGenericArgument val7 = QGenericArgument(), |
|
1161 |
QGenericArgument val8 = QGenericArgument(), |
|
1162 |
QGenericArgument val9 = QGenericArgument()); |
|
1163 |
\overload invokeMethod() |
|
1164 |
||
1165 |
This overload always invokes the member using the connection type Qt::AutoConnection. |
|
1166 |
*/ |
|
1167 |
||
1168 |
/*! \fn bool QMetaObject::invokeMethod(QObject *obj, const char *member, |
|
1169 |
Qt::ConnectionType type, |
|
1170 |
QGenericArgument val0 = QGenericArgument(0), |
|
1171 |
QGenericArgument val1 = QGenericArgument(), |
|
1172 |
QGenericArgument val2 = QGenericArgument(), |
|
1173 |
QGenericArgument val3 = QGenericArgument(), |
|
1174 |
QGenericArgument val4 = QGenericArgument(), |
|
1175 |
QGenericArgument val5 = QGenericArgument(), |
|
1176 |
QGenericArgument val6 = QGenericArgument(), |
|
1177 |
QGenericArgument val7 = QGenericArgument(), |
|
1178 |
QGenericArgument val8 = QGenericArgument(), |
|
1179 |
QGenericArgument val9 = QGenericArgument()) |
|
1180 |
||
1181 |
\overload invokeMethod() |
|
1182 |
||
1183 |
This overload can be used if the return value of the member is of no interest. |
|
1184 |
*/ |
|
1185 |
||
1186 |
/*! |
|
1187 |
\fn bool QMetaObject::invokeMethod(QObject *obj, const char *member, |
|
1188 |
QGenericArgument val0 = QGenericArgument(0), |
|
1189 |
QGenericArgument val1 = QGenericArgument(), |
|
1190 |
QGenericArgument val2 = QGenericArgument(), |
|
1191 |
QGenericArgument val3 = QGenericArgument(), |
|
1192 |
QGenericArgument val4 = QGenericArgument(), |
|
1193 |
QGenericArgument val5 = QGenericArgument(), |
|
1194 |
QGenericArgument val6 = QGenericArgument(), |
|
1195 |
QGenericArgument val7 = QGenericArgument(), |
|
1196 |
QGenericArgument val8 = QGenericArgument(), |
|
1197 |
QGenericArgument val9 = QGenericArgument()) |
|
1198 |
||
1199 |
\overload invokeMethod() |
|
1200 |
||
1201 |
This overload invokes the member using the connection type Qt::AutoConnection and |
|
1202 |
ignores return values. |
|
1203 |
*/ |
|
1204 |
||
1205 |
/*! |
|
1206 |
\class QMetaMethod |
|
1207 |
||
1208 |
\brief The QMetaMethod class provides meta-data about a member |
|
1209 |
function. |
|
1210 |
||
1211 |
\ingroup objectmodel |
|
1212 |
||
1213 |
A QMetaMethod has a methodType(), a signature(), a list of |
|
1214 |
parameterTypes() and parameterNames(), a return typeName(), a |
|
1215 |
tag(), and an access() specifier. You can use invoke() to invoke |
|
1216 |
the method on an arbitrary QObject. |
|
1217 |
||
1218 |
\sa QMetaObject, QMetaEnum, QMetaProperty, {Qt's Property System} |
|
1219 |
*/ |
|
1220 |
||
1221 |
/*! |
|
1222 |
\enum QMetaMethod::Attributes |
|
1223 |
||
1224 |
\internal |
|
1225 |
||
1226 |
\value Compatibility |
|
1227 |
\value Cloned |
|
1228 |
\value Scriptable |
|
1229 |
*/ |
|
1230 |
||
1231 |
/*! |
|
1232 |
\fn const QMetaObject *QMetaMethod::enclosingMetaObject() const |
|
1233 |
\internal |
|
1234 |
*/ |
|
1235 |
||
1236 |
/*! |
|
1237 |
\enum QMetaMethod::MethodType |
|
1238 |
||
1239 |
\value Method The function is a plain member function. |
|
1240 |
\value Signal The function is a signal. |
|
1241 |
\value Slot The function is a slot. |
|
1242 |
\value Constructor The function is a constructor. |
|
1243 |
*/ |
|
1244 |
||
1245 |
/*! |
|
1246 |
\fn QMetaMethod::QMetaMethod() |
|
1247 |
\internal |
|
1248 |
*/ |
|
1249 |
||
1250 |
/*! |
|
1251 |
Returns the signature of this method (e.g., |
|
1252 |
\c{setValue(double)}). |
|
1253 |
||
1254 |
\sa parameterTypes(), parameterNames() |
|
1255 |
*/ |
|
1256 |
const char *QMetaMethod::signature() const |
|
1257 |
{ |
|
1258 |
if (!mobj) |
|
1259 |
return 0; |
|
1260 |
return mobj->d.stringdata + mobj->d.data[handle]; |
|
1261 |
} |
|
1262 |
||
1263 |
/*! |
|
1264 |
Returns a list of parameter types. |
|
1265 |
||
1266 |
\sa parameterNames(), signature() |
|
1267 |
*/ |
|
1268 |
QList<QByteArray> QMetaMethod::parameterTypes() const |
|
1269 |
{ |
|
1270 |
QList<QByteArray> list; |
|
1271 |
if (!mobj) |
|
1272 |
return list; |
|
1273 |
const char *signature = mobj->d.stringdata + mobj->d.data[handle]; |
|
1274 |
while (*signature && *signature != '(') |
|
1275 |
++signature; |
|
1276 |
while (*signature && *signature != ')' && *++signature != ')') { |
|
1277 |
const char *begin = signature; |
|
1278 |
int level = 0; |
|
1279 |
while (*signature && (level > 0 || *signature != ',') && *signature != ')') { |
|
1280 |
if (*signature == '<') |
|
1281 |
++level; |
|
1282 |
else if (*signature == '>') |
|
1283 |
--level; |
|
1284 |
++signature; |
|
1285 |
} |
|
1286 |
list += QByteArray(begin, signature - begin); |
|
1287 |
} |
|
1288 |
return list; |
|
1289 |
} |
|
1290 |
||
1291 |
/*! |
|
1292 |
Returns a list of parameter names. |
|
1293 |
||
1294 |
\sa parameterTypes(), signature() |
|
1295 |
*/ |
|
1296 |
QList<QByteArray> QMetaMethod::parameterNames() const |
|
1297 |
{ |
|
1298 |
QList<QByteArray> list; |
|
1299 |
if (!mobj) |
|
1300 |
return list; |
|
1301 |
const char *names = mobj->d.stringdata + mobj->d.data[handle + 1]; |
|
1302 |
if (*names == 0) { |
|
1303 |
// do we have one or zero arguments? |
|
1304 |
const char *signature = mobj->d.stringdata + mobj->d.data[handle]; |
|
1305 |
while (*signature && *signature != '(') |
|
1306 |
++signature; |
|
1307 |
if (*++signature != ')') |
|
1308 |
list += QByteArray(); |
|
1309 |
} else { |
|
1310 |
--names; |
|
1311 |
do { |
|
1312 |
const char *begin = ++names; |
|
1313 |
while (*names && *names != ',') |
|
1314 |
++names; |
|
1315 |
list += QByteArray(begin, names - begin); |
|
1316 |
} while (*names); |
|
1317 |
} |
|
1318 |
return list; |
|
1319 |
} |
|
1320 |
||
1321 |
||
1322 |
/*! |
|
1323 |
Returns the return type of this method, or an empty string if the |
|
1324 |
return type is \e void. |
|
1325 |
*/ |
|
1326 |
const char *QMetaMethod::typeName() const |
|
1327 |
{ |
|
1328 |
if (!mobj) |
|
1329 |
return 0; |
|
1330 |
return mobj->d.stringdata + mobj->d.data[handle + 2]; |
|
1331 |
} |
|
1332 |
||
1333 |
/*! |
|
1334 |
Returns the tag associated with this method. |
|
1335 |
||
1336 |
Tags are special macros recognized by \c moc that make it |
|
1337 |
possible to add extra information about a method. For the moment, |
|
1338 |
\c moc doesn't support any special tags. |
|
1339 |
*/ |
|
1340 |
const char *QMetaMethod::tag() const |
|
1341 |
{ |
|
1342 |
if (!mobj) |
|
1343 |
return 0; |
|
1344 |
return mobj->d.stringdata + mobj->d.data[handle + 3]; |
|
1345 |
} |
|
1346 |
||
1347 |
||
1348 |
/*! \internal */ |
|
1349 |
int QMetaMethod::attributes() const |
|
1350 |
{ |
|
1351 |
if (!mobj) |
|
1352 |
return false; |
|
1353 |
return ((mobj->d.data[handle + 4])>>4); |
|
1354 |
} |
|
1355 |
||
1356 |
/*! |
|
1357 |
\since 4.6 |
|
1358 |
||
1359 |
Returns this method's index. |
|
1360 |
*/ |
|
1361 |
int QMetaMethod::methodIndex() const |
|
1362 |
{ |
|
1363 |
if (!mobj) |
|
1364 |
return -1; |
|
1365 |
return ((handle - priv(mobj->d.data)->methodData) / 5) + mobj->methodOffset(); |
|
1366 |
} |
|
1367 |
||
1368 |
/*! |
|
1369 |
Returns the access specification of this method (private, |
|
1370 |
protected, or public). |
|
1371 |
||
1372 |
Signals are always protected, meaning that you can only emit them |
|
1373 |
from the class or from a subclass. |
|
1374 |
||
1375 |
\sa methodType() |
|
1376 |
*/ |
|
1377 |
QMetaMethod::Access QMetaMethod::access() const |
|
1378 |
{ |
|
1379 |
if (!mobj) |
|
1380 |
return Private; |
|
1381 |
return (QMetaMethod::Access)(mobj->d.data[handle + 4] & AccessMask); |
|
1382 |
} |
|
1383 |
||
1384 |
/*! |
|
1385 |
Returns the type of this method (signal, slot, or method). |
|
1386 |
||
1387 |
\sa access() |
|
1388 |
*/ |
|
1389 |
QMetaMethod::MethodType QMetaMethod::methodType() const |
|
1390 |
{ |
|
1391 |
if (!mobj) |
|
1392 |
return QMetaMethod::Method; |
|
1393 |
return (QMetaMethod::MethodType)((mobj->d.data[handle + 4] & MethodTypeMask)>>2); |
|
1394 |
} |
|
1395 |
||
1396 |
/*! |
|
1397 |
Invokes this method on the object \a object. Returns true if the member could be invoked. |
|
1398 |
Returns false if there is no such member or the parameters did not match. |
|
1399 |
||
1400 |
The invocation can be either synchronous or asynchronous, depending on the |
|
1401 |
\a connectionType: |
|
1402 |
||
1403 |
\list |
|
1404 |
\o If \a connectionType is Qt::DirectConnection, the member will be invoked immediately. |
|
1405 |
||
1406 |
\o If \a connectionType is Qt::QueuedConnection, |
|
1407 |
a QEvent will be posted and the member is invoked as soon as the application |
|
1408 |
enters the main event loop. |
|
1409 |
||
1410 |
\o If \a connectionType is Qt::AutoConnection, the member is invoked |
|
1411 |
synchronously if \a object lives in the same thread as the |
|
1412 |
caller; otherwise it will invoke the member asynchronously. |
|
1413 |
\endlist |
|
1414 |
||
1415 |
The return value of this method call is placed in \a |
|
1416 |
returnValue. If the invocation is asynchronous, the return value cannot |
|
1417 |
be evaluated. You can pass up to ten arguments (\a val0, \a val1, |
|
1418 |
\a val2, \a val3, \a val4, \a val5, \a val6, \a val7, \a val8, |
|
1419 |
and \a val9) to this method call. |
|
1420 |
||
1421 |
QGenericArgument and QGenericReturnArgument are internal |
|
1422 |
helper classes. Because signals and slots can be dynamically |
|
1423 |
invoked, you must enclose the arguments using the Q_ARG() and |
|
1424 |
Q_RETURN_ARG() macros. Q_ARG() takes a type name and a |
|
1425 |
const reference of that type; Q_RETURN_ARG() takes a type name |
|
1426 |
and a non-const reference. |
|
1427 |
||
1428 |
To asynchronously invoke the |
|
1429 |
\l{QPushButton::animateClick()}{animateClick()} slot on a |
|
1430 |
QPushButton: |
|
1431 |
||
1432 |
\snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 6 |
|
1433 |
||
1434 |
With asynchronous method invocations, the parameters must be of |
|
1435 |
types that are known to Qt's meta-object system, because Qt needs |
|
1436 |
to copy the arguments to store them in an event behind the |
|
1437 |
scenes. If you try to use a queued connection and get the error |
|
1438 |
message |
|
1439 |
||
1440 |
\snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 7 |
|
1441 |
||
1442 |
call qRegisterMetaType() to register the data type before you |
|
1443 |
call QMetaMethod::invoke(). |
|
1444 |
||
1445 |
To synchronously invoke the \c compute(QString, int, double) slot on |
|
1446 |
some arbitrary object \c obj retrieve its return value: |
|
1447 |
||
1448 |
\snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 8 |
|
1449 |
||
1450 |
QMetaObject::normalizedSignature() is used here to ensure that the format |
|
1451 |
of the signature is what invoke() expects. E.g. extra whitespace is |
|
1452 |
removed. |
|
1453 |
||
1454 |
If the "compute" slot does not take exactly one QString, one int |
|
1455 |
and one double in the specified order, the call will fail. |
|
1456 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1457 |
\warning this method will not test the validity of the arguments: \a object |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1458 |
must be an instance of the class of the QMetaObject of which this QMetaMethod |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1459 |
has been constructed with. The arguments must have the same type as the ones |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1460 |
expected by the method, else, the behaviour is undefined. |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1461 |
|
0 | 1462 |
\sa Q_ARG(), Q_RETURN_ARG(), qRegisterMetaType(), QMetaObject::invokeMethod() |
1463 |
*/ |
|
1464 |
bool QMetaMethod::invoke(QObject *object, |
|
1465 |
Qt::ConnectionType connectionType, |
|
1466 |
QGenericReturnArgument returnValue, |
|
1467 |
QGenericArgument val0, |
|
1468 |
QGenericArgument val1, |
|
1469 |
QGenericArgument val2, |
|
1470 |
QGenericArgument val3, |
|
1471 |
QGenericArgument val4, |
|
1472 |
QGenericArgument val5, |
|
1473 |
QGenericArgument val6, |
|
1474 |
QGenericArgument val7, |
|
1475 |
QGenericArgument val8, |
|
1476 |
QGenericArgument val9) const |
|
1477 |
{ |
|
1478 |
if (!object || !mobj) |
|
1479 |
return false; |
|
1480 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1481 |
Q_ASSERT(mobj->cast(object)); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1482 |
|
0 | 1483 |
// check return type |
1484 |
if (returnValue.data()) { |
|
1485 |
const char *retType = typeName(); |
|
1486 |
if (qstrcmp(returnValue.name(), retType) != 0) { |
|
1487 |
// normalize the return value as well |
|
1488 |
// the trick here is to make a function signature out of the return type |
|
1489 |
// so that we can call normalizedSignature() and avoid duplicating code |
|
1490 |
QByteArray unnormalized; |
|
1491 |
int len = qstrlen(returnValue.name()); |
|
1492 |
||
1493 |
unnormalized.reserve(len + 3); |
|
1494 |
unnormalized = "_("; // the function is called "_" |
|
1495 |
unnormalized.append(returnValue.name()); |
|
1496 |
unnormalized.append(')'); |
|
1497 |
||
1498 |
QByteArray normalized = QMetaObject::normalizedSignature(unnormalized.constData()); |
|
1499 |
normalized.truncate(normalized.length() - 1); // drop the ending ')' |
|
1500 |
||
1501 |
if (qstrcmp(normalized.constData() + 2, retType) != 0) |
|
1502 |
return false; |
|
1503 |
} |
|
1504 |
} |
|
1505 |
||
1506 |
// check argument count (we don't allow invoking a method if given too few arguments) |
|
1507 |
const char *typeNames[] = { |
|
1508 |
returnValue.name(), |
|
1509 |
val0.name(), |
|
1510 |
val1.name(), |
|
1511 |
val2.name(), |
|
1512 |
val3.name(), |
|
1513 |
val4.name(), |
|
1514 |
val5.name(), |
|
1515 |
val6.name(), |
|
1516 |
val7.name(), |
|
1517 |
val8.name(), |
|
1518 |
val9.name() |
|
1519 |
}; |
|
1520 |
int paramCount; |
|
1521 |
for (paramCount = 1; paramCount < MaximumParamCount; ++paramCount) { |
|
1522 |
if (qstrlen(typeNames[paramCount]) <= 0) |
|
1523 |
break; |
|
1524 |
} |
|
1525 |
int metaMethodArgumentCount = 0; |
|
1526 |
{ |
|
1527 |
// based on QMetaObject::parameterNames() |
|
1528 |
const char *names = mobj->d.stringdata + mobj->d.data[handle + 1]; |
|
1529 |
if (*names == 0) { |
|
1530 |
// do we have one or zero arguments? |
|
1531 |
const char *signature = mobj->d.stringdata + mobj->d.data[handle]; |
|
1532 |
while (*signature && *signature != '(') |
|
1533 |
++signature; |
|
1534 |
if (*++signature != ')') |
|
1535 |
++metaMethodArgumentCount; |
|
1536 |
} else { |
|
1537 |
--names; |
|
1538 |
do { |
|
1539 |
++names; |
|
1540 |
while (*names && *names != ',') |
|
1541 |
++names; |
|
1542 |
++metaMethodArgumentCount; |
|
1543 |
} while (*names); |
|
1544 |
} |
|
1545 |
} |
|
1546 |
if (paramCount <= metaMethodArgumentCount) |
|
1547 |
return false; |
|
1548 |
||
1549 |
// check connection type |
|
1550 |
QThread *currentThread = QThread::currentThread(); |
|
1551 |
QThread *objectThread = object->thread(); |
|
1552 |
if (connectionType == Qt::AutoConnection) { |
|
1553 |
connectionType = currentThread == objectThread |
|
1554 |
? Qt::DirectConnection |
|
1555 |
: Qt::QueuedConnection; |
|
1556 |
} |
|
1557 |
||
1558 |
// invoke! |
|
1559 |
void *param[] = { |
|
1560 |
returnValue.data(), |
|
1561 |
val0.data(), |
|
1562 |
val1.data(), |
|
1563 |
val2.data(), |
|
1564 |
val3.data(), |
|
1565 |
val4.data(), |
|
1566 |
val5.data(), |
|
1567 |
val6.data(), |
|
1568 |
val7.data(), |
|
1569 |
val8.data(), |
|
1570 |
val9.data() |
|
1571 |
}; |
|
1572 |
// recompute the methodIndex by reversing the arithmetic in QMetaObject::property() |
|
1573 |
int methodIndex = ((handle - priv(mobj->d.data)->methodData) / 5) + mobj->methodOffset(); |
|
1574 |
if (connectionType == Qt::DirectConnection) { |
|
1575 |
return QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, methodIndex, param) < 0; |
|
1576 |
} else { |
|
1577 |
if (returnValue.data()) { |
|
1578 |
qWarning("QMetaMethod::invoke: Unable to invoke methods with return values in " |
|
1579 |
"queued connections"); |
|
1580 |
return false; |
|
1581 |
} |
|
1582 |
||
1583 |
int nargs = 1; // include return type |
|
1584 |
void **args = (void **) qMalloc(paramCount * sizeof(void *)); |
|
1585 |
Q_CHECK_PTR(args); |
|
1586 |
int *types = (int *) qMalloc(paramCount * sizeof(int)); |
|
1587 |
Q_CHECK_PTR(types); |
|
1588 |
types[0] = 0; // return type |
|
1589 |
args[0] = 0; |
|
1590 |
||
1591 |
for (int i = 1; i < paramCount; ++i) { |
|
1592 |
types[i] = QMetaType::type(typeNames[i]); |
|
1593 |
if (types[i]) { |
|
1594 |
args[i] = QMetaType::construct(types[i], param[i]); |
|
1595 |
++nargs; |
|
1596 |
} else if (param[i]) { |
|
1597 |
qWarning("QMetaMethod::invoke: Unable to handle unregistered datatype '%s'", |
|
1598 |
typeNames[i]); |
|
1599 |
for (int x = 1; x < i; ++x) { |
|
1600 |
if (types[x] && args[x]) |
|
1601 |
QMetaType::destroy(types[x], args[x]); |
|
1602 |
} |
|
1603 |
qFree(types); |
|
1604 |
qFree(args); |
|
1605 |
return false; |
|
1606 |
} |
|
1607 |
} |
|
1608 |
||
1609 |
if (connectionType == Qt::QueuedConnection) { |
|
1610 |
QCoreApplication::postEvent(object, new QMetaCallEvent(methodIndex, |
|
1611 |
0, |
|
1612 |
-1, |
|
1613 |
nargs, |
|
1614 |
types, |
|
1615 |
args)); |
|
1616 |
} else { |
|
1617 |
if (currentThread == objectThread) { |
|
1618 |
qWarning("QMetaMethod::invoke: Dead lock detected in " |
|
1619 |
"BlockingQueuedConnection: Receiver is %s(%p)", |
|
1620 |
mobj->className(), object); |
|
1621 |
} |
|
1622 |
||
1623 |
// blocking queued connection |
|
1624 |
#ifdef QT_NO_THREAD |
|
1625 |
QCoreApplication::postEvent(object, new QMetaCallEvent(methodIndex, |
|
1626 |
0, |
|
1627 |
-1, |
|
1628 |
nargs, |
|
1629 |
types, |
|
1630 |
args)); |
|
1631 |
#else |
|
1632 |
QSemaphore semaphore; |
|
1633 |
QCoreApplication::postEvent(object, new QMetaCallEvent(methodIndex, |
|
1634 |
0, |
|
1635 |
-1, |
|
1636 |
nargs, |
|
1637 |
types, |
|
1638 |
args, |
|
1639 |
&semaphore)); |
|
1640 |
semaphore.acquire(); |
|
1641 |
#endif // QT_NO_THREAD |
|
1642 |
} |
|
1643 |
} |
|
1644 |
return true; |
|
1645 |
} |
|
1646 |
||
1647 |
/*! \fn bool QMetaMethod::invoke(QObject *object, |
|
1648 |
QGenericReturnArgument returnValue, |
|
1649 |
QGenericArgument val0 = QGenericArgument(0), |
|
1650 |
QGenericArgument val1 = QGenericArgument(), |
|
1651 |
QGenericArgument val2 = QGenericArgument(), |
|
1652 |
QGenericArgument val3 = QGenericArgument(), |
|
1653 |
QGenericArgument val4 = QGenericArgument(), |
|
1654 |
QGenericArgument val5 = QGenericArgument(), |
|
1655 |
QGenericArgument val6 = QGenericArgument(), |
|
1656 |
QGenericArgument val7 = QGenericArgument(), |
|
1657 |
QGenericArgument val8 = QGenericArgument(), |
|
1658 |
QGenericArgument val9 = QGenericArgument()) const |
|
1659 |
\overload invoke() |
|
1660 |
||
1661 |
This overload always invokes this method using the connection type Qt::AutoConnection. |
|
1662 |
*/ |
|
1663 |
||
1664 |
/*! \fn bool QMetaMethod::invoke(QObject *object, |
|
1665 |
Qt::ConnectionType connectionType, |
|
1666 |
QGenericArgument val0 = QGenericArgument(0), |
|
1667 |
QGenericArgument val1 = QGenericArgument(), |
|
1668 |
QGenericArgument val2 = QGenericArgument(), |
|
1669 |
QGenericArgument val3 = QGenericArgument(), |
|
1670 |
QGenericArgument val4 = QGenericArgument(), |
|
1671 |
QGenericArgument val5 = QGenericArgument(), |
|
1672 |
QGenericArgument val6 = QGenericArgument(), |
|
1673 |
QGenericArgument val7 = QGenericArgument(), |
|
1674 |
QGenericArgument val8 = QGenericArgument(), |
|
1675 |
QGenericArgument val9 = QGenericArgument()) const |
|
1676 |
||
1677 |
\overload invoke() |
|
1678 |
||
1679 |
This overload can be used if the return value of the member is of no interest. |
|
1680 |
*/ |
|
1681 |
||
1682 |
/*! |
|
1683 |
\fn bool QMetaMethod::invoke(QObject *object, |
|
1684 |
QGenericArgument val0 = QGenericArgument(0), |
|
1685 |
QGenericArgument val1 = QGenericArgument(), |
|
1686 |
QGenericArgument val2 = QGenericArgument(), |
|
1687 |
QGenericArgument val3 = QGenericArgument(), |
|
1688 |
QGenericArgument val4 = QGenericArgument(), |
|
1689 |
QGenericArgument val5 = QGenericArgument(), |
|
1690 |
QGenericArgument val6 = QGenericArgument(), |
|
1691 |
QGenericArgument val7 = QGenericArgument(), |
|
1692 |
QGenericArgument val8 = QGenericArgument(), |
|
1693 |
QGenericArgument val9 = QGenericArgument()) const |
|
1694 |
||
1695 |
\overload invoke() |
|
1696 |
||
1697 |
This overload invokes this method using the |
|
1698 |
connection type Qt::AutoConnection and ignores return values. |
|
1699 |
*/ |
|
1700 |
||
1701 |
/*! |
|
1702 |
\class QMetaEnum |
|
1703 |
\brief The QMetaEnum class provides meta-data about an enumerator. |
|
1704 |
||
1705 |
\ingroup objectmodel |
|
1706 |
||
1707 |
Use name() for the enumerator's name. The enumerator's keys (names |
|
1708 |
of each enumerated item) are returned by key(); use keyCount() to find |
|
1709 |
the number of keys. isFlag() returns whether the enumerator is |
|
1710 |
meant to be used as a flag, meaning that its values can be combined |
|
1711 |
using the OR operator. |
|
1712 |
||
1713 |
The conversion functions keyToValue(), valueToKey(), keysToValue(), |
|
1714 |
and valueToKeys() allow conversion between the integer |
|
1715 |
representation of an enumeration or set value and its literal |
|
1716 |
representation. The scope() function returns the class scope this |
|
1717 |
enumerator was declared in. |
|
1718 |
||
1719 |
\sa QMetaObject, QMetaMethod, QMetaProperty |
|
1720 |
*/ |
|
1721 |
||
1722 |
/*! |
|
1723 |
\fn bool QMetaEnum::isValid() const |
|
1724 |
||
1725 |
Returns true if this enum is valid (has a name); otherwise returns |
|
1726 |
false. |
|
1727 |
||
1728 |
\sa name() |
|
1729 |
*/ |
|
1730 |
||
1731 |
/*! |
|
1732 |
\fn const QMetaObject *QMetaEnum::enclosingMetaObject() const |
|
1733 |
\internal |
|
1734 |
*/ |
|
1735 |
||
1736 |
||
1737 |
/*! |
|
1738 |
\fn QMetaEnum::QMetaEnum() |
|
1739 |
\internal |
|
1740 |
*/ |
|
1741 |
||
1742 |
/*! |
|
1743 |
Returns the name of the enumerator (without the scope). |
|
1744 |
||
1745 |
For example, the Qt::AlignmentFlag enumeration has \c |
|
1746 |
AlignmentFlag as the name and \l Qt as the scope. |
|
1747 |
||
1748 |
\sa isValid(), scope() |
|
1749 |
*/ |
|
1750 |
const char *QMetaEnum::name() const |
|
1751 |
{ |
|
1752 |
if (!mobj) |
|
1753 |
return 0; |
|
1754 |
return mobj->d.stringdata + mobj->d.data[handle]; |
|
1755 |
} |
|
1756 |
||
1757 |
/*! |
|
1758 |
Returns the number of keys. |
|
1759 |
||
1760 |
\sa key() |
|
1761 |
*/ |
|
1762 |
int QMetaEnum::keyCount() const |
|
1763 |
{ |
|
1764 |
if (!mobj) |
|
1765 |
return 0; |
|
1766 |
return mobj->d.data[handle + 2]; |
|
1767 |
} |
|
1768 |
||
1769 |
||
1770 |
/*! |
|
1771 |
Returns the key with the given \a index, or 0 if no such key exists. |
|
1772 |
||
1773 |
\sa keyCount(), value(), valueToKey() |
|
1774 |
*/ |
|
1775 |
const char *QMetaEnum::key(int index) const |
|
1776 |
{ |
|
1777 |
if (!mobj) |
|
1778 |
return 0; |
|
1779 |
int count = mobj->d.data[handle + 2]; |
|
1780 |
int data = mobj->d.data[handle + 3]; |
|
1781 |
if (index >= 0 && index < count) |
|
1782 |
return mobj->d.stringdata + mobj->d.data[data + 2*index]; |
|
1783 |
return 0; |
|
1784 |
} |
|
1785 |
||
1786 |
/*! |
|
1787 |
Returns the value with the given \a index; or returns -1 if there |
|
1788 |
is no such value. |
|
1789 |
||
1790 |
\sa keyCount(), key(), keyToValue() |
|
1791 |
*/ |
|
1792 |
int QMetaEnum::value(int index) const |
|
1793 |
{ |
|
1794 |
if (!mobj) |
|
1795 |
return 0; |
|
1796 |
int count = mobj->d.data[handle + 2]; |
|
1797 |
int data = mobj->d.data[handle + 3]; |
|
1798 |
if (index >= 0 && index < count) |
|
1799 |
return mobj->d.data[data + 2*index + 1]; |
|
1800 |
return -1; |
|
1801 |
} |
|
1802 |
||
1803 |
||
1804 |
/*! |
|
1805 |
Returns true if this enumerator is used as a flag; otherwise returns |
|
1806 |
false. |
|
1807 |
||
1808 |
When used as flags, enumerators can be combined using the OR |
|
1809 |
operator. |
|
1810 |
||
1811 |
\sa keysToValue(), valueToKeys() |
|
1812 |
*/ |
|
1813 |
bool QMetaEnum::isFlag() const |
|
1814 |
{ |
|
1815 |
return mobj && mobj->d.data[handle + 1]; |
|
1816 |
} |
|
1817 |
||
1818 |
||
1819 |
/*! |
|
1820 |
Returns the scope this enumerator was declared in. |
|
1821 |
||
1822 |
For example, the Qt::AlignmentFlag enumeration has \c Qt as |
|
1823 |
the scope and \c AlignmentFlag as the name. |
|
1824 |
||
1825 |
\sa name() |
|
1826 |
*/ |
|
1827 |
const char *QMetaEnum::scope() const |
|
1828 |
{ |
|
1829 |
return mobj?mobj->d.stringdata : 0; |
|
1830 |
} |
|
1831 |
||
1832 |
/*! |
|
1833 |
Returns the integer value of the given enumeration \a key, or -1 |
|
1834 |
if \a key is not defined. |
|
1835 |
||
1836 |
For flag types, use keysToValue(). |
|
1837 |
||
1838 |
\sa valueToKey(), isFlag(), keysToValue() |
|
1839 |
*/ |
|
1840 |
int QMetaEnum::keyToValue(const char *key) const |
|
1841 |
{ |
|
1842 |
if (!mobj || !key) |
|
1843 |
return -1; |
|
1844 |
uint scope = 0; |
|
1845 |
const char *qualified_key = key; |
|
1846 |
const char *s = key + qstrlen(key); |
|
1847 |
while (s > key && *s != ':') |
|
1848 |
--s; |
|
1849 |
if (s > key && *(s-1)==':') { |
|
1850 |
scope = s - key - 1; |
|
1851 |
key += scope + 2; |
|
1852 |
} |
|
1853 |
int count = mobj->d.data[handle + 2]; |
|
1854 |
int data = mobj->d.data[handle + 3]; |
|
1855 |
for (int i = 0; i < count; ++i) |
|
1856 |
if ((!scope || (qstrlen(mobj->d.stringdata) == scope && strncmp(qualified_key, mobj->d.stringdata, scope) == 0)) |
|
1857 |
&& strcmp(key, mobj->d.stringdata + mobj->d.data[data + 2*i]) == 0) |
|
1858 |
return mobj->d.data[data + 2*i + 1]; |
|
1859 |
return -1; |
|
1860 |
} |
|
1861 |
||
1862 |
/*! |
|
1863 |
Returns the string that is used as the name of the given |
|
1864 |
enumeration \a value, or 0 if \a value is not defined. |
|
1865 |
||
1866 |
For flag types, use valueToKeys(). |
|
1867 |
||
1868 |
\sa isFlag(), valueToKeys() |
|
1869 |
*/ |
|
1870 |
const char* QMetaEnum::valueToKey(int value) const |
|
1871 |
{ |
|
1872 |
if (!mobj) |
|
1873 |
return 0; |
|
1874 |
int count = mobj->d.data[handle + 2]; |
|
1875 |
int data = mobj->d.data[handle + 3]; |
|
1876 |
for (int i = 0; i < count; ++i) |
|
1877 |
if (value == (int)mobj->d.data[data + 2*i + 1]) |
|
1878 |
return mobj->d.stringdata + mobj->d.data[data + 2*i]; |
|
1879 |
return 0; |
|
1880 |
} |
|
1881 |
||
1882 |
/*! |
|
1883 |
Returns the value derived from combining together the values of |
|
1884 |
the \a keys using the OR operator, or -1 if \a keys is not |
|
1885 |
defined. Note that the strings in \a keys must be '|'-separated. |
|
1886 |
||
1887 |
\sa isFlag(), valueToKey(), valueToKeys() |
|
1888 |
*/ |
|
1889 |
int QMetaEnum::keysToValue(const char *keys) const |
|
1890 |
{ |
|
1891 |
if (!mobj) |
|
1892 |
return -1; |
|
1893 |
QStringList l = QString::fromLatin1(keys).split(QLatin1Char('|')); |
|
1894 |
//#### TODO write proper code, do not use QStringList |
|
1895 |
int value = 0; |
|
1896 |
int count = mobj->d.data[handle + 2]; |
|
1897 |
int data = mobj->d.data[handle + 3]; |
|
1898 |
for (int li = 0; li < l.size(); ++li) { |
|
1899 |
QString trimmed = l.at(li).trimmed(); |
|
1900 |
QByteArray qualified_key = trimmed.toLatin1(); |
|
1901 |
const char *key = qualified_key.constData(); |
|
1902 |
uint scope = 0; |
|
1903 |
const char *s = key + qstrlen(key); |
|
1904 |
while (s > key && *s != ':') |
|
1905 |
--s; |
|
1906 |
if (s > key && *(s-1)==':') { |
|
1907 |
scope = s - key - 1; |
|
1908 |
key += scope + 2; |
|
1909 |
} |
|
1910 |
int i; |
|
1911 |
for (i = count-1; i >= 0; --i) |
|
1912 |
if ((!scope || (qstrlen(mobj->d.stringdata) == scope && strncmp(qualified_key.constData(), mobj->d.stringdata, scope) == 0)) |
|
1913 |
&& strcmp(key, mobj->d.stringdata + mobj->d.data[data + 2*i]) == 0) { |
|
1914 |
value |= mobj->d.data[data + 2*i + 1]; |
|
1915 |
break; |
|
1916 |
} |
|
1917 |
if (i < 0) |
|
1918 |
value |= -1; |
|
1919 |
} |
|
1920 |
return value; |
|
1921 |
} |
|
1922 |
||
1923 |
/*! |
|
1924 |
Returns a byte array of '|'-separated keys that represents the |
|
1925 |
given \a value. |
|
1926 |
||
1927 |
\sa isFlag(), valueToKey(), keysToValue() |
|
1928 |
*/ |
|
1929 |
QByteArray QMetaEnum::valueToKeys(int value) const |
|
1930 |
{ |
|
1931 |
QByteArray keys; |
|
1932 |
if (!mobj) |
|
1933 |
return keys; |
|
1934 |
int count = mobj->d.data[handle + 2]; |
|
1935 |
int data = mobj->d.data[handle + 3]; |
|
1936 |
int v = value; |
|
1937 |
for(int i = 0; i < count; i++) { |
|
1938 |
int k = mobj->d.data[data + 2*i + 1]; |
|
1939 |
if ((k != 0 && (v & k) == k ) || (k == value)) { |
|
1940 |
v = v & ~k; |
|
1941 |
if (!keys.isEmpty()) |
|
1942 |
keys += '|'; |
|
1943 |
keys += mobj->d.stringdata + mobj->d.data[data + 2*i]; |
|
1944 |
} |
|
1945 |
} |
|
1946 |
return keys; |
|
1947 |
} |
|
1948 |
||
1949 |
static QByteArray qualifiedName(const QMetaEnum &e) |
|
1950 |
{ |
|
1951 |
return QByteArray(e.scope()) + "::" + e.name(); |
|
1952 |
} |
|
1953 |
||
1954 |
/*! |
|
1955 |
\class QMetaProperty |
|
1956 |
\brief The QMetaProperty class provides meta-data about a property. |
|
1957 |
||
1958 |
\ingroup objectmodel |
|
1959 |
||
1960 |
Property meta-data is obtained from an object's meta-object. See |
|
1961 |
QMetaObject::property() and QMetaObject::propertyCount() for |
|
1962 |
details. |
|
1963 |
||
1964 |
\section1 Property Meta-Data |
|
1965 |
||
1966 |
A property has a name() and a type(), as well as various |
|
1967 |
attributes that specify its behavior: isReadable(), isWritable(), |
|
1968 |
isDesignable(), isScriptable(), and isStored(). |
|
1969 |
||
1970 |
If the property is an enumeration, isEnumType() returns true; if the |
|
1971 |
property is an enumeration that is also a flag (i.e. its values |
|
1972 |
can be combined using the OR operator), isEnumType() and |
|
1973 |
isFlagType() both return true. The enumerator for these types is |
|
1974 |
available from enumerator(). |
|
1975 |
||
1976 |
The property's values are set and retrieved with read(), write(), |
|
1977 |
and reset(); they can also be changed through QObject's set and get |
|
1978 |
functions. See QObject::setProperty() and QObject::property() for |
|
1979 |
details. |
|
1980 |
||
1981 |
\section1 Copying and Assignment |
|
1982 |
||
1983 |
QMetaProperty objects can be copied by value. However, each copy will |
|
1984 |
refer to the same underlying property meta-data. |
|
1985 |
||
1986 |
\sa QMetaObject, QMetaEnum, QMetaMethod, {Qt's Property System} |
|
1987 |
*/ |
|
1988 |
||
1989 |
/*! |
|
1990 |
\fn bool QMetaProperty::isValid() const |
|
1991 |
||
1992 |
Returns true if this property is valid (readable); otherwise |
|
1993 |
returns false. |
|
1994 |
||
1995 |
\sa isReadable() |
|
1996 |
*/ |
|
1997 |
||
1998 |
/*! |
|
1999 |
\fn const QMetaObject *QMetaProperty::enclosingMetaObject() const |
|
2000 |
\internal |
|
2001 |
*/ |
|
2002 |
||
2003 |
/*! |
|
2004 |
\internal |
|
2005 |
*/ |
|
2006 |
QMetaProperty::QMetaProperty() |
|
2007 |
: mobj(0), handle(0), idx(0) |
|
2008 |
{ |
|
2009 |
} |
|
2010 |
||
2011 |
||
2012 |
/*! |
|
2013 |
Returns this property's name. |
|
2014 |
||
2015 |
\sa type(), typeName() |
|
2016 |
*/ |
|
2017 |
const char *QMetaProperty::name() const |
|
2018 |
{ |
|
2019 |
if (!mobj) |
|
2020 |
return 0; |
|
2021 |
int handle = priv(mobj->d.data)->propertyData + 3*idx; |
|
2022 |
return mobj->d.stringdata + mobj->d.data[handle]; |
|
2023 |
} |
|
2024 |
||
2025 |
/*! |
|
2026 |
Returns the name of this property's type. |
|
2027 |
||
2028 |
\sa type(), name() |
|
2029 |
*/ |
|
2030 |
const char *QMetaProperty::typeName() const |
|
2031 |
{ |
|
2032 |
if (!mobj) |
|
2033 |
return 0; |
|
2034 |
int handle = priv(mobj->d.data)->propertyData + 3*idx; |
|
2035 |
return mobj->d.stringdata + mobj->d.data[handle + 1]; |
|
2036 |
} |
|
2037 |
||
2038 |
/*! |
|
2039 |
Returns this property's type. The return value is one |
|
2040 |
of the values of the QVariant::Type enumeration. |
|
2041 |
||
2042 |
\sa userType(), typeName(), name() |
|
2043 |
*/ |
|
2044 |
QVariant::Type QMetaProperty::type() const |
|
2045 |
{ |
|
2046 |
if (!mobj) |
|
2047 |
return QVariant::Invalid; |
|
2048 |
int handle = priv(mobj->d.data)->propertyData + 3*idx; |
|
2049 |
uint flags = mobj->d.data[handle + 2]; |
|
2050 |
||
2051 |
uint type = flags >> 24; |
|
2052 |
if (type == 0xff) // special value for QVariant |
|
2053 |
type = QVariant::LastType; |
|
2054 |
if (type) |
|
2055 |
return QVariant::Type(type); |
|
2056 |
if (isEnumType()) { |
|
2057 |
int enumMetaTypeId = QMetaType::type(qualifiedName(menum)); |
|
2058 |
if (enumMetaTypeId == 0) |
|
2059 |
return QVariant::Int; |
|
2060 |
} |
|
2061 |
#ifdef QT_COORD_TYPE |
|
2062 |
// qreal metatype must be resolved at runtime. |
|
2063 |
if (strcmp(typeName(), "qreal") == 0) |
|
2064 |
return QVariant::Type(qMetaTypeId<qreal>()); |
|
2065 |
#endif |
|
2066 |
||
2067 |
return QVariant::UserType; |
|
2068 |
} |
|
2069 |
||
2070 |
/*! |
|
2071 |
\since 4.2 |
|
2072 |
||
2073 |
Returns this property's user type. The return value is one |
|
2074 |
of the values that are registered with QMetaType, or 0 if |
|
2075 |
the type is not registered. |
|
2076 |
||
2077 |
\sa type(), QMetaType, typeName() |
|
2078 |
*/ |
|
2079 |
int QMetaProperty::userType() const |
|
2080 |
{ |
|
2081 |
QVariant::Type tp = type(); |
|
2082 |
if (tp != QVariant::UserType) |
|
2083 |
return tp; |
|
2084 |
if (isEnumType()) { |
|
2085 |
int enumMetaTypeId = QMetaType::type(qualifiedName(menum)); |
|
2086 |
return enumMetaTypeId; |
|
2087 |
} |
|
2088 |
return QMetaType::type(typeName()); |
|
2089 |
} |
|
2090 |
||
2091 |
/*! |
|
2092 |
\since 4.6 |
|
2093 |
||
2094 |
Returns this property's index. |
|
2095 |
*/ |
|
2096 |
int QMetaProperty::propertyIndex() const |
|
2097 |
{ |
|
2098 |
if (!mobj) |
|
2099 |
return -1; |
|
2100 |
return idx + mobj->propertyOffset(); |
|
2101 |
} |
|
2102 |
||
2103 |
/*! |
|
2104 |
Returns true if the property's type is an enumeration value that |
|
2105 |
is used as a flag; otherwise returns false. |
|
2106 |
||
2107 |
Flags can be combined using the OR operator. A flag type is |
|
2108 |
implicitly also an enum type. |
|
2109 |
||
2110 |
\sa isEnumType(), enumerator(), QMetaEnum::isFlag() |
|
2111 |
*/ |
|
2112 |
||
2113 |
bool QMetaProperty::isFlagType() const |
|
2114 |
{ |
|
2115 |
return isEnumType() && menum.isFlag(); |
|
2116 |
} |
|
2117 |
||
2118 |
/*! |
|
2119 |
Returns true if the property's type is an enumeration value; |
|
2120 |
otherwise returns false. |
|
2121 |
||
2122 |
\sa enumerator(), isFlagType() |
|
2123 |
*/ |
|
2124 |
bool QMetaProperty::isEnumType() const |
|
2125 |
{ |
|
2126 |
if (!mobj) |
|
2127 |
return false; |
|
2128 |
int handle = priv(mobj->d.data)->propertyData + 3*idx; |
|
2129 |
int flags = mobj->d.data[handle + 2]; |
|
2130 |
return (flags & EnumOrFlag) && menum.name(); |
|
2131 |
} |
|
2132 |
||
2133 |
/*! |
|
2134 |
\internal |
|
2135 |
||
2136 |
Returns true if the property has a C++ setter function that |
|
2137 |
follows Qt's standard "name" / "setName" pattern. Designer and uic |
|
2138 |
query hasStdCppSet() in order to avoid expensive |
|
2139 |
QObject::setProperty() calls. All properties in Qt [should] follow |
|
2140 |
this pattern. |
|
2141 |
*/ |
|
2142 |
bool QMetaProperty::hasStdCppSet() const |
|
2143 |
{ |
|
2144 |
if (!mobj) |
|
2145 |
return false; |
|
2146 |
int handle = priv(mobj->d.data)->propertyData + 3*idx; |
|
2147 |
int flags = mobj->d.data[handle + 2]; |
|
2148 |
return (flags & StdCppSet); |
|
2149 |
} |
|
2150 |
||
2151 |
/*! |
|
2152 |
Returns the enumerator if this property's type is an enumerator |
|
2153 |
type; otherwise the returned value is undefined. |
|
2154 |
||
2155 |
\sa isEnumType(), isFlagType() |
|
2156 |
*/ |
|
2157 |
QMetaEnum QMetaProperty::enumerator() const |
|
2158 |
{ |
|
2159 |
return menum; |
|
2160 |
} |
|
2161 |
||
2162 |
/*! |
|
2163 |
Reads the property's value from the given \a object. Returns the value |
|
2164 |
if it was able to read it; otherwise returns an invalid variant. |
|
2165 |
||
2166 |
\sa write(), reset(), isReadable() |
|
2167 |
*/ |
|
2168 |
QVariant QMetaProperty::read(const QObject *object) const |
|
2169 |
{ |
|
2170 |
if (!object || !mobj) |
|
2171 |
return QVariant(); |
|
2172 |
||
2173 |
uint t = QVariant::Int; |
|
2174 |
if (isEnumType()) { |
|
2175 |
/* |
|
2176 |
try to create a QVariant that can be converted to this enum |
|
2177 |
type (only works if the enum has already been registered |
|
2178 |
with QMetaType) |
|
2179 |
*/ |
|
2180 |
int enumMetaTypeId = QMetaType::type(qualifiedName(menum)); |
|
2181 |
if (enumMetaTypeId != 0) |
|
2182 |
t = enumMetaTypeId; |
|
2183 |
} else { |
|
2184 |
int handle = priv(mobj->d.data)->propertyData + 3*idx; |
|
2185 |
uint flags = mobj->d.data[handle + 2]; |
|
2186 |
const char *typeName = mobj->d.stringdata + mobj->d.data[handle + 1]; |
|
2187 |
t = (flags >> 24); |
|
2188 |
if (t == 0xff) // special value for QVariant |
|
2189 |
t = QVariant::LastType; |
|
2190 |
if (t == QVariant::Invalid) |
|
2191 |
t = QMetaType::type(typeName); |
|
2192 |
if (t == QVariant::Invalid) |
|
2193 |
t = QVariant::nameToType(typeName); |
|
2194 |
if (t == QVariant::Invalid || t == QVariant::UserType) { |
|
2195 |
if (t == QVariant::Invalid) |
|
2196 |
qWarning("QMetaProperty::read: Unable to handle unregistered datatype '%s' for property '%s::%s'", typeName, mobj->className(), name()); |
|
2197 |
return QVariant(); |
|
2198 |
} |
|
2199 |
} |
|
2200 |
||
2201 |
// the status variable is changed by qt_metacall to indicate what it did |
|
2202 |
// this feature is currently only used by QtDBus and should not be depended |
|
2203 |
// upon. Don't change it without looking into QDBusAbstractInterface first |
|
2204 |
// -1 (unchanged): normal qt_metacall, result stored in argv[0] |
|
2205 |
// changed: result stored directly in value |
|
2206 |
int status = -1; |
|
2207 |
QVariant value; |
|
2208 |
void *argv[] = { 0, &value, &status }; |
|
2209 |
if (t == QVariant::LastType) { |
|
2210 |
argv[0] = &value; |
|
2211 |
} else { |
|
2212 |
value = QVariant(t, (void*)0); |
|
2213 |
argv[0] = value.data(); |
|
2214 |
} |
|
2215 |
QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::ReadProperty, |
|
2216 |
idx + mobj->propertyOffset(), argv); |
|
2217 |
||
2218 |
if (status != -1) |
|
2219 |
return value; |
|
2220 |
if (t != QVariant::LastType && argv[0] != value.data()) |
|
2221 |
// pointer or reference |
|
2222 |
return QVariant((QVariant::Type)t, argv[0]); |
|
2223 |
return value; |
|
2224 |
} |
|
2225 |
||
2226 |
/*! |
|
2227 |
Writes \a value as the property's value to the given \a object. Returns |
|
2228 |
true if the write succeeded; otherwise returns false. |
|
2229 |
||
2230 |
\sa read(), reset(), isWritable() |
|
2231 |
*/ |
|
2232 |
bool QMetaProperty::write(QObject *object, const QVariant &value) const |
|
2233 |
{ |
|
2234 |
if (!object || !isWritable()) |
|
2235 |
return false; |
|
2236 |
||
2237 |
QVariant v = value; |
|
2238 |
uint t = QVariant::Invalid; |
|
2239 |
if (isEnumType()) { |
|
2240 |
if (v.type() == QVariant::String |
|
2241 |
#ifdef QT3_SUPPORT |
|
2242 |
|| v.type() == QVariant::CString |
|
2243 |
#endif |
|
2244 |
) { |
|
2245 |
if (isFlagType()) |
|
2246 |
v = QVariant(menum.keysToValue(value.toByteArray())); |
|
2247 |
else |
|
2248 |
v = QVariant(menum.keyToValue(value.toByteArray())); |
|
2249 |
} else if (v.type() != QVariant::Int && v.type() != QVariant::UInt) { |
|
2250 |
int enumMetaTypeId = QMetaType::type(qualifiedName(menum)); |
|
2251 |
if ((enumMetaTypeId == 0) || (v.userType() != enumMetaTypeId) || !v.constData()) |
|
2252 |
return false; |
|
2253 |
v = QVariant(*reinterpret_cast<const int *>(v.constData())); |
|
2254 |
} |
|
2255 |
v.convert(QVariant::Int); |
|
2256 |
} else { |
|
2257 |
int handle = priv(mobj->d.data)->propertyData + 3*idx; |
|
2258 |
uint flags = mobj->d.data[handle + 2]; |
|
2259 |
t = flags >> 24; |
|
2260 |
if (t == 0xff) // special value for QVariant |
|
2261 |
t = QVariant::LastType; |
|
2262 |
if (t == QVariant::Invalid) { |
|
2263 |
const char *typeName = mobj->d.stringdata + mobj->d.data[handle + 1]; |
|
2264 |
const char *vtypeName = value.typeName(); |
|
2265 |
if (vtypeName && strcmp(typeName, vtypeName) == 0) |
|
2266 |
t = value.userType(); |
|
2267 |
else |
|
2268 |
t = QVariant::nameToType(typeName); |
|
2269 |
} |
|
2270 |
if (t == QVariant::Invalid) |
|
2271 |
return false; |
|
2272 |
if (t != QVariant::LastType && t != (uint)value.userType() && (t < QMetaType::User && !v.convert((QVariant::Type)t))) |
|
2273 |
return false; |
|
2274 |
} |
|
2275 |
||
2276 |
// the status variable is changed by qt_metacall to indicate what it did |
|
2277 |
// this feature is currently only used by QtDBus and should not be depended |
|
2278 |
// upon. Don't change it without looking into QDBusAbstractInterface first |
|
2279 |
// -1 (unchanged): normal qt_metacall, result stored in argv[0] |
|
2280 |
// changed: result stored directly in value, return the value of status |
|
2281 |
int status = -1; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2282 |
// the flags variable is used by the declarative module to implement |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2283 |
// interception of property writes. |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2284 |
int flags = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2285 |
void *argv[] = { 0, &v, &status, &flags }; |
0 | 2286 |
if (t == QVariant::LastType) |
2287 |
argv[0] = &v; |
|
2288 |
else |
|
2289 |
argv[0] = v.data(); |
|
2290 |
QMetaObject::metacall(object, QMetaObject::WriteProperty, idx + mobj->propertyOffset(), argv); |
|
2291 |
return status; |
|
2292 |
} |
|
2293 |
||
2294 |
/*! |
|
2295 |
Resets the property for the given \a object with a reset method. |
|
2296 |
Returns true if the reset worked; otherwise returns false. |
|
2297 |
||
2298 |
Reset methods are optional; only a few properties support them. |
|
2299 |
||
2300 |
\sa read(), write() |
|
2301 |
*/ |
|
2302 |
bool QMetaProperty::reset(QObject *object) const |
|
2303 |
{ |
|
2304 |
if (!object || !mobj || !isResettable()) |
|
2305 |
return false; |
|
2306 |
void *argv[] = { 0 }; |
|
2307 |
QMetaObject::metacall(object, QMetaObject::ResetProperty, idx + mobj->propertyOffset(), argv); |
|
2308 |
return true; |
|
2309 |
} |
|
2310 |
||
2311 |
/*! |
|
2312 |
Returns true if this property can be reset to a default value; otherwise |
|
2313 |
returns false. |
|
2314 |
||
2315 |
\sa reset() |
|
2316 |
*/ |
|
2317 |
bool QMetaProperty::isResettable() const |
|
2318 |
{ |
|
2319 |
if (!mobj) |
|
2320 |
return false; |
|
2321 |
int flags = mobj->d.data[handle + 2]; |
|
2322 |
return flags & Resettable; |
|
2323 |
} |
|
2324 |
||
2325 |
/*! |
|
2326 |
Returns true if this property is readable; otherwise returns false. |
|
2327 |
||
2328 |
\sa isWritable(), read(), isValid() |
|
2329 |
*/ |
|
2330 |
bool QMetaProperty::isReadable() const |
|
2331 |
{ |
|
2332 |
if (!mobj) |
|
2333 |
return false; |
|
2334 |
int flags = mobj->d.data[handle + 2]; |
|
2335 |
return flags & Readable; |
|
2336 |
} |
|
2337 |
||
2338 |
/*! |
|
2339 |
Returns true if this property has a corresponding change notify signal; |
|
2340 |
otherwise returns false. |
|
2341 |
||
2342 |
\sa notifySignal() |
|
2343 |
*/ |
|
2344 |
bool QMetaProperty::hasNotifySignal() const |
|
2345 |
{ |
|
2346 |
if (!mobj) |
|
2347 |
return false; |
|
2348 |
int flags = mobj->d.data[handle + 2]; |
|
2349 |
return flags & Notify; |
|
2350 |
} |
|
2351 |
||
2352 |
/*! |
|
2353 |
\since 4.5 |
|
2354 |
||
2355 |
Returns the QMetaMethod instance of the property change notifying signal if |
|
2356 |
one was specified, otherwise returns an invalid QMetaMethod. |
|
2357 |
||
2358 |
\sa hasNotifySignal() |
|
2359 |
*/ |
|
2360 |
QMetaMethod QMetaProperty::notifySignal() const |
|
2361 |
{ |
|
2362 |
int id = notifySignalIndex(); |
|
2363 |
if (id != -1) |
|
2364 |
return mobj->method(id); |
|
2365 |
else |
|
2366 |
return QMetaMethod(); |
|
2367 |
} |
|
2368 |
||
2369 |
/*! |
|
2370 |
\since 4.6 |
|
2371 |
||
2372 |
Returns the index of the property change notifying signal if one was |
|
2373 |
specified, otherwise returns -1. |
|
2374 |
||
2375 |
\sa hasNotifySignal() |
|
2376 |
*/ |
|
2377 |
int QMetaProperty::notifySignalIndex() const |
|
2378 |
{ |
|
2379 |
if (hasNotifySignal()) { |
|
2380 |
int offset = priv(mobj->d.data)->propertyData + |
|
2381 |
priv(mobj->d.data)->propertyCount * 3 + idx; |
|
2382 |
return mobj->d.data[offset] + mobj->methodOffset(); |
|
2383 |
} else { |
|
2384 |
return -1; |
|
2385 |
} |
|
2386 |
} |
|
2387 |
||
2388 |
/*! |
|
2389 |
Returns true if this property is writable; otherwise returns |
|
2390 |
false. |
|
2391 |
||
2392 |
\sa isReadable(), write() |
|
2393 |
*/ |
|
2394 |
bool QMetaProperty::isWritable() const |
|
2395 |
{ |
|
2396 |
if (!mobj) |
|
2397 |
return false; |
|
2398 |
int flags = mobj->d.data[handle + 2]; |
|
2399 |
return flags & Writable; |
|
2400 |
} |
|
2401 |
||
2402 |
||
2403 |
/*! |
|
2404 |
Returns true if this property is designable for the given \a object; |
|
2405 |
otherwise returns false. |
|
2406 |
||
2407 |
If no \a object is given, the function returns false if the |
|
2408 |
\c{Q_PROPERTY()}'s \c DESIGNABLE attribute is false; otherwise |
|
2409 |
returns true (if the attribute is true or is a function or expression). |
|
2410 |
||
2411 |
\sa isScriptable(), isStored() |
|
2412 |
*/ |
|
2413 |
bool QMetaProperty::isDesignable(const QObject *object) const |
|
2414 |
{ |
|
2415 |
if (!mobj) |
|
2416 |
return false; |
|
2417 |
int flags = mobj->d.data[handle + 2]; |
|
2418 |
bool b = flags & Designable; |
|
2419 |
if (object) { |
|
2420 |
void *argv[] = { &b }; |
|
2421 |
QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::QueryPropertyDesignable, |
|
2422 |
idx + mobj->propertyOffset(), argv); |
|
2423 |
} |
|
2424 |
return b; |
|
2425 |
||
2426 |
||
2427 |
} |
|
2428 |
||
2429 |
/*! |
|
2430 |
Returns true if the property is scriptable for the given \a object; |
|
2431 |
otherwise returns false. |
|
2432 |
||
2433 |
If no \a object is given, the function returns false if the |
|
2434 |
\c{Q_PROPERTY()}'s \c SCRIPTABLE attribute is false; otherwise returns |
|
2435 |
true (if the attribute is true or is a function or expression). |
|
2436 |
||
2437 |
\sa isDesignable(), isStored() |
|
2438 |
*/ |
|
2439 |
bool QMetaProperty::isScriptable(const QObject *object) const |
|
2440 |
{ |
|
2441 |
if (!mobj) |
|
2442 |
return false; |
|
2443 |
int flags = mobj->d.data[handle + 2]; |
|
2444 |
bool b = flags & Scriptable; |
|
2445 |
if (object) { |
|
2446 |
void *argv[] = { &b }; |
|
2447 |
QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::QueryPropertyScriptable, |
|
2448 |
idx + mobj->propertyOffset(), argv); |
|
2449 |
} |
|
2450 |
return b; |
|
2451 |
} |
|
2452 |
||
2453 |
/*! |
|
2454 |
Returns true if the property is stored for \a object; otherwise returns |
|
2455 |
false. |
|
2456 |
||
2457 |
If no \a object is given, the function returns false if the |
|
2458 |
\c{Q_PROPERTY()}'s \c STORED attribute is false; otherwise returns |
|
2459 |
true (if the attribute is true or is a function or expression). |
|
2460 |
||
2461 |
\sa isDesignable(), isScriptable() |
|
2462 |
*/ |
|
2463 |
bool QMetaProperty::isStored(const QObject *object) const |
|
2464 |
{ |
|
2465 |
if (!mobj) |
|
2466 |
return false; |
|
2467 |
int flags = mobj->d.data[handle + 2]; |
|
2468 |
bool b = flags & Stored; |
|
2469 |
if (object) { |
|
2470 |
void *argv[] = { &b }; |
|
2471 |
QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::QueryPropertyStored, |
|
2472 |
idx + mobj->propertyOffset(), argv); |
|
2473 |
} |
|
2474 |
return b; |
|
2475 |
} |
|
2476 |
||
2477 |
/*! |
|
2478 |
Returns true if this property is designated as the \c USER |
|
2479 |
property, i.e., the one that the user can edit for \a object or |
|
2480 |
that is significant in some other way. Otherwise it returns |
|
2481 |
false. e.g., the \c text property is the \c USER editable property |
|
2482 |
of a QLineEdit. |
|
2483 |
||
2484 |
If \a object is null, the function returns false if the \c |
|
2485 |
{Q_PROPERTY()}'s \c USER attribute is false. Otherwise it returns |
|
2486 |
true. |
|
2487 |
||
2488 |
\sa QMetaObject::userProperty(), isDesignable(), isScriptable() |
|
2489 |
*/ |
|
2490 |
bool QMetaProperty::isUser(const QObject *object) const |
|
2491 |
{ |
|
2492 |
if (!mobj) |
|
2493 |
return false; |
|
2494 |
int flags = mobj->d.data[handle + 2]; |
|
2495 |
bool b = flags & User; |
|
2496 |
if (object) { |
|
2497 |
void *argv[] = { &b }; |
|
2498 |
QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::QueryPropertyUser, |
|
2499 |
idx + mobj->propertyOffset(), argv); |
|
2500 |
} |
|
2501 |
return b; |
|
2502 |
} |
|
2503 |
||
2504 |
/*! |
|
2505 |
\since 4.6 |
|
2506 |
Returns true if the property is constant; otherwise returns false. |
|
2507 |
||
2508 |
A property is constant if the \c{Q_PROPERTY()}'s \c CONSTANT attribute |
|
2509 |
is set. |
|
2510 |
*/ |
|
2511 |
bool QMetaProperty::isConstant() const |
|
2512 |
{ |
|
2513 |
if (!mobj) |
|
2514 |
return false; |
|
2515 |
int flags = mobj->d.data[handle + 2]; |
|
2516 |
return flags & Constant; |
|
2517 |
} |
|
2518 |
||
2519 |
/*! |
|
2520 |
\since 4.6 |
|
2521 |
Returns true if the property is final; otherwise returns false. |
|
2522 |
||
2523 |
A property is final if the \c{Q_PROPERTY()}'s \c FINAL attribute |
|
2524 |
is set. |
|
2525 |
*/ |
|
2526 |
bool QMetaProperty::isFinal() const |
|
2527 |
{ |
|
2528 |
if (!mobj) |
|
2529 |
return false; |
|
2530 |
int flags = mobj->d.data[handle + 2]; |
|
2531 |
return flags & Final; |
|
2532 |
} |
|
2533 |
||
2534 |
/*! |
|
2535 |
\obsolete |
|
2536 |
||
2537 |
Returns true if the property is editable for the given \a object; |
|
2538 |
otherwise returns false. |
|
2539 |
||
2540 |
If no \a object is given, the function returns false if the |
|
2541 |
\c{Q_PROPERTY()}'s \c EDITABLE attribute is false; otherwise returns |
|
2542 |
true (if the attribute is true or is a function or expression). |
|
2543 |
||
2544 |
\sa isDesignable(), isScriptable(), isStored() |
|
2545 |
*/ |
|
2546 |
bool QMetaProperty::isEditable(const QObject *object) const |
|
2547 |
{ |
|
2548 |
if (!mobj) |
|
2549 |
return false; |
|
2550 |
int flags = mobj->d.data[handle + 2]; |
|
2551 |
bool b = flags & Editable; |
|
2552 |
if (object) { |
|
2553 |
void *argv[] = { &b }; |
|
2554 |
QMetaObject::metacall(const_cast<QObject*>(object), QMetaObject::QueryPropertyEditable, |
|
2555 |
idx + mobj->propertyOffset(), argv); |
|
2556 |
} |
|
2557 |
return b; |
|
2558 |
} |
|
2559 |
||
2560 |
/*! |
|
2561 |
\class QMetaClassInfo |
|
2562 |
||
2563 |
\brief The QMetaClassInfo class provides additional information |
|
2564 |
about a class. |
|
2565 |
||
2566 |
\ingroup objectmodel |
|
2567 |
||
2568 |
Class information items are simple \e{name}--\e{value} pairs that |
|
2569 |
are specified using Q_CLASSINFO() in the source code. The |
|
2570 |
information can be retrieved using name() and value(). For example: |
|
2571 |
||
2572 |
\snippet doc/src/snippets/code/src_corelib_kernel_qmetaobject.cpp 5 |
|
2573 |
||
2574 |
This mechanism is free for you to use in your Qt applications. Qt |
|
2575 |
doesn't use it for any of its classes. |
|
2576 |
||
2577 |
\sa QMetaObject |
|
2578 |
*/ |
|
2579 |
||
2580 |
||
2581 |
/*! |
|
2582 |
\fn QMetaClassInfo::QMetaClassInfo() |
|
2583 |
\internal |
|
2584 |
*/ |
|
2585 |
||
2586 |
/*! |
|
2587 |
\fn const QMetaObject *QMetaClassInfo::enclosingMetaObject() const |
|
2588 |
\internal |
|
2589 |
*/ |
|
2590 |
||
2591 |
/*! |
|
2592 |
Returns the name of this item. |
|
2593 |
||
2594 |
\sa value() |
|
2595 |
*/ |
|
2596 |
const char *QMetaClassInfo::name() const |
|
2597 |
{ |
|
2598 |
if (!mobj) |
|
2599 |
return 0; |
|
2600 |
return mobj->d.stringdata + mobj->d.data[handle]; |
|
2601 |
} |
|
2602 |
||
2603 |
/*! |
|
2604 |
Returns the value of this item. |
|
2605 |
||
2606 |
\sa name() |
|
2607 |
*/ |
|
2608 |
const char* QMetaClassInfo::value() const |
|
2609 |
{ |
|
2610 |
if (!mobj) |
|
2611 |
return 0; |
|
2612 |
return mobj->d.stringdata + mobj->d.data[handle + 1]; |
|
2613 |
} |
|
2614 |
||
2615 |
/*! |
|
2616 |
\macro QGenericArgument Q_ARG(Type, const Type &value) |
|
2617 |
\relates QMetaObject |
|
2618 |
||
2619 |
This macro takes a \a Type and a \a value of that type and |
|
2620 |
returns a \l QGenericArgument object that can be passed to |
|
2621 |
QMetaObject::invokeMethod(). |
|
2622 |
||
2623 |
\sa Q_RETURN_ARG() |
|
2624 |
*/ |
|
2625 |
||
2626 |
/*! |
|
2627 |
\macro QGenericReturnArgument Q_RETURN_ARG(Type, Type &value) |
|
2628 |
\relates QMetaObject |
|
2629 |
||
2630 |
This macro takes a \a Type and a non-const reference to a \a |
|
2631 |
value of that type and returns a QGenericReturnArgument object |
|
2632 |
that can be passed to QMetaObject::invokeMethod(). |
|
2633 |
||
2634 |
\sa Q_ARG() |
|
2635 |
*/ |
|
2636 |
||
2637 |
/*! |
|
2638 |
\class QGenericArgument |
|
2639 |
||
2640 |
\brief The QGenericArgument class is an internal helper class for |
|
2641 |
marshalling arguments. |
|
2642 |
||
2643 |
This class should never be used directly. Please use the \l Q_ARG() |
|
2644 |
macro instead. |
|
2645 |
||
2646 |
\sa Q_ARG(), QMetaObject::invokeMethod(), QGenericReturnArgument |
|
2647 |
*/ |
|
2648 |
||
2649 |
/*! |
|
2650 |
\fn QGenericArgument::QGenericArgument(const char *name, const void *data) |
|
2651 |
||
2652 |
Constructs a QGenericArgument object with the given \a name and \a data. |
|
2653 |
*/ |
|
2654 |
||
2655 |
/*! |
|
2656 |
\fn QGenericArgument::data () const |
|
2657 |
||
2658 |
Returns the data set in the constructor. |
|
2659 |
*/ |
|
2660 |
||
2661 |
/*! |
|
2662 |
\fn QGenericArgument::name () const |
|
2663 |
||
2664 |
Returns the name set in the constructor. |
|
2665 |
*/ |
|
2666 |
||
2667 |
/*! |
|
2668 |
\class QGenericReturnArgument |
|
2669 |
||
2670 |
\brief The QGenericReturnArgument class is an internal helper class for |
|
2671 |
marshalling arguments. |
|
2672 |
||
2673 |
This class should never be used directly. Please use the |
|
2674 |
Q_RETURN_ARG() macro instead. |
|
2675 |
||
2676 |
\sa Q_RETURN_ARG(), QMetaObject::invokeMethod(), QGenericArgument |
|
2677 |
*/ |
|
2678 |
||
2679 |
/*! |
|
2680 |
\fn QGenericReturnArgument::QGenericReturnArgument(const char *name, void *data) |
|
2681 |
||
2682 |
Constructs a QGenericReturnArgument object with the given \a name |
|
2683 |
and \a data. |
|
2684 |
*/ |
|
2685 |
||
2686 |
/*! \internal |
|
2687 |
If the local_method_index is a cloned method, return the index of the original. |
|
2688 |
||
2689 |
Example: if the index of "destroyed()" is passed, the index of "destroyed(QObject*)" is returned |
|
2690 |
*/ |
|
2691 |
int QMetaObjectPrivate::originalClone(const QMetaObject *mobj, int local_method_index) |
|
2692 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2693 |
Q_ASSERT(local_method_index < get(mobj)->methodCount); |
0 | 2694 |
int handle = get(mobj)->methodData + 5 * local_method_index; |
2695 |
while (mobj->d.data[handle + 4] & MethodCloned) { |
|
2696 |
Q_ASSERT(local_method_index > 0); |
|
2697 |
handle -= 5; |
|
2698 |
local_method_index--; |
|
2699 |
} |
|
2700 |
return local_method_index; |
|
2701 |
} |
|
2702 |
||
2703 |
QT_END_NAMESPACE |