QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsRuleBasedLabeling::Rule Class Reference

#include <qgsrulebasedlabeling.h>

Public Types

enum  RegisterResult { Filtered = 0, Inactive, Registered }
 The result of registering a rule. More...
 

Public Member Functions

 Rule (QgsPalLayerSettings *settings, int scaleMinDenom=0, int scaleMaxDenom=0, const QString &filterExp=QString(), const QString &description=QString(), bool elseRule=false)
 takes ownership of settings 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...
 
const RuleListchildren () const
 Return all children rules of this rule. More...
 
RuleListchildren ()
 Return all children rules of this rule. More...
 
Ruleclone () const
 clone this rule, return new instance More...
 
void createSubProviders (QgsVectorLayer *layer, RuleToProviderMap &subProviders, QgsRuleBasedLabelProvider *provider)
 add providers More...
 
bool dependsOnScale () const
 Determines if scale based labeling is active. More...
 
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 filterExpression () const
 A filter that will check if this rule applies. More...
 
const RulefindRuleByKey (const QString &key) const
 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 () const
 Check if this rule is an ELSE rule. More...
 
const Ruleparent () const
 The parent rule. More...
 
Ruleparent ()
 The parent rule. More...
 
void prepare (const QgsRenderContext &context, QStringList &attributeNames, RuleToProviderMap &subProviders)
 call prepare() on sub-providers and populate attributeNames More...
 
RegisterResult registerFeature (QgsFeature &feature, QgsRenderContext &context, RuleToProviderMap &subProviders, QgsGeometry *obstacleGeometry=nullptr)
 register individual features More...
 
void removeChildAt (int i)
 delete child rule More...
 
QString ruleKey () const
 Unique rule identifier (for identification of rule within labeling, used as provider ID) More...
 
QDomElement save (QDomDocument &doc) const
 store labeling info to XML element More...
 
int scaleMaxDenom () const
 The maximum scale denominator at which this label rule should be applied. More...
 
int scaleMinDenom () const
 The minimum scale at which this label rule should be applied. More...
 
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 setRuleKey (const QString &key)
 Override the assigned rule key (should be used just internally by rule-based labeling) 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 setSettings (QgsPalLayerSettings *settings)
 set new settings (or NULL). Deletes old settings if any. More...
 
QgsPalLayerSettingssettings () const
 Get the labeling settings. More...
 
void subProviderIds (QStringList &list) const
 append rule keys of descendants that contain valid settings (i.e. they will be sub-providers) More...
 

Static Public Member Functions

static Rulecreate (const QDomElement &ruleElem)
 Create a rule from an XML definition. More...
 

Protected Member Functions

void initFilter ()
 Initialize filters. More...
 
bool isFilterOK (QgsFeature &f, QgsRenderContext &context) const
 Check if a given feature shall be labelled by this rule. More...
 
bool isScaleOK (double scale) const
 Check if this rule applies for a given scale. More...
 
void updateElseRules ()
 Check which child rules are else rules and update the internal list of else rules. More...
 

Protected Attributes

RuleList mChildren
 
QString mDescription
 
bool mElseRule
 
RuleList mElseRules
 
QgsExpressionmFilter
 
QString mFilterExp
 
bool mIsActive
 
RulemParent
 
QString mRuleKey
 
int mScaleMaxDenom
 
int mScaleMinDenom
 
QgsPalLayerSettingsmSettings
 

Detailed Description

Note
not available in Python bindings
this class is not a part of public API yet. See notes in QgsLabelingEngineV2

Definition at line 53 of file qgsrulebasedlabeling.h.

Member Enumeration Documentation

◆ RegisterResult

The result of registering a rule.

Enumerator
Filtered 

The rule does not apply.

Inactive 

The rule is inactive.

Registered 

Something was registered.

Definition at line 61 of file qgsrulebasedlabeling.h.

Constructor & Destructor Documentation

◆ Rule()

QgsRuleBasedLabeling::Rule::Rule ( QgsPalLayerSettings settings,
int  scaleMinDenom = 0,
int  scaleMaxDenom = 0,
const QString filterExp = QString(),
const QString description = QString(),
bool  elseRule = false 
)

takes ownership of settings

Definition at line 62 of file qgsrulebasedlabeling.cpp.

◆ ~Rule()

QgsRuleBasedLabeling::Rule::~Rule ( )

Definition at line 77 of file qgsrulebasedlabeling.cpp.

Member Function Documentation

◆ active()

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

Returns if this rule is active.

Returns
True if the rule is active

Definition at line 115 of file qgsrulebasedlabeling.h.

◆ appendChild()

void QgsRuleBasedLabeling::Rule::appendChild ( QgsRuleBasedLabeling::Rule rule)

add child rule, take ownership, sets this as parent

