Skip to content

Commit

Permalink
Show correct feature count with rule that requires geometry
Browse files Browse the repository at this point in the history
Fix #14758
  • Loading branch information
m-kuhn committed Jun 6, 2016
1 parent 5ba5055 commit e80e541
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 8 deletions.
5 changes: 5 additions & 0 deletions python/core/symbology-ng/qgsrendererv2.sip
Expand Up @@ -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/;
Expand Down
9 changes: 8 additions & 1 deletion python/core/symbology-ng/qgsrulebasedrendererv2.sip
Expand Up @@ -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/;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -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 )
{
Expand Down
5 changes: 5 additions & 0 deletions src/core/symbology-ng/qgsrendererv2.cpp
Expand Up @@ -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 );
Expand Down
15 changes: 10 additions & 5 deletions src/core/symbology-ng/qgsrendererv2.h
Expand Up @@ -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;
Expand All @@ -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
Expand Down
21 changes: 20 additions & 1 deletion src/core/symbology-ng/qgsrulebasedrendererv2.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/core/symbology-ng/qgsrulebasedrendererv2.h
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e80e541

Please sign in to comment.