Skip to content

Commit b57c0fa

Browse files
authored
Merge pull request #8998 from alexbruy/processing-tempdir
[processing] handle Processing.TEMPORARY_OUTPUT for folder parameters
2 parents d61caab + d5b42ae commit b57c0fa

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/core/processing/qgsprocessingparameters.cpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameter
8282
val = definition->defaultValue();
8383
}
8484

85+
if ( val == QgsProcessing::TEMPORARY_OUTPUT )
86+
{
87+
if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
88+
return destParam->generateTemporaryDestination();
89+
}
90+
8591
return val.toString();
8692
}
8793

@@ -695,7 +701,7 @@ QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParam
695701
if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
696702
{
697703
if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
698-
val = destParam->generateTemporaryDestination();
704+
dest = destParam->generateTemporaryDestination();
699705
}
700706
return dest;
701707
}

tests/src/analysis/testqgsprocessing.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -5495,12 +5495,12 @@ void TestQgsProcessing::parameterFileOut()
54955495
QCOMPARE( QgsProcessingParameters::parameterAsFileOutput( def.get(), params, context ), QStringLiteral( "test.txt" ) );
54965496

54975497
params.insert( QStringLiteral( "non_optional" ), QgsProcessing::TEMPORARY_OUTPUT );
5498-
QCOMPARE( QgsProcessingParameters::parameterAsFileOutput( def.get(), params, context ).right( 7 ), QStringLiteral( "_OUTPUT" ) );
5498+
QCOMPARE( QgsProcessingParameters::parameterAsFileOutput( def.get(), params, context ).right( 18 ), QStringLiteral( "/non_optional.file" ) );
54995499

55005500
QgsProcessingOutputLayerDefinition fs;
55015501
fs.sink = QgsProperty::fromValue( QgsProcessing::TEMPORARY_OUTPUT );
55025502
params.insert( QStringLiteral( "non_optional" ), QVariant::fromValue( fs ) );
5503-
QCOMPARE( QgsProcessingParameters::parameterAsFileOutput( def.get(), params, context ).right( 7 ), QStringLiteral( "_OUTPUT" ) );
5503+
QCOMPARE( QgsProcessingParameters::parameterAsFileOutput( def.get(), params, context ).right( 18 ), QStringLiteral( "/non_optional.file" ) );
55045504

55055505
QCOMPARE( def->valueAsPythonString( QVariant(), context ), QStringLiteral( "None" ) );
55065506
QCOMPARE( def->valueAsPythonString( QStringLiteral( "abc" ), context ), QStringLiteral( "'abc'" ) );
@@ -5656,6 +5656,10 @@ void TestQgsProcessing::parameterFolderOut()
56565656
QCOMPARE( fromCode->description(), QStringLiteral( "optional" ) );
56575657
QCOMPARE( fromCode->flags(), def->flags() );
56585658
QCOMPARE( fromCode->defaultValue(), def->defaultValue() );
5659+
5660+
// temporary directory
5661+
def.reset( new QgsProcessingParameterFolderDestination( "junkdir", QString(), QgsProcessing::TEMPORARY_OUTPUT ) );
5662+
QCOMPARE( QgsProcessingParameters::parameterAsString( def.get(), params, context ).right( 8 ), QStringLiteral( "/junkdir" ) );
56595663
}
56605664

56615665
void TestQgsProcessing::parameterBand()

tests/testdata/points_gpkg.gpkg

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)