Skip to content

Commit

Permalink
Replace multiple calls to featureCount() with just one when loading a…
Browse files Browse the repository at this point in the history
…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@11136 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jul 21, 2009
1 parent 2747842 commit 2360886
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/app/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -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));
}

Expand All @@ -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 )
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit 2360886

Please sign in to comment.