Definition at line 134 of file qgsrulebasedlabeling.cpp.

◆ children() [1/2]

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

Return all children rules of this rule.

Returns
A list of rules

Definition at line 177 of file qgsrulebasedlabeling.h.

◆ children() [2/2]

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

Return all children rules of this rule.

Returns
A list of rules

Definition at line 183 of file qgsrulebasedlabeling.h.

◆ clone()

QgsRuleBasedLabeling::Rule * QgsRuleBasedLabeling::Rule::clone ( ) const

clone this rule, return new instance

Definition at line 171 of file qgsrulebasedlabeling.cpp.

◆ create()

QgsRuleBasedLabeling::Rule * QgsRuleBasedLabeling::Rule::create ( const QDomElement ruleElem)
static

Create a rule from an XML definition.

Parameters
ruleElemThe XML rule element
Returns
A new rule

Definition at line 182 of file qgsrulebasedlabeling.cpp.

◆ createSubProviders()

void QgsRuleBasedLabeling::Rule::createSubProviders ( QgsVectorLayer layer,
QgsRuleBasedLabeling::RuleToProviderMap subProviders,
QgsRuleBasedLabelProvider provider 
)

add providers

Definition at line 250 of file qgsrulebasedlabeling.cpp.

◆ dependsOnScale()

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

Determines if scale based labeling is active.

Returns
True if scale based labeling is active

Definition at line 78 of file qgsrulebasedlabeling.h.

◆ descendants()

RuleList QgsRuleBasedLabeling::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 190 of file qgsrulebasedlabeling.h.

◆ description()

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

A human readable description for this rule.

Returns
Description

Definition at line 109 of file qgsrulebasedlabeling.h.

◆ filterExpression()

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

A filter that will check if this rule applies.

Returns
An expression

Definition at line 103 of file qgsrulebasedlabeling.h.

◆ findRuleByKey()

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

Try to find a rule given its unique key.

Definition at line 155 of file qgsrulebasedlabeling.cpp.

◆ initFilter()

void QgsRuleBasedLabeling::Rule::initFilter ( )
protected

Initialize filters.

Automatically called by setFilterExpression.

Definition at line 94 of file qgsrulebasedlabeling.cpp.

◆ insertChild()

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

add child rule, take ownership, sets this as parent

Definition at line 141 of file qgsrulebasedlabeling.cpp.

◆ isElse()

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

Check if this rule is an ELSE rule.

Returns
True if this rule is an else rule

Definition at line 121 of file qgsrulebasedlabeling.h.

◆ isFilterOK()

bool QgsRuleBasedLabeling::Rule::isFilterOK ( QgsFeature f,
QgsRenderContext context 
) const
protected

Check if a given feature shall be labelled 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 339 of file qgsrulebasedlabeling.cpp.

◆ isScaleOK()

bool QgsRuleBasedLabeling::Rule::isScaleOK ( double  scale) const
protected

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 349 of file qgsrulebasedlabeling.cpp.

◆ parent() [1/2]

const Rule* QgsRuleBasedLabeling::Rule::parent ( ) const
inline

The parent rule.

Returns
Parent rule

Definition at line 197 of file qgsrulebasedlabeling.h.

◆ parent() [2/2]

Rule* QgsRuleBasedLabeling::Rule::parent ( )
inline

The parent rule.

Returns
Parent rule

Definition at line 203 of file qgsrulebasedlabeling.h.

◆ prepare()

void QgsRuleBasedLabeling::Rule::prepare ( const QgsRenderContext context,
QStringList attributeNames,
QgsRuleBasedLabeling::RuleToProviderMap subProviders 
)

call prepare() on sub-providers and populate attributeNames

Definition at line 267 of file qgsrulebasedlabeling.cpp.

◆ registerFeature()

QgsRuleBasedLabeling::Rule::RegisterResult QgsRuleBasedLabeling::Rule::registerFeature ( QgsFeature feature,
QgsRenderContext context,
QgsRuleBasedLabeling::RuleToProviderMap subProviders,
QgsGeometry obstacleGeometry = nullptr 
)

register individual features

Definition at line 292 of file qgsrulebasedlabeling.cpp.

◆ removeChildAt()

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

delete child rule

Definition at line 148 of file qgsrulebasedlabeling.cpp.

◆ ruleKey()

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

Unique rule identifier (for identification of rule within labeling, used as provider ID)

Definition at line 124 of file qgsrulebasedlabeling.h.

◆ save()

QDomElement QgsRuleBasedLabeling::Rule::save ( QDomDocument doc) const

store labeling info to XML element

Definition at line 222 of file qgsrulebasedlabeling.cpp.

◆ scaleMaxDenom()

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

The maximum scale denominator at which this label rule should be applied.

