Skip to content

Commit

Permalink
[processing] Fix QgsProcessingProvider::isSupportedOutputValue handling
Browse files Browse the repository at this point in the history
of optional output parameters

Refs #21374
  • Loading branch information
nyalldawson committed Mar 19, 2019
1 parent a963eaa commit 8cff941
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/core/processing/qgsprocessingprovider.cpp
Expand Up @@ -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() )
{
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -5423,6 +5423,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 ) );
Expand All @@ -5431,6 +5433,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;
Expand Down Expand Up @@ -5546,6 +5551,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 ) );
Expand Down

0 comments on commit 8cff941

Please sign in to comment.