From de164d60f2561fb0ad142b5d4fd31ff9817c2725 Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Tue, 12 Oct 2021 19:17:42 +0200 Subject: Make sure to expose both the flags type and the underlying enum See also https://bugreports.qt.io/browse/QTBUG-82295. --- lib/quotient_common.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'lib/quotient_common.h') diff --git a/lib/quotient_common.h b/lib/quotient_common.h index 13bf7246..e1e14a14 100644 --- a/lib/quotient_common.h +++ b/lib/quotient_common.h @@ -7,6 +7,22 @@ #include +// See https://bugreports.qt.io/browse/QTBUG-82295 - despite the comment that +// Q_FLAG[_NS] "should" be applied to the enum only, Qt doesn't allow to wrap +// a flag type into a QVariant then. The macros below define Q_FLAG_NS and on +// top of that add a part of Q_ENUM() that enables the metatype data but goes +// under the moc radar to avoid double registration of the same data in the map +// defined in moc_*.cpp +#define QUO_DECLARE_FLAGS(Flags, Enum) \ + Q_DECLARE_FLAGS(Flags, Enum) \ + Q_ENUM_IMPL(Enum) \ + Q_FLAG(Flags) + +#define QUO_DECLARE_FLAGS_NS(Flags, Enum) \ + Q_DECLARE_FLAGS(Flags, Enum) \ + Q_ENUM_NS_IMPL(Enum) \ + Q_FLAG_NS(Flags) + namespace Quotient { Q_NAMESPACE @@ -41,8 +57,7 @@ enum class Membership : unsigned int { Ban = 0x10, Undefined = Invalid }; -Q_DECLARE_FLAGS(MembershipMask, Membership) -Q_FLAG_NS(MembershipMask) +QUO_DECLARE_FLAGS_NS(MembershipMask, Membership) constexpr inline auto MembershipStrings = make_array( // The order MUST be the same as the order in the original enum @@ -60,8 +75,7 @@ enum class JoinState : std::underlying_type_t { Invite = std::underlying_type_t(Membership::Invite), Knock = std::underlying_type_t(Membership::Knock), }; -Q_DECLARE_FLAGS(JoinStates, JoinState) -Q_FLAG_NS(JoinStates) +QUO_DECLARE_FLAGS_NS(JoinStates, JoinState) constexpr inline auto JoinStateStrings = make_array( MembershipStrings[0], MembershipStrings[1], MembershipStrings[2], -- cgit v1.2.3 From 65bb0b5fcf029df7a9bfa0b7b7b7e3203fd7862f Mon Sep 17 00:00:00 2001 From: Alexey Rusakov Date: Tue, 9 Nov 2021 13:59:47 +0100 Subject: DECL_DEPRECATED_ENUMERATOR A handy macro that introduces an enumerator with a respective Q_DECL_DEPRECATED_X recommending the substitution. --- lib/jobs/basejob.h | 6 +++--- lib/quotient_common.h | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'lib/quotient_common.h') diff --git a/lib/jobs/basejob.h b/lib/jobs/basejob.h index 119d7cce..ddf243ed 100644 --- a/lib/jobs/basejob.h +++ b/lib/jobs/basejob.h @@ -7,6 +7,7 @@ #include "requestdata.h" #include "../logging.h" #include "../converters.h" +#include "../quotient_common.h" #include #include @@ -33,9 +34,8 @@ class BaseJob : public QObject { } public: -#define WITH_DEPRECATED_ERROR_VERSION(Recommended) \ - Recommended, Recommended##Error Q_DECL_ENUMERATOR_DEPRECATED_X( \ - "Use " #Recommended) = Recommended +#define WITH_DEPRECATED_ERROR_VERSION(Recommended) \ + Recommended, DECL_DEPRECATED_ENUMERATOR(Recommended##Error, Recommended) /*! The status code of a job * diff --git a/lib/quotient_common.h b/lib/quotient_common.h index e1e14a14..3d8ace67 100644 --- a/lib/quotient_common.h +++ b/lib/quotient_common.h @@ -23,6 +23,9 @@ Q_ENUM_NS_IMPL(Enum) \ Q_FLAG_NS(Flags) +#define DECL_DEPRECATED_ENUMERATOR(Deprecated, Recommended) \ + Deprecated Q_DECL_ENUMERATOR_DEPRECATED_X("Use " #Recommended) = Recommended + namespace Quotient { Q_NAMESPACE -- cgit v1.2.3