QGIS API Documentation  3.37.0-Master (a5b4d9743e8)
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
QgsRuleBasedRenderer::Rule Class Reference

This class keeps data about a rules for rule-based renderer. More...

#include <qgsrulebasedrenderer.h>

Public Types

enum  RenderResult { Filtered = 0 , Inactive , Rendered }
 The result of rendering a rule. More...
 

Public Member Functions

 Rule (const Rule &rh)=delete
 Rules cannot be copied. More...
 
 Rule (QgsSymbol *symbol, int maximumScale=0, int minimumScale=0, const QString &filterExp=QString(), const QString &label=QString(), const QString &description=QString(), bool elseRule=false)
 Constructor takes ownership of the symbol. More...
 
 ~Rule ()
 
bool accept (QgsStyleEntityVisitorInterface *visitor) const
 Accepts the specified symbology visitor, causing it to visit all child rules associated with the rule. More...
 
bool active () const
 Returns if this rule is active. More...
 
void appendChild (QgsRuleBasedRenderer::Rule *rule)
 add child rule, take ownership, sets this as parent More...
 
const QgsRuleBasedRenderer::RuleListchildren () const
 Returns all children rules of this rule. More...
 
QgsRuleBasedRenderer::Ruleclone () const
 clone this rule, return new instance More...
 
QSet< int > collectZLevels ()
 Gets all used z-levels from this rule and children. More...
 
bool dependsOnScale () const
 
QgsRuleBasedRenderer::RuleList descendants () const
 Returns all children, grand-children, grand-grand-children, grand-gra... More...
 
QString description () const
 A human readable description for this rule. More...
 
QString dump (int indent=0) const
 Dump for debug purpose. More...
 
QgsExpressionfilter () const
 A filter that will check if this rule applies. More...
 
QString filterExpression () const
 A filter that will check if this rule applies. More...
 
QgsRuleBasedRenderer::RulefindRuleByKey (const QString &key)
 Try to find a rule given its unique key. More...
 
bool hasActiveChildren () const
 Returns true if the rule has any active children. More...
 
void insertChild (int i, QgsRuleBasedRenderer::Rule *rule)
 add child rule, take ownership, sets this as parent More...
 
bool isElse () const
 Check if this rule is an ELSE rule. More...
 
bool isFilterOK (const QgsFeature &f, QgsRenderContext *context=nullptr) const
 Check if a given feature shall be rendered by this rule. More...
 
bool isScaleOK (double scale) const
 Check if this rule applies for a given scale. More...
 
QString label () const
 
QSet< QString > legendKeysForFeature (const QgsFeature &feature, QgsRenderContext *context=nullptr)
 Returns which legend keys match the feature. More...
 
QgsLegendSymbolList legendSymbolItems (int currentLevel=-1) const
 
