Skip to content

Commit f31abe4

Browse files
arnaud-morvanm-kuhn
authored andcommittedMay 26, 2015
Update QgsFields nameToIndex hash on field removed
1 parent 6318f67 commit f31abe4

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed
 

‎src/core/qgsfield.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,12 @@ void QgsFields::remove( int fieldIdx )
259259
if ( !exists( fieldIdx ) )
260260
return;
261261

262-
d->nameToIndex.remove( d->fields[fieldIdx].field.name() );
263262
d->fields.remove( fieldIdx );
263+
d->nameToIndex.clear();
264+
for ( int idx = 0; idx < count(); ++idx )
265+
{
266+
d->nameToIndex.insert( d->fields[idx].field.name(), idx );
267+
}
264268
}
265269

266270
void QgsFields::extend( const QgsFields& other )

‎tests/src/core/testqgsfields.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ void TestQgsFields::remove()
230230
fields.remove( 0 );
231231
QCOMPARE( fields.count(), 1 );
232232
QCOMPARE( fields.at( 0 ).name(), QString( "testfield2" ) );
233+
QCOMPARE( fields.indexFromName(QString( "testfield2" )), 0);
233234
}
234235

235236
void TestQgsFields::extend()

0 commit comments

Comments
 (0)
Please sign in to comment.