Skip to content
Permalink
Browse files

Show correct feature count with rule that requires geometry

Fix #14758
  • Loading branch information
m-kuhn committed Jun 6, 2016
1 parent 5ba5055 commit e80e54162fac2a83cb0c8a9325ffcae71ac9143e
@@ -148,6 +148,11 @@ class QgsFeatureRendererV2
*/
virtual QList<QString> usedAttributes() = 0;

/**
* Returns true if this renderer requires the geometry to apply the filter.
*/
virtual bool filterNeedsGeometry() const;

virtual ~QgsFeatureRendererV2();

virtual QgsFeatureRendererV2* clone() const = 0 /Factory/;
@@ -80,7 +80,12 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2
* Return the attributes used to evaluate the expression of this rule
* @return A set of attribute names
*/
QSet<QString> usedAttributes();
QSet<QString> usedAttributes() const;

/**
* Returns true if this rule or one of its chilren needs the geometry to be applied.
*/
bool needsGeometry() const;

//! @note available in python bindings as symbol2
QgsSymbolV2List symbols( const QgsRenderContext& context = QgsRenderContext() ) /PyName=symbols2/;
@@ -357,6 +362,8 @@ class QgsRuleBasedRendererV2 : QgsFeatureRendererV2

virtual QList<QString> usedAttributes();

virtual bool filterNeedsGeometry() const;

virtual QgsRuleBasedRendererV2* clone() const /Factory/;

virtual void toSld( QDomDocument& doc, QDomElement &element ) const;
@@ -881,7 +881,11 @@ bool QgsVectorLayer::countSymbolFeatures( bool showProgress )
}
int featuresCounted = 0;

QgsFeatureIterator fit = getFeatures( QgsFeatureRequest().setFlags( QgsFeatureRequest::NoGeometry ) );
QgsFeatureRequest request;
if ( !mRendererV2->filterNeedsGeometry() )
request.setFlags( QgsFeatureRequest::NoGeometry );
request.setSubsetOfAttributes( mRendererV2->usedAttributes(), mUpdatedFields );
QgsFeatureIterator fit = getFeatures( request );
QgsVectorLayerInterruptionCheckerDuringCountSymbolFeatures interruptionCheck( &progressDialog );
if ( showProgress )
{
@@ -153,6 +153,11 @@ void QgsFeatureRendererV2::startRender( QgsRenderContext& context, const QgsVect
startRender( context, vlayer->fields() );
}

bool QgsFeatureRendererV2::filterNeedsGeometry() const
{
return false;
}

bool QgsFeatureRendererV2::renderFeature( QgsFeature& feature, QgsRenderContext& context, int layer, bool selected, bool drawVertexMarker )
{
QgsSymbolV2* symbol = symbolForFeature( feature, context );
@@ -169,6 +169,11 @@ class CORE_EXPORT QgsFeatureRendererV2
*/
virtual QList<QString> usedAttributes() = 0;

/**
* Returns true if this renderer requires the geometry to apply the filter.
*/
virtual bool filterNeedsGeometry() const;

virtual ~QgsFeatureRendererV2();

virtual QgsFeatureRendererV2* clone() const = 0;
@@ -190,11 +195,11 @@ class CORE_EXPORT QgsFeatureRendererV2

enum Capabilities
{
SymbolLevels = 1, // rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
RotationField = 1 << 1, // rotate symbols by attribute value
MoreSymbolsPerFeature = 1 << 2, // may use more than one symbol to render a feature: symbolsForFeature() will return them
Filter = 1 << 3, // features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
ScaleDependent = 1 << 4 // depends on scale if feature will be rendered (rule based )
SymbolLevels = 1, //!< rendering with symbol levels (i.e. implements symbols(), symbolForFeature())
RotationField = 1 << 1, //!< rotate symbols by attribute value
MoreSymbolsPerFeature = 1 << 2, //!< may use more than one symbol to render a feature: symbolsForFeature() will return them
Filter = 1 << 3, //!< features may be filtered, i.e. some features may not be rendered (categorized, rule based ...)
ScaleDependent = 1 << 4 //!< depends on scale if feature will be rendered (rule based )
};

//! returns bitwise OR-ed capabilities of the renderer
@@ -197,6 +197,20 @@ QSet<QString> QgsRuleBasedRendererV2::Rule::usedAttributes() const
return attrs;
}

bool QgsRuleBasedRendererV2::Rule::needsGeometry() const
{
if ( mFilter && mFilter->needsGeometry() )
return true;

Q_FOREACH ( Rule* rule, mChildren )
{
if ( rule->needsGeometry() )
return true;
}

return false;
}

QgsSymbolV2List QgsRuleBasedRendererV2::Rule::symbols( const QgsRenderContext& context ) const
{
QgsSymbolV2List lst;
@@ -935,7 +949,12 @@ QString QgsRuleBasedRendererV2::filter( const QgsFields& )
QList<QString> QgsRuleBasedRendererV2::usedAttributes()
{
QSet<QString> attrs = mRootRule->usedAttributes();
return attrs.values();
return attrs.toList();
}

bool QgsRuleBasedRendererV2::filterNeedsGeometry() const
{
return mRootRule->needsGeometry();
}

QgsRuleBasedRendererV2* QgsRuleBasedRendererV2::clone() const
@@ -136,6 +136,11 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2
*/
QSet<QString> usedAttributes() const;

/**
* Returns true if this rule or one of its chilren needs the geometry to be applied.
*/
bool needsGeometry() const;

//! @note available in python bindings as symbol2
QgsSymbolV2List symbols( const QgsRenderContext& context = QgsRenderContext() ) const;

@@ -428,6 +433,8 @@ class CORE_EXPORT QgsRuleBasedRendererV2 : public QgsFeatureRendererV2

virtual QList<QString> usedAttributes() override;

virtual bool filterNeedsGeometry() const override;

virtual QgsRuleBasedRendererV2* clone() const override;

virtual void toSld( QDomDocument& doc, QDomElement &element ) const override;

0 comments on commit e80e541

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