diff --git a/src/blackmisc/blackmiscfreefunctions.cpp b/src/blackmisc/blackmiscfreefunctions.cpp index db1c641fe..49800d353 100644 --- a/src/blackmisc/blackmiscfreefunctions.cpp +++ b/src/blackmisc/blackmiscfreefunctions.cpp @@ -169,6 +169,19 @@ QVariant BlackMisc::fixQVariantFromDbusArgument(const QVariant &variant, int loc // complex Qt type, e.g. QDateTime return complexQtTypeFromDbusArgument(arg, localUserType); } + else if (QMetaType(localUserType).flags() & QMetaType::IsEnumeration) + { + arg.beginStructure(); + int i; + arg >> i; + arg.endStructure(); + + QVariant valueVariant = QVariant::fromValue(i); + bool ok = valueVariant.convert(localUserType); + Q_ASSERT_X(ok, Q_FUNC_INFO, "int could not be converted to enum"); + Q_UNUSED(ok); + return valueVariant; + } else { QVariant valueVariant(localUserType, nullptr); diff --git a/src/blackmisc/dbus.h b/src/blackmisc/dbus.h index f53ae22d1..c4a647ba3 100644 --- a/src/blackmisc/dbus.h +++ b/src/blackmisc/dbus.h @@ -99,20 +99,29 @@ namespace BlackMisc } // BlackMisc /*! - * Non-member non-friend operator for streaming enums to QDBusArgument. - * - * \param argument - * \param enumType - * \return - * \remarks Currently outside namespace for OSX build, see https://dev.vatsim-germany.org/issues/184 + * Operator for streaming enums to QDBusArgument. */ -template typename std::enable_if::value, QDBusArgument>::type const & -operator>>(const QDBusArgument &argument, ENUM &enumType) +template ::value, int>::type = 0> +QDBusArgument &operator <<(QDBusArgument &arg, const E &value) { - uint e; - argument >> e; - enumType = static_cast(e); - return argument; + arg.beginStructure(); + arg << static_cast(value); + arg.endStructure(); + return arg; +} + +/*! + * Operator for streaming enums from QDBusArgument. + */ +template ::value, int>::type = 0> +const QDBusArgument &operator >>(const QDBusArgument &arg, E &value) +{ + int temp; + arg.beginStructure(); + arg >> temp; + arg.endStructure(); + value = static_cast(temp); + return arg; } /*! diff --git a/src/blackmisc/tuple_private.h b/src/blackmisc/tuple_private.h index e4a735c51..5ad918c91 100644 --- a/src/blackmisc/tuple_private.h +++ b/src/blackmisc/tuple_private.h @@ -320,6 +320,8 @@ namespace BlackMisc } template ::value, int>::type = 0> static void marshallHelper(QDBusArgument &arg, const T &val, int) { static_cast(val).marshallToDbus(arg); } + template ::value, int>::type = 0> + static void marshallHelper(QDBusArgument &arg, const T &val, int) { arg << static_cast(val); } template static void marshallHelper(QDBusArgument &arg, const T &val, ...) { arg << val; } @@ -332,6 +334,8 @@ namespace BlackMisc } template ::value, int>::type = 0> static void unmarshallHelper(const QDBusArgument &arg, T &val, int) { static_cast(val).unmarshallFromDbus(arg); } + template ::value, int>::type = 0> + static void unmarshallHelper(const QDBusArgument &arg, T &val, int) { int i; arg >> i; val = static_cast(i); } template static void unmarshallHelper(const QDBusArgument &arg, T &val, ...) { arg >> val; }