From 46b627241c61bcc5d8409dc1c185b91d285dbfe2 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Fri, 24 Feb 2017 11:10:38 +0100 Subject: Settings QStringList --- src/settings.cpp | 21 ++++++++++++++++++++- src/settings.h | 2 ++ test/config.toml | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/settings.cpp b/src/settings.cpp index edbecc0..efaed6f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -20,7 +20,6 @@ #include "settings.h" #include - #include Settings::Settings(const QString &configFile) @@ -84,10 +83,18 @@ QVariant Settings::value(const QString &key, const QVariant &defaultValue) const r = QVariant(x->as()); break; + case toml::Value::DOUBLE_TYPE: + r = QVariant(x->as()); + break; + case toml::Value::STRING_TYPE: r = QVariant(QString::fromStdString(x->as())); break; + case toml::Value::ARRAY_TYPE: + r = fromList(x); + break; + default: qWarning("Unhandled type in configuration"); r = defaultValue; @@ -103,3 +110,15 @@ QVariant Settings::value(const QString &key, const QVariant &defaultValue) const return r; } + +QVariant Settings::fromList(const toml::Value *list) const +{ + QStringList l; + + for(const toml::Value &v : list->as()) { + // TODO check value type + l.append(QString::fromStdString(v.as())); + } + + return QVariant(l); +} diff --git a/src/settings.h b/src/settings.h index 57d868c..b536d62 100644 --- a/src/settings.h +++ b/src/settings.h @@ -36,6 +36,8 @@ public: QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const; private: + QVariant fromList(const toml::Value *list) const; + toml::Value v; QString path; }; diff --git a/test/config.toml b/test/config.toml index 747282b..c64509c 100644 --- a/test/config.toml +++ b/test/config.toml @@ -10,7 +10,7 @@ profile="Default" [blocker] dialogShortcut="Ctrl+Shift+A" path="" -subscriptions="" +subscriptions=[] [bookmarks] dialogShortcut="Ctrl+Shift+B" -- cgit v1.2.1