Skip to content
Permalink
Browse files

[processing] Fix QStringList values are not accepted as valid values …

…for multi field parameters
  • Loading branch information
nyalldawson committed Jan 30, 2020
1 parent 9bcd980 commit abcb8d20c66b3c235802b10e68d6abc34736e2c5
Showing with 20 additions and 0 deletions.
  1. +8 −0 src/core/processing/qgsprocessingparameters.cpp
  2. +12 −0 tests/src/analysis/testqgsprocessing.cpp
@@ -1524,6 +1524,10 @@ QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParam
for ( const QVariant &var : constToList )
resultStringList << var.toString();
}
else if ( val.type() == QVariant::StringList )
{
resultStringList = val.toStringList();
}
else
resultStringList.append( val.toString().split( ';' ) );
}
@@ -1540,6 +1544,10 @@ QStringList QgsProcessingParameters::parameterAsFields( const QgsProcessingParam
for ( const QVariant &var : constToList )
resultStringList << var.toString();
}
else if ( definition->defaultValue().type() == QVariant::StringList )
{
resultStringList = definition->defaultValue().toStringList();
}
else
resultStringList.append( definition->defaultValue().toString().split( ';' ) );
}
@@ -4913,6 +4913,18 @@ void TestQgsProcessing::parameterField()
fields = QgsProcessingParameters::parameterAsFields( def.get(), params, context );
QCOMPARE( fields, QStringList() << "def" );

// optional with string list default
def.reset( new QgsProcessingParameterField( "optional", QString(), QStringList() << QStringLiteral( "def" ) << QStringLiteral( "abc" ), QString(), QgsProcessingParameterField::Any, true, true ) );
QVERIFY( def->checkValueIsAcceptable( QStringList() << "a" << "b" ) );
fields = QgsProcessingParameters::parameterAsFields( def.get(), params, context );
QCOMPARE( fields, QStringList() << "def" << "abc" );
params.insert( "optional", QVariantList() << "f" << "h" );
fields = QgsProcessingParameters::parameterAsFields( def.get(), params, context );
QCOMPARE( fields, QStringList() << "f" << "h" );
params.insert( "optional", QStringList() << "g" << "h" );
fields = QgsProcessingParameters::parameterAsFields( def.get(), params, context );
QCOMPARE( fields, QStringList() << "g" << "h" );

// optional, no default
def.reset( new QgsProcessingParameterField( "optional", QString(), QVariant(), QString(), QgsProcessingParameterField::Any, false, true ) );
params.insert( "optional", QVariant() );

0 comments on commit abcb8d2

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