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 | |
47 | QT_BEGIN_NAMESPACE |
48 | |
49 | |
50 | template <typename T> class QList; |
51 | |
52 | #define Q_METAMETHOD_INVOKE_MAX_ARGS 10 |
53 | |
54 | class Q_CORE_EXPORT QMetaMethod |
55 | { |
56 | public: |
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 | |
181 | private: |
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 | }; |
199 | Q_DECLARE_TYPEINFO(QMetaMethod, Q_MOVABLE_TYPE); |
200 | |
201 | inline bool operator==(const QMetaMethod &m1, const QMetaMethod &m2) |
202 | { return m1.mobj == m2.mobj && m1.handle == m2.handle; } |
203 | inline bool operator!=(const QMetaMethod &m1, const QMetaMethod &m2) |
204 | { return !(m1 == m2); } |
205 | |
206 | class Q_CORE_EXPORT QMetaEnum |
207 | { |
208 | public: |
209 | Q_DECL_CONSTEXPR inline QMetaEnum() : mobj(nullptr), handle(0) {} |
210 | |
211 | const char *name() const; |
212 | const char *enumName() const; |
213 | bool isFlag() const; |
214 | bool isScoped() const; |
215 | |
216 | int keyCount() const; |
217 | const char *key(int index) const; |
218 | int value(int index) const; |
219 | |
220 | const char *scope() const; |
221 | |
222 | int keyToValue(const char *key, bool *ok = nullptr) const; |
223 | const char* valueToKey(int value) const; |
224 | int keysToValue(const char * keys, bool *ok = nullptr) const; |
225 | QByteArray valueToKeys(int value) const; |
226 | |
227 | inline const QMetaObject *enclosingMetaObject() const { return mobj; } |
228 | |
229 | inline bool isValid() const { return name() != nullptr; } |
230 | |
231 | template<typename T> static QMetaEnum fromType() { |
232 | Q_STATIC_ASSERT_X(QtPrivate::IsQEnumHelper<T>::Value, |
233 | "QMetaEnum::fromType only works with enums declared as Q_ENUM or Q_FLAG" ); |
234 | const QMetaObject *metaObject = qt_getEnumMetaObject(T()); |
235 | const char *name = qt_getEnumName(T()); |
236 | return metaObject->enumerator(metaObject->indexOfEnumerator(name)); |
237 | } |
238 | |
239 | private: |
240 | const QMetaObject *mobj; |
241 | uint handle; |
242 | friend struct QMetaObject; |
243 | }; |
244 | Q_DECLARE_TYPEINFO(QMetaEnum, Q_MOVABLE_TYPE); |
245 | |
246 | class Q_CORE_EXPORT QMetaProperty |
247 | { |
248 | public: |
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 | |
257 | bool isReadable() const; |
258 | bool isWritable() const; |
259 | bool isResettable() const; |
260 | bool isDesignable(const QObject *obj = nullptr) const; |
261 | bool isScriptable(const QObject *obj = nullptr) const; |
262 | bool isStored(const QObject *obj = nullptr) const; |
263 | bool isEditable(const QObject *obj = nullptr) const; |
264 | bool isUser(const QObject *obj = nullptr) const; |
265 | bool isConstant() const; |
266 | bool isFinal() const; |
267 | |
268 | bool isFlagType() const; |
269 | bool isEnumType() const; |
270 | QMetaEnum enumerator() const; |
271 | |
272 | bool hasNotifySignal() const; |
273 | QMetaMethod notifySignal() const; |
274 | int notifySignalIndex() const; |
275 | |
276 | int revision() const; |
277 | |
278 | QVariant read(const QObject *obj) const; |
279 | bool write(QObject *obj, const QVariant &value) const; |
280 | bool reset(QObject *obj) const; |
281 | |
282 | QVariant readOnGadget(const void *gadget) const; |
283 | bool writeOnGadget(void *gadget, const QVariant &value) const; |
284 | bool resetOnGadget(void *gadget) const; |
285 | |
286 | bool hasStdCppSet() const; |
287 | inline bool isValid() const { return isReadable(); } |
288 | inline const QMetaObject *enclosingMetaObject() const { return mobj; } |
289 | |
290 | private: |
291 | int registerPropertyType() const; |
292 | |
293 | const QMetaObject *mobj; |
294 | uint handle; |
295 | int idx; |
296 | QMetaEnum ; |
297 | friend struct QMetaObject; |
298 | friend struct QMetaObjectPrivate; |
299 | }; |
300 | |
301 | class Q_CORE_EXPORT QMetaClassInfo |
302 | { |
303 | public: |
304 | Q_DECL_CONSTEXPR inline QMetaClassInfo() : mobj(nullptr), handle(0) {} |
305 | const char *name() const; |
306 | const char *value() const; |
307 | inline const QMetaObject *enclosingMetaObject() const { return mobj; } |
308 | private: |
309 | const QMetaObject *mobj; |
310 | uint handle; |
311 | friend struct QMetaObject; |
312 | }; |
313 | Q_DECLARE_TYPEINFO(QMetaClassInfo, Q_MOVABLE_TYPE); |
314 | |
315 | QT_END_NAMESPACE |
316 | |
317 | #endif // QMETAOBJECT_H |
318 | |