34 , mNodeType( other.mNodeType )
35 , mChecked( other.mChecked )
36 , mExpanded( other.mExpanded )
37 , mProperties( other.mProperties )
39 QList<QgsLayerTreeNode *> clonedChildren;
42 clonedChildren << child->clone();
53 const QList<QgsLayerTreeNode *> orphans {
mChildren };
55 for (
auto orphan : std::as_const( orphans ) )
57 orphan->makeOrphan( );
71 if ( element.tagName() == QLatin1String(
"layer-tree-group" ) )
73 else if ( element.tagName() == QLatin1String(
"layer-tree-layer" ) )
133 if ( !child->isItemVisibilityCheckedRecursive() )
147 if ( !child->isItemVisibilityUncheckedRecursive() )
160 layers << nodeLayer->
layer();
163 const auto constChildren = node->
children();
170 layers << groupLayer;
181 QList<QgsMapLayer *> layers;
243 QDomDocument doc( element.ownerDocument() );
249 if ( nodes.isEmpty() )
254 Q_ASSERT( !node->mParent );
255 node->mParent =
this;
258 if ( index < 0 || index >=
mChildren.count() )
261 for (
int i = 0; i < nodes.count(); ++i )
282 if ( ! orphans.isEmpty() )
294 if ( from < 0 || count <= 0 )
297 const int to = from + count - 1;
302 while ( --count >= 0 )
304 const int last { from + count };
305 Q_ASSERT( last >= 0 && last <
mChildren.count( ) );
A map layer which consists of a set of child layers, where all component layers are rendered as a sin...
Layer tree group node serves as a container for layers and further groups.
static QgsLayerTreeGroup * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read group (tree) from XML element <layer-tree-group> and return the newly created group (or nullptr ...
Layer tree node points to a map layer.
static QgsLayerTreeLayer * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer node from XML.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
This class is a base class for nodes in a layer tree.
void readCommonXml(QDomElement &element)
Read common XML elements.
QList< QgsLayerTreeNode * > abandonChildren()
Removes the childrens, disconnect all the forwarded and external signals and sets their parent to nul...
virtual void makeOrphan()
Sets parent to nullptr and disconnects all external and forwarded signals.
NodeType
Enumeration of possible tree node types.
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)
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.
bool isItemVisibilityUncheckedRecursive() const
Returns whether this node is unchecked and all its children.
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.
void removeCustomProperty(const QString &key)
Remove a custom property from layer. Properties are stored in a map and saved in project file.
~QgsLayerTreeNode() override
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.
void setExpanded(bool expanded)
Sets whether the node should be shown as expanded or collapsed in GUI.
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.
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.
void insertChildrenPrivate(int index, const QList< QgsLayerTreeNode * > &nodes)
Low-level insertion of children to the node. The children must not have any parent yet!
int depth() const
Returns the depth of this node, i.e.
void addedChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes have been added to a node within the tree.
bool takeChild(QgsLayerTreeNode *node)
Remove a child from a node.
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
virtual void setItemVisibilityCheckedRecursive(bool checked)
Check or uncheck a node and all its children (taking into account exclusion rules)
bool mExpanded
whether the node should be shown in GUI as expanded
bool isExpanded() const
Returns whether the node should be shown as expanded or collapsed in GUI.
QStringList customProperties() const
Returns list of keys stored in custom properties.
void setItemVisibilityChecked(bool checked)
Check or uncheck a node (independently of its ancestors or children)
QList< QgsMapLayer * > checkedLayers() const
Returns a list of any checked layers which belong to this node or its children.
QgsLayerTreeNode * mParent
pointer to the parent node - nullptr in case of root node
bool isItemVisibilityCheckedRecursive() const
Returns whether this node is checked and all its 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.
void setItemVisibilityCheckedParentRecursive(bool checked)
Check or uncheck a node and all its parents.
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
void setValue(const QString &key, const QVariant &value)
Add an entry to the store with the specified key.
QStringList keys() const
Returns a list of all stored keys.
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Writes the store contents to an XML node.
void remove(const QString &key)
Removes a key (entry) from the store.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for the given key.
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from an XML node.
bool contains(const QString &key) const
Returns true if the properties contains a key with the specified name.
Resolves relative paths into absolute paths and vice versa.
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
QgsPathResolver pathResolver() const
Returns path resolver object with considering whether the project uses absolute or relative paths and...
The class is used as a container of context for various read/write operations on other objects.
void setProjectTranslator(QgsProjectTranslator *projectTranslator)
Sets the project translator.
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.
void fetchCheckedLayers(const QgsLayerTreeNode *node, QList< QgsMapLayer * > &layers)