Skip to content

Commit 2564339

Browse files
committed
[processing] Fix QgsProcessingProvider::isSupportedOutputValue handling
of optional output parameters Refs #21374
1 parent 0546228 commit 2564339

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/core/processing/qgsprocessingprovider.cpp

+18-4
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,26 @@ QStringList QgsProcessingProvider::supportedOutputTableExtensions() const
109109

110110
bool QgsProcessingProvider::isSupportedOutputValue( const QVariant &outputValue, const QgsProcessingDestinationParameter *parameter, QgsProcessingContext &context, QString &error ) const
111111
{
112-
QString outputPath = QgsProcessingParameters::parameterAsOutputLayer( parameter, outputValue, context );
113112
error.clear();
113+
QString outputPath = QgsProcessingParameters::parameterAsOutputLayer( parameter, outputValue, context ).trimmed();
114+
115+
if ( outputPath.isEmpty() )
116+
{
117+
if ( parameter->flags() & QgsProcessingParameterDefinition::FlagOptional )
118+
{
119+
return true;
120+
}
121+
else
122+
{
123+
error = tr( "Missing parameter value %1" ).arg( parameter->description() );
124+
return false;
125+
}
126+
}
127+
114128
if ( parameter->type() == QgsProcessingParameterVectorDestination::typeName()
115129
|| parameter->type() == QgsProcessingParameterFeatureSink::typeName() )
116130
{
117-
if ( outputPath.isEmpty() || outputPath.startsWith( QLatin1String( "memory:" ) ) )
131+
if ( outputPath.startsWith( QLatin1String( "memory:" ) ) )
118132
{
119133
if ( !supportsNonFileBasedOutput() )
120134
{
@@ -145,7 +159,7 @@ bool QgsProcessingProvider::isSupportedOutputValue( const QVariant &outputValue,
145159

146160
if ( !supportedOutputVectorLayerExtensions().contains( extension, Qt::CaseInsensitive ) )
147161
{
148-
error = tr( "%1 files are not supported as outputs for this algorithm" ).arg( extension );
162+
error = tr( "“.%1” files are not supported as outputs for this algorithm" ).arg( extension );
149163
return false;
150164
}
151165
return true;
@@ -156,7 +170,7 @@ bool QgsProcessingProvider::isSupportedOutputValue( const QVariant &outputValue,
156170
const QString extension = fi.completeSuffix();
157171
if ( !supportedOutputRasterLayerExtensions().contains( extension, Qt::CaseInsensitive ) )
158172
{
159-
error = tr( "%1 files are not supported as outputs for this algorithm" ).arg( extension );
173+
error = tr( "“.%1” files are not supported as outputs for this algorithm" ).arg( extension );
160174
return false;
161175
}
162176
return true;

tests/src/analysis/testqgsprocessing.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -4867,6 +4867,8 @@ void TestQgsProcessing::parameterVectorOut()
48674867
def.reset( new QgsProcessingParameterVectorDestination( "with_geom", QString(), QgsProcessing::TypeVectorAnyGeometry, QString(), true ) );
48684868
DummyProvider3 provider;
48694869
QString error;
4870+
QVERIFY( provider.isSupportedOutputValue( QVariant(), def.get(), context, error ) ); // optional
4871+
QVERIFY( provider.isSupportedOutputValue( QString(), def.get(), context, error ) ); // optional
48704872
QVERIFY( !provider.isSupportedOutputValue( "d:/test.shp", def.get(), context, error ) );
48714873
QVERIFY( !provider.isSupportedOutputValue( "d:/test.SHP", def.get(), context, error ) );
48724874
QVERIFY( !provider.isSupportedOutputValue( "ogr:d:/test.shp", def.get(), context, error ) );
@@ -4875,6 +4877,9 @@ void TestQgsProcessing::parameterVectorOut()
48754877
QVERIFY( provider.isSupportedOutputValue( "d:/test.MIF", def.get(), context, error ) );
48764878
QVERIFY( provider.isSupportedOutputValue( "ogr:d:/test.MIF", def.get(), context, error ) );
48774879
QVERIFY( provider.isSupportedOutputValue( QgsProcessingOutputLayerDefinition( "d:/test.MIF" ), def.get(), context, error ) );
4880+
def.reset( new QgsProcessingParameterVectorDestination( "with_geom", QString(), QgsProcessing::TypeVectorAnyGeometry, QString(), false ) );
4881+
QVERIFY( !provider.isSupportedOutputValue( QVariant(), def.get(), context, error ) ); // non-optional
4882+
QVERIFY( !provider.isSupportedOutputValue( QString(), def.get(), context, error ) ); // non-optional
48784883

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

49874992
DummyProvider3 provider;
49884993
QString error;
4994+
QVERIFY( !provider.isSupportedOutputValue( QVariant(), def.get(), context, error ) );
4995+
QVERIFY( !provider.isSupportedOutputValue( QString(), def.get(), context, error ) );
49894996
QVERIFY( !provider.isSupportedOutputValue( "d:/test.tif", def.get(), context, error ) );
49904997
QVERIFY( !provider.isSupportedOutputValue( "d:/test.TIF", def.get(), context, error ) );
49914998
QVERIFY( !provider.isSupportedOutputValue( QgsProcessingOutputLayerDefinition( "d:/test.tif" ), def.get(), context, error ) );

0 commit comments

Comments
 (0)