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
141 bool invokeOnGadget(void *gadget,
142 QGenericReturnArgument returnValue,
143 QGenericArgument val0 = QGenericArgument(nullptr),
144 QGenericArgument val1 = QGenericArgument(),
145 QGenericArgument val2 = QGenericArgument(),
146 QGenericArgument val3 = QGenericArgument(),
147 QGenericArgument val4 = QGenericArgument(),
148 QGenericArgument val5 = QGenericArgument(),
149 QGenericArgument val6 = QGenericArgument(),
150 QGenericArgument val7 = QGenericArgument(),
151 QGenericArgument val8 = QGenericArgument(),
152 QGenericArgument val9 = QGenericArgument()) const;
153 inline bool invokeOnGadget(void *gadget,
154 QGenericArgument val0 = QGenericArgument(nullptr),
155 QGenericArgument val1 = QGenericArgument(),
156 QGenericArgument val2 = QGenericArgument(),
157 QGenericArgument val3 = QGenericArgument(),
158 QGenericArgument val4 = QGenericArgument(),
159 QGenericArgument val5 = QGenericArgument(),
160 QGenericArgument val6 = QGenericArgument(),
161 QGenericArgument val7 = QGenericArgument(),
162 QGenericArgument val8 = QGenericArgument(),
163 QGenericArgument val9 = QGenericArgument()) const
164 {
165 return invokeOnGadget(gadget, QGenericReturnArgument(),
166 val0, val1, val2, val3, val4, val5, val6, val7, val8, val9);
167 }
168
169 inline bool isValid() const { return mobj != nullptr; }
170
171 template <typename PointerToMemberFunction>
172 static inline QMetaMethod fromSignal(PointerToMemberFunction signal)
173 {
174 typedef QtPrivate::FunctionPointer<PointerToMemberFunction> SignalType;
175 Q_STATIC_ASSERT_X(QtPrivate::HasQ_OBJECT_Macro<typename SignalType::Object>::Value,
176 "No Q_OBJECT in the class with the signal");
177 return fromSignalImpl(&SignalType::Object::staticMetaObject,
178 reinterpret_cast<void **>(&signal));
179 }
180
181private:
182#if QT_DEPRECATED_SINCE(5,0)
183 // signature() has been renamed to methodSignature() in Qt 5.
184 // Warning, that function returns a QByteArray; check the life time if
185 // you convert to char*.
186 char *signature(struct renamedInQt5_warning_checkTheLifeTime * = nullptr) Q_DECL_EQ_DELETE;
187#endif
188 static QMetaMethod fromSignalImpl(const QMetaObject *, void **);
189
190 const QMetaObject *mobj;
191 uint handle;
192 friend class QMetaMethodPrivate;
193 friend struct QMetaObject;
194 friend struct QMetaObjectPrivate;
195 friend class QObject;
196 friend bool operator==(const QMetaMethod &m1, const QMetaMethod &m2);
197 friend bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2);
198};
199Q_DECLARE_TYPEINFO(QMetaMethod, Q_MOVABLE_TYPE);
200
201inline bool operator==(const QMetaMethod &m1, const QMetaMethod &m2)
202{ return m1.mobj == m2.mobj && m1.handle == m2.handle; }
203inline bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2)
204{ return !(m1 == m2); }
205
206class Q_CORE_EXPORT QMetaEnum
207{
208public:
209 Q_DECL_CONSTEXPR inline QMetaEnum() : mobj(nullptr), handle(0) {}
210
211 const char *name() 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 Q_ENUM or Q_FLAG");
233 const QMetaObject *metaObject = qt_getEnumMetaObject(T());
234 const char *name = qt_getEnumName(T());
235 return metaObject->enumerator(metaObject->indexOfEnumerator(name));
236 }
237
238private:
239 const QMetaObject *mobj;
240 uint handle;
241 friend struct QMetaObject;
242};
243Q_DECLARE_TYPEINFO(QMetaEnum, Q_MOVABLE_TYPE);
244
245class Q_CORE_EXPORT QMetaProperty
246{
247public:
248 QMetaProperty();
249
250 const char *name() const;
251 const char *typeName() const;
252 QVariant::Type type() const;
253 int userType() const;
254 int propertyIndex() const;
255
256 bool isReadable() const;
257 bool isWritable() const;
258 bool isResettable() const;
259 bool isDesignable(const QObject *obj = nullptr) const;
260 bool isScriptable(const QObject *obj = nullptr) const;
261 bool isStored(const QObject *obj = nullptr) const;
262 bool isEditable(const QObject *obj = nullptr) const;
263 bool isUser(const QObject *obj = nullptr) const;
264 bool isConstant() const;
265 bool isFinal() const;
266
267 bool isFlagType() const;
268 bool isEnumType() const;
269 QMetaEnum enumerator() const;
270
271 bool hasNotifySignal() const;
272 QMetaMethod notifySignal() const;
273 int notifySignalIndex() const;
274
275 int revision() const;
276
277 QVariant read(const QObject *obj) const;
278 bool write(QObject *obj, const QVariant &value) const;
279 bool reset(QObject *obj) const;
280
281 QVariant readOnGadget(const void *gadget) const;
282 bool writeOnGadget(void *gadget, const QVariant &value) const;
283 bool resetOnGadget(void *gadget) const;
284
285 bool hasStdCppSet() const;
286 inline bool isValid() const { return isReadable(); }
287 inline const QMetaObject *enclosingMetaObject() const { return mobj; }
288
289private:
290 int registerPropertyType() const;
291
292 const QMetaObject *mobj;
293 uint handle;
294 int idx;
295 QMetaEnum menum;
296 friend struct QMetaObject;
297 friend struct QMetaObjectPrivate;
298};
299
300class Q_CORE_EXPORT QMetaClassInfo
301{
302public:
303 Q_DECL_CONSTEXPR inline QMetaClassInfo() : mobj(nullptr), handle(0) {}
304 const char *name() const;
305 const char *value() const;
306 inline const QMetaObject *enclosingMetaObject() const { return mobj; }
307private:
308 const QMetaObject *mobj;
309 uint handle;
310 friend struct QMetaObject;
311};
312Q_DECLARE_TYPEINFO(QMetaClassInfo, Q_MOVABLE_TYPE);
313
314QT_END_NAMESPACE
315
316#endif // QMETAOBJECT_H
317