Class: QgsLegendModel

class qgis.core.QgsLegendModel

Bases: QgsLayerTreeModel

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

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

QgsLegendModel(rootNode: Optional[QgsLayerTree], parent: Optional[QObject] = None, layout: Optional[QgsLayoutItemLegend] = None) Construct the model based on the given layer tree

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

Methods

addLegendToLayer

beginInsertColumns

beginInsertRows

beginMoveColumns

beginMoveRows

beginRemoveColumns

beginRemoveRows

beginResetModel

changePersistentIndex

changePersistentIndexList

childEvent

clearCachedData

Clears any previously cached data for the specified node.

connectNotify

connectToLayer

connectToLayers

connectToRootNode

createIndex

customEvent

data

param index:

decodeData

disconnectFromLayer

disconnectFromLayers

disconnectFromRootNode

disconnectNotify

encodeData

endInsertColumns

endInsertRows

endMoveColumns

endMoveRows

endRemoveColumns

endRemoveRows

endResetModel

filterLegendNodes

Filter nodes from QgsMapLayerLegend according to the current filtering rules

flags

param index:

iconGroup

indexOfParentLayerTreeNode

invalidateLegendMapBasedData

isSignalConnected

layerFlagsChanged

Emitted when layer flags have changed.

layerLegendChanged

layerNeedsUpdate

legendCleanup

legendEmbeddedInParent

legendIconEmbeddedInParent

legendInvalidateMapBasedData

legendNodeData

legendNodeDataChanged

legendNodeFlags

legendNodeIndex

legendNodeRowCount

legendParent

legendRootIndex

legendRootRowCount

nodeAddedChildren

nodeCustomPropertyChanged

nodeLayerLoaded

nodeLayerWillBeUnloaded

nodeNameChanged

Updates model when node's name has changed

nodeRemovedChildren

nodeVisibilityChanged

nodeWillAddChildren

nodeWillRemoveChildren

persistentIndexList

receivers

recursivelyEmitDataChanged

emit dataChanged() for layer tree node items

refreshScaleBasedLayers

Updates layer data for scale dependent layers, should be called when map scale changes.

removeLegendFromLayer

resetInternalData

sender

senderSignalIndex

timerEvent

Signals

refreshLegend

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

addLegendToLayer(self, nodeL: QgsLayerTreeLayer | None)
beginInsertColumns(self, parent: QModelIndex, first: int, last: int)
beginInsertRows(self, parent: QModelIndex, first: int, last: int)
beginMoveColumns(self, sourceParent: QModelIndex, sourceFirst: int, sourceLast: int, destinationParent: QModelIndex, destinationColumn: int) bool
beginMoveRows(self, sourceParent: QModelIndex, sourceFirst: int, sourceLast: int, destinationParent: QModelIndex, destinationRow: int) bool
beginRemoveColumns(self, parent: QModelIndex, first: int, last: int)
beginRemoveRows(self, parent: QModelIndex, first: int, last: int)
beginResetModel(self)
changePersistentIndex(self, from_: QModelIndex, to: QModelIndex)
changePersistentIndexList(self, from_: Iterable[QModelIndex], to: Iterable[QModelIndex])
childEvent(self, a0: QChildEvent | None)
clearCachedData(self, node: QgsLayerTreeNode | None)

Clears any previously cached data for the specified node.

Added in version 3.14.

Parameters:

node (Optional[QgsLayerTreeNode])

connectNotify(self, signal: QMetaMethod)
connectToLayer(self, nodeLayer: QgsLayerTreeLayer | None)
connectToLayers(self, parentGroup: QgsLayerTreeGroup | None)
connectToRootNode(self)
createIndex(self, row: int, column: int, object: Any = None) QModelIndex
customEvent(self, a0: QEvent | None)
data(self, index: QModelIndex, role: int) Any
Parameters:
  • index (QModelIndex)

  • role (int)

Return type:

Any

decodeData(self, row: int, column: int, parent: QModelIndex, stream: QDataStream) bool
disconnectFromLayer(self, nodeLayer: QgsLayerTreeLayer | None)
disconnectFromLayers(self, parentGroup: QgsLayerTreeGroup | None)
disconnectFromRootNode(self)
disconnectNotify(self, signal: QMetaMethod)
encodeData(self, indexes: Iterable[QModelIndex], stream: 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 | None) QModelIndex
invalidateLegendMapBasedData(self)
isSignalConnected(self, signal: QMetaMethod) bool
layerFlagsChanged(self)

Emitted when layer flags have changed.

Added in version 3.18.

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

Updates model when node’s name has changed

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

emit dataChanged() for layer tree node items

refreshLegend

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.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_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.

removeLegendFromLayer(self, nodeLayer: QgsLayerTreeLayer | None)
resetInternalData(self)
sender(self) QObject | None
senderSignalIndex(self) int
timerEvent(self, a0: QTimerEvent | None)