Skip to content

Commit 5defc03

Browse files
committed
Fix slow updates from field calculator
Fixes #20094 Followup 096b4ce
1 parent 0e50b3b commit 5defc03

File tree

5 files changed

+29
-1
lines changed

5 files changed

+29
-1
lines changed

python/core/auto_generated/qgsvectorlayer.sip.in

+7
Original file line numberDiff line numberDiff line change
@@ -2377,6 +2377,13 @@ Is emitted, before changes are committed to the data provider
23772377
void beforeRollBack();
23782378
%Docstring
23792379
Is emitted, before changes are rolled back
2380+
%End
2381+
2382+
void afterRollBack();
2383+
%Docstring
2384+
Is emitted, after changes are rolled back
2385+
2386+
.. versionadded:: 3.4
23802387
%End
23812388

23822389
void attributeAdded( int idx );

src/core/qgsvectorlayer.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2983,6 +2983,8 @@ bool QgsVectorLayer::rollBack( bool deleteBuffer )
29832983

29842984
mEditBuffer->rollBack();
29852985

2986+
emit afterRollBack();
2987+
29862988
if ( isModified() )
29872989
{
29882990
// new undo stack roll back method

src/core/qgsvectorlayer.h

+6
Original file line numberDiff line numberDiff line change
@@ -2173,6 +2173,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
21732173
//! Is emitted, before changes are rolled back
21742174
void beforeRollBack();
21752175

2176+
/**
2177+
* Is emitted, after changes are rolled back
2178+
* \since QGIS 3.4
2179+
*/
2180+
void afterRollBack();
2181+
21762182
/**
21772183
* Will be emitted, when a new attribute has been added to this vector layer.
21782184
* Applies only to types QgsFields::OriginEdit, QgsFields::OriginProvider and QgsFields::OriginExpression

src/gui/attributetable/qgsattributetablemodel.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,20 @@ QgsAttributeTableModel::QgsAttributeTableModel( QgsVectorLayerCache *layerCache,
6262

6363
loadAttributes();
6464

65-
connect( mLayerCache, &QgsVectorLayerCache::attributeValueChanged, this, &QgsAttributeTableModel::attributeValueChanged );
6665
connect( layer(), &QgsVectorLayer::featuresDeleted, this, &QgsAttributeTableModel::featuresDeleted );
6766
connect( layer(), &QgsVectorLayer::attributeDeleted, this, &QgsAttributeTableModel::attributeDeleted );
6867
connect( layer(), &QgsVectorLayer::updatedFields, this, &QgsAttributeTableModel::updatedFields );
68+
69+
connect( layer(), &QgsVectorLayer::editCommandStarted, this, [ = ]( const QString ) { mBulkEditCommandRunning = true; } );
70+
connect( layer(), &QgsVectorLayer::editCommandEnded, this, [ = ] { mBulkEditCommandRunning = false; } );
71+
connect( layer(), &QgsVectorLayer::beforeRollBack, this, [ = ] { mBulkEditCommandRunning = true; } );
72+
connect( layer(), &QgsVectorLayer::afterRollBack, this, [ = ] { mBulkEditCommandRunning = false; } );
73+
6974
connect( layer(), &QgsVectorLayer::editCommandEnded, this, &QgsAttributeTableModel::editCommandEnded );
75+
connect( mLayerCache, &QgsVectorLayerCache::attributeValueChanged, this, &QgsAttributeTableModel::attributeValueChanged );
7076
connect( mLayerCache, &QgsVectorLayerCache::featureAdded, this, [ = ]( QgsFeatureId id ) { featureAdded( id ); } );
7177
connect( mLayerCache, &QgsVectorLayerCache::cachedLayerDeleted, this, &QgsAttributeTableModel::layerDeleted );
78+
7279
}
7380

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

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

299309
for ( SortCache &cache : mSortCaches )

src/gui/attributetable/qgsattributetablemodel.h

+3
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
391391

392392
int mExtraColumns = 0;
393393

394+
//! Edit command or rollback is running
395+
bool mBulkEditCommandRunning = false;
396+
394397
friend class TestQgsAttributeTable;
395398

396399
};

0 commit comments

Comments
 (0)