Skip to content
Permalink
Browse files

Replace multiple calls to featureCount() with just one when loading a…

…ttribute table.

Can speed up loading of attribute table with providers not caching the feature count.
By Vita Cizek.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11136 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jul 21, 2009
1 parent 2f3ed40 commit 3a8592b734039d44f6c57e1c29f9c7979571e2d3
Showing with 8 additions and 7 deletions.
  1. +8 −7 src/app/attributetable/qgsattributetablemodel.cpp
@@ -157,18 +157,19 @@ void QgsAttributeTableModel::loadLayer()
mRowIdMap.clear();
mIdRowMap.clear();

if ( mFeatureCount < mLayer->pendingFeatureCount() )
int pendingFeatureCount = mLayer->pendingFeatureCount();
if ( mFeatureCount < pendingFeatureCount)
{
QgsDebugMsg( "ins" );
ins = true;
beginInsertRows( QModelIndex(), mFeatureCount, mLayer->pendingFeatureCount() - 1 );
beginInsertRows( QModelIndex(), mFeatureCount, pendingFeatureCount - 1 );
// QgsDebugMsg(QString("%1, %2").arg(mFeatureCount).arg(mLayer->pendingFeatureCount() - 1));
}
else if ( mFeatureCount > mLayer->pendingFeatureCount() )
else if ( mFeatureCount > pendingFeatureCount )
{
QgsDebugMsg( "rm" );
rm = true;
beginRemoveRows( QModelIndex(), mLayer->pendingFeatureCount(), mFeatureCount - 1 );
beginRemoveRows( QModelIndex(), pendingFeatureCount, mFeatureCount - 1 );
// QgsDebugMsg(QString("%1, %2").arg(mFeatureCount).arg(mLayer->pendingFeatureCount() -1));
}

@@ -181,7 +182,7 @@ void QgsAttributeTableModel::loadLayer()
}

// not needed when we have featureAdded signal
mFeatureCount = mLayer->pendingFeatureCount();
mFeatureCount = pendingFeatureCount;
mFieldCount = mLayer->pendingFields().size();

if ( ins )
@@ -235,7 +236,7 @@ int QgsAttributeTableModel::idToRow( const int id ) const
{
if ( !mIdRowMap.contains( id ) )
{
QgsDebugMsg( QString( "idToRow: id %1 not in map" ).arg( id ) );
QgsDebugMsg( QString( "idToRow: id %1 not in the map" ).arg( id ) );
return -1;
}

@@ -246,7 +247,7 @@ int QgsAttributeTableModel::rowToId( const int id ) const
{
if ( !mRowIdMap.contains( id ) )
{
QgsDebugMsg( QString( "rowToId: row %1 not in map" ).arg( id ) );
QgsDebugMsg( QString( "rowToId: row %1 not in the map" ).arg( id ) );
return -1;
}

0 comments on commit 3a8592b

Please sign in to comment.
You can’t perform that action at this time.