Skip to content

Commit 3a8592b

Browse files
author
wonder
committedJul 21, 2009
Replace multiple calls to featureCount() with just one when loading attribute 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
1 parent 2f3ed40 commit 3a8592b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed
 

‎src/app/attributetable/qgsattributetablemodel.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,18 +157,19 @@ void QgsAttributeTableModel::loadLayer()
157157
mRowIdMap.clear();
158158
mIdRowMap.clear();
159159

160-
if ( mFeatureCount < mLayer->pendingFeatureCount() )
160+
int pendingFeatureCount = mLayer->pendingFeatureCount();
161+
if ( mFeatureCount < pendingFeatureCount)
161162
{
162163
QgsDebugMsg( "ins" );
163164
ins = true;
164-
beginInsertRows( QModelIndex(), mFeatureCount, mLayer->pendingFeatureCount() - 1 );
165+
beginInsertRows( QModelIndex(), mFeatureCount, pendingFeatureCount - 1 );
165166
// QgsDebugMsg(QString("%1, %2").arg(mFeatureCount).arg(mLayer->pendingFeatureCount() - 1));
166167
}
167-
else if ( mFeatureCount > mLayer->pendingFeatureCount() )
168+
else if ( mFeatureCount > pendingFeatureCount )
168169
{
169170
QgsDebugMsg( "rm" );
170171
rm = true;
171-
beginRemoveRows( QModelIndex(), mLayer->pendingFeatureCount(), mFeatureCount - 1 );
172+
beginRemoveRows( QModelIndex(), pendingFeatureCount, mFeatureCount - 1 );
172173
// QgsDebugMsg(QString("%1, %2").arg(mFeatureCount).arg(mLayer->pendingFeatureCount() -1));
173174
}
174175

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

183184
// not needed when we have featureAdded signal
184-
mFeatureCount = mLayer->pendingFeatureCount();
185+
mFeatureCount = pendingFeatureCount;
185186
mFieldCount = mLayer->pendingFields().size();
186187

187188
if ( ins )
@@ -235,7 +236,7 @@ int QgsAttributeTableModel::idToRow( const int id ) const
235236
{
236237
if ( !mIdRowMap.contains( id ) )
237238
{
238-
QgsDebugMsg( QString( "idToRow: id %1 not in map" ).arg( id ) );
239+
QgsDebugMsg( QString( "idToRow: id %1 not in the map" ).arg( id ) );
239240
return -1;
240241
}
241242

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

0 commit comments

Comments
 (0)
Please sign in to comment.