QGIS API Documentation 3.99.0-Master (21b3aa880ba)
Loading...
Searching...
No Matches
QgsLayerTreeCustomNode Class Reference

Layer tree custom node serves as a node for objects that are not layers nor groups. More...

#include <qgslayertreecustomnode.h>

Inheritance diagram for QgsLayerTreeCustomNode:

Public Member Functions

 QgsLayerTreeCustomNode (const QgsLayerTreeCustomNode &other)
 QgsLayerTreeCustomNode (const QString &nodeId, const QString &nodeName=QString(), bool checked=true)
 Constructor to create custom nodes that represent application objects other than layers and groups.
QgsLayerTreeCustomNodeclone () 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 name () const override
 Returns the node's name.
QString nodeId () const
 Returns the node's unique identifier.
void resolveReferences (const QgsProject *project, bool looseMatching=false) override
 Turn textual references to layers into map layer object from project.
void setName (const QString &name) override
 Sets the node's name.
void writeXml (QDomElement &parentElement, const QgsReadWriteContext &context) override
 Write custom node as XML element <layer-tree-custom-node> and add it to the given parent element.
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 QgsLayerTreeCustomNodereadXml (const QDomElement &element, const QgsReadWriteContext &context)
 Read custom node from XML element <layer-tree-custom-node> and return the newly created node (or nullptr on error).
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.

Additional Inherited Members

Public Types inherited from QgsLayerTreeNode
enum  NodeType { NodeGroup , NodeLayer , NodeCustom }
 Enumeration of possible tree node types. More...
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.
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 (const 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 inherited from QgsLayerTreeNode
bool mChecked
QList< QgsLayerTreeNode * > mChildren
 list of children - node is responsible for their deletion
bool mExpanded = true
 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 custom node serves as a node for objects that are not layers nor groups.

They are created, and can be found based on a node ID, which should be unique in the whole layer tree.

Since
QGIS 4.0

Definition at line 36 of file qgslayertreecustomnode.h.

Constructor & Destructor Documentation

◆ QgsLayerTreeCustomNode() [1/2]

QgsLayerTreeCustomNode::QgsLayerTreeCustomNode ( const QString & nodeId,
const QString & nodeName = QString(),
bool checked = true )
explicit

Constructor to create custom nodes that represent application objects other than layers and groups.

Parameters
nodeIdUnique identifier of the custom node.
nodeNameOptional name of the custom node.
checkedWhether the custom node should be checked or not once it is created.

Definition at line 24 of file qgslayertreecustomnode.cpp.

◆ QgsLayerTreeCustomNode() [2/2]

QgsLayerTreeCustomNode::QgsLayerTreeCustomNode ( const QgsLayerTreeCustomNode & other)

Definition at line 31 of file qgslayertreecustomnode.cpp.

Member Function Documentation

◆ clone()

QgsLayerTreeCustomNode * QgsLayerTreeCustomNode::clone ( ) const
overridevirtual

Create a copy of the node. Returns new instance.

Implements QgsLayerTreeNode.

Definition at line 85 of file qgslayertreecustomnode.cpp.

◆ dump()

QString QgsLayerTreeCustomNode::dump ( ) const
overridevirtual

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

Implements QgsLayerTreeNode.

Definition at line 80 of file qgslayertreecustomnode.cpp.

◆ name()

QString QgsLayerTreeCustomNode::name ( ) const
overridevirtual

Returns the node's name.

Implements QgsLayerTreeNode.

Definition at line 38 of file qgslayertreecustomnode.cpp.

◆ nodeId()

QString QgsLayerTreeCustomNode::nodeId ( ) const
inline

Returns the node's unique identifier.

Definition at line 65 of file qgslayertreecustomnode.h.

◆ readXml()

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

Read custom node from XML element <layer-tree-custom-node> and return the newly created node (or nullptr on error).

Definition at line 52 of file qgslayertreecustomnode.cpp.

◆ resolveReferences()

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

Turn textual references to layers into map layer object from project.

This method should be called after readXml() If looseMatching is true then a looser match will be used, where a layer will match if the name, public source, and data provider match. This can be used to match legend customization from different projects where layers will have different layer IDs.

Implements QgsLayerTreeNode.

Definition at line 90 of file qgslayertreecustomnode.cpp.

◆ setName()

void QgsLayerTreeCustomNode::setName ( const QString & name)
overridevirtual

Sets the node's name.

Implements QgsLayerTreeNode.

Definition at line 43 of file qgslayertreecustomnode.cpp.

◆ writeXml()

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

Write custom node as XML element <layer-tree-custom-node> and add it to the given parent element.

Implements QgsLayerTreeNode.

Definition at line 67 of file qgslayertreecustomnode.cpp.


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