Skip to content

Commit

Permalink
Use QgsFields::rename instead of QgsField::setName when modifying the…
Browse files Browse the repository at this point in the history
… name of a field inside an existing QgsFields.

This is done to avoid corruption of internal nameToIndex data structure.
  • Loading branch information
obrix committed Jan 23, 2020
1 parent 2ddcf00 commit 2540f0f
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmjoinbyattribute.cpp
Expand Up @@ -154,7 +154,7 @@ QVariantMap QgsJoinByAttributeAlgorithm::processAlgorithm( const QVariantMap &pa
{ {
for ( int i = 0; i < outFields2.count(); ++i ) for ( int i = 0; i < outFields2.count(); ++i )
{ {
outFields2[ i ].setName( prefix + outFields2[ i ].name() ); outFields2.rename( i, prefix + outFields2[ i ].name() );
} }
} }


Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmjoinbylocation.cpp
Expand Up @@ -159,7 +159,7 @@ QVariantMap QgsJoinByLocationAlgorithm::processAlgorithm( const QVariantMap &par
{ {
for ( int i = 0; i < joinFields.count(); ++i ) for ( int i = 0; i < joinFields.count(); ++i )
{ {
joinFields[ i ].setName( prefix + joinFields[ i ].name() ); joinFields.rename( i, prefix + joinFields[ i ].name() );
} }
} }


Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmjoinbynearest.cpp
Expand Up @@ -160,7 +160,7 @@ QVariantMap QgsJoinByNearestAlgorithm::processAlgorithm( const QVariantMap &para
{ {
for ( int i = 0; i < outFields2.count(); ++i ) for ( int i = 0; i < outFields2.count(); ++i )
{ {
outFields2[ i ].setName( prefix + outFields2[ i ].name() ); outFields2.rename( i, prefix + outFields2[ i ].name() );
} }
} }


Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/qgsalgorithmrenametablefield.cpp
Expand Up @@ -90,7 +90,7 @@ QgsFields QgsRenameTableFieldAlgorithm::outputFields( const QgsFields &inputFiel
if ( outFields.lookupField( mNewName ) >= 0 ) if ( outFields.lookupField( mNewName ) >= 0 )
throw QgsProcessingException( QObject::tr( "A field already exists with the name %1" ).arg( mNewName ) ); throw QgsProcessingException( QObject::tr( "A field already exists with the name %1" ).arg( mNewName ) );


outFields[ index ].setName( mNewName ); outFields.rename( index, mNewName );
return outFields; return outFields;
} }


Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayerexporter.cpp
Expand Up @@ -276,7 +276,7 @@ QgsVectorLayerExporter::exportLayer( QgsVectorLayer *layer,
// convert field names to lowercase // convert field names to lowercase
for ( int fldIdx = 0; fldIdx < fields.count(); ++fldIdx ) for ( int fldIdx = 0; fldIdx < fields.count(); ++fldIdx )
{ {
fields[fldIdx].setName( fields.at( fldIdx ).name().toLower() ); fields.rename( fldIdx, fields.at( fldIdx ).name().toLower() );
} }
} }


Expand Down

0 comments on commit 2540f0f

Please sign in to comment.