diff options
author | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-10-12 19:17:42 +0200 |
---|---|---|
committer | Alexey Rusakov <Kitsune-Ral@users.sf.net> | 2021-10-12 19:17:42 +0200 |
commit | de164d60f2561fb0ad142b5d4fd31ff9817c2725 (patch) | |
tree | 68ba074d5ba712211218f5926efd88f77fd548d2 /lib | |
parent | fd915b0865bde5741ceb1dd1e76a99d25b8c63fd (diff) | |
download | libquotient-de164d60f2561fb0ad142b5d4fd31ff9817c2725.tar.gz libquotient-de164d60f2561fb0ad142b5d4fd31ff9817c2725.zip |
Make sure to expose both the flags type and the underlying enum
See also https://bugreports.qt.io/browse/QTBUG-82295.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/quotient_common.h | 22 | ||||
-rw-r--r-- | lib/room.h | 3 |
2 files changed, 19 insertions, 6 deletions
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 <array> +// 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<Membership> { Invite = std::underlying_type_t<Membership>(Membership::Invite), Knock = std::underlying_type_t<Membership>(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], @@ -148,8 +148,7 @@ public: OtherChange = 0x8000, AnyChange = 0xFFFF }; - Q_DECLARE_FLAGS(Changes, Change) - Q_FLAG(Changes) + QUO_DECLARE_FLAGS(Changes, Change) Room(Connection* connection, QString id, JoinState initialJoinState); ~Room() override; |