summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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>