Skip to content

Commit 09ffbe7

Browse files
committedSep 26, 2016
Make counting and testing filters in rule based renderers faster
Hand filters off to the provider where possible and avoid fetching unnecessary attributes/geometry (cherry-picked from 9900036)
1 parent 0497e4a commit 09ffbe7

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed
 

‎src/gui/symbology-ng/qgsrulebasedrendererv2widget.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ void QgsRuleBasedRendererV2Widget::countFeatures()
512512
countMap[rule].duplicateCount = 0;
513513
}
514514

515-
QgsFeatureIterator fit = mLayer->getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ) );
515+
QgsFeatureRequest req = QgsFeatureRequest().setFilterExpression( mRenderer->filter( mLayer->fields() ) );
516516

517517
QgsRenderContext renderContext;
518518
renderContext.setRendererScale( 0 ); // ignore scale
@@ -533,9 +533,13 @@ void QgsRuleBasedRendererV2Widget::countFeatures()
533533
context << QgsExpressionContextUtils::layerScope( mLayer );
534534

535535
renderContext.setExpressionContext( context );
536+
req.setExpressionContext( context );
536537

537538
mRenderer->startRender( renderContext, mLayer->fields() );
538539

540+
req.setSubsetOfAttributes( mRenderer->usedAttributes(), mLayer->fields() );
541+
QgsFeatureIterator fit = mLayer->getFeatures( req );
542+
539543
int nFeatures = mLayer->featureCount();
540544
QProgressDialog p( tr( "Calculating feature count." ), tr( "Abort" ), 0, nFeatures );
541545
p.setWindowModality( Qt::WindowModal );
@@ -760,19 +764,18 @@ void QgsRendererRulePropsWidget::testFilter()
760764

761765
QApplication::setOverrideCursor( Qt::WaitCursor );
762766

763-
QgsFeatureIterator fit = mLayer->getFeatures();
767+
QgsFeatureRequest req = QgsFeatureRequest().setSubsetOfAttributes( QgsAttributeList() )
768+
.setFlags( QgsFeatureRequest::NoGeometry )
769+
.setFilterExpression( editFilter->text() )
770+
.setExpressionContext( context );
771+
772+
QgsFeatureIterator fit = mLayer->getFeatures( req );
764773

765774
int count = 0;
766775
QgsFeature f;
767776
while ( fit.nextFeature( f ) )
768777
{
769-
context.setFeature( f );
770-
771-
QVariant value = filter.evaluate( &context );
772-
if ( value.toInt() != 0 )
773-
count++;
774-
if ( filter.hasEvalError() )
775-
break;
778+
count++;
776779
}
777780

778781
QApplication::restoreOverrideCursor();

0 commit comments

Comments
 (0)
Please sign in to comment.