Skip to content

Commit

Permalink
[processing] A non optional, multiple field input must have at least
Browse files Browse the repository at this point in the history
one selected field to be considered valid
  • Loading branch information
nyalldawson committed Sep 7, 2017
1 parent 9a09165 commit 2612c39
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/processing/qgsprocessingparameters.cpp
Expand Up @@ -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 )
{
Expand Down
4 changes: 4 additions & 0 deletions tests/src/core/testqgsprocessing.cpp
Expand Up @@ -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( "" ) );
Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 2612c39

Please sign in to comment.