diff --git a/python/PyQt6/core/auto_generated/processing/qgsprocessingparameters.sip.in b/python/PyQt6/core/auto_generated/processing/qgsprocessingparameters.sip.in index 62c3328742d1..ef7742de2b7e 100644 --- a/python/PyQt6/core/auto_generated/processing/qgsprocessingparameters.sip.in +++ b/python/PyQt6/core/auto_generated/processing/qgsprocessingparameters.sip.in @@ -1189,10 +1189,13 @@ need to handle deletion of the returned layer. Evaluates the parameter with matching ``definition`` to a output layer destination. %End - static QString parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context ); + static QString parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, bool testOnly = false ); %Docstring Evaluates the parameter with matching ``definition`` and ``value`` to a output layer destination. +Since QGIS 3.38 the ``testOnly`` argument can be set to ``True`` to evaluate the parameter to an output layer destination for advance testing only. This +prevents default behavior such as output post-processing which would otherwise occur. + .. versionadded:: 3.4 %End diff --git a/python/core/auto_generated/processing/qgsprocessingparameters.sip.in b/python/core/auto_generated/processing/qgsprocessingparameters.sip.in index 62c3328742d1..ef7742de2b7e 100644 --- a/python/core/auto_generated/processing/qgsprocessingparameters.sip.in +++ b/python/core/auto_generated/processing/qgsprocessingparameters.sip.in @@ -1189,10 +1189,13 @@ need to handle deletion of the returned layer. Evaluates the parameter with matching ``definition`` to a output layer destination. %End - static QString parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context ); + static QString parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, bool testOnly = false ); %Docstring Evaluates the parameter with matching ``definition`` and ``value`` to a output layer destination. +Since QGIS 3.38 the ``testOnly`` argument can be set to ``True`` to evaluate the parameter to an output layer destination for advance testing only. This +prevents default behavior such as output post-processing which would otherwise occur. + .. versionadded:: 3.4 %End diff --git a/src/core/processing/qgsprocessingparameters.cpp b/src/core/processing/qgsprocessingparameters.cpp index b58234ee8c6e..ca013fcd74d5 100644 --- a/src/core/processing/qgsprocessingparameters.cpp +++ b/src/core/processing/qgsprocessingparameters.cpp @@ -937,7 +937,7 @@ QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingPara return parameterAsOutputLayer( definition, val, context ); } -QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context ) +QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, bool testOnly ) { QVariant val = value; @@ -992,7 +992,8 @@ QString QgsProcessingParameters::parameterAsOutputLayer( const QgsProcessingPara else if ( definition && definition->type() == QgsProcessingParameterVectorTileDestination::typeName() ) layerTypeHint = QgsProcessingUtils::LayerHint::VectorTile; - context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, layerTypeHint ) ); + if ( !testOnly ) + context.addLayerToLoadOnCompletion( dest, QgsProcessingContext::LayerDetails( destName, destinationProject, outputName, layerTypeHint ) ); } return dest; diff --git a/src/core/processing/qgsprocessingparameters.h b/src/core/processing/qgsprocessingparameters.h index f9131c869f57..a3475602696d 100644 --- a/src/core/processing/qgsprocessingparameters.h +++ b/src/core/processing/qgsprocessingparameters.h @@ -1303,9 +1303,13 @@ class CORE_EXPORT QgsProcessingParameters /** * Evaluates the parameter with matching \a definition and \a value to a output layer destination. + * + * Since QGIS 3.38 the \a testOnly argument can be set to TRUE to evaluate the parameter to an output layer destination for advance testing only. This + * prevents default behavior such as output post-processing which would otherwise occur. + * * \since QGIS 3.4 */ - static QString parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context ); + static QString parameterAsOutputLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context, bool testOnly = false ); /** * Evaluates the parameter with matching \a definition to a file based output destination. diff --git a/tests/src/analysis/testqgsprocessing.cpp b/tests/src/analysis/testqgsprocessing.cpp index 99e7aeb61c9d..39b9baa29280 100644 --- a/tests/src/analysis/testqgsprocessing.cpp +++ b/tests/src/analysis/testqgsprocessing.cpp @@ -8090,6 +8090,11 @@ void TestQgsProcessing::parameterVectorOut() QCOMPARE( context.layersToLoadOnCompletion().values().at( 0 ).name, QStringLiteral( "desc" ) ); QCOMPARE( context.layersToLoadOnCompletion().values().at( 0 ).layerTypeHint, QgsProcessingUtils::LayerHint::Vector ); + // if we set testOnly = true, then layer should not be loaded on completion + context.setLayersToLoadOnCompletion( {} ); + QCOMPARE( QgsProcessingParameters::parameterAsOutputLayer( def.get(), QVariant::fromValue( fs ), context, true ), QStringLiteral( "test.shp" ) ); + QCOMPARE( context.layersToLoadOnCompletion().size(), 0 ); + // with name overloading QgsProcessingContext context2; fs = QgsProcessingOutputLayerDefinition( QStringLiteral( "test.shp" ) );