Skip to content

Commit ebd3e0d

Browse files
committedMay 22, 2017
Greatly speed up attribute table loading
Don't advise for rows added when a model reset is in progress. Otherwise the rows are tested for sort order, etc triggering a bunch of useless calculations, given that the model is in the process of being reset anyway. Tested using a 150k point shapefile, decreased attribute table load times from 50+ seconds to 4 seconds. Refs #16577, #16239 (forward port from b97a980)
1 parent 48ecee5 commit ebd3e0d

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed
 

‎src/gui/attributetable/qgsattributetablemodel.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayerCache *layerCache,
6767
connect( layer(), &QgsVectorLayer::attributeDeleted, this, &QgsAttributeTableModel::attributeDeleted );
6868
connect( layer(), &QgsVectorLayer::updatedFields, this, &QgsAttributeTableModel::updatedFields );
6969
connect( layer(), &QgsVectorLayer::editCommandEnded, this, &QgsAttributeTableModel::editCommandEnded );
70-
connect( mLayerCache, &QgsVectorLayerCache::featureAdded, this, &QgsAttributeTableModel::featureAdded );
70+
connect( mLayerCache, &QgsVectorLayerCache::featureAdded, this, [ = ]( QgsFeatureId id ) { featureAdded( id ); } );
7171
connect( mLayerCache, &QgsVectorLayerCache::cachedLayerDeleted, this, &QgsAttributeTableModel::layerDeleted );
7272
}
7373

@@ -202,7 +202,7 @@ bool QgsAttributeTableModel::removeRows( int row, int count, const QModelIndex &
202202
return true;
203203
}
204204

205-
void QgsAttributeTableModel::featureAdded( QgsFeatureId fid )
205+
void QgsAttributeTableModel::featureAdded( QgsFeatureId fid, bool resettingModel )
206206
{
207207
QgsDebugMsgLevel( QString( "(%2) fid: %1" ).arg( fid ).arg( mFeatureRequest.filterType() ), 4 );
208208
bool featOk = true;
@@ -230,10 +230,12 @@ void QgsAttributeTableModel::featureAdded( QgsFeatureId fid )
230230
if ( ! mIdRowMap.contains( fid ) )
231231
{
232232
int n = mRowIdMap.size();
233-
beginInsertRows( QModelIndex(), n, n );
233+
if ( !resettingModel )
234+
beginInsertRows( QModelIndex(), n, n );
234235
mIdRowMap.insert( fid, n );
235236
mRowIdMap.insert( n, fid );
236-
endInsertRows();
237+
if ( !resettingModel )
238+
endInsertRows();
237239
reload( index( rowCount() - 1, 0 ), index( rowCount() - 1, columnCount() ) );
238240
}
239241
}
@@ -430,7 +432,7 @@ void QgsAttributeTableModel::loadLayer()
430432

431433
t.restart();
432434
}
433-
featureAdded( mFeat.id() );
435+
featureAdded( mFeat.id(), true );
434436
}
435437

436438
emit finished();

‎src/gui/attributetable/qgsattributetablemodel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,10 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
313313
/**
314314
* Launched when a feature has been added
315315
* \param fid feature id
316+
* \param resettingModel set to true if model is in the process of being reset
317+
* and the normal begin/EndInsertRows calls should not be made
316318
*/
317-
virtual void featureAdded( QgsFeatureId fid );
319+
virtual void featureAdded( QgsFeatureId fid, bool resettingModel = false );
318320

319321
/**
320322
* Launched when layer has been deleted

0 commit comments

Comments
 (0)
Please sign in to comment.