Skip to content

Commit e39abc5

Browse files
authored
Merge pull request #7240 from elpaso/bugfix-19155-layout-legend-undo-crash
[bugfix] Crash on undo layout legend item on deleted item
2 parents a17b77b + c727d44 commit e39abc5

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/core/layertree/qgslayertreelayer.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,13 @@ void QgsLayerTreeLayer::layerWillBeDeleted()
164164
{
165165
Q_ASSERT( mRef );
166166

167+
emit layerWillBeUnloaded();
168+
167169
mLayerName = mRef->name();
168170
// in theory we do not even need to do this - the weak ref should clear itself
169171
mRef.layer.clear();
170172
// layerId stays in the reference
171173

172-
emit layerWillBeUnloaded();
173174
}
174175

175176

tests/src/core/testqgslayertree.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class TestQgsLayerTree : public QObject
4747
void testLegendSymbolRuleBased();
4848
void testResolveReferences();
4949
void testEmbeddedGroup();
50+
void testLayerDeleted();
5051

5152
private:
5253

@@ -588,6 +589,29 @@ void TestQgsLayerTree::testEmbeddedGroup()
588589
}
589590
}
590591

592+
void TestQgsLayerTree::testLayerDeleted()
593+
{
594+
//new memory layer
595+
QgsVectorLayer *vl = new QgsVectorLayer( QStringLiteral( "Point?field=col1:integer" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) );
596+
QVERIFY( vl->isValid() );
597+
598+
QgsProject project;
599+
project.addMapLayer( vl );
600+
601+
QgsLayerTree root;
602+
QgsLayerTreeModel model( &root );
603+
604+
root.addLayer( vl );
605+
QgsLayerTreeLayer *tl( root.findLayer( vl->id() ) );
606+
QCOMPARE( tl->layer(), vl );
607+
608+
QCOMPARE( model.layerLegendNodes( tl ).count(), 1 );
609+
610+
project.removeMapLayer( vl );
611+
612+
QCOMPARE( model.layerLegendNodes( tl ).count(), 0 );
613+
}
614+
591615

592616
QGSTEST_MAIN( TestQgsLayerTree )
593617
#include "testqgslayertree.moc"

0 commit comments

Comments
 (0)