summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorBogDan Vatra <bogdan@kdab.com>2016-08-19 15:44:42 +0300
committerBogDan Vatra <bogdan@kdab.com>2016-08-19 15:41:27 +0000
commit691dc71a011a28743e4cdbd716c192b21d63b68b (patch)
treeb54d9513c31c9bfc4d0e29819dced0ffdd3d6768 /src/corelib/kernel
parenta1c782062c7f2391178060a7105ad9050b1032e1 (diff)
Say hello to Q_NAMESPACE
Q_NAMESPACE is useful to add Q_ENUM_NS/Q_ENUMS, Q_FLAG_NS/Q_FLAGS and Q_CLASSINFO to a namespace. [ChangeLog] Added Q_NAMESPACE which can be used to add Q_ENUM_NS/ Q_ENUMS, Q_FLAG_NS/Q_FLAGS and Q_CLASSINFO to a namespace Task-number: QTBUG-54981 Change-Id: Ic61b972794063e77134681fb347d6c4acddcdb44 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qobject.cpp61
-rw-r--r--src/corelib/kernel/qobjectdefs.h11
2 files changed, 70 insertions, 2 deletions
diff --git a/src/corelib/kernel/qobject.cpp b/src/corelib/kernel/qobject.cpp
index 26c3ce2443..e901d8cefa 100644
--- a/src/corelib/kernel/qobject.cpp
+++ b/src/corelib/kernel/qobject.cpp
@@ -4248,7 +4248,7 @@ QDebug operator<<(QDebug dbg, const QObject *o)
This macro registers an enum type with the meta-object system.
It must be placed after the enum declaration in a class that has the Q_OBJECT or the
- Q_GADGET macro.
+ Q_GADGET macro. For namespaces use \l Q_ENUM_NS instead.
For example:
@@ -4275,7 +4275,7 @@ QDebug operator<<(QDebug dbg, const QObject *o)
This macro registers a single \l{QFlags}{flags type} with the
meta-object system. It is typically used in a class definition to declare
that values of a given enum can be used as flags and combined using the
- bitwise OR operator.
+ bitwise OR operator. For namespaces use \l Q_FLAG_NS instead.
The macro must be placed after the enum declaration.
@@ -4294,6 +4294,48 @@ QDebug operator<<(QDebug dbg, const QObject *o)
\sa {Qt's Property System}
*/
+/*!
+ \macro Q_ENUM_NS(...)
+ \since 5.8
+
+ This macro registers an enum type with the meta-object system.
+ It must be placed after the enum declaration in a namespace that
+ has the Q_NAMESPACE macro. It is the same as \l Q_ENUM but in a
+ namespace.
+
+ Enumerations that are declared with Q_ENUM_NS have their QMetaEnum
+ registered in the enclosing QMetaObject. You can also use
+ QMetaEnum::fromType() to get the QMetaEnum.
+
+ Registered enumerations are automatically registered also to the Qt meta
+ type system, making them known to QMetaType without the need to use
+ Q_DECLARE_METATYPE(). This will enable useful features; for example, if
+ used in a QVariant, you can convert them to strings. Likewise, passing them
+ to QDebug will print out their names.
+
+ \sa {Qt's Property System}
+*/
+
+
+/*!
+ \macro Q_FLAG_NS(...)
+ \since 5.8
+
+ This macro registers a single \l{QFlags}{flags type} with the
+ meta-object system. It is used in a namespace that has the
+ Q_NAMESPACE macro, to declare that values of a given enum can be
+ used as flags and combined using the bitwise OR operator.
+ It is the same as \l Q_FLAG but in a namespace.
+
+ The macro must be placed after the enum declaration.
+
+ \note The Q_FLAG_NS macro takes care of registering individual flag
+ values with the meta-object system, so it is unnecessary to use
+ Q_ENUM_NS() in addition to this macro.
+
+ \sa {Qt's Property System}
+*/
+
/*!
\macro Q_OBJECT
@@ -4335,6 +4377,21 @@ QDebug operator<<(QDebug dbg, const QObject *o)
*/
/*!
+ \macro Q_NAMESPACE
+ \since 5.8
+
+ The Q_NAMESPACE macro can be used to add QMetaObject capabilities
+ to a namespace.
+
+ Q_NAMESPACEs can have Q_CLASSINFO, Q_ENUM_NS, Q_FLAG_NS, but they
+ cannot have Q_ENUM, Q_FLAG, Q_PROPERTY, Q_INVOKABLE, signals nor slots.
+
+ Q_NAMESPACE makes an external variable, \c{staticMetaObject}, available.
+ \c{staticMetaObject} is of type QMetaObject and provides access to the
+ enums declared with Q_ENUM_NS/Q_FLAG_NS.
+*/
+
+/*!
\macro Q_SIGNALS
\relates QObject
diff --git a/src/corelib/kernel/qobjectdefs.h b/src/corelib/kernel/qobjectdefs.h
index 3660d1c0e1..7ed6088d3b 100644
--- a/src/corelib/kernel/qobjectdefs.h
+++ b/src/corelib/kernel/qobjectdefs.h
@@ -124,6 +124,11 @@ class QString;
friend Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; }
#define Q_ENUM(x) Q_ENUMS(x) Q_ENUM_IMPL(x)
#define Q_FLAG(x) Q_FLAGS(x) Q_ENUM_IMPL(x)
+#define Q_ENUM_NS_IMPL(ENUM) \
+ inline Q_DECL_CONSTEXPR const QMetaObject *qt_getEnumMetaObject(ENUM) Q_DECL_NOEXCEPT { return &staticMetaObject; } \
+ inline Q_DECL_CONSTEXPR const char *qt_getEnumName(ENUM) Q_DECL_NOEXCEPT { return #ENUM; }
+#define Q_ENUM_NS(x) Q_ENUMS(x) Q_ENUM_NS_IMPL(x)
+#define Q_FLAG_NS(x) Q_FLAGS(x) Q_ENUM_NS_IMPL(x)
#define Q_SCRIPTABLE QT_ANNOTATE_FUNCTION(qt_scriptable)
#define Q_INVOKABLE QT_ANNOTATE_FUNCTION(qt_invokable)
#define Q_SIGNAL QT_ANNOTATE_FUNCTION(qt_signal)
@@ -227,6 +232,12 @@ private: \
QT_WARNING_POP \
QT_ANNOTATE_CLASS(qt_qgadget, "") \
/*end*/
+
+#define Q_NAMESPACE \
+ extern const QMetaObject staticMetaObject; \
+ QT_ANNOTATE_CLASS(qt_qnamespace, "") \
+ /*end*/
+
#endif // QT_NO_META_MACROS
#else // Q_MOC_RUN