Commit 15eb10db authored by Volker Krause's avatar Volker Krause
Browse files

Factor out JSON to QStringList decoding method

Will be needed for loading the new coverage data.
parent 90c236d7
......@@ -37,6 +37,17 @@ QString Json::translatedValue(const QJsonObject &obj, const QString &key)
return obj.value(key).toString();
}
QStringList Json::toStringList(const QJsonValue &v)
{
const auto a = v.toArray();
QStringList l;
l.reserve(a.size());
for (const auto &av : a) {
l.push_back(av.toString());
}
return l;
}
static QJsonValue variantToJson(const QVariant &v)
{
switch (v.userType()) {
......@@ -164,15 +175,7 @@ static QVariant variantFromJson(const QJsonValue &v, int mt)
case QVariant::Url:
return QUrl(v.toString());
case QVariant::StringList:
{
const auto a = v.toArray();
QStringList l;
l.reserve(a.size());
for (const auto &av : a) {
l.push_back(av.toString());
}
return l;
}
return Json::toStringList(v);
case QVariant::RectF:
{
const auto obj = v.toObject();
......
......@@ -13,6 +13,7 @@
#include <vector>
struct QMetaObject;
class QStringList;
namespace KPublicTransport {
......@@ -21,6 +22,8 @@ namespace Json
{
/** Looks for a translated value in @p obj with @p key. */
QString translatedValue(const QJsonObject &obj, const QString &key);
/** Convert a QJsonValue to a QStringList, assuming it contains an array of strings. */
QStringList toStringList(const QJsonValue &v);
QJsonObject toJson(const QMetaObject *mo, const void *elem);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment