[vlmc-devel] [PATCH 2/2] Implement SettingValue::Type::List

Hugo Beauzée-Luyssen hugo at beauzee.fr
Fri Mar 11 11:31:15 CET 2016


On 03/11/2016 07:09 AM, Yikai Lu wrote:
> In order to remove save/load methods in many classes, we need to be able to save QList.
>
> ---
>   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 ab48a23..2b5dc26 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();
>       }
>

I'm not sure I understand the reason for this patch.
Granted, project save/load is in a bad shape now, but it used to work 
without QList handling. What are the values that *need* QList ?

Regards,


More information about the Vlmc-devel mailing list