Skip to content

Commit

Permalink
fix #3248
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@14754 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 23, 2010
1 parent 10d40f4 commit 1451978
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
10 changes: 10 additions & 0 deletions src/app/attributetable/qgsattributetablememorymodel.cpp
Expand Up @@ -89,3 +89,13 @@ void QgsAttributeTableMemoryModel::attributeValueChanged( int fid, int idx, cons
mFeatureMap[fid].changeAttribute( idx, value );
QgsAttributeTableModel::attributeValueChanged( fid, idx, value );
}

bool QgsAttributeTableMemoryModel::removeRows( int row, int count, const QModelIndex &parent )
{
QgsDebugMsg( "entered." );
for ( int i = row; i < row + count; i++ )
{
mFeatureMap.remove( mRowIdMap[ i ] );
}
return QgsAttributeTableModel::removeRows( row, count, parent );
}
5 changes: 5 additions & 0 deletions src/app/attributetable/qgsattributetablememorymodel.h
Expand Up @@ -39,6 +39,11 @@ class QgsAttributeTableMemoryModel : public QgsAttributeTableModel
*/
QgsAttributeTableMemoryModel( QgsVectorLayer *theLayer );

/**
* Remove rows
*/
bool removeRows( int row, int count, const QModelIndex &parent = QModelIndex() );

protected slots:
/**
* Launched when a feature has been deleted
Expand Down
22 changes: 10 additions & 12 deletions src/app/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -66,13 +66,13 @@ void QgsAttributeTableModel::featureDeleted( int fid )

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

// clean old references
for ( int i = row; i < row + count; i++ )
{
mIdRowMap.remove( mRowIdMap[ row ] );
mRowIdMap.remove( row );
mIdRowMap.remove( mRowIdMap[ i ] );
mRowIdMap.remove( i );
}

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

#ifdef QGISDEBUG
QgsDebugMsgLevel( "id->row", 4 );
QHash<int, int>::iterator it;

QgsDebugMsgLevel( QString( "after removal rows %1, ids %2" ).arg( mRowIdMap.size() ).arg( mIdRowMap.size() ), 4 );
QgsDebugMsgLevel( "id->row", 4 );
for ( it = mIdRowMap.begin(); it != mIdRowMap.end(); ++it )
QgsDebugMsg( QString( "%1->%2" ).arg( it.key() ).arg( *it ) );
QgsDebugMsgLevel( QString( "%1->%2" ).arg( it.key() ).arg( *it ), 4 );

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

Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );

return true;
}

Expand Down Expand Up @@ -201,14 +205,10 @@ void QgsAttributeTableModel::loadLayer()
{
QgsDebugMsg( "entered." );

Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );

beginRemoveRows( QModelIndex(), 0, rowCount() - 1 );
removeRows( 0, rowCount() );
endRemoveRows();

Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );

QSettings settings;
int behaviour = settings.value( "/qgis/attributeTableBehaviour", 0 ).toInt();

Expand Down Expand Up @@ -239,8 +239,6 @@ void QgsAttributeTableModel::loadLayer()
}
}

Q_ASSERT( mRowIdMap.size() == mIdRowMap.size() );

mFieldCount = mAttributes.size();
}

Expand Down

0 comments on commit 1451978

Please sign in to comment.