aboutsummaryrefslogtreecommitdiff
path: root/lib/converters.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/converters.h')
-rw-r--r--lib/converters.h20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/converters.h b/lib/converters.h
index cc6378e4..8ec0fa81 100644
--- a/lib/converters.h
+++ b/lib/converters.h
@@ -134,7 +134,10 @@ struct JsonConverter<QString> : public TrivialJsonDumper<QString> {
template <>
struct JsonConverter<QDateTime> {
- static auto dump(const QDateTime& val) = delete; // not provided yet
+ static auto dump(const QDateTime& val)
+ {
+ return val.isValid() ? val.toMSecsSinceEpoch() : QJsonValue();
+ }
static auto load(const QJsonValue& jv)
{
return QDateTime::fromMSecsSinceEpoch(fromJson<qint64>(jv), Qt::UTC);
@@ -143,7 +146,15 @@ struct JsonConverter<QDateTime> {
template <>
struct JsonConverter<QDate> {
- static auto dump(const QDate& val) = delete; // not provided yet
+ static auto dump(const QDate& val) {
+ return toJson(
+#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
+ QDateTime(val)
+#else
+ val.startOfDay()
+#endif
+ );
+ }
static auto load(const QJsonValue& jv)
{
return fromJson<QDateTime>(jv).date();
@@ -242,12 +253,11 @@ struct JsonObjectConverter<QSet<QString>> {
for (const auto& e : s)
json.insert(toJson(e), QJsonObject {});
}
- static auto fillFrom(const QJsonObject& json, QSet<QString>& s)
+ static void fillFrom(const QJsonObject& json, QSet<QString>& s)
{
s.reserve(s.size() + json.size());
for (auto it = json.begin(); it != json.end(); ++it)
s.insert(it.key());
- return s;
}
};
@@ -260,7 +270,7 @@ struct HashMapFromJson {
}
static void fillFrom(const QJsonObject& jo, HashMapT& h)
{
- h.reserve(jo.size());
+ h.reserve(h.size() + jo.size());
for (auto it = jo.begin(); it != jo.end(); ++it)
h[it.key()] = fromJson<typename HashMapT::mapped_type>(it.value());
}