28 , mCustomLayerOrder( other.mCustomLayerOrder )
29 , mHasCustomLayerOrder( other.mHasCustomLayerOrder )
37 return _qgis_listQPointerToRaw( mCustomLayerOrder );
44 if ( newOrder == mCustomLayerOrder )
47 mCustomLayerOrder = newOrder;
50 if ( mHasCustomLayerOrder )
56 QList<QgsMapLayer *> layers;
69 layers.append( layer );
77 if ( mHasCustomLayerOrder )
83 QList<QgsMapLayer *> layers;
84 const QList< QgsLayerTreeLayer * > foundLayers =
findLayers();
85 for (
const auto &treeLayer : foundLayers )
92 layers.append( layer );
100 return mHasCustomLayerOrder;
127 QDomDocument doc = parentElement.ownerDocument();
128 QDomElement elem = doc.createElement( QStringLiteral(
"layer-tree-group" ) );
133 node->writeXml( elem, context );
135 QDomElement customOrderElem = doc.createElement( QStringLiteral(
"custom-order" ) );
136 customOrderElem.setAttribute( QStringLiteral(
"enabled" ), mHasCustomLayerOrder ? 1 : 0 );
137 elem.appendChild( customOrderElem );
139 for (
QgsMapLayer *layer : qgis::as_const( mCustomLayerOrder ) )
145 QDomElement layerElem = doc.createElement( QStringLiteral(
"item" ) );
146 layerElem.appendChild( doc.createTextNode( layer->id() ) );
147 customOrderElem.appendChild( layerElem );
150 elem.appendChild( customOrderElem );
152 parentElement.appendChild( elem );
167 void QgsLayerTree::nodeAddedChildren(
QgsLayerTreeNode *node,
int indexFrom,
int indexTo )
172 QList<QgsMapLayer *> layers;
175 for (
int i = indexFrom; i <= indexTo; ++i )
186 layers << nodeL->layer();
190 for (
QgsMapLayer *layer : qgis::as_const( layers ) )
192 if ( !mCustomLayerOrder.contains( layer ) && layer )
193 mCustomLayerOrder.append( layer );
200 void QgsLayerTree::nodeRemovedChildren()
203 auto layer = layers.begin();
205 while ( layer != layers.end() )
208 layer = layers.erase( layer );
219 const bool emitSignal = _qgis_listRawToQPointer( layers ) == mCustomLayerOrder;
228 void QgsLayerTree::addMissingLayers()
230 bool changed =
false;
232 const QList< QgsLayerTreeLayer * > layers =
findLayers();
233 for (
const auto layer : layers )
235 if ( !mCustomLayerOrder.contains( layer->layer() ) &&
236 layer->layer() && layer->layer()->isSpatial() )
238 mCustomLayerOrder.append( layer->layer() );
246 if ( mHasCustomLayerOrder )
255 QDomElement customOrderElem = elem.firstChildElement( QStringLiteral(
"custom-order" ) );
256 if ( !customOrderElem.isNull() )
260 QDomElement itemElem = customOrderElem.firstChildElement( QStringLiteral(
"item" ) );
261 while ( !itemElem.isNull() )
263 order.append( itemElem.text() );
264 itemElem = itemElem.nextSiblingElement( QStringLiteral(
"item" ) );