summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarkus Mittendrein <git@maxmitti.tk>2015-10-15 15:49:11 +0200
committerMarkus Mittendrein <git@maxmitti.tk>2015-10-15 15:49:11 +0200
commitf6f6860c0365409a0389681e65e5c46b56db1690 (patch)
treeb96f66d7d7306cac73115725eb608fd2e1a430b4 /src
parent139de5aa8b0a278f23056d8bcd9ad0fffd34db68 (diff)
downloadmanager-f6f6860c0365409a0389681e65e5c46b56db1690.tar.gz
manager-f6f6860c0365409a0389681e65e5c46b56db1690.zip
Add setValue() and value() to map-specialization of ConfigValue
for inline saving
Diffstat (limited to 'src')
-rw-r--r--src/ConfigBase.hpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/ConfigBase.hpp b/src/ConfigBase.hpp
index ae3c3de..7c0bcd5 100644
--- a/src/ConfigBase.hpp
+++ b/src/ConfigBase.hpp
@@ -206,9 +206,11 @@ class ConfigValue<QMap<KeyType, ValueType>> : public ConfigValueMap {
using MapType = QMap<KeyType, ValueType>;
MapType& config;
+ const QChar assignChar;
+ const QChar splitChar;
public:
- ConfigValue(MapType& config) : config(config) {}
+ ConfigValue(MapType& config, const QChar assignChar = ':', const QChar splitChar = ';') : config(config), assignChar(assignChar), splitChar(splitChar) {}
virtual MapType& map() { return config; }
virtual ConfigValueType::Type type() { return ConfigValueType::Type::Map; }
@@ -234,6 +236,31 @@ public:
{
config.remove(ConfigValueBase::getValue<KeyType>(key));
}
+
+ QString value()
+ {
+ QStringList ret;
+ foreach(const KeyType& key, config.keys())
+ {
+ ret.append(Util::joinEscape({ConfigValueBase::getStringValue(key), ConfigValueBase::getStringValue(config.value(key))}, assignChar));
+ }
+ return Util::joinEscape(ret, splitChar);
+ }
+
+ void setValue(const QString& value)
+ {
+ config.clear();
+ QStringList parts = Util::splitEscaped(value, splitChar);
+ foreach(const QString& part, parts)
+ {
+ QStringList parts = Util::splitEscaped(part, assignChar);
+ if(parts.length() != 2)
+ {
+ throw ConfigException("Cannot parse corrupt map key-value-pair");
+ }
+ config[ConfigValueBase::getValue<KeyType>(parts.first())] = ConfigValueBase::getValue<ValueType>(parts.at(1));
+ }
+ }
};
template<typename Type>