Class: QgsAbstractLabelingEngineRule

Abstract base class 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.

Note

QgsAbstractLabelingEngineRule cannot be subclassed in Python. Use one of the existing implementations of this class instead.

Added in version 3.40.

Class Hierarchy

Inheritance diagram of qgis.core.QgsAbstractLabelingEngineRule

Subclasses

QgsAbstractLabelingEngineRuleDistanceFromFeature

Base class for labeling engine rules which prevents labels being placed too close or to far from features from a different layer.

QgsLabelingEngineRuleAvoidLabelOverlapWithFeature

A labeling engine rule which prevents labels being placed overlapping features from a different layer.

QgsLabelingEngineRuleMinimumDistanceLabelToLabel

A labeling engine rule which prevents labels being placed too close to labels from a different layer.

Methods

active

Returns True if the rule is active.

clone

Creates a clone of this rule.

copyCommonProperties

Copies common properties from this object to an other.

description

Returns a user-friendly description of the rule.

displayType

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

id

Returns a string uniquely identifying the rule subclass.

isAvailable

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

name

Returns the name for this instance of the rule.

prepare

Prepares the rule.

readXml

Reads the rule properties from an XML element.

resolveReferences

Resolves reference to layers from stored layer ID.

setActive

Sets whether the rule is active.

setName

Sets the name for this instance of the rule.

writeXml

Writes the rule properties to an XML element.

class qgis.core.QgsAbstractLabelingEngineRule[source]

Bases: object

active(self) bool[source]

Returns True if the rule is active.

See also

setActive()

Return type:

bool

clone(self) QgsAbstractLabelingEngineRule | None[source]

Creates a clone of this rule.

The caller takes ownership of the returned object.

Return type:

Optional[QgsAbstractLabelingEngineRule]

copyCommonProperties(self, other: QgsAbstractLabelingEngineRule | None)[source]

Copies common properties from this object to an other.

Parameters:

other (Optional[QgsAbstractLabelingEngineRule])

description(self) str[source]

Returns a user-friendly description of the rule.

This should include the rule name() if set, and other useful details for users to quickly identify the rule’s purpose when shown in a tooltip.

The returned string may contain HTML formatting.

Return type:

str

displayType(self) str[source]

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

Return type:

str

id(self) str[source]

Returns a string uniquely identifying the rule subclass.

Return type:

str

isAvailable(self) bool[source]

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

The base class method returns True.

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

Return type:

bool

name(self) str[source]

Returns the name for this instance of the rule.

The name is a user-configurable value which helps them identify and describe the rule within their projects.

See also

setName()

Return type:

str

prepare(self, context: QgsRenderContext) bool[source]

Prepares the rule.

This must be called on the main render thread, prior to commencing the render operation. Thread sensitive logic (such as creation of feature sources) can be performed in this method.

Parameters:

context (QgsRenderContext)

Return type:

bool

readXml(self, element: QDomElement, context: QgsReadWriteContext)[source]

Reads the rule properties from an XML element.

See also

writeXml()

Parameters:
resolveReferences(self, project: QgsProject | None)[source]

Resolves reference to layers from stored layer ID.

Should be called following a call readXml().

Parameters:

project (Optional[QgsProject])

setActive(self, active: bool)[source]

Sets whether the rule is active.

See also

active()

Parameters:

active (bool)

setName(self, name: str | None)[source]

Sets the name for this instance of the rule.

The name is a user-configurable value which helps them identify and describe the rule within their projects.

See also

name()

Parameters:

name (Optional[str])

writeXml(self, doc: QDomDocument, element: QDomElement, context: QgsReadWriteContext)[source]

Writes the rule properties to an XML element.

See also

readXml()

Parameters: