Skip to content

Commit 79b3e6a

Browse files
author
jef
committed
fix #3248
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@14754 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 52f38ed commit 79b3e6a

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

src/app/attributetable/qgsattributetablememorymodel.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,13 @@ void QgsAttributeTableMemoryModel::attributeValueChanged( int fid, int idx, cons
8989
mFeatureMap[fid].changeAttribute( idx, value );
9090
QgsAttributeTableModel::attributeValueChanged( fid, idx, value );
9191
}
92+
93+
bool QgsAttributeTableMemoryModel::removeRows( int row, int count, const QModelIndex &parent )
94+
{
95+
QgsDebugMsg( "entered." );
96+
for ( int i = row; i < row + count; i++ )
97+
{
98+
mFeatureMap.remove( mRowIdMap[ i ] );
99+
}
100+
return QgsAttributeTableModel::removeRows( row, count, parent );
101+
}

src/app/attributetable/qgsattributetablememorymodel.h

+5
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ class QgsAttributeTableMemoryModel : public QgsAttributeTableModel
3939
*/
4040
QgsAttributeTableMemoryModel( QgsVectorLayer *theLayer );
4141

42+
/**
43+
* Remove rows
44+
*/
45+
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );
46+
4247
protected slots:
4348
/**
4449
* Launched when a feature has been deleted

src/app/attributetable/qgsattributetablemodel.cpp

+10-12
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ void QgsAttributeTableModel::featureDeleted( int fid )
6666

6767
bool QgsAttributeTableModel::removeRows( int row, int count, const QModelIndex &parent )
6868
{
69-
QgsDebugMsgLevel( QString( "remove %2 rows at %1" ).arg( row ).arg( count ), 3 );
69+
QgsDebugMsgLevel( QString( "remove %2 rows at %1 (rows %3, ids %4)" ).arg( row ).arg( count ).arg( mRowIdMap.size() ).arg( mIdRowMap.size() ), 3 );
7070

7171
// clean old references
7272
for ( int i = row; i < row + count; i++ )
7373
{
74-
mIdRowMap.remove( mRowIdMap[ row ] );
75-
mRowIdMap.remove( row );
74+
mIdRowMap.remove( mRowIdMap[ i ] );
75+
mRowIdMap.remove( i );
7676
}
7777

7878
// update maps
@@ -86,16 +86,20 @@ bool QgsAttributeTableModel::removeRows( int row, int count, const QModelIndex &
8686
}
8787

8888
#ifdef QGISDEBUG
89-
QgsDebugMsgLevel( "id->row", 4 );
9089
QHash<int, int>::iterator it;
90+
91+
QgsDebugMsgLevel( QString( "after removal rows %1, ids %2" ).arg( mRowIdMap.size() ).arg( mIdRowMap.size() ), 4 );
92+
QgsDebugMsgLevel( "id->row", 4 );
9193
for ( it = mIdRowMap.begin(); it != mIdRowMap.end(); ++it )
92-
QgsDebugMsg( QString( "%1->%2" ).arg( it.key() ).arg( *it ) );
94+
QgsDebugMsgLevel( QString( "%1->%2" ).arg( it.key() ).arg( *it ), 4 );
9395

9496
QgsDebugMsgLevel( "row->id", 4 );
9597
for ( it = mRowIdMap.begin(); it != mRowIdMap.end(); ++it )
96-
QgsDebugMsg( QString( "%1->%2" ).arg( it.key() ).arg( *it ) );
98+
QgsDebugMsgLevel( QString( "%1->%2" ).arg( it.key() ).arg( *it ), 4 );
9799
#endif
98100

101+
Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
102+
99103
return true;
100104
}
101105

@@ -201,14 +205,10 @@ void QgsAttributeTableModel::loadLayer()
201205
{
202206
QgsDebugMsg( "entered." );
203207

204-
Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
205-
206208
beginRemoveRows( QModelIndex(), 0, rowCount() - 1 );
207209
removeRows( 0, rowCount() );
208210
endRemoveRows();
209211

210-
Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
211-
212212
QSettings settings;
213213
int behaviour = settings.value( "/qgis/attributeTableBehaviour", 0 ).toInt();
214214

@@ -239,8 +239,6 @@ void QgsAttributeTableModel::loadLayer()
239239
}
240240
}
241241

242-
Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );
243-
244242
mFieldCount = mAttributes.size();
245243
}
246244

0 commit comments

Comments
 (0)