Class: QgsLegendModel

class qgis.core.QgsLegendModel(rootNode: QgsLayerTree, parent: QObject = None, layout: QgsLayoutItemLegend = None)

Bases: QgsLayerTreeModel

Construct the model based on the given layer tree

QgsLegendModel(rootNode: QgsLayerTree, layout: QgsLayoutItemLegend) Alternative constructor.

Item model implementation based on layer tree model for layout legend.

Overrides some functionality of QgsLayerTreeModel to better fit the needs of layout legends.

New in version 2.6.

Parameters
  • rootNode (QgsLayerTree) –

  • parent (QObject = None) –

  • layout

addLegendToLayer(self, nodeL: QgsLayerTreeLayer)
QgsLegendModel.beginInsertColumns(self, QModelIndex, int, int)
QgsLegendModel.beginInsertRows(self, QModelIndex, int, int)
QgsLegendModel.beginMoveColumns(self, QModelIndex, int, int, QModelIndex, int) -> bool
QgsLegendModel.beginMoveRows(self, QModelIndex, int, int, QModelIndex, int) -> bool
QgsLegendModel.beginRemoveColumns(self, QModelIndex, int, int)
QgsLegendModel.beginRemoveRows(self, QModelIndex, int, int)
beginResetModel(self)
QgsLegendModel.changePersistentIndex(self, QModelIndex, QModelIndex)
changePersistentIndexList(self, Iterable[QModelIndex], Iterable[QModelIndex])
childEvent(self, QChildEvent)
clearCachedData(self, node: QgsLayerTreeNode)

Clears any previously cached data for the specified node.

New in version 3.14.

Parameters

node (QgsLayerTreeNode) –

connectNotify(self, QMetaMethod)
connectToLayer(self, nodeLayer: QgsLayerTreeLayer)
connectToLayers(self, parentGroup: QgsLayerTreeGroup)
connectToRootNode(self)
QgsLegendModel.createIndex(self, int, int, object: object = 0) -> QModelIndex
customEvent(self, QEvent)
data(self, index: QModelIndex, role: int) → Any
Parameters
  • index (QModelIndex) –

  • role (int) –

Return type

Any

QgsLegendModel.decodeData(self, int, int, QModelIndex, QDataStream) -> bool
disconnectFromLayer(self, nodeLayer: QgsLayerTreeLayer)
disconnectFromLayers(self, parentGroup: QgsLayerTreeGroup)
disconnectFromRootNode(self)
disconnectNotify(self, QMetaMethod)
encodeData(self, Iterable[QModelIndex], QDataStream)
endInsertColumns(self)
endInsertRows(self)
endMoveColumns(self)
endMoveRows(self)
endRemoveColumns(self)
endRemoveRows(self)
endResetModel(self)
filterLegendNodes(self, nodes: Iterable[QgsLayerTreeModelLegendNode]) → List[QgsLayerTreeModelLegendNode]

Filter nodes from QgsMapLayerLegend according to the current filtering rules

flags(self, index: QModelIndex) → Qt.ItemFlags
Parameters

index (QModelIndex) –

Return type

Qt.ItemFlags

iconGroup() → QIcon
indexOfParentLayerTreeNode(self, parentNode: QgsLayerTreeNode) → QModelIndex
invalidateLegendMapBasedData(self)
isSignalConnected(self, QMetaMethod) → bool
layerFlagsChanged(self)

Emitted when layer flags have changed.

New in version 3.18.

layerLegendChanged(self)
layerNeedsUpdate(self)
legendCleanup(self)
legendEmbeddedInParent(self, nodeLayer: QgsLayerTreeLayer) → bool
legendIconEmbeddedInParent(self, nodeLayer: QgsLayerTreeLayer) → QIcon
legendInvalidateMapBasedData(self)
legendNodeData(self, node: QgsLayerTreeModelLegendNode, role: int) → Any
legendNodeDataChanged(self)
legendNodeFlags(self, node: QgsLayerTreeModelLegendNode) → Qt.ItemFlags
legendNodeIndex(self, row: int, column: int, node: QgsLayerTreeModelLegendNode) → QModelIndex
legendNodeRowCount(self, node: QgsLayerTreeModelLegendNode) → int
legendParent(self, legendNode: QgsLayerTreeModelLegendNode) → QModelIndex
legendRootIndex(self, row: int, column: int, nL: QgsLayerTreeLayer) → QModelIndex
legendRootRowCount(self, nL: QgsLayerTreeLayer) → int
nodeAddedChildren(self, node: QgsLayerTreeNode, indexFrom: int, indexTo: int)
nodeCustomPropertyChanged(self, node: QgsLayerTreeNode, key: str)
nodeLayerLoaded(self)
nodeLayerWillBeUnloaded(self)
nodeNameChanged(self, node: QgsLayerTreeNode, name: str)

Updates model when node’s name has changed

New in version 3.0.

nodeRemovedChildren(self)
nodeVisibilityChanged(self, node: QgsLayerTreeNode)
nodeWillAddChildren(self, node: QgsLayerTreeNode, indexFrom: int, indexTo: int)
nodeWillRemoveChildren(self, node: QgsLayerTreeNode, indexFrom: int, indexTo: int)
persistentIndexList(self) → List[QModelIndex]
receivers(self, PYQT_SIGNAL) → int
recursivelyEmitDataChanged(self, index: QModelIndex = QModelIndex())

emit dataChanged() for layer tree node items

refreshLegend

Emitted to refresh the legend.

New in version 3.10: [signal]

refreshScaleBasedLayers(self, index: QModelIndex = QModelIndex(), previousScale: float = 0)

Updates layer data for scale dependent layers, should be called when map scale changes. Emits dataChanged() for all scale dependent layers.

New in version 2.16.

removeLegendFromLayer(self, nodeLayer: QgsLayerTreeLayer)
resetInternalData(self)
sender(self) → QObject
senderSignalIndex(self) → int
timerEvent(self, QTimerEvent)