Skip to content
Permalink
Browse files

[processing] Fix QgsProcessingProvider::isSupportedOutputValue handling

of optional output parameters

Refs #21374
  • Loading branch information
nyalldawson committed Mar 19, 2019
1 parent 0546228 commit 2564339e369aa4b2d69f01fb291fedab5d97750a
Showing with 25 additions and 4 deletions.
  1. +18 −4 src/core/processing/qgsprocessingprovider.cpp
  2. +7 −0 tests/src/analysis/testqgsprocessing.cpp
@@ -109,12 +109,26 @@ QStringList QgsProcessingProvider::supportedOutputTableExtensions() const

bool QgsProcessingProvider::isSupportedOutputValue( const QVariant &outputValue, const QgsProcessingDestinationParameter *parameter, QgsProcessingContext &context, QString &error ) const
{
QString outputPath = QgsProcessingParameters::parameterAsOutputLayer( parameter, outputValue, context );
error.clear();
QString outputPath = QgsProcessingParameters::parameterAsOutputLayer( parameter, outputValue, context ).trimmed();

if ( outputPath.isEmpty() )
{
if ( parameter->flags() & QgsProcessingParameterDefinition::FlagOptional )
{
return true;
}
else
{
error = tr( "Missing parameter value %1" ).arg( parameter->description() );
return false;
}
}

if ( parameter->type() == QgsProcessingParameterVectorDestination::typeName()
|| parameter->type() == QgsProcessingParameterFeatureSink::typeName() )
{
if ( outputPath.isEmpty() || outputPath.startsWith( QLatin1String( "memory:" ) ) )
if ( outputPath.startsWith( QLatin1String( "memory:" ) ) )
{
if ( !supportsNonFileBasedOutput() )
{
@@ -145,7 +159,7 @@ bool QgsProcessingProvider::isSupportedOutputValue( const QVariant &outputValue,

if ( !supportedOutputVectorLayerExtensions().contains( extension, Qt::CaseInsensitive ) )
{
error = tr( "%1 files are not supported as outputs for this algorithm" ).arg( extension );
error = tr( "“.%1” files are not supported as outputs for this algorithm" ).arg( extension );
return false;
}
return true;
@@ -156,7 +170,7 @@ bool QgsProcessingProvider::isSupportedOutputValue( const QVariant &outputValue,
const QString extension = fi.completeSuffix();
if ( !supportedOutputRasterLayerExtensions().contains( extension, Qt::CaseInsensitive ) )
{
error = tr( "%1 files are not supported as outputs for this algorithm" ).arg( extension );
error = tr( "“.%1” files are not supported as outputs for this algorithm" ).arg( extension );
return false;
}
return true;
@@ -4867,6 +4867,8 @@ void TestQgsProcessing::parameterVectorOut()
def.reset( new QgsProcessingParameterVectorDestination( "with_geom", QString(), QgsProcessing::TypeVectorAnyGeometry, QString(), true ) );
DummyProvider3 provider;
QString error;
QVERIFY( provider.isSupportedOutputValue( QVariant(), def.get(), context, error ) ); // optional
QVERIFY( provider.isSupportedOutputValue( QString(), def.get(), context, error ) ); // optional
QVERIFY( !provider.isSupportedOutputValue( "d:/test.shp", def.get(), context, error ) );
QVERIFY( !provider.isSupportedOutputValue( "d:/test.SHP", def.get(), context, error ) );
QVERIFY( !provider.isSupportedOutputValue( "ogr:d:/test.shp", def.get(), context, error ) );
@@ -4875,6 +4877,9 @@ void TestQgsProcessing::parameterVectorOut()
QVERIFY( provider.isSupportedOutputValue( "d:/test.MIF", def.get(), context, error ) );
QVERIFY( provider.isSupportedOutputValue( "ogr:d:/test.MIF", def.get(), context, error ) );
QVERIFY( provider.isSupportedOutputValue( QgsProcessingOutputLayerDefinition( "d:/test.MIF" ), def.get(), context, error ) );
def.reset( new QgsProcessingParameterVectorDestination( "with_geom", QString(), QgsProcessing::TypeVectorAnyGeometry, QString(), false ) );
QVERIFY( !provider.isSupportedOutputValue( QVariant(), def.get(), context, error ) ); // non-optional
QVERIFY( !provider.isSupportedOutputValue( QString(), def.get(), context, error ) ); // non-optional

provider.loadAlgorithms();
def->mOriginalProvider = &provider;
@@ -4986,6 +4991,8 @@ void TestQgsProcessing::parameterRasterOut()

DummyProvider3 provider;
QString error;
QVERIFY( !provider.isSupportedOutputValue( QVariant(), def.get(), context, error ) );
QVERIFY( !provider.isSupportedOutputValue( QString(), def.get(), context, error ) );
QVERIFY( !provider.isSupportedOutputValue( "d:/test.tif", def.get(), context, error ) );
QVERIFY( !provider.isSupportedOutputValue( "d:/test.TIF", def.get(), context, error ) );
QVERIFY( !provider.isSupportedOutputValue( QgsProcessingOutputLayerDefinition( "d:/test.tif" ), def.get(), context, error ) );

0 comments on commit 2564339

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