1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2016 Intel Corporation.
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 QOBJECTDEFS_H
42#define QOBJECTDEFS_H
43
44#if defined(__OBJC__) && !defined(__cplusplus)
45# warning "File built in Objective-C mode (.m), but using Qt requires Objective-C++ (.mm)"
46#endif
47
48#include <QtCore/qnamespace.h>
49
50#include <QtCore/qobjectdefs_impl.h>
51
52QT_BEGIN_NAMESPACE
53
54
55class QByteArray;
56struct QArrayData;
57typedef QArrayData QByteArrayData;
58
59class QString;
60
61#ifndef Q_MOC_OUTPUT_REVISION
62#define Q_MOC_OUTPUT_REVISION 67
63#endif
64
65// The following macros can be defined by tools that understand Qt
66// to have the information from the macro.
67#ifndef QT_ANNOTATE_CLASS
68# ifndef Q_COMPILER_VARIADIC_MACROS
69# define QT_ANNOTATE_CLASS(type, x)
70# else
71# define QT_ANNOTATE_CLASS(type, ...)
72# endif
73#endif
74#ifndef QT_ANNOTATE_CLASS2
75# define QT_ANNOTATE_CLASS2(type, a1, a2)
76#endif
77#ifndef QT_ANNOTATE_FUNCTION
78# define QT_ANNOTATE_FUNCTION(x)
79#endif
80#ifndef QT_ANNOTATE_ACCESS_SPECIFIER
81# define QT_ANNOTATE_ACCESS_SPECIFIER(x)
82#endif
83
84// The following macros are our "extensions" to C++
85// They are used, strictly speaking, only by the moc.
86
87#ifndef Q_MOC_RUN
88#ifndef QT_NO_META_MACROS
89# if defined(QT_NO_KEYWORDS)
90# define QT_NO_EMIT
91# else
92# ifndef QT_NO_SIGNALS_SLOTS_KEYWORDS
93# define slots Q_SLOTS
94# define signals Q_SIGNALS
95# endif
96# endif
97# define Q_SLOTS QT_ANNOTATE_ACCESS_SPECIFIER(qt_slot)
98# define Q_SIGNALS public QT_ANNOTATE_ACCESS_SPECIFIER(qt_signal)
99# define Q_PRIVATE_SLOT(d, signature) QT_ANNOTATE_CLASS2(qt_private_slot, d, signature)
100# define Q_EMIT
101#ifndef QT_NO_EMIT
102# define emit
103#endif
104#ifndef Q_CLASSINFO
105# define Q_CLASSINFO(name, value)
106#endif
107#define Q_PLUGIN_METADATA(x) QT_ANNOTATE_CLASS(qt_plugin_metadata, x)
108#define Q_INTERFACES(x) QT_ANNOTATE_CLASS(qt_interfaces, x)
109#ifdef Q_COMPILER_VARIADIC_MACROS
110# define Q_PROPERTY(...) QT_ANNOTATE_CLASS(qt_property, __VA_ARGS__)
111#else
112# define Q_PROPERTY(text) QT_ANNOTATE_CLASS(qt_property, text)
113#endif
114#define Q_PRIVATE_PROPERTY(d, text) QT_ANNOTATE_CLASS2(qt_private_property, d, text)
115#ifndef Q_REVISION
116# define Q_REVISION(v)
117#endif
118#define Q_OVERRIDE(text) QT_ANNOTATE_CLASS(qt_override, text)
119#define QDOC_PROPERTY(text) QT_ANNOTATE_CLASS(qt_qdoc_property, text)
120#define Q_ENUMS(x) QT_ANNOTATE_CLASS(qt_enums, x)
121#define Q_FLAGS(x) QT_ANNOTATE_CLASS(qt_enums, x)
122#define Q_ENUM_IMPL(ENUM) \
123 friend Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return &staticMetaObject; } \
124 friend Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; }
125#define Q_ENUM(x) Q_ENUMS(x) Q_ENUM_IMPL(x)
126#define Q_FLAG(x) Q_FLAGS(x) Q_ENUM_IMPL(x)
127#define Q_ENUM_NS_IMPL(ENUM) \
128 inline Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return &staticMetaObject; } \
129 inline Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; }
130#define Q_ENUM_NS(x) Q_ENUMS(x) Q_ENUM_NS_IMPL(x)
131#define Q_FLAG_NS(x) Q_FLAGS(x) Q_ENUM_NS_IMPL(x)
132#define Q_SCRIPTABLE QT_ANNOTATE_FUNCTION(qt_scriptable)
133#define Q_INVOKABLE QT_ANNOTATE_FUNCTION(qt_invokable)
134#define Q_SIGNAL QT_ANNOTATE_FUNCTION(qt_signal)
135#define Q_SLOT QT_ANNOTATE_FUNCTION(qt_slot)
136#endif // QT_NO_META_MACROS
137
138#ifndef QT_NO_TRANSLATION
139// full set of tr functions
140# define QT_TR_FUNCTIONS \
141 static inline QString tr(const char *s, const char *c = Q_NULLPTR, int n = -1) \
142 { return staticMetaObject.tr(s, c, n); } \
143 QT_DEPRECATED static inline QString trUtf8(const char *s, const char *c = Q_NULLPTR, int n = -1) \
144 { return staticMetaObject.tr(s, c, n); }
145#else
146// inherit the ones from QObject
147# define QT_TR_FUNCTIONS
148#endif
149
150// ### Qt6: remove
151#define Q_OBJECT_CHECK /* empty, unused since Qt 5.2 */
152
153#if defined(Q_CC_INTEL)
154// Cannot redefine the visibility of a method in an exported class
155# define Q_DECL_HIDDEN_STATIC_METACALL
156#else
157# define Q_DECL_HIDDEN_STATIC_METACALL Q_DECL_HIDDEN
158#endif
159
160#if defined(Q_CC_CLANG) && Q_CC_CLANG >= 306
161# define Q_OBJECT_NO_OVERRIDE_WARNING QT_WARNING_DISABLE_CLANG("-Winconsistent-missing-override")
162#elif defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 501
163# define Q_OBJECT_NO_OVERRIDE_WARNING QT_WARNING_DISABLE_GCC("-Wsuggest-override")
164#else
165# define Q_OBJECT_NO_OVERRIDE_WARNING
166#endif
167
168#if defined(Q_CC_GNU) && !defined(Q_CC_INTEL) && Q_CC_GNU >= 600
169# define Q_OBJECT_NO_ATTRIBUTES_WARNING QT_WARNING_DISABLE_GCC("-Wattributes")
170#else
171# define Q_OBJECT_NO_ATTRIBUTES_WARNING
172#endif
173
174/* qmake ignore Q_OBJECT */
175#define Q_OBJECT \
176public: \
177 QT_WARNING_PUSH \
178 Q_OBJECT_NO_OVERRIDE_WARNING \
179 static const QMetaObject staticMetaObject; \
180 virtual const QMetaObject *metaObject() const; \
181 virtual void *qt_metacast(const char *); \
182 virtual int qt_metacall(QMetaObject::Call, int, void **); \
183 QT_TR_FUNCTIONS \
184private: \
185 Q_OBJECT_NO_ATTRIBUTES_WARNING \
186 Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); \
187 QT_WARNING_POP \
188 struct QPrivateSignal {}; \
189 QT_ANNOTATE_CLASS(qt_qobject, "")
190
191/* qmake ignore Q_OBJECT */
192#define Q_OBJECT_FAKE Q_OBJECT QT_ANNOTATE_CLASS(qt_fake, "")
193
194#ifndef QT_NO_META_MACROS
195/* qmake ignore Q_GADGET */
196#define Q_GADGET \
197public: \
198 static const QMetaObject staticMetaObject; \
199 void qt_check_for_QGADGET_macro(); \
200 typedef void QtGadgetHelper; \
201private: \
202 QT_WARNING_PUSH \
203 Q_OBJECT_NO_ATTRIBUTES_WARNING \
204 Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); \
205 QT_WARNING_POP \
206 QT_ANNOTATE_CLASS(qt_qgadget, "") \
207 /*end*/
208
209#define Q_NAMESPACE \
210 extern const QMetaObject staticMetaObject; \
211 QT_ANNOTATE_CLASS(qt_qnamespace, "") \
212 /*end*/
213
214#endif // QT_NO_META_MACROS
215
216#else // Q_MOC_RUN
217#define slots slots
218#define signals signals
219#define Q_SLOTS Q_SLOTS
220#define Q_SIGNALS Q_SIGNALS
221#define Q_CLASSINFO(name, value) Q_CLASSINFO(name, value)
222#define Q_INTERFACES(x) Q_INTERFACES(x)
223#define Q_PROPERTY(text) Q_PROPERTY(text)
224#define Q_PRIVATE_PROPERTY(d, text) Q_PRIVATE_PROPERTY(d, text)
225#define Q_REVISION(v) Q_REVISION(v)
226#define Q_OVERRIDE(text) Q_OVERRIDE(text)
227#define Q_ENUMS(x) Q_ENUMS(x)
228#define Q_FLAGS(x) Q_FLAGS(x)
229#define Q_ENUM(x) Q_ENUM(x)
230#define Q_FLAGS(x) Q_FLAGS(x)
231 /* qmake ignore Q_OBJECT */
232#define Q_OBJECT Q_OBJECT
233 /* qmake ignore Q_OBJECT */
234#define Q_OBJECT_FAKE Q_OBJECT_FAKE
235 /* qmake ignore Q_GADGET */
236#define Q_GADGET Q_GADGET
237#define Q_SCRIPTABLE Q_SCRIPTABLE
238#define Q_INVOKABLE Q_INVOKABLE
239#define Q_SIGNAL Q_SIGNAL
240#define Q_SLOT Q_SLOT
241#endif //Q_MOC_RUN
242
243#ifdef Q_CLANG_QDOC
244#undef Q_GADGET
245#define Q_GADGET
246#endif
247
248#ifndef QT_NO_META_MACROS
249// macro for onaming members
250#ifdef METHOD
251#undef METHOD
252#endif
253#ifdef SLOT
254#undef SLOT
255#endif
256#ifdef SIGNAL
257#undef SIGNAL
258#endif
259#endif // QT_NO_META_MACROS
260
261Q_CORE_EXPORT const char *qFlagLocation(const char *method);
262
263#ifndef QT_NO_META_MACROS
264#ifndef QT_NO_DEBUG
265# define QLOCATION "\0" __FILE__ ":" QT_STRINGIFY(__LINE__)
266# ifndef QT_NO_KEYWORDS
267# define METHOD(a) qFlagLocation("0"#a QLOCATION)
268# endif
269# define SLOT(a) qFlagLocation("1"#a QLOCATION)
270# define SIGNAL(a) qFlagLocation("2"#a QLOCATION)
271#else
272# ifndef QT_NO_KEYWORDS
273# define METHOD(a) "0"#a
274# endif
275# define SLOT(a) "1"#a
276# define SIGNAL(a) "2"#a
277#endif
278
279#define QMETHOD_CODE 0 // member type codes
280#define QSLOT_CODE 1
281#define QSIGNAL_CODE 2
282#endif // QT_NO_META_MACROS
283
284#define Q_ARG(type, data) QArgument<type >(#type, data)
285#define Q_RETURN_ARG(type, data) QReturnArgument<type >(#type, data)
286
287class QObject;
288class QMetaMethod;
289class QMetaEnum;
290class QMetaProperty;
291class QMetaClassInfo;
292
293
294class Q_CORE_EXPORT QGenericArgument
295{
296public:
297 inline QGenericArgument(const char *aName = Q_NULLPTR, const void *aData = Q_NULLPTR)
298 : _data(aData), _name(aName) {}
299 inline void *data() const { return const_cast<void *>(_data); }
300 inline const char *name() const { return _name; }
301
302private:
303 const void *_data;
304 const char *_name;
305};
306
307class Q_CORE_EXPORT QGenericReturnArgument: public QGenericArgument
308{
309public:
310 inline QGenericReturnArgument(const char *aName = Q_NULLPTR, void *aData = Q_NULLPTR)
311 : QGenericArgument(aName, aData)
312 {}
313};
314
315template <class T>
316class QArgument: public QGenericArgument
317{
318public:
319 inline QArgument(const char *aName, const T &aData)
320 : QGenericArgument(aName, static_cast<const void *>(&aData))
321 {}
322};
323template <class T>
324class QArgument<T &>: public QGenericArgument
325{
326public:
327 inline QArgument(const char *aName, T &aData)
328 : QGenericArgument(aName, static_cast<const void *>(&aData))
329 {}
330};
331
332
333template <typename T>
334class QReturnArgument: public QGenericReturnArgument
335{
336public:
337 inline QReturnArgument(const char *aName, T &aData)
338 : QGenericReturnArgument(aName, static_cast<void *>(&aData))
339 {}
340};
341
342struct Q_CORE_EXPORT QMetaObject
343{
344 class Connection;
345 const char *className() const;
346 const QMetaObject *superClass() const;
347
348 bool inherits(const QMetaObject *metaObject) const Q_DECL_NOEXCEPT;
349 QObject *cast(QObject *obj) const;
350 const QObject *cast(const QObject *obj) const;
351
352#ifndef QT_NO_TRANSLATION
353 QString tr(const char *s, const char *c, int n = -1) const;
354#endif // QT_NO_TRANSLATION
355
356 int methodOffset() const;
357 int enumeratorOffset() const;
358 int propertyOffset() const;
359 int classInfoOffset() const;
360
361 int constructorCount() const;
362 int methodCount() const;
363 int enumeratorCount() const;
364 int propertyCount() const;
365 int classInfoCount() const;
366
367 int indexOfConstructor(const char *constructor) const;
368 int indexOfMethod(const char *method) const;
369 int indexOfSignal(const char *signal) const;
370 int indexOfSlot(const char *slot) const;
371 int indexOfEnumerator(const char *name) const;
372 int indexOfProperty(const char *name) const;
373 int indexOfClassInfo(const char *name) const;
374
375 QMetaMethod constructor(int index) const;
376 QMetaMethod method(int index) const;
377 QMetaEnum enumerator(int index) const;
378 QMetaProperty property(int index) const;
379 QMetaClassInfo classInfo(int index) const;
380 QMetaProperty userProperty() const;
381
382 static bool checkConnectArgs(const char *signal, const char *method);
383 static bool checkConnectArgs(const QMetaMethod &signal,
384 const QMetaMethod &method);
385 static QByteArray normalizedSignature(const char *method);
386 static QByteArray normalizedType(const char *type);
387
388 // internal index-based connect
389 static Connection connect(const QObject *sender, int signal_index,
390 const QObject *receiver, int method_index,
391 int type = 0, int *types = Q_NULLPTR);
392 // internal index-based disconnect
393 static bool disconnect(const QObject *sender, int signal_index,
394 const QObject *receiver, int method_index);
395 static bool disconnectOne(const QObject *sender, int signal_index,
396 const QObject *receiver, int method_index);
397 // internal slot-name based connect
398 static void connectSlotsByName(QObject *o);
399
400 // internal index-based signal activation
401 static void activate(QObject *sender, int signal_index, void **argv);
402 static void activate(QObject *sender, const QMetaObject *, int local_signal_index, void **argv);
403 static void activate(QObject *sender, int signal_offset, int local_signal_index, void **argv);
404
405 static bool invokeMethod(QObject *obj, const char *member,
406 Qt::ConnectionType,
407 QGenericReturnArgument ret,
408 QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
409 QGenericArgument val1 = QGenericArgument(),
410 QGenericArgument val2 = QGenericArgument(),
411 QGenericArgument val3 = QGenericArgument(),
412 QGenericArgument val4 = QGenericArgument(),
413 QGenericArgument val5 = QGenericArgument(),
414 QGenericArgument val6 = QGenericArgument(),
415 QGenericArgument val7 = QGenericArgument(),
416 QGenericArgument val8 = QGenericArgument(),
417 QGenericArgument val9 = QGenericArgument());
418
419 static inline bool invokeMethod(QObject *obj, const char *member,
420 QGenericReturnArgument ret,
421 QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
422 QGenericArgument val1 = QGenericArgument(),
423 QGenericArgument val2 = QGenericArgument(),
424 QGenericArgument val3 = QGenericArgument(),
425 QGenericArgument val4 = QGenericArgument(),
426 QGenericArgument val5 = QGenericArgument(),
427 QGenericArgument val6 = QGenericArgument(),
428 QGenericArgument val7 = QGenericArgument(),
429 QGenericArgument val8 = QGenericArgument(),
430 QGenericArgument val9 = QGenericArgument())
431 {
432 return invokeMethod(obj, member, Qt::AutoConnection, ret, val0, val1, val2, val3,
433 val4, val5, val6, val7, val8, val9);
434 }
435
436 static inline bool invokeMethod(QObject *obj, const char *member,
437 Qt::ConnectionType type,
438 QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
439 QGenericArgument val1 = QGenericArgument(),
440 QGenericArgument val2 = QGenericArgument(),
441 QGenericArgument val3 = QGenericArgument(),
442 QGenericArgument val4 = QGenericArgument(),
443 QGenericArgument val5 = QGenericArgument(),
444 QGenericArgument val6 = QGenericArgument(),
445 QGenericArgument val7 = QGenericArgument(),
446 QGenericArgument val8 = QGenericArgument(),
447 QGenericArgument val9 = QGenericArgument())
448 {
449 return invokeMethod(obj, member, type, QGenericReturnArgument(), val0, val1, val2,
450 val3, val4, val5, val6, val7, val8, val9);
451 }
452
453 static inline bool invokeMethod(QObject *obj, const char *member,
454 QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
455 QGenericArgument val1 = QGenericArgument(),
456 QGenericArgument val2 = QGenericArgument(),
457 QGenericArgument val3 = QGenericArgument(),
458 QGenericArgument val4 = QGenericArgument(),
459 QGenericArgument val5 = QGenericArgument(),
460 QGenericArgument val6 = QGenericArgument(),
461 QGenericArgument val7 = QGenericArgument(),
462 QGenericArgument val8 = QGenericArgument(),
463 QGenericArgument val9 = QGenericArgument())
464 {
465 return invokeMethod(obj, member, Qt::AutoConnection, QGenericReturnArgument(), val0,
466 val1, val2, val3, val4, val5, val6, val7, val8, val9);
467 }
468
469 QObject *newInstance(QGenericArgument val0 = QGenericArgument(Q_NULLPTR),
470 QGenericArgument val1 = QGenericArgument(),
471 QGenericArgument val2 = QGenericArgument(),
472 QGenericArgument val3 = QGenericArgument(),
473 QGenericArgument val4 = QGenericArgument(),
474 QGenericArgument val5 = QGenericArgument(),
475 QGenericArgument val6 = QGenericArgument(),
476 QGenericArgument val7 = QGenericArgument(),
477 QGenericArgument val8 = QGenericArgument(),
478 QGenericArgument val9 = QGenericArgument()) const;
479
480 enum Call {
481 InvokeMetaMethod,
482 ReadProperty,
483 WriteProperty,
484 ResetProperty,
485 QueryPropertyDesignable,
486 QueryPropertyScriptable,
487 QueryPropertyStored,
488 QueryPropertyEditable,
489 QueryPropertyUser,
490 CreateInstance,
491 IndexOfMethod,
492 RegisterPropertyMetaType,
493 RegisterMethodArgumentMetaType
494 };
495
496 int static_metacall(Call, int, void **) const;
497 static int metacall(QObject *, Call, int, void **);
498
499 struct { // private data
500 const QMetaObject *superdata;
501 const QByteArrayData *stringdata;
502 const uint *data;
503 typedef void (*StaticMetacallFunction)(QObject *, QMetaObject::Call, int, void **);
504 StaticMetacallFunction static_metacall;
505 const QMetaObject * const *relatedMetaObjects;
506 void *extradata; //reserved for future use
507 } d;
508};
509
510class Q_CORE_EXPORT QMetaObject::Connection {
511 void *d_ptr; //QObjectPrivate::Connection*
512 explicit Connection(void *data) : d_ptr(data) { }
513 friend class QObject;
514 friend class QObjectPrivate;
515 friend struct QMetaObject;
516 bool isConnected_helper() const;
517public:
518 ~Connection();
519 Connection();
520 Connection(const Connection &other);
521 Connection &operator=(const Connection &other);
522#ifdef Q_QDOC
523 operator bool() const;
524#else
525 typedef void *Connection::*RestrictedBool;
526 operator RestrictedBool() const { return d_ptr && isConnected_helper() ? &Connection::d_ptr : Q_NULLPTR; }
527#endif
528
529#ifdef Q_COMPILER_RVALUE_REFS
530 inline Connection(Connection &&o) : d_ptr(o.d_ptr) { o.d_ptr = Q_NULLPTR; }
531 inline Connection &operator=(Connection &&other)
532 { qSwap(d_ptr, other.d_ptr); return *this; }
533#endif
534};
535
536inline const QMetaObject *QMetaObject::superClass() const
537{ return d.superdata; }
538
539namespace QtPrivate {
540 /* Trait that tells is a the Object has a Q_OBJECT macro */
541 template <typename Object> struct HasQ_OBJECT_Macro {
542 template <typename T>
543 static char test(int (T::*)(QMetaObject::Call, int, void **));
544 static int test(int (Object::*)(QMetaObject::Call, int, void **));
545 enum { Value = sizeof(test(&Object::qt_metacall)) == sizeof(int) };
546 };
547}
548
549QT_END_NAMESPACE
550
551#endif // QOBJECTDEFS_H
552