Skip to content
Permalink
Browse files

Don't crash when findLayer is called with a nullptr

  • Loading branch information
nyalldawson committed Jun 22, 2018
1 parent 41d6b9d commit cd495fbb801e5ed4bade61c7e71d33c9f4416576
Showing with 27 additions and 0 deletions.
  1. +3 −0 src/core/layertree/qgslayertreegroup.cpp
  2. +24 −0 tests/src/core/testqgslayertree.cpp
@@ -193,6 +193,9 @@ void QgsLayerTreeGroup::removeAllChildren()

QgsLayerTreeLayer *QgsLayerTreeGroup::findLayer( QgsMapLayer *layer ) const
{
if ( !layer )
return nullptr;

return findLayer( layer->id() );
}

@@ -47,6 +47,7 @@ class TestQgsLayerTree : public QObject
void testLegendSymbolRuleBased();
void testResolveReferences();
void testEmbeddedGroup();
void testFindLayer();
void testLayerDeleted();

private:
@@ -589,6 +590,29 @@ void TestQgsLayerTree::testEmbeddedGroup()
}
}

void TestQgsLayerTree::testFindLayer()
{
//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 );

QVERIFY( !root.findLayer( vl->id() ) );
QVERIFY( !root.findLayer( nullptr ) );

root.addLayer( vl );

QCOMPARE( root.findLayer( vl->id() )->layer(), vl );
QCOMPARE( root.findLayer( vl )->layer(), vl );
QVERIFY( !root.findLayer( QStringLiteral( "xxx" ) ) );
QVERIFY( !root.findLayer( nullptr ) );
}

void TestQgsLayerTree::testLayerDeleted()
{
//new memory layer

0 comments on commit cd495fb

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