[vlmc-devel] [PATCH 3/4] Implement SettingValue::Type::Map
Yikai Lu
luyikei.qmltu at gmail.com
Sat Mar 12 06:32:36 CET 2016
---
src/Settings/SettingValue.h | 1 +
src/Settings/Settings.cpp | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
diff --git a/src/Settings/SettingValue.h b/src/Settings/SettingValue.h
index cf9932f..7ff9486 100644
--- a/src/Settings/SettingValue.h
+++ b/src/Settings/SettingValue.h
@@ -47,6 +47,7 @@ class SettingValue : public QObject
KeyboardShortcut,
Path,
List,
+ Map,
ByteArray, // For now this is only for private variables, and is not expected to be used at any time
//For effect engine settings:
Color,
diff --git a/src/Settings/Settings.cpp b/src/Settings/Settings.cpp
index e317b8c..abeaaa1 100644
--- a/src/Settings/Settings.cpp
+++ b/src/Settings/Settings.cpp
@@ -88,6 +88,23 @@ Settings::save( QXmlStreamWriter& project )
project.writeEndElement();
}
}
+ else if ( val->type() == SettingValue::Map )
+ {
+ const QMap<QString, QVariant>& map = val->get().toMap();
+ project.writeAttribute( "key", val->key() + "/Map" );
+ for ( auto it = map.begin();
+ it != map.end();
+ ++it
+ )
+ {
+ project.writeStartElement( "setting" );
+ project.writeAttribute( "key", it.key() );
+ if ( it.value().canConvert<QString>() == false )
+ vlmcWarning() << "Can't serialize" << it.key();
+ project.writeAttribute( "value", it.value().toString() );
+ project.writeEndElement();
+ }
+ }
else
{
project.writeAttribute( "key", val->key() );
@@ -136,6 +153,25 @@ Settings::load( const QDomDocument& document )
if ( setValue( key, list ) == false )
vlmcWarning() << "Loaded invalid project setting:" << key;
}
+ else if ( key.endsWith("/Map") )
+ {
+ key.chop(4);
+ if ( key.isEmpty() == true )
+ vlmcWarning() << "Invalid setting node.";
+ s = s.firstChildElement( "setting" );
+ QMap<QString, QVariant> map;
+ QString mKey;
+ while ( s.isNull() == false )
+ {
+ value = s.attribute( "value" );
+ mKey = s.attribute( "key" );
+ vlmcDebug() << "Loading" << key << ":" << mKey << "=>" << value;
+ map[ mKey ] = value;
+ s = s.nextSiblingElement();
+ }
+ if ( setValue( key, map ) == false )
+ vlmcWarning() << "Loaded invalid project setting:" << key;
+ }
else
{
value = s.attribute( "value" );
--
1.9.1
More information about the Vlmc-devel
mailing list