Skip to content

Commit b12f33b

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

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/core/processing/qgsprocessingprovider.cpp

Lines changed: 18 additions & 4 deletions
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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5319,6 +5319,8 @@ void TestQgsProcessing::parameterVectorOut()
53195319
def.reset( new QgsProcessingParameterVectorDestination( "with_geom", QString(), QgsProcessing::TypeVectorAnyGeometry, QString(), true ) );
53205320
DummyProvider3 provider;
53215321
QString error;
5322+
QVERIFY( provider.isSupportedOutputValue( QVariant(), def.get(), context, error ) ); // optional
5323+
QVERIFY( provider.isSupportedOutputValue( QString(), def.get(), context, error ) ); // optional
53225324
QVERIFY( !provider.isSupportedOutputValue( "d:/test.shp", def.get(), context, error ) );
53235325
QVERIFY( !provider.isSupportedOutputValue( "d:/test.SHP", def.get(), context, error ) );
53245326
QVERIFY( !provider.isSupportedOutputValue( "ogr:d:/test.shp", def.get(), context, error ) );
@@ -5327,6 +5329,9 @@ void TestQgsProcessing::parameterVectorOut()
53275329
QVERIFY( provider.isSupportedOutputValue( "d:/test.MIF", def.get(), context, error ) );
53285330
QVERIFY( provider.isSupportedOutputValue( "ogr:d:/test.MIF", def.get(), context, error ) );
53295331
QVERIFY( provider.isSupportedOutputValue( QgsProcessingOutputLayerDefinition( "d:/test.MIF" ), def.get(), context, error ) );
5332+
def.reset( new QgsProcessingParameterVectorDestination( "with_geom", QString(), QgsProcessing::TypeVectorAnyGeometry, QString(), false ) );
5333+
QVERIFY( !provider.isSupportedOutputValue( QVariant(), def.get(), context, error ) ); // non-optional
5334+
QVERIFY( !provider.isSupportedOutputValue( QString(), def.get(), context, error ) ); // non-optional
53305335

53315336
provider.loadAlgorithms();
53325337
def->mOriginalProvider = &provider;
@@ -5442,6 +5447,8 @@ void TestQgsProcessing::parameterRasterOut()
54425447

54435448
DummyProvider3 provider;
54445449
QString error;
5450+
QVERIFY( !provider.isSupportedOutputValue( QVariant(), def.get(), context, error ) );
5451+
QVERIFY( !provider.isSupportedOutputValue( QString(), def.get(), context, error ) );
54455452
QVERIFY( !provider.isSupportedOutputValue( "d:/test.tif", def.get(), context, error ) );
54465453
QVERIFY( !provider.isSupportedOutputValue( "d:/test.TIF", def.get(), context, error ) );
54475454
QVERIFY( !provider.isSupportedOutputValue( QgsProcessingOutputLayerDefinition( "d:/test.tif" ), def.get(), context, error ) );

0 commit comments

Comments
 (0)