Skip to content

Commit

Permalink
[bugfix] Crash on undo layout legend item on deleted item
Browse files Browse the repository at this point in the history
Added test
  • Loading branch information
elpaso committed Jun 17, 2018
1 parent 583ccec commit c727d44
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/layertree/qgslayertreelayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand Down
24 changes: 24 additions & 0 deletions tests/src/core/testqgslayertree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class TestQgsLayerTree : public QObject
void testLegendSymbolRuleBased();
void testResolveReferences();
void testEmbeddedGroup();
void testLayerDeleted();

private:

Expand Down Expand Up @@ -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.