Skip to content
Permalink
Browse files

Merge pull request #8998 from alexbruy/processing-tempdir

[processing] handle Processing.TEMPORARY_OUTPUT for folder parameters
  • Loading branch information
alexbruy committed Jan 29, 2019
2 parents d61caab + d5b42ae commit b57c0fa9ede9b1e3bf1ae103b9d74eac3b02dd1a
@@ -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();
}

@@ -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;
}
@@ -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'" ) );
@@ -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()
BIN +0 Bytes (100%) tests/testdata/points_gpkg.gpkg
Binary file not shown.

0 comments on commit b57c0fa

Please sign in to comment.
You can’t perform that action at this time.