Skip to content
Permalink
Browse files

[processing] A non-optional multiple enum parameter must have at

least one choice selected to be valid
  • Loading branch information
nyalldawson committed Sep 15, 2017
1 parent 4bae647 commit dd441f6154ad5355ec16ef12551537e43b2a2110
Showing with 9 additions and 1 deletion.
  1. +5 −1 src/core/processing/qgsprocessingparameters.cpp
  2. +4 −0 tests/src/core/testqgsprocessing.cpp
@@ -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 );
@@ -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 ) );
@@ -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 ) );
@@ -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 ) );
@@ -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 ) );

0 comments on commit dd441f6

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