diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-04-13 19:49:55 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-04-13 20:33:00 +0900 |
commit | bf1dc1484ad5aefd5b86f7f79f23f5d6fc9b940a (patch) | |
tree | 887e97b7387b0c3354ad24b59b35797d76e804c7 /lib/converters.h | |
parent | 7ca442a432994a19a86d43c917a1f537bcebb387 (diff) | |
download | libquotient-bf1dc1484ad5aefd5b86f7f79f23f5d6fc9b940a.tar.gz libquotient-bf1dc1484ad5aefd5b86f7f79f23f5d6fc9b940a.zip |
converters.h: Support QVariantMap and QVariantHash
Diffstat (limited to 'lib/converters.h')
-rw-r--r-- | lib/converters.h | 31 |
1 files changed, 31 insertions, 0 deletions
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 <QtCore/QJsonObject> #include <QtCore/QJsonArray> // Includes <QtCore/QJsonValue> #include <QtCore/QDate> +#include <QtCore/QVariant> 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 <typename T> inline QJsonObject toJson(const QHash<QString, T>& hashMap) { @@ -163,6 +176,24 @@ namespace QMatrixClient } }; + template <> struct FromJson<QVariantMap> + { + inline auto operator()(const QJsonValue& jv) const + { + return jv.toObject().toVariantMap(); + } + }; + +#if (QT_VERSION >= QT_VERSION_CHECK(5, 5, 0)) + template <> struct FromJson<QVariantHash> + { + inline auto operator()(const QJsonValue& jv) const + { + return jv.toObject().toVariantHash(); + } + }; +#endif + template <typename T> struct FromJson<QHash<QString, T>> { QHash<QString, T> operator()(const QJsonValue& jv) const |