@@ -512,7 +512,7 @@ void QgsRuleBasedRendererV2Widget::countFeatures()
512
512
countMap[rule].duplicateCount = 0 ;
513
513
}
514
514
515
- QgsFeatureIterator fit = mLayer -> getFeatures ( QgsFeatureRequest ().setFlags ( QgsFeatureRequest::NoGeometry ) );
515
+ QgsFeatureRequest req = QgsFeatureRequest ().setFilterExpression ( mRenderer -> filter ( mLayer -> fields () ) );
516
516
517
517
QgsRenderContext renderContext;
518
518
renderContext.setRendererScale ( 0 ); // ignore scale
@@ -533,9 +533,13 @@ void QgsRuleBasedRendererV2Widget::countFeatures()
533
533
context << QgsExpressionContextUtils::layerScope ( mLayer );
534
534
535
535
renderContext.setExpressionContext ( context );
536
+ req.setExpressionContext ( context );
536
537
537
538
mRenderer ->startRender ( renderContext, mLayer ->fields () );
538
539
540
+ req.setSubsetOfAttributes ( mRenderer ->usedAttributes (), mLayer ->fields () );
541
+ QgsFeatureIterator fit = mLayer ->getFeatures ( req );
542
+
539
543
int nFeatures = mLayer ->featureCount ();
540
544
QProgressDialog p ( tr ( " Calculating feature count." ), tr ( " Abort" ), 0 , nFeatures );
541
545
p.setWindowModality ( Qt::WindowModal );
@@ -760,19 +764,18 @@ void QgsRendererRulePropsWidget::testFilter()
760
764
761
765
QApplication::setOverrideCursor ( Qt::WaitCursor );
762
766
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 );
764
773
765
774
int count = 0 ;
766
775
QgsFeature f;
767
776
while ( fit.nextFeature ( f ) )
768
777
{
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++;
776
779
}
777
780
778
781
QApplication::restoreOverrideCursor ();
0 commit comments