Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Don't crash when findLayer is called with a nullptr
- Loading branch information
|
@@ -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 |
|
|