Class: QgsLayerTreeLayer¶
- class qgis.core.QgsLayerTreeLayer¶
Bases:
QgsLayerTreeNode
Layer tree node points to a map layer.
The node can exist also without a valid instance of a layer (just ID). That means the referenced layer does not need to be loaded in order to use it in layer tree. In such case,
resolveReferences()
method can be called once the layer is loaded.A map layer is supposed to be present in one layer tree just once. It is however possible that temporarily a layer exists in one tree more than just once, e.g. while reordering items with drag and drop.
New in version 2.4.
QgsLayerTreeLayer(layer:
QgsMapLayer
)QgsLayerTreeLayer(layerId: str, name: str = ‘’, source: str = ‘’, provider: str = ‘’) Constructor for
QgsLayerTreeLayer
using weak references to layer ID,name
, publicsource
, andprovider
key.Methods
- rtype:
QgsLayerTreeLayer
- rtype:
str
Low-level insertion of children to the node.
Returns the expression member of the LayerTreeNode
Returns the map layer associated with this node.
Returns the ID for the map layer associated with this node.
Returns the column split behavior for the node.
Returns the layer's name.
Returns the symbol patch shape to use when rendering the legend node symbol.
Returns the user (overridden) size for the legend node.
Read common XML elements.
Read layer node from XML.
Low-level removal of children from the node.
Resolves reference to layer from stored layer ID (if it has not been resolved already)
set the expression to evaluate
Sets the column split
behavior
for the node.Sets the layer's name.
Sets the symbol patch
shape
to use when rendering the legend node symbol.Sets the user (overridden)
size
for the legend node.Uses the layer's name if
use
isTrue
, or the name manually set ifFalse
.Returns whether the layer's name is used, or the name manually set.
Write common XML elements.
- param parentElement:
Signals
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL
Attributes
- AllowSplittingLegendNodesOverMultipleColumns = 1¶
- class LegendNodesSplitBehavior¶
Bases:
int
- PreventSplittingLegendNodesOverMultipleColumns = 2¶
- UseDefaultLegendSetting = 0¶
- attachToLayer(self)¶
- childEvent(self, QChildEvent)¶
- clone(self) QgsLayerTreeLayer ¶
- Return type:
- connectNotify(self, QMetaMethod)¶
- customEvent(self, QEvent)¶
- disconnectNotify(self, QMetaMethod)¶
- dump(self) str ¶
- Return type:
str
- insertChildrenPrivate(self, index: int, nodes: Iterable[QgsLayerTreeNode])¶
Low-level insertion of children to the node. The children must not have any parent yet!
- isSignalConnected(self, QMetaMethod) bool ¶
- labelExpression(self) str ¶
Returns the expression member of the LayerTreeNode
New in version 3.10.
- Return type:
str
- layer(self) QgsMapLayer ¶
Returns the map layer associated with this node.
Warning
This can be (and often is!)
None
, e.g. in the case of a layer node representing a layer which has not yet been fully loaded into a project, or a layer node representing a layer with an invalid data source. The returned pointer must ALWAYS be checked to avoid dereferencingNone
.See also
- Return type:
- layerId(self) str ¶
Returns the ID for the map layer associated with this node.
See also
- Return type:
str
- layerLoaded¶
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
- layerWillBeUnloaded¶
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
- legendSplitBehavior(self) QgsLayerTreeLayer.LegendNodesSplitBehavior ¶
Returns the column split behavior for the node.
This value controls how legend nodes belonging the to layer may be split over multiple columns in legends.
See also
New in version 3.14.
- Return type:
- patchShape(self) QgsLegendPatchShape ¶
Returns the symbol patch shape to use when rendering the legend node symbol.
See also
New in version 3.14.
- Return type:
- patchSize(self) QSizeF ¶
Returns the user (overridden) size for the legend node.
If either the width or height are non-zero, they will be used when rendering the legend node instead of the default symbol width or height from
QgsLegendSettings
.See also
New in version 3.14.
- Return type:
QSizeF
- readCommonXml(self, element: QDomElement)¶
Read common XML elements.
- readXml(element: QDomElement, context: QgsReadWriteContext) QgsLayerTreeLayer ¶
Read layer node from XML. Returns new instance. Does not resolve textual references to layers. Call
resolveReferences()
afterwards to do it.readXml(element: QDomElement, project:
QgsProject
, context:QgsReadWriteContext
) -> QgsLayerTreeLayer Read layer node from XML. Returns new instance. Also resolves textual references to layers from the project (callsresolveReferences()
internally).New in version 3.0.
- Parameters:
element (QDomElement) –
context (QgsReadWriteContext) –
- Return type:
- receivers(self, PYQT_SIGNAL) int ¶
- removeChildrenPrivate(self, from_: int, count: int, destroy: bool = True)¶
Low-level removal of children from the node.
- resolveReferences(self, project: QgsProject, looseMatching: bool = False)¶
Resolves reference to layer from stored layer ID (if it has not been resolved already)
New in version 3.0.
- Parameters:
project (QgsProject) –
looseMatching (bool = False) –
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setLabelExpression(self, expression: str)¶
set the expression to evaluate
New in version 3.10.
- Parameters:
expression (str) –
- setLegendSplitBehavior(self, behavior: QgsLayerTreeLayer.LegendNodesSplitBehavior)¶
Sets the column split
behavior
for the node.This value controls how legend nodes belonging the to layer may be split over multiple columns in legends.
See also
New in version 3.14.
- Parameters:
behavior (QgsLayerTreeLayer.LegendNodesSplitBehavior) –
- setName(self, n: str)¶
Sets the layer’s name.
See also
New in version 3.0.
- Parameters:
n (str) –
- setPatchShape(self, shape: QgsLegendPatchShape)¶
Sets the symbol patch
shape
to use when rendering the legend node symbol.See also
New in version 3.14.
- Parameters:
shape (QgsLegendPatchShape) –
- setPatchSize(self, size: QSizeF)¶
Sets the user (overridden)
size
for the legend node.If either the width or height are non-zero, they will be used when rendering the legend node instead of the default symbol width or height from
QgsLegendSettings
.See also
New in version 3.14.
- Parameters:
size (QSizeF) –
- setUseLayerName(self, use: bool = True)¶
Uses the layer’s name if
use
isTrue
, or the name manually set ifFalse
.New in version 3.8.
- Parameters:
use (bool = True) –
- timerEvent(self, QTimerEvent)¶
- useLayerName(self) bool ¶
Returns whether the layer’s name is used, or the name manually set.
New in version 3.8.
- Return type:
bool
- writeCommonXml(self, element: QDomElement)¶
Write common XML elements.
- writeXml(self, parentElement: QDomElement, context: QgsReadWriteContext)¶
- Parameters:
parentElement (QDomElement) –
context (QgsReadWriteContext) –