Skip to content
Permalink
Browse files

Also use FilterFids when field calculator is only updating selected

features. Results in similar speed improvements when updating
only selected features from a large PostGIS layer
  • Loading branch information
nyalldawson committed Nov 5, 2015
1 parent f0d31b0 commit 33fe0e2d4984be37ff8c4b0619860522f5e7b8f7
Showing with 6 additions and 12 deletions.
  1. +6 −12 src/app/qgsfieldcalculator.cpp
@@ -258,9 +258,6 @@ void QgsFieldCalculator::accept()
bool calculationSuccess = true;
QString error;

bool onlySelected = mOnlyUpdateSelectedCheckBox->isChecked();
QgsFeatureIds selectedIds = mVectorLayer->selectedFeaturesIds();

bool useGeometry = exp.needsGeometry();
int rownum = 1;

@@ -271,17 +268,14 @@ void QgsFieldCalculator::accept()
if ( newField )
emptyAttribute = QVariant( field.type() );

QgsFeatureIterator fit = mVectorLayer->getFeatures( QgsFeatureRequest().setFlags( useGeometry ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry ) );
QgsFeatureRequest req = QgsFeatureRequest().setFlags( useGeometry ? QgsFeatureRequest::NoFlags : QgsFeatureRequest::NoGeometry );
if ( mOnlyUpdateSelectedCheckBox->isChecked() )
{
req.setFilterFids( mVectorLayer->selectedFeaturesIds() );
}
QgsFeatureIterator fit = mVectorLayer->getFeatures( req );
while ( fit.nextFeature( feature ) )
{
if ( onlySelected )
{
if ( !selectedIds.contains( feature.id() ) )
{
continue;
}
}

expContext.setFeature( feature );
expContext.lastScope()->setVariable( QString( "row_number" ), rownum );

0 comments on commit 33fe0e2

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