[vlmc-devel] [PATCH 2/3] Implement SettingValue::Type::List
Yikai Lu
luyikei.qmltu at gmail.com
Fri Mar 11 18:04:46 CET 2016
---
src/Settings/SettingValue.h | 1 +
src/Settings/Settings.cpp | 52 ++++++++++++++++++++++++++++++++++++++-------
2 files changed, 45 insertions(+), 8 deletions(-)
diff --git a/src/Settings/SettingValue.h b/src/Settings/SettingValue.h
index ebc225e..cf9932f 100644
--- a/src/Settings/SettingValue.h
+++ b/src/Settings/SettingValue.h
@@ -46,6 +46,7 @@ class SettingValue : public QObject
Language,
KeyboardShortcut,
Path,
+ List,
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 e888b78..6493546 100644
--- a/src/Settings/Settings.cpp
+++ b/src/Settings/Settings.cpp
@@ -77,10 +77,25 @@ Settings::save( QXmlStreamWriter& project )
if ( ( val->flags() & SettingValue::Runtime ) != 0 )
continue ;
project.writeStartElement( "setting" );
- project.writeAttribute( "key", val->key() );
- if ( val->get().canConvert<QString>() == false )
- vlmcWarning() << "Can't serialize" << val->key();
- project.writeAttribute( "value", val->get().toString() );
+ if ( val->type() == SettingValue::List )
+ {
+ project.writeAttribute( "key", val->key() + "/List" );
+ for ( const QVariant& var: val->get().toList() ) {
+ project.writeStartElement( "setting" );
+ project.writeAttribute( "key", val->key() );
+ if ( var.canConvert<QString>() == false )
+ vlmcWarning() << "Can't serialize" << val->key();
+ project.writeAttribute( "value", var.toString() );
+ project.writeEndElement();
+ }
+ }
+ else
+ {
+ project.writeAttribute( "key", val->key() );
+ if ( val->get().canConvert<QString>() == false )
+ vlmcWarning() << "Can't serialize" << val->key();
+ project.writeAttribute( "value", val->get().toString() );
+ }
project.writeEndElement();
}
project.writeEndElement();
@@ -100,15 +115,36 @@ Settings::load( const QDomDocument& document )
while ( s.isNull() == false )
{
QString key = s.attribute( "key" );
- QString value = s.attribute( "value" );
+ QString value;
if ( key.isEmpty() == true )
vlmcWarning() << "Invalid setting node.";
else
{
- vlmcDebug() << "Loading" << key << "=>" << value;
- if ( setValue( key, value ) == false )
- vlmcWarning() << "Loaded invalid project setting:" << key;
+ if ( key.endsWith("/List") )
+ {
+ key.chop(5);
+ s = s.firstChildElement( "setting" );
+ QList<QVariant> list;
+ while ( s.isNull() == false )
+ {
+ if ( key.isEmpty() == true )
+ vlmcWarning() << "Invalid setting node.";
+ value = s.attribute( "value" );
+ vlmcDebug() << "Loading" << key << "=>" << value;
+ list << QVariant::fromValue( value );
+ s = s.nextSiblingElement();
+ }
+ if ( setValue( key, list ) == false )
+ vlmcWarning() << "Loaded invalid project setting:" << key;
+ }
+ else
+ {
+ value = s.attribute( "value" );
+ vlmcDebug() << "Loading" << key << "=>" << value;
+ if ( setValue( key, value ) == false )
+ vlmcWarning() << "Loaded invalid project setting:" << key;
+ }
}
s = s.nextSiblingElement();
}
--
1.9.1
More information about the Vlmc-devel
mailing list