QGIS API Documentation 3.40.0-Bratislava (b56115d8743)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
QgsRuleBasedLabeling::Rule Class Reference

A child rule for QgsRuleBasedLabeling. More...

#include <qgsrulebasedlabeling.h>

Public Types

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

Public Member Functions

 Rule (const Rule &rh)=delete
 
 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 ()
 
bool accept (QgsStyleEntityVisitorInterface *visitor) const
 Accepts the specified symbology visitor, causing it to visit all child rules associated with the rule.
 
bool active () const
 Returns if this rule is active.
 
void appendChild (QgsRuleBasedLabeling::Rule *rule)
 add child rule, take ownership, sets this as parent
 
QgsRuleBasedLabeling::RuleListchildren ()
 Returns all children rules of this rule.
 
const QgsRuleBasedLabeling::RuleListchildren () const
 Returns all children rules of this rule.
 
QgsRuleBasedLabeling::Ruleclone () const
 clone this rule, return new instance
 
void createSubProviders (QgsVectorLayer *layer, RuleToProviderMap &subProviders, QgsRuleBasedLabelProvider *provider)
 add providers
 
bool dependsOnScale () const
 Determines if scale based labeling is active.
 
QgsRuleBasedLabeling::RuleList descendants () const
 Returns all children, grand-children, grand-grand-children, grand-gra... you get it.
 
QString description () const
 A human readable description for this rule.
 
QString filterExpression () const
 A filter that will check if this rule applies.
 
QgsRuleBasedLabeling::RulefindRuleByKey (const QString &key)
 Find a labeling rule thanks to its key.
 
const QgsRuleBasedLabeling::RulefindRuleByKey (const QString &key) const
 Try to find a rule given its unique key.
 
void insertChild (int i, QgsRuleBasedLabeling::Rule *rule)
 add child rule, take ownership, sets this as parent
 
bool isElse () const
 Check if this rule is an ELSE rule.
 
