/
qmetaobject.cpp
3623 lines (3074 loc) · 109 KB
/
qmetaobject.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Copyright (C) 2015 Olivier Goffart <ogoffart@woboq.com>
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtCore module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qmetaobject.h"
#include "qmetatype.h"
#include "qobject.h"
#include "qmetaobject_p.h"
#include <qcoreapplication.h>
#include <qcoreevent.h>
#include <qdatastream.h>
#include <qstringlist.h>
#include <qthread.h>
#include <qvariant.h>
#include <qdebug.h>
#include <qsemaphore.h>
#include "private/qobject_p.h"
#include "private/qmetaobject_p.h"
// for normalizeTypeInternal
#include "private/qmetaobject_moc_p.h"
#include <ctype.h>
QT_BEGIN_NAMESPACE
/*!
\class QMetaObject
\inmodule QtCore
\brief The QMetaObject class contains meta-information about Qt
objects.
\ingroup objectmodel
The Qt \l{Meta-Object System} in Qt is responsible for the
signals and slots inter-object communication mechanism, runtime
type information, and the Qt property system. A single
QMetaObject instance is created for each QObject subclass that is
used in an application, and this instance stores all the
meta-information for the QObject subclass. This object is
available as QObject::metaObject().
This class is not normally required for application programming,
but it is useful if you write meta-applications, such as scripting
engines or GUI builders.
The functions you are most likely to find useful are these:
\list
\li className() returns the name of a class.
\li superClass() returns the superclass's meta-object.
\li method() and methodCount() provide information
about a class's meta-methods (signals, slots and other
\l{Q_INVOKABLE}{invokable} member functions).
\li enumerator() and enumeratorCount() and provide information about
a class's enumerators.
\li propertyCount() and property() provide information about a
class's properties.
\li constructor() and constructorCount() provide information
about a class's meta-constructors.
\endlist
The index functions indexOfConstructor(), indexOfMethod(),
indexOfEnumerator(), and indexOfProperty() map names of constructors,
member functions, enumerators, or properties to indexes in the
meta-object. For example, Qt uses indexOfMethod() internally when you
connect a signal to a slot.
Classes can also have a list of \e{name}--\e{value} pairs of
additional class information, stored in QMetaClassInfo objects.
The number of pairs is returned by classInfoCount(), single pairs
are returned by classInfo(), and you can search for pairs with
indexOfClassInfo().
\sa QMetaClassInfo, QMetaEnum, QMetaMethod, QMetaProperty, QMetaType,
{Meta-Object System}
*/
/*!
\enum QMetaObject::Call
\internal
\value InvokeSlot
\value EmitSignal
\value ReadProperty
\value WriteProperty
\value ResetProperty
\value QueryPropertyDesignable
\value QueryPropertyScriptable
\value QueryPropertyStored
\value QueryPropertyEditable
\value QueryPropertyUser
\value CreateInstance
*/
/*!
\enum QMetaMethod::Access
This enum describes the access level of a method, following the conventions used in C++.
\value Private
\value Protected
\value Public
*/
static inline const QMetaObjectPrivate *priv(const uint* data)
{ return reinterpret_cast<const QMetaObjectPrivate*>(data); }
static inline const QByteArray stringData(const QMetaObject *mo, int index)
{
Q_ASSERT(priv(mo->d.data)->revision >= 7);
const QByteArrayDataPtr data = { const_cast<QByteArrayData*>(&mo->d.stringdata[index]) };
Q_ASSERT(data.ptr->ref.isStatic());
Q_ASSERT(data.ptr->alloc == 0);
Q_ASSERT(data.ptr->capacityReserved == 0);
Q_ASSERT(data.ptr->size >= 0);
return data;
}
static inline const char *rawStringData(const QMetaObject *mo, int index)
{
return stringData(mo, index).data();
}
static inline QByteArray typeNameFromTypeInfo(const QMetaObject *mo, uint typeInfo)
{
if (typeInfo & IsUnresolvedType) {
return stringData(mo, typeInfo & TypeNameIndexMask);
} else {
// ### Use the QMetaType::typeName() that returns QByteArray
const char *t = QMetaType::typeName(typeInfo);
return QByteArray::fromRawData(t, qstrlen(t));
}
}
static inline const char *rawTypeNameFromTypeInfo(const QMetaObject *mo, uint typeInfo)
{
return typeNameFromTypeInfo(mo, typeInfo).constData();
}
static inline int typeFromTypeInfo(const QMetaObject *mo, uint typeInfo)
{
if (!(typeInfo & IsUnresolvedType))
return typeInfo;
return QMetaType::type(stringData(mo, typeInfo & TypeNameIndexMask));
}
class QMetaMethodPrivate : public QMetaMethod
{
public:
static const QMetaMethodPrivate *get(const QMetaMethod *q)
{ return static_cast<const QMetaMethodPrivate *>(q); }
inline QByteArray signature() const;
inline QByteArray name() const;
inline int typesDataIndex() const;
inline const char *rawReturnTypeName() const;
inline int returnType() const;
inline int parameterCount() const;
inline int parametersDataIndex() const;
inline uint parameterTypeInfo(int index) const;
inline int parameterType(int index) const;
inline void getParameterTypes(int *types) const;
inline QList<QByteArray> parameterTypes() const;
inline QList<QByteArray> parameterNames() const;
inline QByteArray tag() const;
inline int ownMethodIndex() const;
private:
QMetaMethodPrivate();
};
/*!
\since 4.5
Constructs a new instance of this class. You can pass up to ten arguments
(\a val0, \a val1, \a val2, \a val3, \a val4, \a val5, \a val6, \a val7,
\a val8, and \a val9) to the constructor. Returns the new object, or 0 if
no suitable constructor is available.
Note that only constructors that are declared with the Q_INVOKABLE
modifier are made available through the meta-object system.
\sa Q_ARG(), constructor()
*/
QObject *QMetaObject::newInstance(QGenericArgument val0,
QGenericArgument val1,
QGenericArgument val2,
QGenericArgument val3,
QGenericArgument val4,
QGenericArgument val5,
QGenericArgument val6,
QGenericArgument val7,
QGenericArgument val8,
QGenericArgument val9) const
{
QByteArray constructorName = className();
{
int idx = constructorName.lastIndexOf(':');
if (idx != -1)
constructorName.remove(0, idx+1); // remove qualified part
}
QVarLengthArray<char, 512> sig;
sig.append(constructorName.constData(), constructorName.length());
sig.append('(');
enum { MaximumParamCount = 10 };
const char *typeNames[] = {val0.name(), val1.name(), val2.name(), val3.name(), val4.name(),
val5.name(), val6.name(), val7.name(), val8.name(), val9.name()};
int paramCount;
for (paramCount = 0; paramCount < MaximumParamCount; ++paramCount) {
int len = qstrlen(typeNames[paramCount]);
if (len <= 0)
break;
sig.append(typeNames[paramCount], len);
sig.append(',');
}
if (paramCount == 0)
sig.append(')'); // no parameters
else
sig[sig.size() - 1] = ')';
sig.append('\0');
int idx = indexOfConstructor(sig.constData());
if (idx < 0) {
QByteArray norm = QMetaObject::normalizedSignature(sig.constData());
idx = indexOfConstructor(norm.constData());
}
if (idx < 0)
return 0;
QObject *returnValue = 0;
void *param[] = {&returnValue, val0.data(), val1.data(), val2.data(), val3.data(), val4.data(),
val5.data(), val6.data(), val7.data(), val8.data(), val9.data()};
if (static_metacall(CreateInstance, idx, param) >= 0)
return 0;
return returnValue;
}
/*!
\internal
*/
int QMetaObject::static_metacall(Call cl, int idx, void **argv) const
{
Q_ASSERT(priv(d.data)->revision >= 6);
if (!d.static_metacall)
return 0;
d.static_metacall(0, cl, idx, argv);
return -1;
}
/*!
\internal
*/
int QMetaObject::metacall(QObject *object, Call cl, int idx, void **argv)
{
if (object->d_ptr->metaObject)
return object->d_ptr->metaObject->metaCall(object, cl, idx, argv);
else
return object->qt_metacall(cl, idx, argv);
}
static inline const char *objectClassName(const QMetaObject *m)
{
return rawStringData(m, priv(m->d.data)->className);
}
/*!
Returns the class name.
\sa superClass()
*/
const char *QMetaObject::className() const
{
return objectClassName(this);
}
/*!
\fn QMetaObject *QMetaObject::superClass() const
Returns the meta-object of the superclass, or 0 if there is no
such object.
\sa className()
*/
/*!
\internal
Returns \a obj if object \a obj inherits from this
meta-object; otherwise returns 0.
*/
QObject *QMetaObject::cast(QObject *obj) const
{
if (obj) {
const QMetaObject *m = obj->metaObject();
do {
if (m == this)
return obj;
} while ((m = m->d.superdata));
}
return 0;
}
/*!
\internal
Returns \a obj if object \a obj inherits from this
meta-object; otherwise returns 0.
*/
const QObject *QMetaObject::cast(const QObject *obj) const
{
if (obj) {
const QMetaObject *m = obj->metaObject();
do {
if (m == this)
return obj;
} while ((m = m->d.superdata));
}
return 0;
}
#ifndef QT_NO_TRANSLATION
/*!
\internal
*/
QString QMetaObject::tr(const char *s, const char *c, int n) const
{
return QCoreApplication::translate(objectClassName(this), s, c, n);
}
#endif // QT_NO_TRANSLATION
/*!
Returns the method offset for this class; i.e. the index position
of this class's first member function.
The offset is the sum of all the methods in the class's
superclasses (which is always positive since QObject has the
deleteLater() slot and a destroyed() signal).
\sa method(), methodCount(), indexOfMethod()
*/
int QMetaObject::methodOffset() const
{
int offset = 0;
const QMetaObject *m = d.superdata;
while (m) {
offset += priv(m->d.data)->methodCount;
m = m->d.superdata;
}
return offset;
}
/*!
Returns the enumerator offset for this class; i.e. the index
position of this class's first enumerator.
If the class has no superclasses with enumerators, the offset is
0; otherwise the offset is the sum of all the enumerators in the
class's superclasses.
\sa enumerator(), enumeratorCount(), indexOfEnumerator()
*/
int QMetaObject::enumeratorOffset() const
{
int offset = 0;
const QMetaObject *m = d.superdata;
while (m) {
offset += priv(m->d.data)->enumeratorCount;
m = m->d.superdata;
}
return offset;
}
/*!
Returns the property offset for this class; i.e. the index
position of this class's first property.
The offset is the sum of all the properties in the class's
superclasses (which is always positive since QObject has the
name() property).
\sa property(), propertyCount(), indexOfProperty()
*/
int QMetaObject::propertyOffset() const
{
int offset = 0;
const QMetaObject *m = d.superdata;
while (m) {
offset += priv(m->d.data)->propertyCount;
m = m->d.superdata;
}
return offset;
}
/*!
Returns the class information offset for this class; i.e. the
index position of this class's first class information item.
If the class has no superclasses with class information, the
offset is 0; otherwise the offset is the sum of all the class
information items in the class's superclasses.
\sa classInfo(), classInfoCount(), indexOfClassInfo()
*/
int QMetaObject::classInfoOffset() const
{
int offset = 0;
const QMetaObject *m = d.superdata;
while (m) {
offset += priv(m->d.data)->classInfoCount;
m = m->d.superdata;
}
return offset;
}
/*!
\since 4.5
Returns the number of constructors in this class.
\sa constructor(), indexOfConstructor()
*/
int QMetaObject::constructorCount() const
{
Q_ASSERT(priv(d.data)->revision >= 2);
return priv(d.data)->constructorCount;
}
/*!
Returns the number of methods in this class, including the number of
methods provided by each base class. These include signals and slots
as well as normal member functions.
Use code like the following to obtain a QStringList containing the methods
specific to a given class:
\snippet code/src_corelib_kernel_qmetaobject.cpp methodCount
\sa method(), methodOffset(), indexOfMethod()
*/
int QMetaObject::methodCount() const
{
int n = priv(d.data)->methodCount;
const QMetaObject *m = d.superdata;
while (m) {
n += priv(m->d.data)->methodCount;
m = m->d.superdata;
}
return n;
}
/*!
Returns the number of enumerators in this class.
\sa enumerator(), enumeratorOffset(), indexOfEnumerator()
*/
int QMetaObject::enumeratorCount() const
{
int n = priv(d.data)->enumeratorCount;
const QMetaObject *m = d.superdata;
while (m) {
n += priv(m->d.data)->enumeratorCount;
m = m->d.superdata;
}
return n;
}
/*!
Returns the number of properties in this class, including the number of
properties provided by each base class.
Use code like the following to obtain a QStringList containing the properties
specific to a given class:
\snippet code/src_corelib_kernel_qmetaobject.cpp propertyCount
\sa property(), propertyOffset(), indexOfProperty()
*/
int QMetaObject::propertyCount() const
{
int n = priv(d.data)->propertyCount;
const QMetaObject *m = d.superdata;
while (m) {
n += priv(m->d.data)->propertyCount;
m = m->d.superdata;
}
return n;
}
/*!
Returns the number of items of class information in this class.
\sa classInfo(), classInfoOffset(), indexOfClassInfo()
*/
int QMetaObject::classInfoCount() const
{
int n = priv(d.data)->classInfoCount;
const QMetaObject *m = d.superdata;
while (m) {
n += priv(m->d.data)->classInfoCount;
m = m->d.superdata;
}
return n;
}
// Returns \c true if the method defined by the given meta-object&handle
// matches the given name, argument count and argument types, otherwise
// returns \c false.
static bool methodMatch(const QMetaObject *m, int handle,
const QByteArray &name, int argc,
const QArgumentType *types)
{
Q_ASSERT(priv(m->d.data)->revision >= 7);
if (int(m->d.data[handle + 1]) != argc)
return false;
if (stringData(m, m->d.data[handle]) != name)
return false;
int paramsIndex = m->d.data[handle + 2] + 1;
for (int i = 0; i < argc; ++i) {
uint typeInfo = m->d.data[paramsIndex + i];
if (types[i].type()) {
if (types[i].type() != typeFromTypeInfo(m, typeInfo))
return false;
} else {
if (types[i].name() != typeNameFromTypeInfo(m, typeInfo))
return false;
}
}
return true;
}
/**
* \internal
* helper function for indexOf{Method,Slot,Signal}, returns the relative index of the method within
* the baseObject
* \a MethodType might be MethodSignal or MethodSlot, or 0 to match everything.
*/
template<int MethodType>
static inline int indexOfMethodRelative(const QMetaObject **baseObject,
const QByteArray &name, int argc,
const QArgumentType *types)
{
for (const QMetaObject *m = *baseObject; m; m = m->d.superdata) {
Q_ASSERT(priv(m->d.data)->revision >= 7);
int i = (MethodType == MethodSignal)
? (priv(m->d.data)->signalCount - 1) : (priv(m->d.data)->methodCount - 1);
const int end = (MethodType == MethodSlot)
? (priv(m->d.data)->signalCount) : 0;
for (; i >= end; --i) {
int handle = priv(m->d.data)->methodData + 5*i;
if (methodMatch(m, handle, name, argc, types)) {
*baseObject = m;
return i;
}
}
}
return -1;
}
/*!
\since 4.5
Finds \a constructor and returns its index; otherwise returns -1.
Note that the \a constructor has to be in normalized form, as returned
by normalizedSignature().
\sa constructor(), constructorCount(), normalizedSignature()
*/
int QMetaObject::indexOfConstructor(const char *constructor) const
{
Q_ASSERT(priv(d.data)->revision >= 7);
QArgumentTypeArray types;
QByteArray name = QMetaObjectPrivate::decodeMethodSignature(constructor, types);
return QMetaObjectPrivate::indexOfConstructor(this, name, types.size(), types.constData());
}
/*!
Finds \a method and returns its index; otherwise returns -1.
Note that the \a method has to be in normalized form, as returned
by normalizedSignature().
\sa method(), methodCount(), methodOffset(), normalizedSignature()
*/
int QMetaObject::indexOfMethod(const char *method) const
{
const QMetaObject *m = this;
int i;
Q_ASSERT(priv(m->d.data)->revision >= 7);
QArgumentTypeArray types;
QByteArray name = QMetaObjectPrivate::decodeMethodSignature(method, types);
i = indexOfMethodRelative<0>(&m, name, types.size(), types.constData());
if (i >= 0)
i += m->methodOffset();
return i;
}
// Parses a string of comma-separated types into QArgumentTypes.
// No normalization of the type names is performed.
static void argumentTypesFromString(const char *str, const char *end,
QArgumentTypeArray &types)
{
Q_ASSERT(str <= end);
while (str != end) {
if (!types.isEmpty())
++str; // Skip comma
const char *begin = str;
int level = 0;
while (str != end && (level > 0 || *str != ',')) {
if (*str == '<')
++level;
else if (*str == '>')
--level;
++str;
}
types += QArgumentType(QByteArray(begin, str - begin));
}
}
// Given a method \a signature (e.g. "foo(int,double)"), this function
// populates the argument \a types array and returns the method name.
QByteArray QMetaObjectPrivate::decodeMethodSignature(
const char *signature, QArgumentTypeArray &types)
{
Q_ASSERT(signature != 0);
const char *lparens = strchr(signature, '(');
if (!lparens)
return QByteArray();
const char *rparens = strrchr(lparens + 1, ')');
if (!rparens || *(rparens+1))
return QByteArray();
int nameLength = lparens - signature;
argumentTypesFromString(lparens + 1, rparens, types);
return QByteArray::fromRawData(signature, nameLength);
}
/*!
Finds \a signal and returns its index; otherwise returns -1.
This is the same as indexOfMethod(), except that it will return
-1 if the method exists but isn't a signal.
Note that the \a signal has to be in normalized form, as returned
by normalizedSignature().
\sa indexOfMethod(), normalizedSignature(), method(), methodCount(), methodOffset()
*/
int QMetaObject::indexOfSignal(const char *signal) const
{
const QMetaObject *m = this;
int i;
Q_ASSERT(priv(m->d.data)->revision >= 7);
QArgumentTypeArray types;
QByteArray name = QMetaObjectPrivate::decodeMethodSignature(signal, types);
i = QMetaObjectPrivate::indexOfSignalRelative(&m, name, types.size(), types.constData());
if (i >= 0)
i += m->methodOffset();
return i;
}
/*!
\internal
Same as QMetaObject::indexOfSignal, but the result is the local offset to the base object.
\a baseObject will be adjusted to the enclosing QMetaObject, or 0 if the signal is not found
*/
int QMetaObjectPrivate::indexOfSignalRelative(const QMetaObject **baseObject,
const QByteArray &name, int argc,
const QArgumentType *types)
{
int i = indexOfMethodRelative<MethodSignal>(baseObject, name, argc, types);
#ifndef QT_NO_DEBUG
const QMetaObject *m = *baseObject;
if (i >= 0 && m && m->d.superdata) {
int conflict = indexOfMethod(m->d.superdata, name, argc, types);
if (conflict >= 0) {
QMetaMethod conflictMethod = m->d.superdata->method(conflict);
qWarning("QMetaObject::indexOfSignal: signal %s from %s redefined in %s",
conflictMethod.methodSignature().constData(),
objectClassName(m->d.superdata), objectClassName(m));
}
}
#endif
return i;
}
/*!
Finds \a slot and returns its index; otherwise returns -1.
This is the same as indexOfMethod(), except that it will return
-1 if the method exists but isn't a slot.
\sa indexOfMethod(), method(), methodCount(), methodOffset()
*/
int QMetaObject::indexOfSlot(const char *slot) const
{
const QMetaObject *m = this;
int i;
Q_ASSERT(priv(m->d.data)->revision >= 7);
QArgumentTypeArray types;
QByteArray name = QMetaObjectPrivate::decodeMethodSignature(slot, types);
i = QMetaObjectPrivate::indexOfSlotRelative(&m, name, types.size(), types.constData());
if (i >= 0)
i += m->methodOffset();
return i;
}
// same as indexOfSignalRelative but for slots.
int QMetaObjectPrivate::indexOfSlotRelative(const QMetaObject **m,
const QByteArray &name, int argc,
const QArgumentType *types)
{
return indexOfMethodRelative<MethodSlot>(m, name, argc, types);
}
int QMetaObjectPrivate::indexOfSignal(const QMetaObject *m, const QByteArray &name,
int argc, const QArgumentType *types)
{
int i = indexOfSignalRelative(&m, name, argc, types);
if (i >= 0)
i += m->methodOffset();
return i;
}
int QMetaObjectPrivate::indexOfSlot(const QMetaObject *m, const QByteArray &name,
int argc, const QArgumentType *types)
{
int i = indexOfSlotRelative(&m, name, argc, types);
if (i >= 0)
i += m->methodOffset();
return i;
}
int QMetaObjectPrivate::indexOfMethod(const QMetaObject *m, const QByteArray &name,
int argc, const QArgumentType *types)
{
int i = indexOfMethodRelative<0>(&m, name, argc, types);
if (i >= 0)
i += m->methodOffset();
return i;
}
int QMetaObjectPrivate::indexOfConstructor(const QMetaObject *m, const QByteArray &name,
int argc, const QArgumentType *types)
{
for (int i = priv(m->d.data)->constructorCount-1; i >= 0; --i) {
int handle = priv(m->d.data)->constructorData + 5*i;
if (methodMatch(m, handle, name, argc, types))
return i;
}
return -1;
}
/*!
\internal
\since 5.0
Returns the signal offset for the class \a m; i.e., the index position
of the class's first signal.
Similar to QMetaObject::methodOffset(), but non-signal methods are
excluded.
*/
int QMetaObjectPrivate::signalOffset(const QMetaObject *m)
{
Q_ASSERT(m != 0);
int offset = 0;
for (m = m->d.superdata; m; m = m->d.superdata)
offset += priv(m->d.data)->signalCount;
return offset;
}
/*!
\internal
\since 5.0
Returns the number of signals for the class \a m, including the signals
for the base class.
Similar to QMetaObject::methodCount(), but non-signal methods are
excluded.
*/
int QMetaObjectPrivate::absoluteSignalCount(const QMetaObject *m)
{
Q_ASSERT(m != 0);
int n = priv(m->d.data)->signalCount;
for (m = m->d.superdata; m; m = m->d.superdata)
n += priv(m->d.data)->signalCount;
return n;
}
/*!
\internal
\since 5.0
Returns the index of the signal method \a m.
Similar to QMetaMethod::methodIndex(), but non-signal methods are
excluded.
*/
int QMetaObjectPrivate::signalIndex(const QMetaMethod &m)
{
if (!m.mobj)
return -1;
return QMetaMethodPrivate::get(&m)->ownMethodIndex() + signalOffset(m.mobj);
}
/*!
\internal
\since 5.0
Returns the signal for the given meta-object \a m at \a signal_index.
It it different from QMetaObject::method(); the index should not include
non-signal methods.
*/
QMetaMethod QMetaObjectPrivate::signal(const QMetaObject *m, int signal_index)
{
QMetaMethod result;
if (signal_index < 0)
return result;
Q_ASSERT(m != 0);
int i = signal_index;
i -= signalOffset(m);
if (i < 0 && m->d.superdata)
return signal(m->d.superdata, signal_index);
if (i >= 0 && i < priv(m->d.data)->signalCount) {
result.mobj = m;
result.handle = priv(m->d.data)->methodData + 5*i;
}
return result;
}
/*!
\internal
Returns \c true if the \a signalTypes and \a methodTypes are
compatible; otherwise returns \c false.
*/
bool QMetaObjectPrivate::checkConnectArgs(int signalArgc, const QArgumentType *signalTypes,
int methodArgc, const QArgumentType *methodTypes)
{
if (signalArgc < methodArgc)
return false;
for (int i = 0; i < methodArgc; ++i) {
if (signalTypes[i] != methodTypes[i])
return false;
}
return true;
}
/*!
\internal
Returns \c true if the \a signal and \a method arguments are
compatible; otherwise returns \c false.
*/
bool QMetaObjectPrivate::checkConnectArgs(const QMetaMethodPrivate *signal,
const QMetaMethodPrivate *method)
{
if (signal->methodType() != QMetaMethod::Signal)
return false;
if (signal->parameterCount() < method->parameterCount())
return false;
const QMetaObject *smeta = signal->enclosingMetaObject();
const QMetaObject *rmeta = method->enclosingMetaObject();
for (int i = 0; i < method->parameterCount(); ++i) {
uint sourceTypeInfo = signal->parameterTypeInfo(i);
uint targetTypeInfo = method->parameterTypeInfo(i);
if ((sourceTypeInfo & IsUnresolvedType)
|| (targetTypeInfo & IsUnresolvedType)) {
QByteArray sourceName = typeNameFromTypeInfo(smeta, sourceTypeInfo);
QByteArray targetName = typeNameFromTypeInfo(rmeta, targetTypeInfo);
if (sourceName != targetName)
return false;
} else {
int sourceType = typeFromTypeInfo(smeta, sourceTypeInfo);
int targetType = typeFromTypeInfo(rmeta, targetTypeInfo);
if (sourceType != targetType)
return false;
}
}
return true;
}
static const QMetaObject *QMetaObject_findMetaObject(const QMetaObject *self, const char *name)
{
while (self) {
if (strcmp(objectClassName(self), name) == 0)
return self;
if (self->d.relatedMetaObjects) {
Q_ASSERT(priv(self->d.data)->revision >= 2);
const QMetaObject * const *e = self->d.relatedMetaObjects;
if (e) {
while (*e) {
if (const QMetaObject *m =QMetaObject_findMetaObject((*e), name))
return m;
++e;
}
}
}
self = self->d.superdata;
}
return self;
}
/*!
Finds enumerator \a name and returns its index; otherwise returns
-1.
\sa enumerator(), enumeratorCount(), enumeratorOffset()
*/
int QMetaObject::indexOfEnumerator(const char *name) const
{
const QMetaObject *m = this;
while (m) {
const QMetaObjectPrivate *d = priv(m->d.data);
for (int i = d->enumeratorCount - 1; i >= 0; --i) {
const char *prop = rawStringData(m, m->d.data[d->enumeratorData + 4*i]);
if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) {
i += m->enumeratorOffset();
return i;
}
}
m = m->d.superdata;
}
return -1;
}
/*!
Finds property \a name and returns its index; otherwise returns
-1.
\sa property(), propertyCount(), propertyOffset()
*/
int QMetaObject::indexOfProperty(const char *name) const
{
const QMetaObject *m = this;
while (m) {
const QMetaObjectPrivate *d = priv(m->d.data);
for (int i = d->propertyCount-1; i >= 0; --i) {
const char *prop = rawStringData(m, m->d.data[d->propertyData + 3*i]);
if (name[0] == prop[0] && strcmp(name + 1, prop + 1) == 0) {
i += m->propertyOffset();
return i;
}
}
m = m->d.superdata;
}
Q_ASSERT(priv(this->d.data)->revision >= 3);
if (priv(this->d.data)->flags & DynamicMetaObject) {
QAbstractDynamicMetaObject *me =
const_cast<QAbstractDynamicMetaObject *>(static_cast<const QAbstractDynamicMetaObject *>(this));
return me->createProperty(name, 0);