16#ifndef QGSLAYERTREENODE_H
17#define QGSLAYERTREENODE_H
27using namespace Qt::StringLiterals;
86 if ( sipCpp->inherits(
"QgsLayerTreeNode" ) )
88 sipType = sipType_QgsLayerTreeNode;
91 sipType = sipType_QgsLayerTreeLayer;
92 else if ( qobject_cast<QgsLayerTree *>( sipCpp ) )
93 sipType = sipType_QgsLayerTree;
95 sipType = sipType_QgsLayerTreeGroup;
97 sipType = sipType_QgsLayerTreeCustomNode;
117 SIP_PYOBJECT __repr__();
119 QString str = u
"<QgsLayerTreeNode: %1>"_s.arg( sipCpp->name() );
120 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
130 sipRes = sipCpp->children().count();
141 const QList< QgsLayerTreeNode * > children = sipCpp->children();
142 const int count = children.count();
143 if ( a0 < 0 || a0 >= count )
145 PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
150 QgsLayerTreeNode *child = children.at( a0 );
151 sipRes = sipConvertFromType( child, sipType_QgsLayerTreeNode, NULL );
170 QList<QgsLayerTreeNode *> abandonChildren()
SIP_SKIP;
175 virtual QString
name() const = 0;
198 virtual QString
dump() const = 0;
229 void setItemVisibilityChecked(
bool checked );
234 virtual void setItemVisibilityCheckedRecursive(
bool checked );
239 void setItemVisibilityCheckedParentRecursive(
bool checked );
244 bool isItemVisibilityCheckedRecursive()
const;
249 bool isItemVisibilityUncheckedRecursive()
const;
255 QList< QgsMapLayer * > checkedLayers()
const;
264 bool isExpanded()
const;
266 void setExpanded(
bool expanded );
269 void setCustomProperty(
const QString &key,
const QVariant &value );
271 QVariant customProperty(
const QString &key,
const QVariant &defaultValue = QVariant() )
const;
273 void removeCustomProperty(
const QString &key );
275 QStringList customProperties()
const;
Base class for nodes in a layer tree.
virtual void setName(const QString &name)=0
Set name of the node.
virtual void makeOrphan()
Sets parent to nullptr and disconnects all external and forwarded signals.
NodeType
Enumeration of possible tree node types.
@ NodeCustom
Leaf node pointing to a custom object.
@ NodeGroup
Container of other groups and layers.
@ NodeLayer
Leaf node pointing to a layer.
void removedChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes has been removed from a node within the tree.
void nameChanged(QgsLayerTreeNode *node, QString name)
Emitted when the name of the node is changed.
bool isVisible() const
Returns whether a node is really visible (ie checked and all its ancestors checked as well).
virtual QString dump() const =0
Returns string with layer tree structure. For debug purposes only.
virtual void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context)=0
Write layer tree to XML.
static QgsLayerTreeNode * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer tree from XML.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
void willRemoveChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes will be removed from a node within the tree.
virtual QString name() const =0
Returns name of the node.
QgsLayerTreeNode * parent()
Gets pointer to the parent. If parent is nullptr, the node is a root node.
QgsLayerTreeNode(NodeType t, bool checked=true)
Constructor.
void writeCommonXml(QDomElement &element)
Write common XML elements.
NodeType nodeType() const
Find out about type of the node. It is usually shorter to use convenience functions from QgsLayerTree...
QgsObjectCustomProperties mProperties
custom properties attached to the node
void customPropertyChanged(QgsLayerTreeNode *node, const QString &key)
Emitted when a custom property of a node within the tree has been changed or removed.
NodeType mNodeType
type of the node - determines which subclass is used
void insertChildrenPrivate(int index, const QList< QgsLayerTreeNode * > &nodes)
Low-level insertion of children to the node. The children must not have any parent yet!
QList< QgsLayerTreeNode * > children() const
Gets list of children of the node. Children are owned by the parent.
void addedChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes have been added to a node within the tree.
void willAddChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes will be added to a node within the tree.
void visibilityChanged(QgsLayerTreeNode *node)
Emitted when check state of a node within the tree has been changed.
QList< QgsLayerTreeNode * > mChildren
list of children - node is responsible for their deletion
bool mExpanded
whether the node should be shown in GUI as expanded
void readCommonXml(const QDomElement &element)
Read common XML elements.
QgsLayerTreeNode * mParent
pointer to the parent node - nullptr in case of root node
virtual QgsLayerTreeNode * clone() const =0
Create a copy of the node. Returns new instance.
bool itemVisibilityChecked() const
Returns whether a node is checked (independently of its ancestors or children).
virtual void resolveReferences(const QgsProject *project, bool looseMatching=false)=0
Turn textual references to layers into map layer object from project.
void expandedChanged(QgsLayerTreeNode *node, bool expanded)
Emitted when the collapsed/expanded state of a node within the tree has been changed.
void removeChildrenPrivate(int from, int count, bool destroy=true)
Low-level removal of children from the node.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
static bool isCustomNode(const QgsLayerTreeNode *node)
Check whether the node is a valid custom node.
Base class for all map layer types.
Simple key-value store (keys = strings, values = variants) that supports loading/saving to/from XML i...
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
A container for the context for various read/write operations on objects.
#define SIP_TYPEHINT(type)
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)