Skip to content
Permalink
Browse files

Fix slow updates from field calculator

Fixes #20094

Followup 096b4ce
  • Loading branch information
elpaso committed Oct 15, 2018
1 parent 0e50b3b commit 5defc03086eda4b481ad550becff631704832147
@@ -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 );
@@ -2983,6 +2983,8 @@ bool QgsVectorLayer::rollBack( bool deleteBuffer )

mEditBuffer->rollBack();

emit afterRollBack();

if ( isModified() )
{
// new undo stack roll back method
@@ -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
@@ -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
@@ -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 )
@@ -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;

};

0 comments on commit 5defc03

Please sign in to comment.
You can’t perform that action at this time.