Skip to content

Commit

Permalink
Merge pull request #8998 from alexbruy/processing-tempdir
Browse files Browse the repository at this point in the history
[processing] handle Processing.TEMPORARY_OUTPUT for folder parameters
  • Loading branch information
alexbruy committed Jan 29, 2019
2 parents d61caab + d5b42ae commit b57c0fa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 7 additions & 1 deletion src/core/processing/qgsprocessingparameters.cpp
Expand Up @@ -82,6 +82,12 @@ QString QgsProcessingParameters::parameterAsString( const QgsProcessingParameter
val = definition->defaultValue();
}

if ( val == QgsProcessing::TEMPORARY_OUTPUT )
{
if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
return destParam->generateTemporaryDestination();
}

return val.toString();
}

Expand Down Expand Up @@ -695,7 +701,7 @@ QString QgsProcessingParameters::parameterAsFileOutput( const QgsProcessingParam
if ( dest == QgsProcessing::TEMPORARY_OUTPUT )
{
if ( const QgsProcessingDestinationParameter *destParam = dynamic_cast< const QgsProcessingDestinationParameter * >( definition ) )
val = destParam->generateTemporaryDestination();
dest = destParam->generateTemporaryDestination();
}
return dest;
}
Expand Down
8 changes: 6 additions & 2 deletions tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -5495,12 +5495,12 @@ void TestQgsProcessing::parameterFileOut()
QCOMPARE( QgsProcessingParameters::parameterAsFileOutput( def.get(), params, context ), QStringLiteral( "test.txt" ) );

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

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

QCOMPARE( def->valueAsPythonString( QVariant(), context ), QStringLiteral( "None" ) );
QCOMPARE( def->valueAsPythonString( QStringLiteral( "abc" ), context ), QStringLiteral( "'abc'" ) );
Expand Down Expand Up @@ -5656,6 +5656,10 @@ void TestQgsProcessing::parameterFolderOut()
QCOMPARE( fromCode->description(), QStringLiteral( "optional" ) );
QCOMPARE( fromCode->flags(), def->flags() );
QCOMPARE( fromCode->defaultValue(), def->defaultValue() );

// temporary directory
def.reset( new QgsProcessingParameterFolderDestination( "junkdir", QString(), QgsProcessing::TEMPORARY_OUTPUT ) );
QCOMPARE( QgsProcessingParameters::parameterAsString( def.get(), params, context ).right( 8 ), QStringLiteral( "/junkdir" ) );
}

void TestQgsProcessing::parameterBand()
Expand Down
Binary file modified tests/testdata/points_gpkg.gpkg
Binary file not shown.

0 comments on commit b57c0fa

Please sign in to comment.