QgsRuleBasedLabeling::Rule class

Public types

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

Public static functions

static auto create(const QDomElement& ruleElem, const QgsReadWriteContext& context) -> QgsRuleBasedLabeling::Rule*
Create a rule from an XML definition.

Constructors, destructors, conversion operators

Rule(QgsPalLayerSettings* settings, double maximumScale = 0, double minimumScale = 0, const QString& filterExp = QString(), const QString& description = QString(), bool elseRule = false)
takes ownership of settings, settings may be nullptr
Rule(const Rule& rh) deleted
Rules cannot be copied.

Public functions

auto active() const -> bool
Returns if this rule is active.
void appendChild(QgsRuleBasedLabeling::Rule* rule)
add child rule, take ownership, sets this as parent
auto children() const -> const QgsRuleBasedLabeling::RuleList&
Returns all children rules of this rule.
auto children() -> QgsRuleBasedLabeling::RuleList&
Returns all children rules of this rule.
auto clone() const -> QgsRuleBasedLabeling::Rule*
clone this rule, return new instance
void createSubProviders(QgsVectorLayer* layer, RuleToProviderMap& subProviders, QgsRuleBasedLabelProvider* provider)
add providers
auto dependsOnScale() const -> bool
Determines if scale based labeling is active.
auto descendants() const -> QgsRuleBasedLabeling::RuleList
Returns all children, grand-children, grand-grand-children, grand-gra...
auto description() const -> QString
A human readable description for this rule.
auto filterExpression() const -> QString
A filter that will check if this rule applies.
auto findRuleByKey(const QString& key) const -> const QgsRuleBasedLabeling::Rule*
Try to find a rule given its unique key.
auto findRuleByKey(const QString& key) -> QgsRuleBasedLabeling::Rule*
Find a labeling rule thanks to its key.
void insertChild(int i, QgsRuleBasedLabeling::Rule* rule)
add child rule, take ownership, sets this as parent
auto isElse() const -> bool
Check if this rule is an ELSE rule.
auto maximumScale() const -> double
Returns the maximum map scale (i.e.
auto minimumScale() const -> double
Returns the minimum map scale (i.e.
auto operator=(const Rule& rh) -> Rule& deleted
Rules cannot be copied.
auto parent() const -> const QgsRuleBasedLabeling::Rule*
The parent rule.
auto parent() -> QgsRuleBasedLabeling::Rule*
The parent rule.
void prepare(const QgsRenderContext& context, QSet<QString>& attributeNames, RuleToProviderMap& subProviders)
call prepare() on sub-providers and populate attributeNames
auto registerFeature(QgsFeature& feature, QgsRenderContext& context, RuleToProviderMap& subProviders, const QgsGeometry& obstacleGeometry = QgsGeometry()) -> RegisterResult
register individual features
void removeChildAt(int i)
delete child rule
auto requiresAdvancedEffects() const -> bool
Returns true if this rule or any of its children requires advanced composition effects to render.
auto ruleKey() const -> QString
Unique rule identifier (for identification of rule within labeling, used as provider ID)
auto save(QDomDocument& doc, const QgsReadWriteContext& context) const -> QDomElement
store labeling info to XML element
void setActive(bool state)
Sets if this rule is active.
void setDescription(const QString& description)
Set a human readable description for this rule.
void setFilterExpression(const QString& filterExp)
Set the expression used to check if a given feature shall be rendered with this rule.
void setIsElse(bool iselse)
Sets if this rule is an ELSE rule.
void setMaximumScale(double scale)
Sets the maximum map scale (i.e.
void setMinimumScale(double scale)
Sets the minimum map scale (i.e.
void setRuleKey(const QString& key)
Override the assigned rule key (should be used just internally by rule-based labeling)
void setSettings(QgsPalLayerSettings* settings)
Sets new settings (or NULL). Deletes old settings if any.
auto settings() const -> QgsPalLayerSettings*
Gets the labeling settings.
void subProviderIds(QStringList& list) const
append rule keys of descendants that contain valid settings (i.e.

Enum documentation

enum QgsRuleBasedLabeling::Rule::RegisterResult

The result of registering a rule.

Enumerators
Filtered

The rule does not apply.

Inactive

The rule is inactive.

Registered

Something was registered.

Function documentation

static QgsRuleBasedLabeling::Rule* QgsRuleBasedLabeling::Rule::create(const QDomElement& ruleElem, const QgsReadWriteContext& context)

Create a rule from an XML definition.

Parameters
ruleElem The XML rule element
context reading context
Returns A new rule

bool QgsRuleBasedLabeling::Rule::active() const

Returns if this rule is active.

Returns True if the rule is active

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

Returns all children rules of this rule.

Returns A list of rules

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

Returns all children rules of this rule.

Returns A list of rules

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

add providers

bool QgsRuleBasedLabeling::Rule::dependsOnScale() const

Determines if scale based labeling is active.

Returns True if scale based labeling is active

QgsRuleBasedLabeling::RuleList QgsRuleBasedLabeling::Rule::descendants() const

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

Returns A list of descendant rules

you get it

QString QgsRuleBasedLabeling::Rule::description() const

A human readable description for this rule.

Returns Description

QString QgsRuleBasedLabeling::Rule::filterExpression() const

A filter that will check if this rule applies.

Returns An expression

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

Find a labeling rule thanks to its key.

Parameters
key The key of the rule to find
Returns The rule or a nullptr if not found

bool QgsRuleBasedLabeling::Rule::isElse() const

Check if this rule is an ELSE rule.

Returns True if this rule is an else rule

double QgsRuleBasedLabeling::Rule::maximumScale() const

Returns the maximum map scale (i.e.

most "zoomed in" scale) at which the label 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.

double QgsRuleBasedLabeling::Rule::minimumScale() const

Returns the minimum map scale (i.e.

most "zoomed out" scale) at which the label 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.

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

The parent rule.

Returns Parent rule

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

The parent rule.

Returns Parent rule

void QgsRuleBasedLabeling::Rule::prepare(const QgsRenderContext& context, QSet<QString>& attributeNames, RuleToProviderMap& subProviders)

call prepare() on sub-providers and populate attributeNames

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

register individual features

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

Sets if this rule is active.

Parameters
state Determines if the rule should be activated or deactivated

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

Set a human readable description for this rule.

Parameters
description Description

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

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

Parameters
filterExp An expression

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

Sets if this rule is an ELSE rule.

Parameters
iselse If true, this rule is an ELSE rule

void QgsRuleBasedLabeling::Rule::setMaximumScale(double scale)

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.

void QgsRuleBasedLabeling::Rule::setMinimumScale(double scale)

Sets the minimum map scale (i.e.

most "zoomed out" scale) at which the label 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.

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

Gets the labeling settings.

May return a null pointer.

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

append rule keys of descendants that contain valid settings (i.e.

they will be sub-providers)