From bf1dc1484ad5aefd5b86f7f79f23f5d6fc9b940a Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Fri, 13 Apr 2018 19:49:55 +0900 Subject: converters.h: Support QVariantMap and QVariantHash --- lib/converters.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'lib/converters.h') diff --git a/lib/converters.h b/lib/converters.h index bba298e0..22b22f25 100644 --- a/lib/converters.h +++ b/lib/converters.h @@ -21,6 +21,7 @@ #include #include // Includes #include +#include namespace QMatrixClient { @@ -51,6 +52,18 @@ namespace QMatrixClient return QJsonValue(bytes.constData()); } + inline QJsonObject toJson(const QVariantMap& map) + { + return QJsonObject::fromVariantMap(map); + } + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)) + inline QJsonObject toJson(const QVariantHash& hMap) + { + return QJsonObject::fromVariantHash(hMap); + } +#endif + template inline QJsonObject toJson(const QHash& hashMap) { @@ -163,6 +176,24 @@ namespace QMatrixClient } }; + template <> struct FromJson + { + inline auto operator()(const QJsonValue& jv) const + { + return jv.toObject().toVariantMap(); + } + }; + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)) + template <> struct FromJson + { + inline auto operator()(const QJsonValue& jv) const + { + return jv.toObject().toVariantHash(); + } + }; +#endif + template struct FromJson> { QHash operator()(const QJsonValue& jv) const -- cgit v1.2.3