aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2017-02-24 11:10:38 +0100
committerAqua-sama <aqua@iserlohn-fortress.net>2017-02-24 11:10:38 +0100
commit46b627241c61bcc5d8409dc1c185b91d285dbfe2 (patch)
tree4a1b36bac5c58d46650e9e4dfa0f8686fccaf3bf
parentSettings class rework (diff)
downloadsmolbote-46b627241c61bcc5d8409dc1c185b91d285dbfe2.tar.xz
Settings QStringList
-rw-r--r--src/settings.cpp21
-rw-r--r--src/settings.h2
-rw-r--r--test/config.toml2
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 <QStandardPaths>
-
#include <fstream>
Settings::Settings(const QString &configFile)
@@ -84,10 +83,18 @@ QVariant Settings::value(const QString &key, const QVariant &defaultValue) const
r = QVariant(x->as<int>());
break;
+ case toml::Value::DOUBLE_TYPE:
+ r = QVariant(x->as<double>());
+ break;
+
case toml::Value::STRING_TYPE:
r = QVariant(QString::fromStdString(x->as<std::string>()));
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<toml::Array>()) {
+ // TODO check value type
+ l.append(QString::fromStdString(v.as<std::string>()));
+ }
+
+ 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"