QGIS API Documentation
3.14.0-Pi (9f7028fd23)
|
Go to the documentation of this file.
21 #include <QDomElement>
22 #include <QStringList>
34 , mNodeType( other.mNodeType )
35 , mChecked( other.mChecked )
36 , mExpanded( other.mExpanded )
37 , mProperties( other.mProperties )
39 QList<QgsLayerTreeNode *> clonedChildren;
42 clonedChildren << child->clone();
54 if ( element.tagName() == QLatin1String(
"layer-tree-group" ) )
56 else if ( element.tagName() == QLatin1String(
"layer-tree-layer" ) )
116 if ( !child->isItemVisibilityCheckedRecursive() )
130 if ( !child->isItemVisibilityUncheckedRecursive() )
143 layers << nodeLayer->
layer();
146 const auto constChildren = node->
children();
153 QList<QgsMapLayer *> layers;
215 QDomDocument doc( element.ownerDocument() );
221 if ( nodes.isEmpty() )
224 const auto constNodes = nodes;
227 Q_ASSERT( !node->mParent );
228 node->mParent =
this;
231 if ( index < 0 || index >=
mChildren.count() )
234 int indexTo = index + nodes.count() - 1;
236 for (
int i = 0; i < nodes.count(); ++i )
256 if ( from < 0 || count <= 0 )
259 int to = from + count - 1;
263 while ( --count >= 0 )
void setPathResolver(const QgsPathResolver &resolver)
Sets up path resolver for conversion between relative and absolute paths.
void setItemVisibilityChecked(bool checked)
Check or uncheck a node (independently of its ancestors or children)
void removedChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes has been removed from a node within the tree.
void writeCommonXml(QDomElement &element)
Write common XML elements.
virtual void resolveReferences(const QgsProject *project, bool looseMatching=false)=0
Turn textual references to layers into map layer object from project.
QgsLayerTreeNode(NodeType t, bool checked=true)
Constructor.
void expandedChanged(QgsLayerTreeNode *node, bool expanded)
Emitted when the collapsed/expanded state of a node within the tree has been changed.
QgsPathResolver pathResolver() const
Returns path resolver object with considering whether the project uses absolute or relative paths and...
void insertChildrenPrivate(int index, QList< QgsLayerTreeNode * > nodes)
Low-level insertion of children to the node. The children must not have any parent yet!
~QgsLayerTreeNode() override
QList< QgsLayerTreeNode * > mChildren
list of children - node is responsible for their deletion
QgsLayerTreeNode * mParent
pointer to the parent node - nullptr in case of root node
void readXml(const QDomNode &parentNode, const QString &keyStartsWith=QString())
Read store contents from an XML 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 fetchCheckedLayers(const QgsLayerTreeNode *node, QList< QgsMapLayer * > &layers)
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
void nameChanged(QgsLayerTreeNode *node, QString name)
Emitted when the name of the node is changed.
void setProjectTranslator(QgsProjectTranslator *projectTranslator)
Sets the project translator.
void setItemVisibilityCheckedParentRecursive(bool checked)
Check or uncheck a node and all its parents.
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.
void setValue(const QString &key, const QVariant &value)
Add an entry to the store with the specified key.
int depth() const
Returns the depth of this node, i.e.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
bool isExpanded() const
Returns whether the node should be shown as expanded or collapsed in GUI.
static QgsLayerTreeNode * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer tree from XML.
void remove(const QString &key)
Removes a key (entry) from the store.
QgsObjectCustomProperties mProperties
custom properties attached to the node
NodeType
Enumeration of possible tree node types.
QStringList customProperties() const
Returns list of keys stored in custom properties.
void willAddChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes will be added to a node within the tree.
virtual void setItemVisibilityCheckedRecursive(bool checked)
Check or uncheck a node and all its children (taking into account exclusion rules)
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 ...
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
bool contains(const QString &key) const
Returns true if the properties contains a key with the specified name.
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.
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.
QStringList keys() const
Returns a list of all stored keys.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for the given key.
QList< QgsLayerTreeNode * > children()
Gets list of children of the node. Children are owned by the parent.
bool takeChild(QgsLayerTreeNode *node)
Remove a child from a node.
bool mExpanded
whether the node should be shown in GUI as expanded
void addedChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes have been added to a node within the tree.
QgsLayerTreeNode * parent()
Gets pointer to the parent. If parent is nullptr, the node is a root node.
void willRemoveChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes will be removed from a node within the tree.
bool isVisible() const
Returns whether a node is really visible (ie checked and all its ancestors checked as well)
void setExpanded(bool expanded)
Sets whether the node should be shown as expanded or collapsed in GUI.
void removeCustomProperty(const QString &key)
Remove a custom property from layer. Properties are stored in a map and saved in project file.
void removeChildrenPrivate(int from, int count, bool destroy=true)
Low-level removal of children from the node.
static QgsLayerTreeLayer * readXml(QDomElement &element, const QgsReadWriteContext &context)
Read layer node from XML.
QList< QgsMapLayer * > checkedLayers() const
Returns a list of any checked layers which belong to this node or its children.
void writeXml(QDomNode &parentNode, QDomDocument &doc) const
Writes the store contents to an XML node.
void visibilityChanged(QgsLayerTreeNode *node)
Emitted when check state of a node within the tree has been changed.
void readCommonXml(QDomElement &element)
Read common XML elements.