1// Copyright (C) 2019 The Qt Company Ltd.
2// Copyright (C) 2019 Olivier Goffart <ogoffart@woboq.com>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QTMETAMACROS_H
6#define QTMETAMACROS_H
7
8#include <QtCore/qglobal.h>
9#include <QtCore/qtclasshelpermacros.h>
10
11QT_BEGIN_NAMESPACE
12
13#ifndef Q_MOC_OUTPUT_REVISION
14#define Q_MOC_OUTPUT_REVISION 68
15#endif
16
17// The following macros can be defined by tools that understand Qt
18// to have the information from the macro.
19#ifndef QT_ANNOTATE_CLASS
20# define QT_ANNOTATE_CLASS(type, ...)
21#endif
22#ifndef QT_ANNOTATE_CLASS2
23# define QT_ANNOTATE_CLASS2(type, a1, a2)
24#endif
25#ifndef QT_ANNOTATE_FUNCTION
26# define QT_ANNOTATE_FUNCTION(x)
27#endif
28#ifndef QT_ANNOTATE_ACCESS_SPECIFIER
29# define QT_ANNOTATE_ACCESS_SPECIFIER(x)
30#endif
31
32// The following macros are our "extensions" to C++
33// They are used, strictly speaking, only by the moc.
34
35#ifndef Q_MOC_RUN
36#ifndef QT_NO_META_MACROS
37# if defined(QT_NO_KEYWORDS)
38# define QT_NO_EMIT
39# else
40# ifndef QT_NO_SIGNALS_SLOTS_KEYWORDS
41# define slots Q_SLOTS
42# define signals Q_SIGNALS
43# endif
44# endif
45# define Q_SLOTS QT_ANNOTATE_ACCESS_SPECIFIER(qt_slot)
46# define Q_SIGNALS public QT_ANNOTATE_ACCESS_SPECIFIER(qt_signal)
47# define Q_PRIVATE_SLOT(d, signature) QT_ANNOTATE_CLASS2(qt_private_slot, d, signature)
48# define Q_EMIT
49#ifndef QT_NO_EMIT
50# define emit
51#endif
52#ifndef Q_CLASSINFO
53# define Q_CLASSINFO(name, value)
54#endif
55#define Q_PLUGIN_METADATA(x) QT_ANNOTATE_CLASS(qt_plugin_metadata, x)
56#define Q_INTERFACES(x) QT_ANNOTATE_CLASS(qt_interfaces, x)
57#define Q_PROPERTY(...) QT_ANNOTATE_CLASS(qt_property, __VA_ARGS__)
58#define Q_PRIVATE_PROPERTY(d, text) QT_ANNOTATE_CLASS2(qt_private_property, d, text)
59#ifndef Q_REVISION
60# define Q_REVISION(...)
61#endif
62#define Q_OVERRIDE(text) QT_ANNOTATE_CLASS(qt_override, text)
63#define QDOC_PROPERTY(text) QT_ANNOTATE_CLASS(qt_qdoc_property, text)
64#define Q_ENUMS(x) QT_ANNOTATE_CLASS(qt_enums, x)
65#define Q_FLAGS(x) QT_ANNOTATE_CLASS(qt_enums, x)
66#define Q_ENUM_IMPL(ENUM) \
67 friend constexpr const QMetaObject *qt_getEnumMetaObject(ENUM) noexcept { return &staticMetaObject; } \
68 friend constexpr const char *qt_getEnumName(ENUM) noexcept { return #ENUM; }
69#define Q_ENUM(x) Q_ENUMS(x) Q_ENUM_IMPL(x)
70#define Q_FLAG(x) Q_FLAGS(x) Q_ENUM_IMPL(x)
71#define Q_ENUM_NS_IMPL(ENUM) \
72 inline constexpr const QMetaObject *qt_getEnumMetaObject(ENUM) noexcept { return &staticMetaObject; } \
73 inline constexpr const char *qt_getEnumName(ENUM) noexcept { return #ENUM; }
74#define Q_ENUM_NS(x) Q_ENUMS(x) Q_ENUM_NS_IMPL(x)
75#define Q_FLAG_NS(x) Q_FLAGS(x) Q_ENUM_NS_IMPL(x)
76#define Q_SCRIPTABLE QT_ANNOTATE_FUNCTION(qt_scriptable)
77#define Q_INVOKABLE QT_ANNOTATE_FUNCTION(qt_invokable)
78#define Q_SIGNAL QT_ANNOTATE_FUNCTION(qt_signal)
79#define Q_SLOT QT_ANNOTATE_FUNCTION(qt_slot)
80#define Q_MOC_INCLUDE(...) QT_ANNOTATE_CLASS(qt_moc_include, __VA_ARGS__)
81#endif // QT_NO_META_MACROS
82
83#ifndef QT_NO_TRANSLATION
84// full set of tr functions
85# define QT_TR_FUNCTIONS \
86 static inline QString tr(const char *s, const char *c = nullptr, int n = -1) \
87 { return staticMetaObject.tr(s, c, n); }
88#else
89// inherit the ones from QObject
90# define QT_TR_FUNCTIONS
91#endif
92
93#ifdef Q_QDOC
94#define QT_TR_FUNCTIONS
95#endif
96
97#define Q_DECL_HIDDEN_STATIC_METACALL Q_DECL_HIDDEN
98
99#if defined(Q_CC_CLANG)
100# if Q_CC_CLANG >= 1100
101# define Q_OBJECT_NO_OVERRIDE_WARNING QT_WARNING_DISABLE_CLANG("-Winconsistent-missing-override") QT_WARNING_DISABLE_CLANG("-Wsuggest-override")
102# elif Q_CC_CLANG >= 306
103# define Q_OBJECT_NO_OVERRIDE_WARNING QT_WARNING_DISABLE_CLANG("-Winconsistent-missing-override")
104# endif
105#elif defined(Q_CC_GNU) && Q_CC_GNU >= 501
106# define Q_OBJECT_NO_OVERRIDE_WARNING QT_WARNING_DISABLE_GCC("-Wsuggest-override")
107#elif defined(Q_CC_MSVC)
108# define Q_OBJECT_NO_OVERRIDE_WARNING QT_WARNING_DISABLE_MSVC(26433)
109#else
110# define Q_OBJECT_NO_OVERRIDE_WARNING
111#endif
112
113#if defined(Q_CC_GNU) && Q_CC_GNU >= 600
114# define Q_OBJECT_NO_ATTRIBUTES_WARNING QT_WARNING_DISABLE_GCC("-Wattributes")
115#else
116# define Q_OBJECT_NO_ATTRIBUTES_WARNING
117#endif
118
119/* qmake ignore Q_OBJECT */
120#define Q_OBJECT \
121public: \
122 QT_WARNING_PUSH \
123 Q_OBJECT_NO_OVERRIDE_WARNING \
124 static const QMetaObject staticMetaObject; \
125 virtual const QMetaObject *metaObject() const; \
126 virtual void *qt_metacast(const char *); \
127 virtual int qt_metacall(QMetaObject::Call, int, void **); \
128 QT_TR_FUNCTIONS \
129private: \
130 Q_OBJECT_NO_ATTRIBUTES_WARNING \
131 Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); \
132 QT_WARNING_POP \
133 QT_DEFINE_TAG_STRUCT(QPrivateSignal); \
134 QT_ANNOTATE_CLASS(qt_qobject, "")
135
136/* qmake ignore Q_OBJECT */
137#define Q_OBJECT_FAKE Q_OBJECT QT_ANNOTATE_CLASS(qt_fake, "")
138
139#ifndef QT_NO_META_MACROS
140/* qmake ignore Q_GADGET_EXPORT */
141#define Q_GADGET_EXPORT(...) \
142public: \
143 static __VA_ARGS__ const QMetaObject staticMetaObject; \
144 void qt_check_for_QGADGET_macro(); \
145 typedef void QtGadgetHelper; \
146private: \
147 QT_WARNING_PUSH \
148 Q_OBJECT_NO_ATTRIBUTES_WARNING \
149 Q_DECL_HIDDEN_STATIC_METACALL static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); \
150 QT_WARNING_POP \
151 QT_ANNOTATE_CLASS(qt_qgadget, "") \
152 /*end*/
153
154/* qmake ignore Q_GADGET */
155#define Q_GADGET Q_GADGET_EXPORT()
156
157 /* qmake ignore Q_NAMESPACE_EXPORT */
158#define Q_NAMESPACE_EXPORT(...) \
159 extern __VA_ARGS__ const QMetaObject staticMetaObject; \
160 QT_ANNOTATE_CLASS(qt_qnamespace, "") \
161 /*end*/
162
163/* qmake ignore Q_NAMESPACE */
164#define Q_NAMESPACE Q_NAMESPACE_EXPORT() \
165 /*end*/
166
167#endif // QT_NO_META_MACROS
168
169#else // Q_MOC_RUN
170#define slots slots
171#define signals signals
172#define Q_SLOTS Q_SLOTS
173#define Q_SIGNALS Q_SIGNALS
174#define Q_CLASSINFO(name, value) Q_CLASSINFO(name, value)
175#define Q_INTERFACES(x) Q_INTERFACES(x)
176#define Q_PROPERTY(text) Q_PROPERTY(text)
177#define Q_PRIVATE_PROPERTY(d, text) Q_PRIVATE_PROPERTY(d, text)
178#define Q_PRIVATE_QPROPERTY(accessor, type, name, setter, ...) Q_PRIVATE_QPROPERTY(accessor, type, name, setter, __VA_ARGS__)
179#define Q_PRIVATE_QPROPERTIES_BEGIN
180#define Q_PRIVATE_QPROPERTY_IMPL(name)
181#define Q_PRIVATE_QPROPERTIES_END
182#define Q_REVISION(...) Q_REVISION(__VA_ARGS__)
183#define Q_OVERRIDE(text) Q_OVERRIDE(text)
184#define Q_ENUMS(x) Q_ENUMS(x)
185#define Q_FLAGS(x) Q_FLAGS(x)
186#define Q_ENUM(x) Q_ENUM(x)
187#define Q_FLAGS(x) Q_FLAGS(x)
188 /* qmake ignore Q_OBJECT */
189#define Q_OBJECT Q_OBJECT
190 /* qmake ignore Q_OBJECT */
191#define Q_OBJECT_FAKE Q_OBJECT_FAKE
192 /* qmake ignore Q_GADGET */
193#define Q_GADGET Q_GADGET
194#define Q_SCRIPTABLE Q_SCRIPTABLE
195#define Q_INVOKABLE Q_INVOKABLE
196#define Q_SIGNAL Q_SIGNAL
197#define Q_SLOT Q_SLOT
198#endif //Q_MOC_RUN
199
200QT_END_NAMESPACE
201
202#endif // QTMETAMACROS_H
203

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