Skip to content
Permalink
Browse files

[processing] A non optional, multiple field input must have at least

one selected field to be considered valid
  • Loading branch information
nyalldawson committed Sep 7, 2017
1 parent 9a09165 commit 2612c3957843b455e0cf022f3c2b7b76e740e77b
Showing with 7 additions and 0 deletions.
  1. +3 −0 src/core/processing/qgsprocessingparameters.cpp
  2. +4 −0 tests/src/core/testqgsprocessing.cpp
@@ -2301,6 +2301,9 @@ bool QgsProcessingParameterField::checkValueIsAcceptable( const QVariant &input,
{
if ( !mAllowMultiple )
return false;

if ( input.toList().isEmpty() && !( mFlags & FlagOptional ) )
return false;
}
else if ( input.type() == QVariant::String )
{
@@ -2258,6 +2258,8 @@ void TestQgsProcessing::parameterLayerList()
QVERIFY( !def->checkValueIsAcceptable( true ) );
QVERIFY( !def->checkValueIsAcceptable( 5 ) );
QVERIFY( !def->checkValueIsAcceptable( "layer12312312" ) );
QVERIFY( !def->checkValueIsAcceptable( QVariantList() ) );
QVERIFY( !def->checkValueIsAcceptable( QStringList() ) );
QVERIFY( def->checkValueIsAcceptable( QStringList() << "layer12312312" << "layerB" ) );
QVERIFY( def->checkValueIsAcceptable( QVariantList() << "layer12312312" << "layerB" ) );
QVERIFY( !def->checkValueIsAcceptable( "" ) );
@@ -3183,6 +3185,8 @@ void TestQgsProcessing::parameterField()
QVERIFY( def->checkValueIsAcceptable( QVariantList() << "a" << "b" ) );
QVERIFY( !def->checkValueIsAcceptable( "" ) );
QVERIFY( !def->checkValueIsAcceptable( QVariant() ) );
QVERIFY( !def->checkValueIsAcceptable( QStringList() ) );
QVERIFY( !def->checkValueIsAcceptable( QVariantList() ) );

params.insert( "non_optional", QString( "a;b" ) );
fields = QgsProcessingParameters::parameterAsFields( def.get(), params, context );

0 comments on commit 2612c39

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