25
25
QgsLayerTreeRegistryBridge::QgsLayerTreeRegistryBridge ( QgsLayerTreeGroup *root, QObject *parent )
26
26
: QObject( parent )
27
27
, mRoot( root )
28
+ , mRegistryRemovingLayers( false )
28
29
, mEnabled( true )
29
30
, mNewLayersVisible( true )
30
31
, mInsertionPointGroup( root )
@@ -74,12 +75,18 @@ void QgsLayerTreeRegistryBridge::layersWillBeRemoved( QStringList layerIds )
74
75
if ( !mEnabled )
75
76
return ;
76
77
78
+ // when we start removing child nodes, the bridge would try to remove those layers from
79
+ // the registry _again_ in groupRemovedChildren() - this prevents it
80
+ mRegistryRemovingLayers = true ;
81
+
77
82
foreach ( QString layerId, layerIds )
78
83
{
79
84
QgsLayerTreeLayer* nodeLayer = mRoot ->findLayer ( layerId );
80
85
if ( nodeLayer )
81
86
qobject_cast<QgsLayerTreeGroup*>( nodeLayer->parent () )->removeChildNode ( nodeLayer );
82
87
}
88
+
89
+ mRegistryRemovingLayers = false ;
83
90
}
84
91
85
92
@@ -101,6 +108,9 @@ static void _collectLayerIdsInGroup( QgsLayerTreeGroup* group, int indexFrom, in
101
108
102
109
void QgsLayerTreeRegistryBridge::groupWillRemoveChildren ( QgsLayerTreeNode* node, int indexFrom, int indexTo )
103
110
{
111
+ if ( mRegistryRemovingLayers )
112
+ return ; // do not try to remove those layers again
113
+
104
114
Q_ASSERT ( mLayerIdsForRemoval .isEmpty () );
105
115
106
116
Q_ASSERT ( QgsLayerTree::isGroup ( node ) );
@@ -111,6 +121,9 @@ void QgsLayerTreeRegistryBridge::groupWillRemoveChildren( QgsLayerTreeNode* node
111
121
112
122
void QgsLayerTreeRegistryBridge::groupRemovedChildren ()
113
123
{
124
+ if ( mRegistryRemovingLayers )
125
+ return ; // do not try to remove those layers again
126
+
114
127
// remove only those that really do not exist in the tree
115
128
// (ignores layers that were dragged'n'dropped: 1. drop new 2. remove old)
116
129
QStringList toRemove;
0 commit comments