Skip to content
Permalink
Browse files

[processing] Allow case-different duplicate parameter names

But always prefer case-exact matches for parameter names. Turns
out the grass provider requires use of parameters with the same
name but different case, so we need to be able to handle this.
  • Loading branch information
nyalldawson committed Jan 31, 2018
1 parent 28ff28a commit fc68bb25d736a943908316054084e526c34e1d86
@@ -224,7 +224,7 @@ Returns an ordered list of parameter definitions utilized by the algorithm.
const QgsProcessingParameterDefinition *parameterDefinition( const QString &name ) const;
%Docstring
Returns a matching parameter by ``name``. Matching is done in a case-insensitive
manner.
manner, but exact case matches will be preferred.

.. seealso:: :py:func:`parameterDefinitions`
%End
@@ -243,7 +243,8 @@ bool QgsProcessingAlgorithm::addParameter( QgsProcessingParameterDefinition *def
return false;

// check for duplicate named parameters
if ( QgsProcessingAlgorithm::parameterDefinition( definition->name() ) )
const QgsProcessingParameterDefinition *existingDef = QgsProcessingAlgorithm::parameterDefinition( definition->name() );
if ( existingDef && existingDef->name() == definition->name() ) // parameterDefinition is case-insensitive, but we DO allow case-different duplicate names
{
QgsLogger::warning( QStringLiteral( "Duplicate parameter %1 registered for alg %2" ).arg( definition->name(), id() ) );
return false;
@@ -300,7 +301,15 @@ QVariantMap QgsProcessingAlgorithm::postProcessAlgorithm( QgsProcessingContext &

const QgsProcessingParameterDefinition *QgsProcessingAlgorithm::parameterDefinition( const QString &name ) const
{
Q_FOREACH ( const QgsProcessingParameterDefinition *def, mParameters )
// first pass - case sensitive match
for ( const QgsProcessingParameterDefinition *def : mParameters )
{
if ( def->name() == name )
return def;
}

// second pass - case insensitive
for ( const QgsProcessingParameterDefinition *def : mParameters )
{
if ( def->name().compare( name, Qt::CaseInsensitive ) == 0 )
return def;
@@ -247,7 +247,7 @@ class CORE_EXPORT QgsProcessingAlgorithm

/**
* Returns a matching parameter by \a name. Matching is done in a case-insensitive
* manner.
* manner, but exact case matches will be preferred.
* \see parameterDefinitions()
*/
const QgsProcessingParameterDefinition *parameterDefinition( const QString &name ) const;
@@ -147,6 +147,15 @@ class DummyAlgorithm : public QgsProcessingAlgorithm
QCOMPARE( rasterParam->defaultFileExtension(), QStringLiteral( "tif" ) ); // before alg is accessible
addParameter( rasterParam );
QCOMPARE( rasterParam->defaultFileExtension(), QStringLiteral( "tif" ) );

// should allow parameters with same name but different case (required for grass provider)
QgsProcessingParameterBoolean *p1C = new QgsProcessingParameterBoolean( "P1" );
QVERIFY( addParameter( p1C ) );
QCOMPARE( parameterDefinitions().count(), 8 );

// parameterDefinition should be case insensitive, but prioritise correct case matches
QCOMPARE( parameterDefinition( "p1" ), parameterDefinitions().at( 0 ) );
QCOMPARE( parameterDefinition( "P1" ), parameterDefinitions().at( 7 ) );
}

void runParameterChecks2()

0 comments on commit fc68bb2

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