Class: QgsMapLayerLegend

An abstract interface for implementations of legends for one map layer.

Note

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

The following methods must be implemented: createLayerTreeModelLegendNodes()

Class Hierarchy

Inheritance diagram of qgis.core.QgsMapLayerLegend

Base classes

QObject

Subclasses

QgsDefaultMeshLayerLegend

Default legend implementation for mesh layers.

QgsDefaultPointCloudLayerLegend

Default legend implementation for point cloud layers.

QgsDefaultRasterLayerLegend

Default legend implementation for raster layers.

QgsDefaultVectorLayerLegend

Default legend implementation for vector layers.

class qgis.core.QgsMapLayerLegend[source]

Bases: QObject

__init__(parent: QObject | None = None)

Constructor for QgsMapLayerLegend

Parameters:

parent (Optional[QObject] = None)

abstract createLayerTreeModelLegendNodes(self, nodeLayer: QgsLayerTreeLayer | None) List[QgsLayerTreeModelLegendNode]

Returns list of legend nodes to be used for a particular layer tree layer node. Ownership is transferred to the caller.

Parameters:

nodeLayer (Optional[QgsLayerTreeLayer])

Return type:

List[QgsLayerTreeModelLegendNode]

static defaultMeshLegend(ml: QgsMeshLayer | None) QgsMapLayerLegend | None[source]

Create new legend implementation for mesh layer

Parameters:

ml (Optional[QgsMeshLayer])

Return type:

Optional[QgsMapLayerLegend]

static defaultPointCloudLegend(layer: QgsPointCloudLayer | None) QgsMapLayerLegend | None[source]

Create new legend implementation for a point cloud layer.

Added in version 3.18.

Parameters:

layer (Optional[QgsPointCloudLayer])

Return type:

Optional[QgsMapLayerLegend]

static defaultRasterLegend(rl: QgsRasterLayer | None) QgsMapLayerLegend | None[source]

Create new legend implementation for raster layer

Parameters:

rl (Optional[QgsRasterLayer])

Return type:

Optional[QgsMapLayerLegend]

static defaultVectorLegend(vl: QgsVectorLayer | None) QgsMapLayerLegend | None[source]

Create new legend implementation for vector layer

Parameters:

vl (Optional[QgsVectorLayer])

Return type:

Optional[QgsMapLayerLegend]

flags(self) Qgis.MapLayerLegendFlags[source]

Returns flags associated with the legend.

See also

setFlag()

See also

setFlags()

Added in version 4.0.

Return type:

Qgis.MapLayerLegendFlags

signal itemsChanged[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

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

Reads configuration from a DOM element previously written by writeXml()

Added in version 3.2.

Parameters:
setFlag(self, flag: Qgis.MapLayerLegendFlag, on: bool = True)[source]

Enables or disables a particular flag (other flags are not affected).

See also

flags()

See also

setFlags()

Added in version 4.0.

Parameters:
setFlags(self, flags: Qgis.MapLayerLegendFlags | Qgis.MapLayerLegendFlag)[source]

Sets the flags associated with the legend.

See also

setFlag()

See also

flags()

Added in version 4.0.

Parameters:

flags (Union[Qgis.MapLayerLegendFlags, Qgis.MapLayerLegendFlag])

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

Writes configuration to a DOM element, to be used later with readXml()

Added in version 3.2.

Parameters:
Return type:

QDomElement