diff --git a/src/core/processing/qgsprocessingparameters.cpp b/src/core/processing/qgsprocessingparameters.cpp index db83a397888..0e7574b2afb 100644 --- a/src/core/processing/qgsprocessingparameters.cpp +++ b/src/core/processing/qgsprocessingparameters.cpp @@ -622,7 +622,7 @@ QList 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 diff --git a/tests/src/core/testqgsprocessing.cpp b/tests/src/core/testqgsprocessing.cpp index 10915eaf1a1..6055079e74a 100644 --- a/tests/src/core/testqgsprocessing.cpp +++ b/tests/src/core/testqgsprocessing.cpp @@ -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 ) ) );