Skip to content

Commit

Permalink
Fix slow updates from field calculator
Browse files Browse the repository at this point in the history
Fixes #20094

Followup 096b4ce
  • Loading branch information
elpaso committed Oct 16, 2018
1 parent 0e50b3b commit 5defc03
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgsvectorlayer.sip.in
Expand Up @@ -2377,6 +2377,13 @@ Is emitted, before changes are committed to the data provider
void beforeRollBack();
%Docstring
Is emitted, before changes are rolled back
%End

void afterRollBack();
%Docstring
Is emitted, after changes are rolled back

.. versionadded:: 3.4
%End

void attributeAdded( int idx );
Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2983,6 +2983,8 @@ bool QgsVectorLayer::rollBack( bool deleteBuffer )

mEditBuffer->rollBack();

emit afterRollBack();

if ( isModified() )
{
// new undo stack roll back method
Expand Down
6 changes: 6 additions & 0 deletions src/core/qgsvectorlayer.h
Expand Up @@ -2173,6 +2173,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
//! Is emitted, before changes are rolled back
void beforeRollBack();

/**
* Is emitted, after changes are rolled back
* \since QGIS 3.4
*/
void afterRollBack();

/**
* Will be emitted, when a new attribute has been added to this vector layer.
* Applies only to types QgsFields::OriginEdit, QgsFields::OriginProvider and QgsFields::OriginExpression
Expand Down
12 changes: 11 additions & 1 deletion src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -62,13 +62,20 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayerCache *layerCache,

loadAttributes();

connect( mLayerCache, &QgsVectorLayerCache::attributeValueChanged, this, &QgsAttributeTableModel::attributeValueChanged );
connect( layer(), &QgsVectorLayer::featuresDeleted, this, &QgsAttributeTableModel::featuresDeleted );
connect( layer(), &QgsVectorLayer::attributeDeleted, this, &QgsAttributeTableModel::attributeDeleted );
connect( layer(), &QgsVectorLayer::updatedFields, this, &QgsAttributeTableModel::updatedFields );

connect( layer(), &QgsVectorLayer::editCommandStarted, this, [ = ]( const QString ) { mBulkEditCommandRunning = true; } );
connect( layer(), &QgsVectorLayer::editCommandEnded, this, [ = ] { mBulkEditCommandRunning = false; } );
connect( layer(), &QgsVectorLayer::beforeRollBack, this, [ = ] { mBulkEditCommandRunning = true; } );
connect( layer(), &QgsVectorLayer::afterRollBack, this, [ = ] { mBulkEditCommandRunning = false; } );

connect( layer(), &QgsVectorLayer::editCommandEnded, this, &QgsAttributeTableModel::editCommandEnded );
connect( mLayerCache, &QgsVectorLayerCache::attributeValueChanged, this, &QgsAttributeTableModel::attributeValueChanged );
connect( mLayerCache, &QgsVectorLayerCache::featureAdded, this, [ = ]( QgsFeatureId id ) { featureAdded( id ); } );
connect( mLayerCache, &QgsVectorLayerCache::cachedLayerDeleted, this, &QgsAttributeTableModel::layerDeleted );

}

bool QgsAttributeTableModel::loadFeatureAtId( QgsFeatureId fid ) const
Expand Down Expand Up @@ -294,6 +301,9 @@ void QgsAttributeTableModel::fieldFormatterRemoved( QgsFieldFormatter *fieldForm

void QgsAttributeTableModel::attributeValueChanged( QgsFeatureId fid, int idx, const QVariant &value )
{
// Skip all updates if an edit command is running
if ( mBulkEditCommandRunning )
return;
QgsDebugMsgLevel( QStringLiteral( "(%4) fid: %1, idx: %2, value: %3" ).arg( fid ).arg( idx ).arg( value.toString() ).arg( mFeatureRequest.filterType() ), 3 );

for ( SortCache &cache : mSortCaches )
Expand Down
3 changes: 3 additions & 0 deletions src/gui/attributetable/qgsattributetablemodel.h
Expand Up @@ -391,6 +391,9 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel

int mExtraColumns = 0;

//! Edit command or rollback is running
bool mBulkEditCommandRunning = false;

friend class TestQgsAttributeTable;

};
Expand Down

0 comments on commit 5defc03

Please sign in to comment.