Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Update QgsFields nameToIndex hash on field removed
  • Loading branch information
arnaud-morvan authored and m-kuhn committed May 26, 2015
1 parent 6318f67 commit f31abe4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/core/qgsfield.cpp
Expand Up @@ -259,8 +259,12 @@ void QgsFields::remove( int fieldIdx )
if ( !exists( fieldIdx ) )
return;

d->nameToIndex.remove( d->fields[fieldIdx].field.name() );
d->fields.remove( fieldIdx );
d->nameToIndex.clear();
for ( int idx = 0; idx < count(); ++idx )
{
d->nameToIndex.insert( d->fields[idx].field.name(), idx );
}
}

void QgsFields::extend( const QgsFields& other )
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgsfields.cpp
Expand Up @@ -230,6 +230,7 @@ void TestQgsFields::remove()
fields.remove( 0 );
QCOMPARE( fields.count(), 1 );
QCOMPARE( fields.at( 0 ).name(), QString( "testfield2" ) );
QCOMPARE( fields.indexFromName(QString( "testfield2" )), 0);
}

void TestQgsFields::extend()
Expand Down

0 comments on commit f31abe4

Please sign in to comment.