Warning: That file was not part of the compilation database. It may have many parsing errors.
1 | /**************************************************************************** |
---|---|
2 | ** |
3 | ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). |
4 | ** Contact: http://www.qt-project.org/legal |
5 | ** |
6 | ** This file is part of the QtTest module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and Digia. For licensing terms and |
14 | ** conditions see http://qt.digia.com/licensing. For further information |
15 | ** use the contact form at http://qt.digia.com/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 2.1 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
24 | ** |
25 | ** In addition, as a special exception, Digia gives you certain additional |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
28 | ** |
29 | ** GNU General Public License Usage |
30 | ** Alternatively, this file may be used under the terms of the GNU |
31 | ** General Public License version 3.0 as published by the Free Software |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the |
33 | ** packaging of this file. Please review the following information to |
34 | ** ensure the GNU General Public License version 3.0 requirements will be |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. |
36 | ** |
37 | ** |
38 | ** $QT_END_LICENSE$ |
39 | ** |
40 | ****************************************************************************/ |
41 | |
42 | #ifndef QSIGNALSPY_H |
43 | #define QSIGNALSPY_H |
44 | |
45 | #include <QtCore/qbytearray.h> |
46 | #include <QtCore/qlist.h> |
47 | #include <QtCore/qobject.h> |
48 | #include <QtCore/qmetaobject.h> |
49 | #include <QtCore/qvariant.h> |
50 | |
51 | QT_BEGIN_HEADER |
52 | |
53 | QT_BEGIN_NAMESPACE |
54 | |
55 | QT_MODULE(Test) |
56 | |
57 | class QVariant; |
58 | |
59 | /* ### Qt5: change the class to use regular BC mechanisms, such that we can |
60 | * implement things like suggested in task 160192. */ |
61 | class QSignalSpy: public QObject, public QList<QList<QVariant> > |
62 | { |
63 | public: |
64 | QSignalSpy(QObject *obj, const char *aSignal) |
65 | { |
66 | #ifdef Q_CC_BOR |
67 | const int memberOffset = QObject::staticMetaObject.methodCount(); |
68 | #else |
69 | static const int memberOffset = QObject::staticMetaObject.methodCount(); |
70 | #endif |
71 | Q_ASSERT(obj); |
72 | Q_ASSERT(aSignal); |
73 | |
74 | if (((aSignal[0] - |
75 | qWarning("QSignalSpy: Not a valid signal, use the SIGNAL macro"); |
76 | return; |
77 | } |
78 | |
79 | QByteArray ba = QMetaObject::normalizedSignature(aSignal + 1); |
80 | const QMetaObject *mo = obj->metaObject(); |
81 | int sigIndex = mo->indexOfMethod(ba.constData()); |
82 | if (sigIndex < 0) { |
83 | qWarning("QSignalSpy: No such signal: '%s'", ba.constData()); |
84 | return; |
85 | } |
86 | |
87 | if (!QMetaObject::connect(obj, sigIndex, this, memberOffset, |
88 | Qt::DirectConnection, 0)) { |
89 | qWarning("QSignalSpy: QMetaObject::connect returned false. Unable to connect."); |
90 | return; |
91 | } |
92 | sig = ba; |
93 | initArgs(mo->method(sigIndex)); |
94 | } |
95 | |
96 | inline bool isValid() const { return !sig.isEmpty(); } |
97 | inline QByteArray signal() const { return sig; } |
98 | |
99 | |
100 | int qt_metacall(QMetaObject::Call call, int methodId, void **a) |
101 | { |
102 | methodId = QObject::qt_metacall(call, methodId, a); |
103 | if (methodId < 0) |
104 | return methodId; |
105 | |
106 | if (call == QMetaObject::InvokeMetaMethod) { |
107 | if (methodId == 0) { |
108 | appendArgs(a); |
109 | } |
110 | --methodId; |
111 | } |
112 | return methodId; |
113 | } |
114 | |
115 | private: |
116 | void initArgs(const QMetaMethod &member) |
117 | { |
118 | QList<QByteArray> params = member.parameterTypes(); |
119 | for (int i = 0; i < params.count(); ++i) { |
120 | int tp = QMetaType::type(params.at(i).constData()); |
121 | if (tp == QMetaType::Void) |
122 | qWarning("Don't know how to handle '%s', use qRegisterMetaType to register it.", |
123 | params.at(i).constData()); |
124 | args << tp; |
125 | } |
126 | } |
127 | |
128 | void appendArgs(void **a) |
129 | { |
130 | QList<QVariant> list; |
131 | for (int i = 0; i < args.count(); ++i) { |
132 | QMetaType::Type type = static_cast<QMetaType::Type>(args.at(i)); |
133 | list << QVariant(type, a[i + 1]); |
134 | } |
135 | append(list); |
136 | } |
137 | |
138 | // the full, normalized signal name |
139 | QByteArray sig; |
140 | // holds the QMetaType types for the argument list of the signal |
141 | QList<int> args; |
142 | }; |
143 | |
144 | QT_END_NAMESPACE |
145 | |
146 | QT_END_HEADER |
147 | |
148 | #endif |
149 |
Warning: That file was not part of the compilation database. It may have many parsing errors.