QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
Public Types | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
QgsLayerTreeLayer Class Reference

Layer tree node points to a map layer. More...

#include <qgslayertreelayer.h>

Inheritance diagram for QgsLayerTreeLayer:
Inheritance graph
[legend]

Public Types

enum  LegendNodesSplitBehavior { UseDefaultLegendSetting , AllowSplittingLegendNodesOverMultipleColumns , PreventSplittingLegendNodesOverMultipleColumns }
 Legend node column split behavior. More...
 
- Public Types inherited from QgsLayerTreeNode
enum  NodeType { NodeGroup , NodeLayer }
 Enumeration of possible tree node types. More...
 

Signals

void layerLoaded ()
 Emitted when a previously unavailable layer got loaded.
 
void layerWillBeUnloaded ()
 Emitted when a previously available layer got unloaded (from layer registry).
 
- Signals inherited from QgsLayerTreeNode
void addedChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo)
 Emitted when one or more nodes have been added to a node within the tree.
 
void customPropertyChanged (QgsLayerTreeNode *node, const QString &key)
 Emitted when a custom property of a node within the tree has been changed or removed.
 
void expandedChanged (QgsLayerTreeNode *node, bool expanded)
 Emitted when the collapsed/expanded state of a node within the tree has been changed.
 
void nameChanged (QgsLayerTreeNode *node, QString name)
 Emitted when the name of the node is changed.
 
void removedChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo)
 Emitted when one or more nodes has been removed from a node within the tree.
 
void visibilityChanged (QgsLayerTreeNode *node)
 Emitted when check state of a node within the tree has been changed.
 
void willAddChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo)
 Emitted when one or more nodes will be added to a node within the tree.
 
void willRemoveChildren (QgsLayerTreeNode *node, int indexFrom, int indexTo)
 Emitted when one or more nodes will be removed from a node within the tree.
 

Public Member Functions

 QgsLayerTreeLayer (const QgsLayerTreeLayer &other)
 
 QgsLayerTreeLayer (const QString &layerId, const QString &name=QString(), const QString &source=QString(), const QString &provider=QString())
 Constructor for QgsLayerTreeLayer using weak references to layer ID, name, public source, and provider key.
 
 QgsLayerTreeLayer (QgsMapLayer *layer)
 
QgsLayerTreeLayerclone () const override
 Create a copy of the node. Returns new instance.
 
QString dump () const override
 Returns string with layer tree structure. For debug purposes only.
 
QString labelExpression () const
 Returns the expression member of the LayerTreeNode.
 
QgsMapLayerlayer () const
 Returns the map layer associated with this node.
 
QString layerId () const
 Returns the ID for the map layer associated with this node.
 
LegendNodesSplitBehavior legendSplitBehavior () const
 Returns the column split behavior for the node.
 
QString name () const override
 Returns the layer's name.
 
QgsLegendPatchShape patchShape () const
 Returns the symbol patch shape to use when rendering the legend node symbol.
 
QSizeF patchSize () const
 Returns the user (overridden) size for the legend node.
 
void resolveReferences (const QgsProject *project, bool looseMatching=false) override
 Resolves reference to layer from stored layer ID (if it has not been resolved already)
 
void setLabelExpression (const QString &expression)
 set the expression to evaluate
 
void setLegendSplitBehavior (LegendNodesSplitBehavior behavior)
 Sets the column split behavior for the node.
 
void setName (const QString &n) override
 Sets the layer's name.
 
void setPatchShape (const QgsLegendPatchShape &shape)
 Sets the symbol patch shape to use when rendering the legend node symbol.
 
void setPatchSize (QSizeF size)
 Sets the user (overridden) size for the legend node.
 
void setUseLayerName (bool use=true)
 Uses the layer's name if use is true, or the name manually set if false.
 
bool useLayerName () const
 Returns whether the layer's name is used, or the name manually set.
 
void writeXml (QDomElement &parentElement, const QgsReadWriteContext &context) override
 Write layer tree to XML.
 
- Public Member Functions inherited from QgsLayerTreeNode
 ~QgsLayerTreeNode () override
 
QList< QgsLayerTreeNode * > abandonChildren ()
 Removes the children, disconnect all the forwarded and external signals and sets their parent to nullptr.
 