double maximumScale () const
 Returns the maximum map scale (i.e.
 
double minimumScale () const
 Returns the minimum map scale (i.e.
 
Ruleoperator= (const Rule &rh)=delete
 
QgsRuleBasedLabeling::Ruleparent ()
 The parent rule.
 
const QgsRuleBasedLabeling::Ruleparent () const
 The parent rule.
 
void prepare (QgsRenderContext &context, QSet< QString > &attributeNames, RuleToProviderMap &subProviders)
 call prepare() on sub-providers and populate attributeNames
 
std::tuple< RegisterResult, QList< QgsLabelFeature * > > registerFeature (const QgsFeature &feature, QgsRenderContext &context, RuleToProviderMap &subProviders, const QgsGeometry &obstacleGeometry=QgsGeometry(), const QgsSymbol *symbol=nullptr)
 Register individual features.
 
void removeChildAt (int i)
 delete child rule
 
bool requiresAdvancedEffects () const
 Returns true if this rule or any of its children requires advanced composition effects to render.
 
QString ruleKey () const
 Unique rule identifier (for identification of rule within labeling, used as provider ID)
 
QDomElement save (QDomDocument &doc, const QgsReadWriteContext &context) const
 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 nullptr). Deletes old settings if any.
 
QgsPalLayerSettingssettings () const
 Returns the labeling settings.
 
void subProviderIds (QStringList &list) const
 append rule keys of descendants that contain valid settings (i.e.
 

Static Public Member Functions

static QgsRuleBasedLabeling::Rulecreate (const QDomElement &ruleElem, const QgsReadWriteContext &context, bool reuseId=true)
 Create a rule from an XML definition.
 

Detailed Description

A child rule for QgsRuleBasedLabeling.

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 64 of file qgsrulebasedlabeling.h.

Constructor & Destructor Documentation

◆ Rule() [1/2]

QgsRuleBasedLabeling::Rule::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

Definition at line 59 of file qgsrulebasedlabeling.cpp.

◆ ~Rule()

QgsRuleBasedLabeling::Rule::~Rule ( )

Definition at line 73 of file qgsrulebasedlabeling.cpp.

◆ Rule() [2/2]

QgsRuleBasedLabeling::Rule::Rule ( const Rule rh)
delete

Member Function Documentation

◆ accept()

bool QgsRuleBasedLabeling::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 141 of file qgsrulebasedlabeling.cpp.

◆ active()

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

Returns if this rule is active.

Returns
true if the rule is active

Definition at line 119 of file qgsrulebasedlabeling.h.

◆ appendChild()

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

add child rule, take ownership, sets this as parent

Definition at line 181 of file qgsrulebasedlabeling.cpp.

◆ children() [1/2]

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

Returns all children rules of this rule.

Returns
A list of rules

Definition at line 196 of file qgsrulebasedlabeling.h.

◆ children() [2/2]

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

Returns all children rules of this rule.

Returns
A list of rules

Definition at line 189 of file qgsrulebasedlabeling.h.

◆ clone()

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

clone this rule, return new instance

Definition at line 232 of file qgsrulebasedlabeling.cpp.

◆ create()

QgsRuleBasedLabeling::Rule * QgsRuleBasedLabeling::Rule::create ( const QDomElement &  ruleElem,
const QgsReadWriteContext context,
bool  reuseId = true 
)
static

Create a rule from an XML definition.

Parameters
ruleElemThe XML rule element
contextreading context
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 243 of file qgsrulebasedlabeling.cpp.

◆ createSubProviders()

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

add providers

Note
not available in Python bindings

Definition at line 315 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 81 of file qgsrulebasedlabeling.h.

◆ descendants()

QgsRuleBasedLabeling::RuleList QgsRuleBasedLabeling::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 87 of file qgsrulebasedlabeling.cpp.

◆ description()

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

A human readable description for this rule.

Returns
Description

Definition at line 112 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 105 of file qgsrulebasedlabeling.h.

◆ findRuleByKey() [1/2]

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

Find a labeling rule thanks to its key.

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

Definition at line 218 of file qgsrulebasedlabeling.cpp.

◆ findRuleByKey() [2/2]

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

Try to find a rule given its unique key.

Definition at line 202 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 188 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 126 of file qgsrulebasedlabeling.h.

◆ maximumScale()

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

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.

See also
minimumScale()
setMaximumScale()

Definition at line 90 of file qgsrulebasedlabeling.h.

◆ minimumScale()

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

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.

See also
maximumScale()
setMinimumScale()

Definition at line 99 of file qgsrulebasedlabeling.h.

◆ operator=()

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

◆ parent() [1/2]

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

The parent rule.

Returns
Parent rule

Definition at line 217 of file qgsrulebasedlabeling.h.

◆ parent() [2/2]

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

The parent rule.

Returns
Parent rule

Definition at line 210 of file qgsrulebasedlabeling.h.

◆ prepare()

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

call prepare() on sub-providers and populate attributeNames

Note
not available in Python bindings

Definition at line 332 of file qgsrulebasedlabeling.cpp.

◆ registerFeature()

std::tuple< QgsRuleBasedLabeling::Rule::RegisterResult, QList< QgsLabelFeature * > > QgsRuleBasedLabeling::Rule::registerFeature ( const QgsFeature feature,
QgsRenderContext context,
QgsRuleBasedLabeling::RuleToProviderMap subProviders,
const QgsGeometry obstacleGeometry = QgsGeometry(),
const QgsSymbol symbol = nullptr 
)

Register individual features.

Returns result of registration, together with a list of all label features which were created as a result of registering feature. Ownership of these label features is not transferred (it has already been assigned to the label provider).

Note
not available in Python bindings

Definition at line 357 of file qgsrulebasedlabeling.cpp.

◆ removeChildAt()

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

delete child rule

Definition at line 195 of file qgsrulebasedlabeling.cpp.

◆ requiresAdvancedEffects()

bool QgsRuleBasedLabeling::Rule::requiresAdvancedEffects ( ) const

Returns true if this rule or any of its children requires advanced composition effects to render.

Definition at line 127 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 129 of file qgsrulebasedlabeling.h.

◆ save()

QDomElement QgsRuleBasedLabeling::Rule::save ( QDomDocument &  doc,
const QgsReadWriteContext context 
) const

store labeling info to XML element

Definition at line 287 of file qgsrulebasedlabeling.cpp.

◆ 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 170 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 164 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 157 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 177 of file qgsrulebasedlabeling.h.

◆ setMaximumScale()

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

◆ setMinimumScale()

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

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.

See also
minimumScale()
setMaximumScale()

Definition at line 141 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 180 of file qgsrulebasedlabeling.h.

◆ setSettings()

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

Sets new settings (or nullptr). Deletes old settings if any.

Definition at line 79 of file qgsrulebasedlabeling.cpp.

◆ settings()

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

Returns the labeling settings.

May return nullptr.

Definition at line 74 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)

Note
not available in Python bindings

Definition at line 169 of file qgsrulebasedlabeling.cpp.


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