double maximumScale () const
 Returns the maximum map scale (i.e. More...
 
double minimumScale () const
 Returns the minimum map scale (i.e. More...
 
bool needsGeometry () const
 Returns true if this rule or one of its children needs the geometry to be applied. More...
 
Ruleoperator= (const Rule &rh)=delete
 Rules cannot be copied. More...
 
QgsRuleBasedRenderer::Ruleparent ()
 The parent rule. More...
 
void removeChild (QgsRuleBasedRenderer::Rule *rule)
 delete child rule More...
 
void removeChildAt (int i)
 delete child rule More...
 
QgsRuleBasedRenderer::Rule::RenderResult renderFeature (QgsRuleBasedRenderer::FeatureToRender &featToRender, QgsRenderContext &context, QgsRuleBasedRenderer::RenderQueue &renderQueue)
 Render a given feature, will recursively call subclasses and only render if the constraints apply. More...
 
QString ruleKey () const
 Unique rule identifier (for identification of rule within renderer) More...
 
QgsRuleBasedRenderer::RuleList rulesForFeature (const QgsFeature &feature, QgsRenderContext *context=nullptr, bool onlyActive=true)
 Returns the list of rules used to render the feature in a specific context. More...
 
QDomElement save (QDomDocument &doc, QgsSymbolMap &symbolMap) const
 
void setActive (bool state)
 Sets if this rule is active. More...
 
void setDescription (const QString &description)
 Set a human readable description for this rule. More...
 
void setFilterExpression (const QString &filterExp)
 Set the expression used to check if a given feature shall be rendered with this rule. More...
 
void setIsElse (bool iselse)
 Sets if this rule is an ELSE rule. More...
 
void setLabel (const QString &label)
 
void setMaximumScale (double scale)
 Sets the maximum map scale (i.e. More...
 
void setMinimumScale (double scale)
 Sets the minimum map scale (i.e. More...
 
void setNormZLevels (const QMap< int, int > &zLevelsToNormLevels)
 assign normalized z-levels [0..N-1] for this rule's symbol for quick access during rendering More...
 
void setRuleKey (const QString &key)
 Override the assigned rule key (should be used just internally by rule-based renderer) More...
 
void setSymbol (QgsSymbol *sym)
 Sets a new symbol (or nullptr). Deletes old symbol. More...
 
bool startRender (QgsRenderContext &context, const QgsFields &fields, QString &filter)
 prepare the rule for rendering and its children (build active children array) More...
 
void stopRender (QgsRenderContext &context)
 Stop a rendering process. More...
 
QgsSymbolsymbol ()
 
QgsSymbolList symbols (const QgsRenderContext &context=QgsRenderContext()) const
 
QgsSymbolList symbolsForFeature (const QgsFeature &feature, QgsRenderContext *context=nullptr)
 tell which symbols will be used to render the feature More...
 
QgsRuleBasedRenderer::RuletakeChild (QgsRuleBasedRenderer::Rule *rule)
 take child rule out, set parent as nullptr More...
 
QgsRuleBasedRenderer::RuletakeChildAt (int i)
 take child rule out, set parent as nullptr More...
 
void toSld (QDomDocument &doc, QDomElement &element, QVariantMap props) const
 Saves the symbol layer as SLD. More...
 
QSet< QString > usedAttributes (const QgsRenderContext &context) const
 Returns the attributes used to evaluate the expression of this rule. More...
 
bool willRenderFeature (const QgsFeature &feature, QgsRenderContext *context=nullptr)
 only tell whether a feature will be rendered without actually rendering it More...
 

Static Public Member Functions

static QgsRuleBasedRenderer::Rulecreate (QDomElement &ruleElem, QgsSymbolMap &symbolMap, bool reuseId=true)
 Create a rule from an XML definition. More...
 
static QgsRuleBasedRenderer::RulecreateFromSld (QDomElement &element, Qgis::GeometryType geomType)
 Create a rule from the SLD provided in element and for the specified geometry type. More...
 

Protected Member Functions

void initFilter ()
 

Detailed Description

This class keeps data about a rules for rule-based renderer.

A rule consists of a symbol, filter expression and range of scales. If filter is empty, it matches all features. If scale range has both values zero, it matches all scales. If one of the min/max scale denominators is zero, there is no lower/upper bound for scales. A rule matches if both filter and scale range match.

Definition at line 149 of file qgsrulebasedrenderer.h.

Member Enumeration Documentation

◆ RenderResult

The result of rendering a rule.

Enumerator
Filtered 

The rule does not apply.

Inactive 

The rule is inactive.

Rendered 

Something was rendered.

Definition at line 153 of file qgsrulebasedrenderer.h.

Constructor & Destructor Documentation

◆ Rule() [1/2]

QgsRuleBasedRenderer::Rule::Rule ( QgsSymbol symbol,
int  maximumScale = 0,
int  minimumScale = 0,
const QString &  filterExp = QString(),
const QString &  label = QString(),
const QString &  description = QString(),
bool  elseRule = false 
)

Constructor takes ownership of the symbol.

Definition at line 41 of file qgsrulebasedrenderer.cpp.

◆ ~Rule()

QgsRuleBasedRenderer::Rule::~Rule ( )

Definition at line 58 of file qgsrulebasedrenderer.cpp.

◆ Rule() [2/2]

QgsRuleBasedRenderer::Rule::Rule ( const Rule rh)
delete

Rules cannot be copied.

Member Function Documentation

◆ accept()

bool QgsRuleBasedRenderer::Rule::accept ( QgsStyleEntityVisitorInterface visitor) const

Accepts the specified symbology visitor, causing it to visit all child rules associated with the rule.

Returns true if the visitor should continue visiting other objects, or false if visiting should be canceled.

Since
QGIS 3.10

Definition at line 161 of file qgsrulebasedrenderer.cpp.

◆ active()

bool QgsRuleBasedRenderer::Rule::active ( ) const
inline

Returns if this rule is active.

Returns
true if the rule is active

Definition at line 257 of file qgsrulebasedrenderer.h.

◆ appendChild()

void QgsRuleBasedRenderer::Rule::appendChild ( QgsRuleBasedRenderer::Rule rule)

add child rule, take ownership, sets this as parent

Definition at line 83 of file qgsrulebasedrenderer.cpp.

◆ children()

const QgsRuleBasedRenderer::RuleList& QgsRuleBasedRenderer::Rule::children ( ) const
inline

Returns all children rules of this rule.

Returns
A list of rules

Definition at line 400 of file qgsrulebasedrenderer.h.

◆ clone()

QgsRuleBasedRenderer::Rule * QgsRuleBasedRenderer::Rule::clone ( ) const

clone this rule, return new instance

Definition at line 307 of file qgsrulebasedrenderer.cpp.

◆ collectZLevels()

QSet< int > QgsRuleBasedRenderer::Rule::collectZLevels ( )

Gets all used z-levels from this rule and children.

Definition at line 527 of file qgsrulebasedrenderer.cpp.

◆ create()

QgsRuleBasedRenderer::Rule * QgsRuleBasedRenderer::Rule::create ( QDomElement &  ruleElem,
QgsSymbolMap symbolMap,
bool  reuseId = true 
)
static

Create a rule from an XML definition.

Parameters
ruleElemThe XML rule element
symbolMapSymbol map
reuseIdset to true to create an exact copy of the original symbol or false to create a new rule with the same parameters as the original but a new unique ruleKey(). (Since QGIS 3.30)
Returns
A new rule

Definition at line 764 of file qgsrulebasedrenderer.cpp.

◆ createFromSld()

QgsRuleBasedRenderer::Rule * QgsRuleBasedRenderer::Rule::createFromSld ( QDomElement &  element,
Qgis::GeometryType  geomType 
)
static

Create a rule from the SLD provided in element and for the specified geometry type.

Definition at line 826 of file qgsrulebasedrenderer.cpp.

◆ dependsOnScale()

bool QgsRuleBasedRenderer::Rule::dependsOnScale ( ) const
inline

Definition at line 213 of file qgsrulebasedrenderer.h.

◆ descendants()

QgsRuleBasedRenderer::RuleList QgsRuleBasedRenderer::Rule::descendants ( ) const

Returns all children, grand-children, grand-grand-children, grand-gra...

you get it

Returns
A list of descendant rules

Definition at line 815 of file qgsrulebasedrenderer.cpp.

◆ description()

QString QgsRuleBasedRenderer::Rule::description ( ) const
inline

A human readable description for this rule.

Returns
Description

Definition at line 250 of file qgsrulebasedrenderer.h.

◆ dump()

QString QgsRuleBasedRenderer::Rule::dump ( int  indent = 0) const

Dump for debug purpose.

Parameters
indentHow many characters to indent. Will increase by two with every of the recursive calls
Returns
A string representing this rule

Definition at line 190 of file qgsrulebasedrenderer.cpp.

◆ filter()

QgsExpression* QgsRuleBasedRenderer::Rule::filter ( ) const
inline

A filter that will check if this rule applies.

Returns
An expression

Definition at line 237 of file qgsrulebasedrenderer.h.

◆ filterExpression()

QString QgsRuleBasedRenderer::Rule::filterExpression ( ) const
inline

A filter that will check if this rule applies.

Returns
An expression

Definition at line 243 of file qgsrulebasedrenderer.h.

◆ findRuleByKey()

QgsRuleBasedRenderer::Rule * QgsRuleBasedRenderer::Rule::findRuleByKey ( const QString &  key)

Try to find a rule given its unique key.

Definition at line 126 of file qgsrulebasedrenderer.cpp.

◆ hasActiveChildren()

bool QgsRuleBasedRenderer::Rule::hasActiveChildren ( ) const

Returns true if the rule has any active children.

Note
Must be called after startRender()
Since
QGIS 3.30

Definition at line 522 of file qgsrulebasedrenderer.cpp.

◆ initFilter()

void QgsRuleBasedRenderer::Rule::initFilter ( )
protected

Definition at line 64 of file qgsrulebasedrenderer.cpp.

◆ insertChild()

void QgsRuleBasedRenderer::Rule::insertChild ( int  i,
QgsRuleBasedRenderer::Rule rule 
)

add child rule, take ownership, sets this as parent

Definition at line 90 of file qgsrulebasedrenderer.cpp.

◆ isElse()

bool QgsRuleBasedRenderer::Rule::isElse ( ) const
inline

Check if this rule is an ELSE rule.

Returns
true if this rule is an else rule

Definition at line 451 of file qgsrulebasedrenderer.h.

◆ isFilterOK()

bool QgsRuleBasedRenderer::Rule::isFilterOK ( const QgsFeature f,
QgsRenderContext context = nullptr 
) const

Check if a given feature shall be rendered by this rule.

Parameters
fThe feature to test
contextThe context in which the rendering happens
Returns
true if the feature shall be rendered

Definition at line 284 of file qgsrulebasedrenderer.cpp.

◆ isScaleOK()

bool QgsRuleBasedRenderer::Rule::isScaleOK ( double  scale) const

Check if this rule applies for a given scale.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. If set to 0, it will always return true.

Returns
If the rule will be evaluated at this scale

Definition at line 294 of file qgsrulebasedrenderer.cpp.

◆ label()

QString QgsRuleBasedRenderer::Rule::label ( ) const
inline

Definition at line 212 of file qgsrulebasedrenderer.h.

◆ legendKeysForFeature()

QSet< QString > QgsRuleBasedRenderer::Rule::legendKeysForFeature ( const QgsFeature feature,
QgsRenderContext context = nullptr 
)

Returns which legend keys match the feature.

Definition at line 678 of file qgsrulebasedrenderer.cpp.

◆ legendSymbolItems()

QgsLegendSymbolList QgsRuleBasedRenderer::Rule::legendSymbolItems ( int  currentLevel = -1) const

Definition at line 267 of file qgsrulebasedrenderer.cpp.

◆ maximumScale()

double QgsRuleBasedRenderer::Rule::maximumScale ( ) const
inline

Returns the maximum map scale (i.e.

most "zoomed in" scale) at which the rule will be active. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. A scale of 0 indicates no maximum scale visibility.

See also
minimumScale()
setMaximumScale()

Definition at line 222 of file qgsrulebasedrenderer.h.

◆ minimumScale()

double QgsRuleBasedRenderer::Rule::minimumScale ( ) const
inline

Returns the minimum map scale (i.e.

most "zoomed out" scale) at which the rule will be active. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. A scale of 0 indicates no minimum scale visibility.

See also
maximumScale()
setMinimumScale()

Definition at line 231 of file qgsrulebasedrenderer.h.

◆ needsGeometry()

bool QgsRuleBasedRenderer::Rule::needsGeometry ( ) const

Returns true if this rule or one of its children needs the geometry to be applied.

Definition at line 227 of file qgsrulebasedrenderer.cpp.

◆ operator=()

Rule& QgsRuleBasedRenderer::Rule::operator= ( const Rule rh)
delete

Rules cannot be copied.

◆ parent()

QgsRuleBasedRenderer::Rule* QgsRuleBasedRenderer::Rule::parent ( )
inline

The parent rule.

Returns
Parent rule

Definition at line 414 of file qgsrulebasedrenderer.h.

◆ removeChild()

void QgsRuleBasedRenderer::Rule::removeChild ( QgsRuleBasedRenderer::Rule rule)

delete child rule

Definition at line 97 of file qgsrulebasedrenderer.cpp.

◆ removeChildAt()

void QgsRuleBasedRenderer::Rule::removeChildAt ( int  i)

delete child rule

Definition at line 104 of file qgsrulebasedrenderer.cpp.

◆ renderFeature()

QgsRuleBasedRenderer::Rule::RenderResult QgsRuleBasedRenderer::Rule::renderFeature ( QgsRuleBasedRenderer::FeatureToRender featToRender,
QgsRenderContext context,
QgsRuleBasedRenderer::RenderQueue renderQueue 
)

Render a given feature, will recursively call subclasses and only render if the constraints apply.

Parameters
featToRenderThe feature to render
contextThe rendering context
renderQueueThe rendering queue to which the feature should be added
Returns
The result of the rendering. In explicit if the feature is added to the queue or the reason for not rendering the feature.

Definition at line 571 of file qgsrulebasedrenderer.cpp.

◆ ruleKey()

QString QgsRuleBasedRenderer::Rule::ruleKey ( ) const
inline

Unique rule identifier (for identification of rule within renderer)

Definition at line 262 of file qgsrulebasedrenderer.h.

◆ rulesForFeature()

QgsRuleBasedRenderer::RuleList QgsRuleBasedRenderer::Rule::rulesForFeature ( const QgsFeature feature,
QgsRenderContext context = nullptr,
bool  onlyActive = true 
)

Returns the list of rules used to render the feature in a specific context.

Parameters
featureThe feature for which rules have to be find
contextThe rendering context
onlyActivetrue to search for active rules only, false otherwise

Definition at line 728 of file qgsrulebasedrenderer.cpp.

◆ save()

QDomElement QgsRuleBasedRenderer::Rule::save ( QDomDocument &  doc,
QgsSymbolMap symbolMap 
) const

Definition at line 319 of file qgsrulebasedrenderer.cpp.

◆ setActive()

void QgsRuleBasedRenderer::Rule::setActive ( bool  state)
inline

Sets if this rule is active.

Parameters
stateDetermines if the rule should be activated or deactivated

Definition at line 309 of file qgsrulebasedrenderer.h.

◆ setDescription()

void QgsRuleBasedRenderer::Rule::setDescription ( const QString &  description)
inline

Set a human readable description for this rule.

Parameters
descriptionDescription

Definition at line 303 of file qgsrulebasedrenderer.h.

◆ setFilterExpression()

void QgsRuleBasedRenderer::Rule::setFilterExpression ( const QString &  filterExp)

Set the expression used to check if a given feature shall be rendered with this rule.

Parameters
filterExpAn expression

Definition at line 261 of file qgsrulebasedrenderer.cpp.

◆ setIsElse()

void QgsRuleBasedRenderer::Rule::setIsElse ( bool  iselse)

Sets if this rule is an ELSE rule.

Parameters
iselseIf true, this rule is an ELSE rule

Definition at line 154 of file qgsrulebasedrenderer.cpp.

◆ setLabel()

void QgsRuleBasedRenderer::Rule::setLabel ( const QString &  label)
inline

Definition at line 271 of file qgsrulebasedrenderer.h.

◆ setMaximumScale()

void QgsRuleBasedRenderer::Rule::setMaximumScale ( double  scale)
inline

Sets the maximum map scale (i.e.

most "zoomed in" scale) at which the rule will be active. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. A scale of 0 indicates no maximum scale visibility.

See also
maximumScale()
setMinimumScale()

Definition at line 289 of file qgsrulebasedrenderer.h.

◆ setMinimumScale()

void QgsRuleBasedRenderer::Rule::setMinimumScale ( double  scale)
inline

Sets the minimum map scale (i.e.

most "zoomed out" scale) at which the rule will be active. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. A scale of 0 indicates no minimum scale visibility.

See also
minimumScale()
setMaximumScale()

Definition at line 280 of file qgsrulebasedrenderer.h.

◆ setNormZLevels()

void QgsRuleBasedRenderer::Rule::setNormZLevels ( const QMap< int, int > &  zLevelsToNormLevels)

assign normalized z-levels [0..N-1] for this rule's symbol for quick access during rendering

Note
not available in Python bindings

Definition at line 551 of file qgsrulebasedrenderer.cpp.

◆ setRuleKey()

void QgsRuleBasedRenderer::Rule::setRuleKey ( const QString &  key)
inline

Override the assigned rule key (should be used just internally by rule-based renderer)

Definition at line 267 of file qgsrulebasedrenderer.h.

◆ setSymbol()

void QgsRuleBasedRenderer::Rule::setSymbol ( QgsSymbol sym)

Sets a new symbol (or nullptr). Deletes old symbol.

Definition at line 256 of file qgsrulebasedrenderer.cpp.

◆ startRender()

bool QgsRuleBasedRenderer::Rule::startRender ( QgsRenderContext context,
const QgsFields fields,
QString &  filter 
)

prepare the rule for rendering and its children (build active children array)

Definition at line 416 of file qgsrulebasedrenderer.cpp.

◆ stopRender()

void QgsRuleBasedRenderer::Rule::stopRender ( QgsRenderContext context)

Stop a rendering process.

Used to clean up the internal state of this rule

Parameters
contextThe rendering context

Definition at line 749 of file qgsrulebasedrenderer.cpp.

◆ symbol()

QgsSymbol* QgsRuleBasedRenderer::Rule::symbol ( )
inline

Definition at line 211 of file qgsrulebasedrenderer.h.

◆ symbols()

QgsSymbolList QgsRuleBasedRenderer::Rule::symbols ( const QgsRenderContext context = QgsRenderContext()) const
Note
available in Python bindings as symbol2

Definition at line 242 of file qgsrulebasedrenderer.cpp.

◆ symbolsForFeature()

QgsSymbolList QgsRuleBasedRenderer::Rule::symbolsForFeature ( const QgsFeature feature,
QgsRenderContext context = nullptr 
)

tell which symbols will be used to render the feature

Definition at line 662 of file qgsrulebasedrenderer.cpp.

◆ takeChild()

QgsRuleBasedRenderer::Rule * QgsRuleBasedRenderer::Rule::takeChild ( QgsRuleBasedRenderer::Rule rule)

take child rule out, set parent as nullptr

Definition at line 110 of file qgsrulebasedrenderer.cpp.

◆ takeChildAt()

QgsRuleBasedRenderer::Rule * QgsRuleBasedRenderer::Rule::takeChildAt ( int  i)

take child rule out, set parent as nullptr

Definition at line 118 of file qgsrulebasedrenderer.cpp.

◆ toSld()

void QgsRuleBasedRenderer::Rule::toSld ( QDomDocument &  doc,
QDomElement &  element,
QVariantMap  props 
) const

Saves the symbol layer as SLD.

Definition at line 351 of file qgsrulebasedrenderer.cpp.

◆ usedAttributes()

QSet< QString > QgsRuleBasedRenderer::Rule::usedAttributes ( const QgsRenderContext context) const

Returns the attributes used to evaluate the expression of this rule.

Returns
A set of attribute names

Definition at line 209 of file qgsrulebasedrenderer.cpp.

◆ willRenderFeature()

bool QgsRuleBasedRenderer::Rule::willRenderFeature ( const QgsFeature feature,
QgsRenderContext context = nullptr 
)

only tell whether a feature will be rendered without actually rendering it

Definition at line 626 of file qgsrulebasedrenderer.cpp.


The documentation for this class was generated from the following files: