Skip to content
Permalink
Browse files
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)
  • Loading branch information
nyalldawson committed May 22, 2017
1 parent 48ecee5 commit ebd3e0d7a55788a6fef957f6465968ad22c29afc
Showing with 10 additions and 6 deletions.
  1. +7 −5 src/gui/attributetable/qgsattributetablemodel.cpp
  2. +3 −1 src/gui/attributetable/qgsattributetablemodel.h
@@ -67,7 +67,7 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayerCache *layerCache,
connect( layer(), &QgsVectorLayer::attributeDeleted, this, &QgsAttributeTableModel::attributeDeleted );
connect( layer(), &QgsVectorLayer::updatedFields, this, &QgsAttributeTableModel::updatedFields );
connect( layer(), &QgsVectorLayer::editCommandEnded, this, &QgsAttributeTableModel::editCommandEnded );
connect( mLayerCache, &QgsVectorLayerCache::featureAdded, this, &QgsAttributeTableModel::featureAdded );
connect( mLayerCache, &QgsVectorLayerCache::featureAdded, this, [ = ]( QgsFeatureId id ) { featureAdded( id ); } );
connect( mLayerCache, &QgsVectorLayerCache::cachedLayerDeleted, this, &QgsAttributeTableModel::layerDeleted );
}

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

void QgsAttributeTableModel::featureAdded( QgsFeatureId fid )
void QgsAttributeTableModel::featureAdded( QgsFeatureId fid, bool resettingModel )
{
QgsDebugMsgLevel( QString( "(%2) fid: %1" ).arg( fid ).arg( mFeatureRequest.filterType() ), 4 );
bool featOk = true;
@@ -230,10 +230,12 @@ void QgsAttributeTableModel::featureAdded( QgsFeatureId fid )
if ( ! mIdRowMap.contains( fid ) )
{
int n = mRowIdMap.size();
beginInsertRows( QModelIndex(), n, n );
if ( !resettingModel )
beginInsertRows( QModelIndex(), n, n );
mIdRowMap.insert( fid, n );
mRowIdMap.insert( n, fid );
endInsertRows();
if ( !resettingModel )
endInsertRows();
reload( index( rowCount() - 1, 0 ), index( rowCount() - 1, columnCount() ) );
}
}
@@ -430,7 +432,7 @@ void QgsAttributeTableModel::loadLayer()

t.restart();
}
featureAdded( mFeat.id() );
featureAdded( mFeat.id(), true );
}

emit finished();
@@ -313,8 +313,10 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
/**
* Launched when a feature has been added
* \param fid feature id
* \param resettingModel set to true if model is in the process of being reset
* and the normal begin/EndInsertRows calls should not be made
*/
virtual void featureAdded( QgsFeatureId fid );
virtual void featureAdded( QgsFeatureId fid, bool resettingModel = false );

/**
* Launched when layer has been deleted

0 comments on commit ebd3e0d

Please sign in to comment.