E.g. Denominator 1000 is a scale of 1:1000, where a rule with maximum denominator of 900 will be applied while a rule with 2000 will not be applied.

Returns
The maximum scale denominator

Definition at line 98 of file qgsrulebasedlabeling.h.

◆ scaleMinDenom()

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

The minimum scale at which this label rule should be applied.

E.g. Denominator 1000 is a scale of 1:1000, where a rule with minimum denominator of 900 will not be applied while a rule with 2000 will be applied.

Returns
The minimum scale denominator

Definition at line 88 of file qgsrulebasedlabeling.h.

◆ setActive()

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

Sets if this rule is active.

Parameters
stateDetermines if the rule should be activated or deactivated

Definition at line 159 of file qgsrulebasedlabeling.h.

◆ setDescription()

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

Set a human readable description for this rule.

Parameters
descriptionDescription

Definition at line 154 of file qgsrulebasedlabeling.h.

◆ setFilterExpression()

void QgsRuleBasedLabeling::Rule::setFilterExpression ( const QString filterExp)
inline

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

Parameters
filterExpAn expression

Definition at line 148 of file qgsrulebasedlabeling.h.

◆ setIsElse()

void QgsRuleBasedLabeling::Rule::setIsElse ( bool  iselse)
inline

Sets if this rule is an ELSE rule.

Parameters
iselseIf true, this rule is an ELSE rule

Definition at line 165 of file qgsrulebasedlabeling.h.

◆ setRuleKey()

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

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

Definition at line 168 of file qgsrulebasedlabeling.h.

◆ setScaleMaxDenom()

void QgsRuleBasedLabeling::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 142 of file qgsrulebasedlabeling.h.

◆ setScaleMinDenom()

void QgsRuleBasedLabeling::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 135 of file qgsrulebasedlabeling.h.

◆ setSettings()

void QgsRuleBasedLabeling::Rule::setSettings ( QgsPalLayerSettings settings)

set new settings (or NULL). Deletes old settings if any.

Definition at line 85 of file qgsrulebasedlabeling.cpp.

◆ settings()

QgsPalLayerSettings* QgsRuleBasedLabeling::Rule::settings ( ) const
inline

Get the labeling settings.

May return a null pointer.

Definition at line 71 of file qgsrulebasedlabeling.h.

◆ subProviderIds()

void QgsRuleBasedLabeling::Rule::subProviderIds ( QStringList list) const

append rule keys of descendants that contain valid settings (i.e. they will be sub-providers)

Definition at line 122 of file qgsrulebasedlabeling.cpp.

◆ updateElseRules()

void QgsRuleBasedLabeling::Rule::updateElseRules ( )
protected

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

Definition at line 112 of file qgsrulebasedlabeling.cpp.

Member Data Documentation

◆ mChildren

RuleList QgsRuleBasedLabeling::Rule::mChildren
protected

Definition at line 279 of file qgsrulebasedlabeling.h.

◆ mDescription

QString QgsRuleBasedLabeling::Rule::mDescription
protected

Definition at line 277 of file qgsrulebasedlabeling.h.

◆ mElseRule

bool QgsRuleBasedLabeling::Rule::mElseRule
protected

Definition at line 278 of file qgsrulebasedlabeling.h.

◆ mElseRules

RuleList QgsRuleBasedLabeling::Rule::mElseRules
protected

Definition at line 280 of file qgsrulebasedlabeling.h.

◆ mFilter

QgsExpression* QgsRuleBasedLabeling::Rule::mFilter
protected

Definition at line 286 of file qgsrulebasedlabeling.h.

◆ mFilterExp

QString QgsRuleBasedLabeling::Rule::mFilterExp
protected

Definition at line 277 of file qgsrulebasedlabeling.h.

◆ mIsActive

bool QgsRuleBasedLabeling::Rule::mIsActive
protected

Definition at line 281 of file qgsrulebasedlabeling.h.

◆ mParent

Rule* QgsRuleBasedLabeling::Rule::mParent
protected

Definition at line 274 of file qgsrulebasedlabeling.h.

◆ mRuleKey

QString QgsRuleBasedLabeling::Rule::mRuleKey
protected

Definition at line 283 of file qgsrulebasedlabeling.h.

◆ mScaleMaxDenom

int QgsRuleBasedLabeling::Rule::mScaleMaxDenom
protected

Definition at line 276 of file qgsrulebasedlabeling.h.

◆ mScaleMinDenom

int QgsRuleBasedLabeling::Rule::mScaleMinDenom
protected

Definition at line 276 of file qgsrulebasedlabeling.h.

◆ mSettings

QgsPalLayerSettings* QgsRuleBasedLabeling::Rule::mSettings
protected

Definition at line 275 of file qgsrulebasedlabeling.h.


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