QGIS API Documentation  2.17.0-Master (8784312)
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsRuleBasedRendererV2::Rule Class Reference

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

#include <qgsrulebasedrendererv2.h>

Public Types

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

Public Member Functions

 Rule (QgsSymbolV2 *symbol, int scaleMinDenom=0, int scaleMaxDenom=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 active () const
 Returns if this rule is active. More...
 
void appendChild (Rule *rule)
 add child rule, take ownership, sets this as parent More...
 
Q_DECL_DEPRECATED bool checkState () const
 
RuleListchildren ()
 Return all children rules of this rule. More...
 
Ruleclone () const
 clone this rule, return new instance More...
 
QSet< int > collectZLevels ()
 get all used z-levels from this rule and children More...
 
bool dependsOnScale () const
 
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...
 
RulefindRuleByKey (const QString &key)
 Try to find a rule given its unique key. More...
 
void insertChild (int i, Rule *rule)
 add child rule, take ownership, sets this as parent More...
 
bool isElse ()
 Check if this rule is an ELSE rule. More...
 
bool isFilterOK (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< QStringlegendKeysForFeature (QgsFeature &feat, QgsRenderContext *context=nullptr)
 Returns which legend keys match the feature. More...
 
QgsLegendSymbolList legendSymbolItems (double scaleDenominator=-1, const QString &rule="") const
 
QgsLegendSymbolListV2 legendSymbolItemsV2 (int currentLevel=-1) const
 
bool needsGeometry () const
 Returns true if this rule or one of its chilren needs the geometry to be applied. More...
 
Ruleparent ()
 The parent rule. More...
 
void removeChild (Rule *rule)
 delete child rule More...
 
void removeChildAt (int i)
 delete child rule More...
 
RenderResult renderFeature (FeatureToRender &featToRender, QgsRenderContext &context, 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...
 
RuleList rulesForFeature (QgsFeature &feat, QgsRenderContext *context=nullptr)
 tell which rules will be used to render the feature More...
 
QDomElement save (QDomDocument &doc, QgsSymbolV2Map &symbolMap) const
 
int scaleMaxDenom () const
 
int scaleMinDenom () const
 
void setActive (bool state)
 Sets if this rule is active. More...
 
Q_DECL_DEPRECATED void setCheckState (bool state)
 
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 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 setScaleMaxDenom (int scaleMaxDenom)
 Set the maximum denominator for which this rule shall apply. More...
 
void setScaleMinDenom (int scaleMinDenom)
 Set the minimum denominator for which this rule shall apply. More...
 
void setSymbol (QgsSymbolV2 *sym)
 set a new symbol (or NULL). Deletes old symbol. More...
 
Q_DECL_DEPRECATED bool startRender (QgsRenderContext &context, const QgsFields &fields)
 Prepare the rule for rendering and its children (build active children array) 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...
 
QgsSymbolV2symbol ()
 
QgsSymbolV2List symbols (const QgsRenderContext &context=QgsRenderContext()) const
 
QgsSymbolV2List symbolsForFeature (QgsFeature &feat, QgsRenderContext *context=nullptr)
 tell which symbols will be used to render the feature More...
 
RuletakeChild (Rule *rule)
 take child rule out, set parent as null More...
 
RuletakeChildAt (int i)
 take child rule out, set parent as null More...
 
void toSld (QDomDocument &doc, QDomElement &element, QgsStringMap props) const
 
void updateElseRules ()
 Check which child rules are else rules and update the internal list of else rules. More...
 
QSet< QStringusedAttributes () const
 Return the attributes used to evaluate the expression of this rule. More...
 
bool willRenderFeature (QgsFeature &feat, QgsRenderContext *context=nullptr)
 only tell whether a feature will be rendered without actually rendering it More...
 

Static Public Member Functions

static Rulecreate (QDomElement &ruleElem, QgsSymbolV2Map &symbolMap)
 Create a rule from an XML definition. More...
 
static RulecreateFromSld (QDomElement &element, QGis::GeometryType geomType)
 

Protected Member Functions

void initFilter ()
 

Protected Attributes

RuleList mActiveChildren
 
RuleList mChildren
 
QString mDescription
 
bool mElseRule
 
RuleList mElseRules
 
QgsExpressionmFilter
 
QString mFilterExp
 
bool mIsActive
 
QString mLabel
 
RulemParent
 
QString mRuleKey
 
int mScaleMaxDenom
 
int mScaleMinDenom
 
QgsSymbolV2mSymbol
 
QSet< int > mSymbolNormZLevels
 

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 110 of file qgsrulebasedrendererv2.h.

Member Enumeration Documentation

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 114 of file qgsrulebasedrendererv2.h.

Constructor & Destructor Documentation

QgsRuleBasedRendererV2::Rule::Rule ( QgsSymbolV2 symbol,
int  scaleMinDenom = 0,
int  scaleMaxDenom = 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 38 of file qgsrulebasedrendererv2.cpp.

QgsRuleBasedRendererV2::Rule::~Rule ( )

Definition at line 57 of file qgsrulebasedrendererv2.cpp.

Member Function Documentation

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

Returns if this rule is active.

Returns
True if the rule is active

Definition at line 204 of file qgsrulebasedrendererv2.h.

void QgsRuleBasedRendererV2::Rule::appendChild ( Rule rule)

add child rule, take ownership, sets this as parent

Definition at line 87 of file qgsrulebasedrendererv2.cpp.

Q_DECL_DEPRECATED bool QgsRuleBasedRendererV2::Rule::checkState ( ) const
inline
Note
added in 2.6
Deprecated:
use active instead

Definition at line 197 of file qgsrulebasedrendererv2.h.

RuleList& QgsRuleBasedRendererV2::Rule::children ( )
inline

Return all children rules of this rule.

Returns
A list of rules

Definition at line 327 of file qgsrulebasedrendererv2.h.

QgsRuleBasedRendererV2::Rule * QgsRuleBasedRendererV2::Rule::clone ( ) const

clone this rule, return new instance

Definition at line 295 of file qgsrulebasedrendererv2.cpp.

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

get all used z-levels from this rule and children

Definition at line 506 of file qgsrulebasedrendererv2.cpp.

QgsRuleBasedRendererV2::Rule * QgsRuleBasedRendererV2::Rule::create ( QDomElement ruleElem,
QgsSymbolV2Map symbolMap 
)
static

Create a rule from an XML definition.

Parameters
ruleElemThe XML rule element
symbolMapSymbol map
Returns
A new rule

Definition at line 673 of file qgsrulebasedrendererv2.cpp.

QgsRuleBasedRendererV2::Rule * QgsRuleBasedRendererV2::Rule::createFromSld ( QDomElement element,
QGis::GeometryType  geomType 
)
static

Definition at line 720 of file qgsrulebasedrendererv2.cpp.

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

Definition at line 172 of file qgsrulebasedrendererv2.h.

RuleList QgsRuleBasedRendererV2::Rule::descendants ( ) const
inline

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

you get it

Returns
A list of descendant rules

Definition at line 334 of file qgsrulebasedrendererv2.h.

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

A human readable description for this rule.

Returns
Description

Definition at line 193 of file qgsrulebasedrendererv2.h.

QString QgsRuleBasedRendererV2::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 165 of file qgsrulebasedrendererv2.cpp.

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

A filter that will check if this rule applies.

Returns
An expression

Definition at line 180 of file qgsrulebasedrendererv2.h.

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

A filter that will check if this rule applies.

Returns
An expression

Definition at line 186 of file qgsrulebasedrendererv2.h.

QgsRuleBasedRendererV2::Rule * QgsRuleBasedRendererV2::Rule::findRuleByKey ( const QString key)

Try to find a rule given its unique key.

Note
added in 2.6

Definition at line 130 of file qgsrulebasedrendererv2.cpp.

void QgsRuleBasedRendererV2::Rule::initFilter ( )
protected

Definition at line 65 of file qgsrulebasedrendererv2.cpp.

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

add child rule, take ownership, sets this as parent

Definition at line 94 of file qgsrulebasedrendererv2.cpp.

bool QgsRuleBasedRendererV2::Rule::isElse ( )
inline

Check if this rule is an ELSE rule.

Returns
True if this rule is an else rule

Definition at line 384 of file qgsrulebasedrendererv2.h.

bool QgsRuleBasedRendererV2::Rule::isFilterOK ( 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 272 of file qgsrulebasedrendererv2.cpp.

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

Check if this rule applies for a given scale.

Parameters
scaleThe scale to check. If set to 0, it will always return true.
Returns
If the rule will be evaluated at this scale

Definition at line 282 of file qgsrulebasedrendererv2.cpp.

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

Definition at line 171 of file qgsrulebasedrendererv2.h.

QSet< QString > QgsRuleBasedRendererV2::Rule::legendKeysForFeature ( QgsFeature feat,
QgsRenderContext context = nullptr 
)

Returns which legend keys match the feature.

Note
added in QGIS 2.14

Definition at line 629 of file qgsrulebasedrendererv2.cpp.

QgsLegendSymbolList QgsRuleBasedRendererV2::Rule::legendSymbolItems ( double  scaleDenominator = -1,
const QString rule = "" 
) const
Note
not available in python bindings

Definition at line 239 of file qgsrulebasedrendererv2.cpp.

QgsLegendSymbolListV2 QgsRuleBasedRendererV2::Rule::legendSymbolItemsV2 ( int  currentLevel = -1) const
Note
added in 2.6

Definition at line 255 of file qgsrulebasedrendererv2.cpp.

bool QgsRuleBasedRendererV2::Rule::needsGeometry ( ) const

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

Definition at line 200 of file qgsrulebasedrendererv2.cpp.

Rule* QgsRuleBasedRendererV2::Rule::parent ( )
inline

The parent rule.

Returns
Parent rule

Definition at line 341 of file qgsrulebasedrendererv2.h.

void QgsRuleBasedRendererV2::Rule::removeChild ( Rule rule)

delete child rule

Definition at line 101 of file qgsrulebasedrendererv2.cpp.

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

delete child rule

Definition at line 108 of file qgsrulebasedrendererv2.cpp.

QgsRuleBasedRendererV2::Rule::RenderResult QgsRuleBasedRendererV2::Rule::renderFeature ( QgsRuleBasedRendererV2::FeatureToRender featToRender,
QgsRenderContext context,
QgsRuleBasedRendererV2::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 549 of file qgsrulebasedrendererv2.cpp.

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

Unique rule identifier (for identification of rule within renderer)

Note
added in 2.6

Definition at line 208 of file qgsrulebasedrendererv2.h.

QgsRuleBasedRendererV2::RuleList QgsRuleBasedRendererV2::Rule::rulesForFeature ( QgsFeature feat,
QgsRenderContext context = nullptr 
)

tell which rules will be used to render the feature

Definition at line 643 of file qgsrulebasedrendererv2.cpp.

QDomElement QgsRuleBasedRendererV2::Rule::save ( QDomDocument doc,
QgsSymbolV2Map symbolMap 
) const

Definition at line 306 of file qgsrulebasedrendererv2.cpp.

int QgsRuleBasedRendererV2::Rule::scaleMaxDenom ( ) const
inline

Definition at line 174 of file qgsrulebasedrendererv2.h.

int QgsRuleBasedRendererV2::Rule::scaleMinDenom ( ) const
inline

Definition at line 173 of file qgsrulebasedrendererv2.h.

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

Sets if this rule is active.

Parameters
stateDetermines if the rule should be activated or deactivated

Definition at line 255 of file qgsrulebasedrendererv2.h.

Q_DECL_DEPRECATED void QgsRuleBasedRendererV2::Rule::setCheckState ( bool  state)
inline
Note
added in 2.6
Deprecated:
use setActive instead

Definition at line 249 of file qgsrulebasedrendererv2.h.

void QgsRuleBasedRendererV2::Rule::setDescription ( const QString description)
inline

Set a human readable description for this rule.

Parameters
descriptionDescription

Definition at line 245 of file qgsrulebasedrendererv2.h.

void QgsRuleBasedRendererV2::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 233 of file qgsrulebasedrendererv2.cpp.

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

Sets if this rule is an ELSE rule.

Parameters
iselseIf true, this rule is an ELSE rule

Definition at line 156 of file qgsrulebasedrendererv2.cpp.

void QgsRuleBasedRendererV2::Rule::setLabel ( const QString label)
inline

Definition at line 215 of file qgsrulebasedrendererv2.h.

void QgsRuleBasedRendererV2::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 530 of file qgsrulebasedrendererv2.cpp.

void QgsRuleBasedRendererV2::Rule::setRuleKey ( const QString key)
inline

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

Note
added in 2.6

Definition at line 211 of file qgsrulebasedrendererv2.h.

void QgsRuleBasedRendererV2::Rule::setScaleMaxDenom ( int  scaleMaxDenom)
inline

Set the maximum denominator for which this rule shall apply.

E.g. 100'000 if it shall be evaluated between 1:1000 and 1:100'000 Set to 0 to disable the maximum check

Parameters
scaleMaxDenommaximum scale denominator for this rule

Definition at line 231 of file qgsrulebasedrendererv2.h.

void QgsRuleBasedRendererV2::Rule::setScaleMinDenom ( int  scaleMinDenom)
inline

Set the minimum denominator for which this rule shall apply.

E.g. 1000 if it shall be evaluated between 1:1000 and 1:100'000 Set to 0 to disable the minimum check

Parameters
scaleMinDenomThe minimum scale denominator for this rule

Definition at line 223 of file qgsrulebasedrendererv2.h.

void QgsRuleBasedRendererV2::Rule::setSymbol ( QgsSymbolV2 sym)

set a new symbol (or NULL). Deletes old symbol.

Definition at line 227 of file qgsrulebasedrendererv2.cpp.

bool QgsRuleBasedRendererV2::Rule::startRender ( QgsRenderContext context,
const QgsFields fields 
)

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

Deprecated:
use startRender( QgsRenderContext& context, const QgsFields& fields, QString& filter ) instead

Definition at line 429 of file qgsrulebasedrendererv2.cpp.

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

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

Definition at line 435 of file qgsrulebasedrendererv2.cpp.

void QgsRuleBasedRendererV2::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 659 of file qgsrulebasedrendererv2.cpp.

QgsSymbolV2* QgsRuleBasedRendererV2::Rule::symbol ( )
inline

Definition at line 170 of file qgsrulebasedrendererv2.h.

QgsSymbolV2List QgsRuleBasedRendererV2::Rule::symbols ( const QgsRenderContext context = QgsRenderContext()) const
Note
available in python bindings as symbol2

Definition at line 214 of file qgsrulebasedrendererv2.cpp.

QgsSymbolV2List QgsRuleBasedRendererV2::Rule::symbolsForFeature ( QgsFeature feat,
QgsRenderContext context = nullptr 
)

tell which symbols will be used to render the feature

Definition at line 614 of file qgsrulebasedrendererv2.cpp.

QgsRuleBasedRendererV2::Rule * QgsRuleBasedRendererV2::Rule::takeChild ( Rule rule)

take child rule out, set parent as null

Definition at line 114 of file qgsrulebasedrendererv2.cpp.

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

take child rule out, set parent as null

Definition at line 122 of file qgsrulebasedrendererv2.cpp.

void QgsRuleBasedRendererV2::Rule::toSld ( QDomDocument doc,
QDomElement element,
QgsStringMap  props 
) const

Definition at line 337 of file qgsrulebasedrendererv2.cpp.

void QgsRuleBasedRendererV2::Rule::updateElseRules ( )

Check which child rules are else rules and update the internal list of else rules.

TODO QGIS 3: Does this need to be public?

Definition at line 146 of file qgsrulebasedrendererv2.cpp.

QSet< QString > QgsRuleBasedRendererV2::Rule::usedAttributes ( ) const

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

Returns
A set of attribute names

Definition at line 183 of file qgsrulebasedrendererv2.cpp.

bool QgsRuleBasedRendererV2::Rule::willRenderFeature ( QgsFeature feat,
QgsRenderContext context = nullptr 
)

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

Definition at line 599 of file qgsrulebasedrendererv2.cpp.

Member Data Documentation

RuleList QgsRuleBasedRendererV2::Rule::mActiveChildren
protected

Definition at line 404 of file qgsrulebasedrendererv2.h.

RuleList QgsRuleBasedRendererV2::Rule::mChildren
protected

Definition at line 394 of file qgsrulebasedrendererv2.h.

QString QgsRuleBasedRendererV2::Rule::mDescription
protected

Definition at line 392 of file qgsrulebasedrendererv2.h.

bool QgsRuleBasedRendererV2::Rule::mElseRule
protected

Definition at line 393 of file qgsrulebasedrendererv2.h.

RuleList QgsRuleBasedRendererV2::Rule::mElseRules
protected

Definition at line 395 of file qgsrulebasedrendererv2.h.

QgsExpression* QgsRuleBasedRendererV2::Rule::mFilter
protected

Definition at line 401 of file qgsrulebasedrendererv2.h.

QString QgsRuleBasedRendererV2::Rule::mFilterExp
protected

Definition at line 392 of file qgsrulebasedrendererv2.h.

bool QgsRuleBasedRendererV2::Rule::mIsActive
protected

Definition at line 396 of file qgsrulebasedrendererv2.h.

QString QgsRuleBasedRendererV2::Rule::mLabel
protected

Definition at line 392 of file qgsrulebasedrendererv2.h.

Rule* QgsRuleBasedRendererV2::Rule::mParent
protected

Definition at line 389 of file qgsrulebasedrendererv2.h.

QString QgsRuleBasedRendererV2::Rule::mRuleKey
protected

Definition at line 398 of file qgsrulebasedrendererv2.h.

int QgsRuleBasedRendererV2::Rule::mScaleMaxDenom
protected

Definition at line 391 of file qgsrulebasedrendererv2.h.

int QgsRuleBasedRendererV2::Rule::mScaleMinDenom
protected

Definition at line 391 of file qgsrulebasedrendererv2.h.

QgsSymbolV2* QgsRuleBasedRendererV2::Rule::mSymbol
protected

Definition at line 390 of file qgsrulebasedrendererv2.h.

QSet<int> QgsRuleBasedRendererV2::Rule::mSymbolNormZLevels
protected

Definition at line 403 of file qgsrulebasedrendererv2.h.


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