Skip to content

Commit

Permalink
Also use FilterFids when field calculator is only updating selected
Browse files Browse the repository at this point in the history
features. Results in similar speed improvements when updating
only selected features from a large PostGIS layer

(cherry-picked from 33fe0e2)
  • Loading branch information
nyalldawson committed Nov 18, 2015
1 parent 57381f4 commit e604a48
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/app/qgsfieldcalculator.cpp
Expand Up @@ -246,9 +246,6 @@ void QgsFieldCalculator::accept()
bool calculationSuccess = true;
QString error;

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

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

Expand All @@ -259,17 +256,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 );

Expand Down

0 comments on commit e604a48

Please sign in to comment.