Skip to content

Commit

Permalink
[processing]field calculator : allow creating field already present (…
Browse files Browse the repository at this point in the history
…case insensitive equal)

Fixes #40701
  • Loading branch information
jdlom committed Jan 4, 2021
1 parent c7a9d5a commit 472b950
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/analysis/processing/qgsalgorithmfieldcalculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ QgsFieldCalculatorAlgorithm *QgsFieldCalculatorAlgorithm::createInstance() const
}


bool QgsFieldCalculatorAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
bool QgsFieldCalculatorAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
std::unique_ptr< QgsProcessingFeatureSource > source( parameterAsSource( parameters, QStringLiteral( "INPUT" ), context ) );

Expand Down Expand Up @@ -131,10 +131,16 @@ bool QgsFieldCalculatorAlgorithm::prepareAlgorithm( const QVariantMap &parameter

mFields = source->fields();

int fieldIdx = mFields.lookupField( field.name() );
int fieldIdx = mFields.indexFromName( field.name() );

if ( fieldIdx < 0 )
{
mFields.append( field );
}
else
{
feedback->pushWarning( QObject::tr( "Field name %1 already exists and will be replaced" ).arg( field.name() ) );
}

QString dest;

Expand Down Expand Up @@ -205,4 +211,3 @@ bool QgsFieldCalculatorAlgorithm::supportInPlaceEdit( const QgsMapLayer *layer )
}

///@endcond

0 comments on commit 472b950

Please sign in to comment.