Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[bugfix] Crash on undo layout legend item on deleted item
- Loading branch information
|
@@ -164,12 +164,13 @@ void QgsLayerTreeLayer::layerWillBeDeleted() |
|
|
{ |
|
|
Q_ASSERT( mRef ); |
|
|
|
|
|
emit layerWillBeUnloaded(); |
|
|
|
|
|
mLayerName = mRef->name(); |
|
|
// in theory we do not even need to do this - the weak ref should clear itself |
|
|
mRef.layer.clear(); |
|
|
// layerId stays in the reference |
|
|
|
|
|
emit layerWillBeUnloaded(); |
|
|
} |
|
|
|
|
|
|
|
|
|
@@ -47,6 +47,7 @@ class TestQgsLayerTree : public QObject |
|
|
void testLegendSymbolRuleBased(); |
|
|
void testResolveReferences(); |
|
|
void testEmbeddedGroup(); |
|
|
void testLayerDeleted(); |
|
|
|
|
|
private: |
|
|
|
|
@@ -588,6 +589,29 @@ void TestQgsLayerTree::testEmbeddedGroup() |
|
|
} |
|
|
} |
|
|
|
|
|
void TestQgsLayerTree::testLayerDeleted() |
|
|
{ |
|
|
//new memory layer |
|
|
QgsVectorLayer *vl = new QgsVectorLayer( QStringLiteral( "Point?field=col1:integer" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) ); |
|
|
QVERIFY( vl->isValid() ); |
|
|
|
|
|
QgsProject project; |
|
|
project.addMapLayer( vl ); |
|
|
|
|
|
QgsLayerTree root; |
|
|
QgsLayerTreeModel model( &root ); |
|
|
|
|
|
root.addLayer( vl ); |
|
|
QgsLayerTreeLayer *tl( root.findLayer( vl->id() ) ); |
|
|
QCOMPARE( tl->layer(), vl ); |
|
|
|
|
|
QCOMPARE( model.layerLegendNodes( tl ).count(), 1 ); |
|
|
|
|
|
project.removeMapLayer( vl ); |
|
|
|
|
|
QCOMPARE( model.layerLegendNodes( tl ).count(), 0 ); |
|
|
} |
|
|
|
|
|
|
|
|
QGSTEST_MAIN( TestQgsLayerTree ) |
|
|
#include "testqgslayertree.moc" |