QList< QgsMapLayer * > checkedLayers () const
 Returns a list of any checked layers which belong to this node or its children.
 
QList< QgsLayerTreeNode * > children ()
 Gets list of children of the node. Children are owned by the parent.
 
QList< QgsLayerTreeNode * > children () const
 Gets list of children of the node. Children are owned by the parent.
 
QStringList customProperties () const
 Returns list of keys stored in custom properties.
 
QVariant customProperty (const QString &key, const QVariant &defaultValue=QVariant()) const
 Read a custom property from layer. Properties are stored in a map and saved in project file.
 
int depth () const
 Returns the depth of this node, i.e.
 
bool isExpanded () const
 Returns whether the node should be shown as expanded or collapsed in GUI.
 
bool isItemVisibilityCheckedRecursive () const
 Returns whether this node is checked and all its children.
 
bool isItemVisibilityUncheckedRecursive () const
 Returns whether this node is unchecked and all its children.
 
bool isVisible () const
 Returns whether a node is really visible (ie checked and all its ancestors checked as well)
 
bool itemVisibilityChecked () const
 Returns whether a node is checked (independently of its ancestors or children)
 
NodeType nodeType () const
 Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree namespace for that.
 
QgsLayerTreeNodeparent ()
 Gets pointer to the parent. If parent is nullptr, the node is a root node.
 
void removeCustomProperty (const QString &key)
 Remove a custom property from layer. Properties are stored in a map and saved in project file.
 
void setCustomProperty (const QString &key, const QVariant &value)
 Sets a custom property for the node. Properties are stored in a map and saved in project file.
 
void setExpanded (bool expanded)
 Sets whether the node should be shown as expanded or collapsed in GUI.
 
void setItemVisibilityChecked (bool checked)
 Check or uncheck a node (independently of its ancestors or children)
 
void setItemVisibilityCheckedParentRecursive (bool checked)
 Check or uncheck a node and all its parents.
 
virtual void setItemVisibilityCheckedRecursive (bool checked)
 Check or uncheck a node and all its children (taking into account exclusion rules)
 
bool takeChild (QgsLayerTreeNode *node)
 Remove a child from a node.
 

Static Public Member Functions

static QgsLayerTreeLayerreadXml (QDomElement &element, const QgsProject *project, const QgsReadWriteContext &context)
 Read layer node from XML.
 
static QgsLayerTreeLayerreadXml (QDomElement &element, const QgsReadWriteContext &context)
 Read layer node from XML.
 
- Static Public Member Functions inherited from QgsLayerTreeNode
static QgsLayerTreeNodereadXml (QDomElement &element, const QgsProject *project)
 Read layer tree from XML.
 
static QgsLayerTreeNodereadXml (QDomElement &element, const QgsReadWriteContext &context)
 Read layer tree from XML.
 

Protected Member Functions

void attachToLayer ()
 
- Protected Member Functions inherited from QgsLayerTreeNode
 QgsLayerTreeNode (const QgsLayerTreeNode &other)
 
 QgsLayerTreeNode (NodeType t, bool checked=true)
 Constructor.
 
void insertChildrenPrivate (int index, const QList< QgsLayerTreeNode * > &nodes)
 Low-level insertion of children to the node. The children must not have any parent yet!
 
virtual void makeOrphan ()
 Sets parent to nullptr and disconnects all external and forwarded signals.
 
void readCommonXml (QDomElement &element)
 Read common XML elements.
 
void removeChildrenPrivate (int from, int count, bool destroy=true)
 Low-level removal of children from the node.
 
void writeCommonXml (QDomElement &element)
 Write common XML elements.
 

Protected Attributes

QString mLabelExpression
 Expression to evaluate in the legend.
 
QString mLayerName
 Layer name - only used if layer does not exist or if mUseLayerName is false.
 
