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.

Note

This is an abstract class, with methods which must be implemented by a subclass.

The following methods must be implemented: clone(), displayType(), id(), prepare(), readXml(), writeXml()

Class Hierarchy

Inheritance diagram of qgis.core.QgsAbstractLabelingEngineRule

Subclasses

QgsAbstractLabelingEngineRuleDistanceFromFeature

Base class for labeling engine rules which prevent labels being placed too close or too 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.

Abstract Methods

clone

Creates a clone of this rule.

displayType

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

id

Returns a string uniquely identifying the rule subclass.

prepare

Prepares the rule.

readXml

Reads the rule properties from an XML element.

writeXml

Writes the rule properties to an XML element.

Methods

active

Returns True if the rule is active.

name

Returns the name for this instance of the rule.

setActive

Sets whether the rule is active.

setName

Sets the name for this instance of the rule.

Virtual Methods

In PyQGIS, only methods marked as virtual can be safely overridden in a Python subclass of QgsAbstractLabelingEngineRule. See the FAQ for more details.

copyCommonProperties

Copies common properties from this object to an other.

description

Returns a user-friendly description of the rule.

isAvailable

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

resolveReferences

Resolves reference to layers from stored layer ID.

class qgis.core.QgsAbstractLabelingEngineRule[source]

Bases: object

active(self) bool[source]

Returns True if the rule is active.

See also

setActive()

Return type:

bool

abstract clone(self) QgsAbstractLabelingEngineRule | None[source]

Creates a clone of this rule.

The caller takes ownership of the returned object.

Return type:

Optional[QgsAbstractLabelingEngineRule]

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

Copies common properties from this object to an other.

Parameters:

other (Optional[QgsAbstractLabelingEngineRule])

virtual 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

abstract displayType(self) str[source]

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

Return type:

str

abstract id(self) str[source]

Returns a string uniquely identifying the rule subclass.

Return type:

str

virtual 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

abstract 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

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

Reads the rule properties from an XML element.

See also

writeXml()

Parameters:
virtual 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])

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

Writes the rule properties to an XML element.

See also

readXml()

Parameters: