aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-08-07 22:06:42 +0200
committerAlexey Rusakov <Kitsune-Ral@users.sf.net>2021-08-07 22:06:42 +0200
commit35ce036407e1865402d01070e9680a9cda4f361c (patch)
tree6d32773e42ad1bca7e9d8f8eaf48be1c332fee45 /lib
parentf81aa4d723577ce30518424510e45ef39ff0e29e (diff)
downloadlibquotient-35ce036407e1865402d01070e9680a9cda4f361c.tar.gz
libquotient-35ce036407e1865402d01070e9680a9cda4f361c.zip
converters.h: (actually) enable QUrl; drop unused types
QUrl can now be converted even with QT_NO_URL_CAST_FROM_STRING; and it can also be put to queries. QByteArray did not really need conversion in JSON context; and QJsonObject is/was never used in queries.
Diffstat (limited to 'lib')
-rw-r--r--lib/converters.h33
1 files changed, 15 insertions, 18 deletions
diff --git a/lib/converters.h b/lib/converters.h
index af6c0192..cc6378e4 100644
--- a/lib/converters.h
+++ b/lib/converters.h
@@ -151,10 +151,17 @@ struct JsonConverter<QDate> {
};
template <>
-struct JsonConverter<QUrl> : JsonConverter<QString> {
- static auto dump(const QUrl& url) // Override on top of that for QString
+struct JsonConverter<QUrl> {
+ static auto load(const QJsonValue& jv)
+ {
+ // QT_NO_URL_CAST_FROM_STRING makes this a bit more verbose
+ QUrl url;
+ url.setUrl(jv.toString());
+ return url;
+ }
+ static auto dump(const QUrl& url)
{
- return JsonConverter<QString>::dump(url.toString(QUrl::FullyEncoded));
+ return url.toString(QUrl::FullyEncoded);
}
};
@@ -164,15 +171,6 @@ struct JsonConverter<QJsonArray> : public TrivialJsonDumper<QJsonArray> {
};
template <>
-struct JsonConverter<QByteArray> {
- static QString dump(const QByteArray& ba) { return ba.constData(); }
- static auto load(const QJsonValue& jv)
- {
- return fromJson<QString>(jv).toLatin1();
- }
-};
-
-template <>
struct JsonConverter<QVariant> {
static QJsonValue dump(const QVariant& v);
static QVariant load(const QJsonValue& jv);
@@ -304,16 +302,15 @@ namespace _impl {
q.addQueryItem(k, v ? QStringLiteral("true") : QStringLiteral("false"));
}
- inline void addTo(QUrlQuery& q, const QString& k, const QStringList& vals)
+ inline void addTo(QUrlQuery& q, const QString& k, const QUrl& v)
{
- for (const auto& v : vals)
- q.addQueryItem(k, v);
+ q.addQueryItem(k, v.toEncoded());
}
- inline void addTo(QUrlQuery& q, const QString&, const QJsonObject& vals)
+ inline void addTo(QUrlQuery& q, const QString& k, const QStringList& vals)
{
- for (auto it = vals.begin(); it != vals.end(); ++it)
- q.addQueryItem(it.key(), it.value().toString());
+ for (const auto& v : vals)
+ q.addQueryItem(k, v);
}
// This one is for types that don't have isEmpty() and for all types