Class: QgsLayerTreeRegistryBridge

Listens to layer changes from a QgsProject and applies changes to a QgsLayerTree.

When connected to a layer tree, any layers added to the map layer registry will be also added to the layer tree. Similarly, map layers that are removed from registry will be removed from the layer tree.

If a layer is completely removed from the layer tree, it will be also removed from the map layer registry.

Class Hierarchy

Inheritance diagram of qgis.core.QgsLayerTreeRegistryBridge

Base classes

QObject

Methods

groupRemovedChildren

groupWillRemoveChildren

isEnabled

layerInsertionMethod

Returns the insertion method used to add layers to the tree

layerInsertionPoint

Returns the insertion point used to add layers to the tree

layersAdded

layersWillBeRemoved

newLayersVisible

removeLayersFromRegistry

setEnabled

setLayerInsertionMethod

Sets the insertion method used to add layers to the tree

setLayerInsertionPoint

Set where the new layers should be inserted - can be used to follow current selection.

setNewLayersVisible

Signals

addedLayersToLayerTree

Tell others we have just added layers to the tree (used in QGIS to auto-select first newly added layer)

class qgis.core.QgsLayerTreeRegistryBridge[source]

Bases: QObject

__init__(root: QgsLayerTreeGroup | None, project: QgsProject | None, parent: QObject | None = None)

Create the instance that synchronizes given project with a layer tree root

Parameters:
class InsertionPoint

Bases: object

A structure to define the insertion point to the layer tree. This represents the current layer tree group and index where newly added map layers should be inserted into.

Added in version 3.10.

group
position
signal addedLayersToLayerTree(layers: List[QgsMapLayer])[source]

Tell others we have just added layers to the tree (used in QGIS to auto-select first newly added layer)

Parameters:

layers (List[QgsMapLayer])

groupRemovedChildren(self)[source]
groupWillRemoveChildren(self, node: QgsLayerTreeNode | None, indexFrom: int, indexTo: int)[source]
Parameters:
isEnabled(self) bool[source]
Return type:

bool

layerInsertionMethod(self) Qgis.LayerTreeInsertionMethod[source]

Returns the insertion method used to add layers to the tree

Added in version 3.30.

Return type:

Qgis.LayerTreeInsertionMethod

layerInsertionPoint(self) QgsLayerTreeRegistryBridge.InsertionPoint[source]

Returns the insertion point used to add layers to the tree

Added in version 3.42.

Return type:

QgsLayerTreeRegistryBridge.InsertionPoint

layersAdded(self, layers: Iterable[QgsMapLayer])[source]
Parameters:

layers (Iterable[QgsMapLayer])

layersWillBeRemoved(self, layerIds: Iterable[str | None])[source]
Parameters:

layerIds (Iterable[Optional[str]])

newLayersVisible(self) bool[source]
Return type:

bool

removeLayersFromRegistry(self, layerIds: Iterable[str | None])[source]
Parameters:

layerIds (Iterable[Optional[str]])

setEnabled(self, enabled: bool)[source]
Parameters:

enabled (bool)

setLayerInsertionMethod(self, method: Qgis.LayerTreeInsertionMethod)[source]

Sets the insertion method used to add layers to the tree

Added in version 3.30.

Parameters:

method (Qgis.LayerTreeInsertionMethod)

setLayerInsertionPoint(self, parentGroup: QgsLayerTreeGroup | None, index: int)[source]

Set where the new layers should be inserted - can be used to follow current selection. By default it is root group with zero index.

Deprecated since version 3.10: Use setLayerInsertionPoint( const InsertionPoint &insertionPoint ) instead.

Parameters:
setLayerInsertionPoint(self, insertionPoint: QgsLayerTreeRegistryBridge.InsertionPoint)[source]

Set where the new layers should be inserted - can be used to follow current selection. By default it is root group with zero index.

Added in version 3.10.

Parameters:

insertionPoint (QgsLayerTreeRegistryBridge.InsertionPoint)

setNewLayersVisible(self, enabled: bool)[source]
Parameters:

enabled (bool)