Skip to content

Commit

Permalink
[processing] A non-optional multiple enum parameter must have at
Browse files Browse the repository at this point in the history
least one choice selected to be valid
  • Loading branch information
nyalldawson committed Sep 15, 2017
1 parent 4bae647 commit dd441f6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/core/processing/qgsprocessingparameters.cpp
Expand Up @@ -1988,7 +1988,11 @@ bool QgsProcessingParameterEnum::checkValueIsAcceptable( const QVariant &input,
if ( !mAllowMultiple )
return false;

Q_FOREACH ( const QVariant &val, input.toList() )
const QVariantList values = input.toList();
if ( values.empty() && !( mFlags & FlagOptional ) )
return false;

for ( const QVariant &val : values )
{
bool ok = false;
int res = val.toInt( &ok );
Expand Down
4 changes: 4 additions & 0 deletions tests/src/core/testqgsprocessing.cpp
Expand Up @@ -2784,6 +2784,7 @@ void TestQgsProcessing::parameterEnum()
QVERIFY( def->checkValueIsAcceptable( "1" ) );
QVERIFY( !def->checkValueIsAcceptable( "1,2" ) );
QVERIFY( def->checkValueIsAcceptable( 0 ) );
QVERIFY( !def->checkValueIsAcceptable( QVariantList() ) );
QVERIFY( !def->checkValueIsAcceptable( QVariantList() << 1 ) );
QVERIFY( !def->checkValueIsAcceptable( QVariantList() << "a" ) );
QVERIFY( !def->checkValueIsAcceptable( 15 ) );
Expand Down Expand Up @@ -2853,6 +2854,7 @@ void TestQgsProcessing::parameterEnum()
QVERIFY( def->checkValueIsAcceptable( "1" ) );
QVERIFY( def->checkValueIsAcceptable( "1,2" ) );
QVERIFY( def->checkValueIsAcceptable( 0 ) );
QVERIFY( !def->checkValueIsAcceptable( QVariantList() ) ); // since non-optional, empty list not allowed
QVERIFY( def->checkValueIsAcceptable( QVariantList() << 1 ) );
QVERIFY( !def->checkValueIsAcceptable( QVariantList() << "a" ) );
QVERIFY( !def->checkValueIsAcceptable( 15 ) );
Expand Down Expand Up @@ -2893,6 +2895,7 @@ void TestQgsProcessing::parameterEnum()
QVERIFY( def->checkValueIsAcceptable( "1" ) );
QVERIFY( !def->checkValueIsAcceptable( "1,2" ) );
QVERIFY( def->checkValueIsAcceptable( 0 ) );
QVERIFY( !def->checkValueIsAcceptable( QVariantList() ) );
QVERIFY( !def->checkValueIsAcceptable( QVariantList() << 1 ) );
QVERIFY( !def->checkValueIsAcceptable( QVariantList() << "a" ) );
QVERIFY( !def->checkValueIsAcceptable( 15 ) );
Expand Down Expand Up @@ -2925,6 +2928,7 @@ void TestQgsProcessing::parameterEnum()
QVERIFY( def->checkValueIsAcceptable( "1" ) );
QVERIFY( def->checkValueIsAcceptable( "1,2" ) );
QVERIFY( def->checkValueIsAcceptable( 0 ) );
QVERIFY( def->checkValueIsAcceptable( QVariantList() ) );
QVERIFY( def->checkValueIsAcceptable( QVariantList() << 1 ) );
QVERIFY( !def->checkValueIsAcceptable( QVariantList() << "a" ) );
QVERIFY( !def->checkValueIsAcceptable( 15 ) );
Expand Down

0 comments on commit dd441f6

Please sign in to comment.