Fixes slow update in field calculator

by blocking the vector signals ...
... and emitting dataChanged at
the end.

I'm a bit worried of side effects,
but I can't see any other solution.

The root of the issue here is that
for each changed field/row an attribute
valueChanged signal is emitted, and the
QgsVectorLayerCache::featureAtId
loads the feature again.
This commit is contained in:
Alessandro Pasotti 2018-10-12 22:13:33 +02:00
parent 42ea216478
commit d79e3adf72

View File

@ -163,8 +163,14 @@ void QgsFieldCalculator::accept()
{ {
builder->saveToRecent( QStringLiteral( "fieldcalc" ) ); builder->saveToRecent( QStringLiteral( "fieldcalc" ) );
if ( !mVectorLayer ) if ( ! mVectorLayer )
{
return; return;
}
else // Need a scope for the blocker let's keep the else for clarity
{
QgsSignalBlocker<QgsVectorLayer> vectorBlocker( mVectorLayer );
// Set up QgsDistanceArea each time we (re-)calculate // Set up QgsDistanceArea each time we (re-)calculate
QgsDistanceArea myDa; QgsDistanceArea myDa;
@ -323,9 +329,11 @@ void QgsFieldCalculator::accept()
mVectorLayer->destroyEditCommand(); mVectorLayer->destroyEditCommand();
return; return;
} }
mVectorLayer->endEditCommand(); mVectorLayer->endEditCommand();
} }
}
// Vector signals unlocked! Tell the world that the layer has changed
mVectorLayer->dataChanged();
QDialog::accept(); QDialog::accept();
} }