mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
[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.
This commit is contained in:
parent
28ff28a223
commit
fc68bb25d7
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user