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