Class: QgsLabelingEngineRuleRegistry

A registry for labeling engine rules.

Labeling engine rules implement custom logic to modify the labeling solution for a map render, e.g. by preventing labels being placed which violate custom constraints.

This registry stores available rules and is responsible for creating rules.

QgsLabelingEngineRuleRegistry is not usually directly created, but rather accessed through QgsApplication.labelEngineRuleRegistry().

Added in version 3.40.

Methods

addRule

Adds a new rule type to the registry.

create

Creates a new rule from the type with matching id.

displayType

Returns a user-friendly, translated string representing the rule type with matching id.

isAvailable

Returns True if the rule is with matching id is available for use within the current QGIS environment.

removeRule

Removes the rule with matching id from the registry.

ruleIds

Returns a list of the rule IDs for rules present in the registry.

class qgis.core.QgsLabelingEngineRuleRegistry[source]

Bases: object

__init__()

Constructor for QgsLabelingEngineRuleRegistry, containing a set of default rules.

addRule(self, rule: QgsAbstractLabelingEngineRule | None) bool[source]

Adds a new rule type to the registry.

The registry takes ownership of rule.

Return type:

bool

Returns:

True if the rule was successfully added.

See also

removeRule()

Parameters:

rule (Optional[QgsAbstractLabelingEngineRule])

create(self, id: str | None) QgsAbstractLabelingEngineRule | None[source]

Creates a new rule from the type with matching id.

Returns None if no matching rule was found in the registry.

The caller takes ownership of the returned object.

Parameters:

id (Optional[str])

Return type:

Optional[QgsAbstractLabelingEngineRule]

displayType(self, id: str | None) str[source]

Returns a user-friendly, translated string representing the rule type with matching id.

Parameters:

id (Optional[str])

Return type:

str

isAvailable(self, id: str | None) bool[source]

Returns True if the rule is with matching id is available for use within the current QGIS environment.

Rules can return False if required dependencies are not available, e.g. if a library version is too old for the rule.

Parameters:

id (Optional[str])

Return type:

bool

removeRule(self, id: str | None)[source]

Removes the rule with matching id from the registry.

See also

addRule()

Parameters:

id (Optional[str])

ruleIds(self) List[str][source]

Returns a list of the rule IDs for rules present in the registry.

Return type:

List[str]