Fix default layer sometimes inserted into multi layer parameter values

This commit is contained in:
Nyall Dawson 2017-08-17 04:38:36 +10:00
parent 48eccc379d
commit e1b0f78619
2 changed files with 4 additions and 1 deletions

View File

@ -622,7 +622,7 @@ QList<QgsMapLayer *> QgsProcessingParameters::parameterAsLayerList( const QgsPro
else
resultStringList << val.toString();
if ( ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
if ( layers.isEmpty() && ( resultStringList.isEmpty() || resultStringList.at( 0 ).isEmpty() ) )
{
resultStringList.clear();
// check default

View File

@ -2310,6 +2310,9 @@ void TestQgsProcessing::parameterLayerList()
params.insert( "optional", QVariant() );
QCOMPARE( QgsProcessingParameters::parameterAsLayerList( def.get(), params, context ), QList< QgsMapLayer *>() << v1 );
params.insert( "optional", QVariantList() << QVariant::fromValue( r1 ) );
QCOMPARE( QgsProcessingParameters::parameterAsLayerList( def.get(), params, context ), QList< QgsMapLayer *>() << r1 );
code = def->asScriptCode();
QCOMPARE( code, QStringLiteral( "##optional=optional multiple vector " ) + v1->id() );
fromCode.reset( dynamic_cast< QgsProcessingParameterMultipleLayers * >( QgsProcessingParameters::parameterFromScriptCode( code ) ) );