aboutsummaryrefslogtreecommitdiff
path: root/lib/converters.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/converters.h')
-rw-r--r--lib/converters.h31
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