[vlmc-devel] [PATCH 2/2] Implement SettingValue::Type::List
yikei lu
luyikei.qmltu at gmail.com
Fri Mar 11 11:44:42 CET 2016
In Library,
QDomElement media = medias.firstChildElement();
while ( media.isNull() == false )
{
if ( media.hasAttribute( "mrl" ) == true )
{
QString mrl = media.attribute( "mrl" );
mrl = m_workspace->toAbsolutePath( mrl );
Media* m = addMedia( mrl );
if ( m == NULL )
vlmcWarning() << "Failed to load media" << mrl <<
"when loading project.";
else
m_nbMediaToLoad.fetchAndAddAcquire( 1 );
}
media = media.nextSiblingElement();
}
Like this code, while we don't have to use QList, I'm sure that it
will be convenient if we can use it. Especially if we want to save a
list of tracks, recent projects....
2016-03-11 19:31 GMT+09:00 Hugo Beauzée-Luyssen <hugo at beauzee.fr>:
> 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,
> _______________________________________________
> Vlmc-devel mailing list
> Vlmc-devel at videolan.org
> https://mailman.videolan.org/listinfo/vlmc-devel
More information about the Vlmc-devel
mailing list