QgsMapLayerRef mRef
 Weak reference to the layer (or just it's ID if the reference is not resolved yet)
 
bool mUseLayerName = true
 
- Protected Attributes inherited from QgsLayerTreeNode
bool mChecked
 
QList< QgsLayerTreeNode * > mChildren
 list of children - node is responsible for their deletion
 
bool mExpanded
 whether the node should be shown in GUI as expanded
 
NodeType mNodeType
 type of the node - determines which subclass is used
 
QgsLayerTreeNodemParent = nullptr
 pointer to the parent node - nullptr in case of root node
 
QgsObjectCustomProperties mProperties
 custom properties attached to the node
 

Detailed Description

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.

Definition at line 42 of file qgslayertreelayer.h.

Member Enumeration Documentation

◆ LegendNodesSplitBehavior

Legend node column split behavior.

Since
QGIS 3.14
Enumerator
UseDefaultLegendSetting 

Inherit default legend column splitting setting.

AllowSplittingLegendNodesOverMultipleColumns 

Allow splitting node's legend nodes across multiple columns.

PreventSplittingLegendNodesOverMultipleColumns 

Prevent splitting node's legend nodes across multiple columns.

Definition at line 192 of file qgslayertreelayer.h.

Constructor & Destructor Documentation

◆ QgsLayerTreeLayer() [1/3]

QgsLayerTreeLayer::QgsLayerTreeLayer ( QgsMapLayer layer)
explicit

Definition at line 25 of file qgslayertreelayer.cpp.

◆ QgsLayerTreeLayer() [2/3]

QgsLayerTreeLayer::QgsLayerTreeLayer ( const QgsLayerTreeLayer other)

Definition at line 40 of file qgslayertreelayer.cpp.

◆ QgsLayerTreeLayer() [3/3]

QgsLayerTreeLayer::QgsLayerTreeLayer ( const QString &  layerId,
const QString &  name = QString(),
const QString &  source = QString(),
const QString &  provider = QString() 
)
explicit

Constructor for QgsLayerTreeLayer using weak references to layer ID, name, public source, and provider key.

Definition at line 33 of file qgslayertreelayer.cpp.

Member Function Documentation

◆ attachToLayer()

void QgsLayerTreeLayer::attachToLayer ( )
protected

Definition at line 72 of file qgslayertreelayer.cpp.

◆ clone()

QgsLayerTreeLayer * QgsLayerTreeLayer::clone ( ) const
overridevirtual

Create a copy of the node. Returns new instance.

Implements QgsLayerTreeNode.

Definition at line 192 of file qgslayertreelayer.cpp.

◆ dump()

QString QgsLayerTreeLayer::dump ( ) const
overridevirtual

Returns string with layer tree structure. For debug purposes only.

Implements QgsLayerTreeNode.

Definition at line 187 of file qgslayertreelayer.cpp.

◆ labelExpression()

QString QgsLayerTreeLayer::labelExpression ( ) const
inline

Returns the expression member of the LayerTreeNode.

Since
QGIS 3.10

Definition at line 147 of file qgslayertreelayer.h.

◆ layer()

QgsMapLayer * QgsLayerTreeLayer::layer ( ) const
inline

Returns the map layer associated with this node.

Warning
This can be (and often is!) nullptr, 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 dereferencing nullptr.
See also
layerId()

Definition at line 81 of file qgslayertreelayer.h.

◆ layerId()

QString QgsLayerTreeLayer::layerId ( ) const
inline

Returns the ID for the map layer associated with this node.

See also
layer()

Definition at line 70 of file qgslayertreelayer.h.

◆ layerLoaded

void QgsLayerTreeLayer::layerLoaded ( )
signal

Emitted when a previously unavailable layer got loaded.

◆ layerWillBeUnloaded

void QgsLayerTreeLayer::layerWillBeUnloaded ( )
signal

Emitted when a previously available layer got unloaded (from layer registry).

◆ legendSplitBehavior()

LegendNodesSplitBehavior QgsLayerTreeLayer::legendSplitBehavior ( ) const
inline

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
setLegendSplitBehavior()
Since
QGIS 3.14

Definition at line 207 of file qgslayertreelayer.h.

◆ name()

QString QgsLayerTreeLayer::name ( ) const
overridevirtual

Returns the layer's name.

See also
setName()

Implements QgsLayerTreeNode.

Definition at line 82 of file qgslayertreelayer.cpp.

◆ patchShape()

QgsLegendPatchShape QgsLayerTreeLayer::patchShape ( ) const

Returns the symbol patch shape to use when rendering the legend node symbol.

See also
setPatchShape()
Since
QGIS 3.14

Definition at line 231 of file qgslayertreelayer.cpp.

◆ patchSize()

QSizeF QgsLayerTreeLayer::patchSize ( ) const
inline

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
setPatchSize()
Since
QGIS 3.14

Definition at line 174 of file qgslayertreelayer.h.

◆ readXml() [1/2]

QgsLayerTreeLayer * QgsLayerTreeLayer::readXml ( QDomElement &  element,
const QgsProject project,
const QgsReadWriteContext context 
)
static

Read layer node from XML.

Returns new instance. Also resolves textual references to layers from the project (calls resolveReferences() internally).

Definition at line 145 of file qgslayertreelayer.cpp.

◆ readXml() [2/2]

QgsLayerTreeLayer * QgsLayerTreeLayer::readXml ( QDomElement &  element,
const QgsReadWriteContext context 
)
static

Read layer node from XML.

Returns new instance. Does not resolve textual references to layers. Call resolveReferences() afterwards to do it.

Definition at line 105 of file qgslayertreelayer.cpp.

◆ resolveReferences()

void QgsLayerTreeLayer::resolveReferences ( const QgsProject project,
bool  looseMatching = false 
)
overridevirtual

Resolves reference to layer from stored layer ID (if it has not been resolved already)

Implements QgsLayerTreeNode.

Definition at line 51 of file qgslayertreelayer.cpp.

◆ setLabelExpression()

void QgsLayerTreeLayer::setLabelExpression ( const QString &  expression)

set the expression to evaluate

Since
QGIS 3.10

Definition at line 226 of file qgslayertreelayer.cpp.

◆ setLegendSplitBehavior()

void QgsLayerTreeLayer::setLegendSplitBehavior ( LegendNodesSplitBehavior  behavior)
inline

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
legendSplitBehavior()
Since
QGIS 3.14

Definition at line 217 of file qgslayertreelayer.h.

◆ setName()

void QgsLayerTreeLayer::setName ( const QString &  n)
overridevirtual

Sets the layer's name.

See also
name()

Implements QgsLayerTreeNode.

Definition at line 87 of file qgslayertreelayer.cpp.

◆ setPatchShape()

void QgsLayerTreeLayer::setPatchShape ( const QgsLegendPatchShape shape)

Sets the symbol patch shape to use when rendering the legend node symbol.

See also
patchShape()
Since
QGIS 3.14

Definition at line 236 of file qgslayertreelayer.cpp.

◆ setPatchSize()

void QgsLayerTreeLayer::setPatchSize ( QSizeF  size)
inline

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
patchSize()
Since
QGIS 3.14

Definition at line 185 of file qgslayertreelayer.h.

◆ setUseLayerName()

void QgsLayerTreeLayer::setUseLayerName ( bool  use = true)

Uses the layer's name if use is true, or the name manually set if false.

Since
QGIS 3.8

Definition at line 210 of file qgslayertreelayer.cpp.

◆ useLayerName()

bool QgsLayerTreeLayer::useLayerName ( ) const

Returns whether the layer's name is used, or the name manually set.

Since
QGIS 3.8

Definition at line 215 of file qgslayertreelayer.cpp.

◆ writeXml()

void QgsLayerTreeLayer::writeXml ( QDomElement &  parentElement,
const QgsReadWriteContext context 
)
overridevirtual

Write layer tree to XML.

Implements QgsLayerTreeNode.

Definition at line 153 of file qgslayertreelayer.cpp.

Member Data Documentation

◆ mLabelExpression

QString QgsLayerTreeLayer::mLabelExpression
protected

Expression to evaluate in the legend.

Definition at line 239 of file qgslayertreelayer.h.

◆ mLayerName

QString QgsLayerTreeLayer::mLayerName
protected

Layer name - only used if layer does not exist or if mUseLayerName is false.

Definition at line 237 of file qgslayertreelayer.h.

◆ mRef

QgsMapLayerRef QgsLayerTreeLayer::mRef
protected

Weak reference to the layer (or just it's ID if the reference is not resolved yet)

Definition at line 235 of file qgslayertreelayer.h.

◆ mUseLayerName

bool QgsLayerTreeLayer::mUseLayerName = true
protected

Definition at line 242 of file qgslayertreelayer.h.


The documentation for this class was generated from the following files: