Skip to content
Permalink
Browse files
Update QgsFields nameToIndex hash on field removed
  • Loading branch information
arnaud-morvan authored and m-kuhn committed May 26, 2015
1 parent 6318f67 commit f31abe4dfe965af660d60c2131c2ece2524f367c
Showing with 6 additions and 1 deletion.
  1. +5 −1 src/core/qgsfield.cpp
  2. +1 −0 tests/src/core/testqgsfields.cpp
@@ -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 )
@@ -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()

0 comments on commit f31abe4

Please sign in to comment.