1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2014 Olivier Goffart <ogoffart@woboq.com>
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#ifndef QMETAOBJECT_H
42#define QMETAOBJECT_H
43
44#include <QtCore/qobjectdefs.h>
45#include <QtCore/qvariant.h>
46
47QT_BEGIN_NAMESPACE
48
49
50template <typename T> class QList;
51
52#define Q_METAMETHOD_INVOKE_MAX_ARGS 10
53
54class Q_CORE_EXPORT QMetaMethod
55{
56public:
57 Q_DECL_CONSTEXPR inline QMetaMethod() : mobj(nullptr), handle(0) {}
58
59 QByteArray methodSignature() const;
60 QByteArray name() const;
61 const char *typeName() const;
62 int returnType() const;
63 int parameterCount() const;
64 int parameterType(int index) const;
65 void getParameterTypes(int *types) const;
66 QList<QByteArray> parameterTypes() const;
67 QList<QByteArray> parameterNames() const;
68 const char *tag() const;
69 enum Access { Private, Protected, Public };
70 Access access() const;
71 enum MethodType { Method, Signal, Slot, Constructor };
72 MethodType methodType() const;
73 enum Attributes { Compatibility = 0x1, Cloned = 0x2, Scriptable = 0x4 };
74 int attributes() const;
75 int methodIndex() const;
76 int revision() const;
77
78 inline const QMetaObject *enclosingMetaObject() const { return mobj; }
79
80 bool invoke(QObject *object,
81 Qt::ConnectionType connectionType,
82 QGenericReturnArgument returnValue,
83 QGenericArgument val0 = QGenericArgument(nullptr),
84 QGenericArgument val1 = QGenericArgument(),
85 QGenericArgument val2 = QGenericArgument(),
86 QGenericArgument val3 = QGenericArgument(),
87 QGenericArgument val4 = QGenericArgument(),
88 QGenericArgument val5 = QGenericArgument(),
89 QGenericArgument val6 = QGenericArgument(),
90 QGenericArgument val7 = QGenericArgument(),
91 QGenericArgument val8 = QGenericArgument(),
92 QGenericArgument val9 = QGenericArgument()) const;
93 inline bool invoke(QObject *object,
94 QGenericReturnArgument returnValue,
95 QGenericArgument val0 = QGenericArgument(nullptr),
96 QGenericArgument val1 = QGenericArgument(),
97 QGenericArgument val2 = QGenericArgument(),
98 QGenericArgument val3 = QGenericArgument(),
99 QGenericArgument val4 = QGenericArgument(),
100 QGenericArgument val5 = QGenericArgument(),
101 QGenericArgument val6 = QGenericArgument(),
102 QGenericArgument val7 = QGenericArgument(),
103 QGenericArgument val8 = QGenericArgument(),
104 QGenericArgument val9 = QGenericArgument()) const
105 {
106 return invoke(object, Qt::AutoConnection, returnValue,
107 val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
108 }
109 inline bool invoke(QObject *object,
110 Qt::ConnectionType connectionType,
111 QGenericArgument val0 = QGenericArgument(nullptr),
112 QGenericArgument val1 = QGenericArgument(),
113 QGenericArgument val2 = QGenericArgument(),
114 QGenericArgument val3 = QGenericArgument(),
115 QGenericArgument val4 = QGenericArgument(),
116 QGenericArgument val5 = QGenericArgument(),
117 QGenericArgument val6 = QGenericArgument(),
118 QGenericArgument val7 = QGenericArgument(),
119 QGenericArgument val8 = QGenericArgument(),
120 QGenericArgument val9 = QGenericArgument()) const
121 {
122 return invoke(object, connectionType, QGenericReturnArgument(),
123 val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
124 }
125 inline bool invoke(QObject *object,
126 QGenericArgument val0 = QGenericArgument(nullptr),
127 QGenericArgument val1 = QGenericArgument(),
128 QGenericArgument val2 = QGenericArgument(),
129 QGenericArgument val3 = QGenericArgument(),
130 QGenericArgument val4 = QGenericArgument(),
131 QGenericArgument val5 = QGenericArgument(),
132 QGenericArgument val6 = QGenericArgument(),
133 QGenericArgument val7 = QGenericArgument(),
134 QGenericArgument val8 = QGenericArgument(),
135 QGenericArgument val9 = QGenericArgument()) const
136 {
137 return invoke(object, Qt::AutoConnection, QGenericReturnArgument(),
138 val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
139 }
140 bool invokeOnGadget(void *gadget,
141 QGenericReturnArgument returnValue,
142 QGenericArgument val0 = QGenericArgument(nullptr),
143 QGenericArgument val1 = QGenericArgument(),
144 QGenericArgument val2 = QGenericArgument(),
145 QGenericArgument val3 = QGenericArgument(),
146 QGenericArgument val4 = QGenericArgument(),
147 QGenericArgument val5 = QGenericArgument(),
148 QGenericArgument val6 = QGenericArgument(),
149 QGenericArgument val7 = QGenericArgument(),
150 QGenericArgument val8 = QGenericArgument(),
151 QGenericArgument val9 = QGenericArgument()) const;
152 inline bool invokeOnGadget(void *gadget,
153 QGenericArgument val0 = QGenericArgument(nullptr),
154 QGenericArgument val1 = QGenericArgument(),
155 QGenericArgument val2 = QGenericArgument(),
156 QGenericArgument val3 = QGenericArgument(),
157 QGenericArgument val4 = QGenericArgument(),
158 QGenericArgument val5 = QGenericArgument(),
159 QGenericArgument val6 = QGenericArgument(),
160 QGenericArgument val7 = QGenericArgument(),
161 QGenericArgument val8 = QGenericArgument(),
162 QGenericArgument val9 = QGenericArgument()) const
163 {
164 return invokeOnGadget(gadget, QGenericReturnArgument(),
165 val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
166 }
167
168 inline bool isValid() const { return mobj != nullptr; }
169
170 template <typename PointerToMemberFunction>
171 static inline QMetaMethod fromSignal(PointerToMemberFunction signal)
172 {
173 typedef QtPrivate::FunctionPointer<PointerToMemberFunction> SignalType;
174 Q_STATIC_ASSERT_X(QtPrivate::HasQ_OBJECT_Macro<typename SignalType::Object>::Value,
175 "No Q_OBJECT in the class with the signal");
176 return fromSignalImpl(&SignalType::Object::staticMetaObject,
177 reinterpret_cast<void **>(&signal));
178 }
179
180private:
181#if QT_DEPRECATED_SINCE(5,0)
182 // signature() has been renamed to methodSignature() in Qt 5.
183 // Warning, that function returns a QByteArray; check the life time if
184 // you convert to char*.
185 char *signature(struct renamedInQt5_warning_checkTheLifeTime * = nullptr) = delete;
186#endif
187 static QMetaMethod fromSignalImpl(const QMetaObject *, void **);
188
189 const QMetaObject *mobj;
190 uint handle;
191 friend class QMetaMethodPrivate;
192 friend struct QMetaObject;
193 friend struct QMetaObjectPrivate;
194 friend class QObject;
195 friend bool operator==(const QMetaMethod &m1, const QMetaMethod &m2);
196 friend bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2);
197};
198Q_DECLARE_TYPEINFO(QMetaMethod, Q_MOVABLE_TYPE);
199
200inline bool operator==(const QMetaMethod &m1, const QMetaMethod &m2)
201{ return m1.mobj == m2.mobj && m1.handle == m2.handle; }
202inline bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2)
203{ return !(m1 == m2); }
204
205class Q_CORE_EXPORT QMetaEnum
206{
207public:
208 Q_DECL_CONSTEXPR inline QMetaEnum() : mobj(nullptr), handle(0) {}
209
210 const char *name() const;
211 const char *enumName() const;
212 bool isFlag() const;
213 bool isScoped() const;
214
215 int keyCount() const;
216 const char *key(int index) const;
217 int value(int index) const;
218
219 const char *scope() const;
220
221 int keyToValue(const char *key, bool *ok = nullptr) const;
222 const char* valueToKey(int value) const;
223 int keysToValue(const char * keys, bool *ok = nullptr) const;
224 QByteArray valueToKeys(int value) const;
225
226 inline const QMetaObject *enclosingMetaObject() const { return mobj; }
227
228 inline bool isValid() const { return name() != nullptr; }
229
230 template<typename T> static QMetaEnum fromType() {
231 Q_STATIC_ASSERT_X(QtPrivate::IsQEnumHelper<T>::Value,
232 "QMetaEnum::fromType only works with enums declared as "
233 "Q_ENUM, Q_ENUM_NS, Q_FLAG or Q_FLAG_NS");
234 const QMetaObject *metaObject = qt_getEnumMetaObject(T());
235 const char *name = qt_getEnumName(T());
236 return metaObject->enumerator(metaObject->indexOfEnumerator(name));
237 }
238
239private:
240 const QMetaObject *mobj;
241 uint handle;
242 friend struct QMetaObject;
243};
244Q_DECLARE_TYPEINFO(QMetaEnum, Q_MOVABLE_TYPE);
245
246class Q_CORE_EXPORT QMetaProperty
247{
248public:
249 QMetaProperty();
250
251 const char *name() const;
252 const char *typeName() const;
253 QVariant::Type type() const;
254 int userType() const;
255 int propertyIndex() const;
256 int relativePropertyIndex() const;
257
258 bool isReadable() const;
259 bool isWritable() const;
260 bool isResettable() const;
261 bool isDesignable(const QObject *obj = nullptr) const;
262 bool isScriptable(const QObject *obj = nullptr) const;
263 bool isStored(const QObject *obj = nullptr) const;
264#if QT_DEPRECATED_SINCE(5, 15)
265 QT_DEPRECATED_VERSION_5_15 bool isEditable(const QObject *obj = nullptr) const;
266#endif
267 bool isUser(const QObject *obj = nullptr) const;
268 bool isConstant() const;
269 bool isFinal() const;
270 bool isRequired() const;
271
272 bool isFlagType() const;
273 bool isEnumType() const;
274 QMetaEnum enumerator() const;
275
276 bool hasNotifySignal() const;
277 QMetaMethod notifySignal() const;
278 int notifySignalIndex() const;
279
280 int revision() const;
281
282 QVariant read(const QObject *obj) const;
283 bool write(QObject *obj, const QVariant &value) const;
284 bool reset(QObject *obj) const;
285
286 QVariant readOnGadget(const void *gadget) const;
287 bool writeOnGadget(void *gadget, const QVariant &value) const;
288 bool resetOnGadget(void *gadget) const;
289
290 bool hasStdCppSet() const;
291 inline bool isValid() const { return isReadable(); }
292 inline const QMetaObject *enclosingMetaObject() const { return mobj; }
293
294private:
295 int registerPropertyType() const;
296
297 const QMetaObject *mobj;
298 uint handle;
299 int idx;
300 QMetaEnum menum;
301 friend struct QMetaObject;
302 friend struct QMetaObjectPrivate;
303};
304
305class Q_CORE_EXPORT QMetaClassInfo
306{
307public:
308 Q_DECL_CONSTEXPR inline QMetaClassInfo() : mobj(nullptr), handle(0) {}
309 const char *name() const;
310 const char *value() const;
311 inline const QMetaObject *enclosingMetaObject() const { return mobj; }
312private:
313 const QMetaObject *mobj;
314 uint handle;
315 friend struct QMetaObject;
316};
317Q_DECLARE_TYPEINFO(QMetaClassInfo, Q_MOVABLE_TYPE);
318
319QT_END_NAMESPACE
320
321#endif // QMETAOBJECT_H
322

source code of qtbase/src/corelib/kernel/qmetaobject.h