Skip to content
Permalink
Browse files

[bugfix] Crash on undo layout legend item on deleted item

Added test
  • Loading branch information
elpaso committed Jun 17, 2018
1 parent 583ccec commit c727d449e8590c7ff42bd3e3dd34216b3b5f2a72
Showing with 26 additions and 1 deletion.
  1. +2 −1 src/core/layertree/qgslayertreelayer.cpp
  2. +24 −0 tests/src/core/testqgslayertree.cpp
@@ -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"

0 comments on commit c727d44

Please sign in to comment.
You can’t perform that action at this time.