QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
|
Go to the documentation of this file.
27 , mCustomLayerOrder( other.mCustomLayerOrder )
28 , mHasCustomLayerOrder( other.mHasCustomLayerOrder )
33 void QgsLayerTree::init()
41 return _qgis_listQPointerToRaw( mCustomLayerOrder );
48 if ( newOrder == mCustomLayerOrder )
51 mCustomLayerOrder = newOrder;
54 if ( mHasCustomLayerOrder )
60 QList<QgsMapLayer *> layers;
73 layers.append( layer );
81 if ( mHasCustomLayerOrder )
93 return mHasCustomLayerOrder;
120 QDomDocument doc = parentElement.ownerDocument();
121 QDomElement elem = doc.createElement( QStringLiteral(
"layer-tree-group" ) );
126 node->writeXml( elem, context );
128 QDomElement customOrderElem = doc.createElement( QStringLiteral(
"custom-order" ) );
129 customOrderElem.setAttribute( QStringLiteral(
"enabled" ), mHasCustomLayerOrder ? 1 : 0 );
130 elem.appendChild( customOrderElem );
132 for (
QgsMapLayer *layer : std::as_const( mCustomLayerOrder ) )
138 QDomElement layerElem = doc.createElement( QStringLiteral(
"item" ) );
139 layerElem.appendChild( doc.createTextNode( layer->id() ) );
140 customOrderElem.appendChild( layerElem );
143 elem.appendChild( customOrderElem );
145 parentElement.appendChild( elem );
160 void QgsLayerTree::nodeAddedChildren(
QgsLayerTreeNode *node,
int indexFrom,
int indexTo )
165 QList<QgsMapLayer *> layers;
168 for (
int i = indexFrom; i <= indexTo; ++i )
179 layers << nodeL->layer();
183 for (
QgsMapLayer *layer : std::as_const( layers ) )
185 if ( !mCustomLayerOrder.contains( layer ) && layer )
186 mCustomLayerOrder.append( layer );
193 void QgsLayerTree::nodeRemovedChildren()
196 auto layer = layers.begin();
198 while ( layer != layers.end() )
201 layer = layers.erase( layer );
212 const bool emitSignal = _qgis_listRawToQPointer( layers ) == mCustomLayerOrder;
221 void QgsLayerTree::addMissingLayers()
223 bool changed =
false;
225 const QList< QgsLayerTreeLayer * > layers =
findLayers();
226 for (
const auto layer : layers )
228 if ( !mCustomLayerOrder.contains( layer->layer() ) &&
229 layer->layer() && layer->layer()->isSpatial() )
231 mCustomLayerOrder.append( layer->layer() );
239 if ( mHasCustomLayerOrder )
248 QDomElement customOrderElem = elem.firstChildElement( QStringLiteral(
"custom-order" ) );
249 if ( !customOrderElem.isNull() )
253 QDomElement itemElem = customOrderElem.firstChildElement( QStringLiteral(
"item" ) );
254 while ( !itemElem.isNull() )
256 order.append( itemElem.text() );
257 itemElem = itemElem.nextSiblingElement( QStringLiteral(
"item" ) );
QgsLayerTreeLayer * findLayer(QgsMapLayer *layer) const
Find layer node representing the map layer.
QList< QgsLayerTreeLayer * > findLayers() const
Find all layer nodes.
This class is a base class for nodes in a layer tree.
QList< QgsWeakMapLayerPointer > QgsWeakMapLayerPointerList
A list of weak pointers to QgsMapLayers.
void removedChildren(QgsLayerTreeNode *node, int indexFrom, int indexTo)
Emitted when one or more nodes has been removed from a node within the tree.
The class is used as a container of context for various read/write operations on other objects.
void removeAllChildren()
Remove all child nodes.
void writeCommonXml(QDomElement &element)
Write common XML elements.
QList< QgsMapLayer * > customLayerOrder() const
The order in which layers will be rendered on the canvas.
void readChildrenFromXml(QDomElement &element, const QgsReadWriteContext &context)
Read children from XML and append them to the group.
void setCustomLayerOrder(const QList< QgsMapLayer * > &customLayerOrder)
The order in which layers will be rendered on the canvas.
QList< QgsLayerTreeNode * > mChildren
list of children - node is responsible for their deletion
static QgsLayerTreeLayer * toLayer(QgsLayerTreeNode *node)
Cast node to a layer.
void setHasCustomLayerOrder(bool hasCustomLayerOrder)
Determines if the layer order should be derived from the layer tree or if a custom override order sha...
static QgsLayerTreeGroup * toGroup(QgsLayerTreeNode *node)
Cast node to a group.
void layerOrderChanged()
Emitted when the layer order has changed.
QList< QgsMapLayer * > layerOrderRespectingGroupLayers() const
Returns an ordered list of map layers in the group, ignoring any layers which are child layers of Qgs...
void customLayerOrderChanged()
Emitted when the custom layer order has changed.
Namespace with helper functions for layer tree operations.
void hasCustomLayerOrderChanged(bool hasCustomLayerOrder)
Emitted when the hasCustomLayerOrder flag changes.
QList< QgsMapLayer * > layerOrder() const
The order in which layers will be rendered on the canvas.
Layer tree node points to a map layer.
Layer tree group node serves as a container for layers and further groups.
void writeXml(QDomElement &parentElement, const QgsReadWriteContext &context) override
Write layer tree to XML.
QgsMapLayer * layer() const
Returns the map layer associated with this node.
void clear()
Clear any information from this layer tree.
static bool isLayer(const QgsLayerTreeNode *node)
Check whether the node is a valid layer node.
QgsLayerTree()
Create a new empty layer tree.
QgsLayerTree * clone() const override
Create a copy of the node. Returns new instance.
bool hasCustomLayerOrder() const
Determines if the layer order should be derived from the layer tree or if a custom override order sha...
Base class for all map layer types. This is the base class for all map layer types (vector,...
QList< QgsLayerTreeNode * > children()
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 readLayerOrderFromXml(const QDomElement &doc)
Load the layer order from an XML element.
virtual bool isSpatial() const
Returns true if the layer is considered a spatial layer, ie it has some form of geometry associated w...
static QgsLayerTree * readXml(QDomElement &element, const QgsReadWriteContext &context)
Load the layer tree from an XML element.
static bool isGroup(QgsLayerTreeNode *node)
Check whether the node is a valid group node.
void readCommonXml(QDomElement &element)
Read common XML elements.