Skip to content

Commit 3b2d717

Browse files
committed
legend interface: guard layer dereferences (fixes #13899)
1 parent c14352f commit 3b2d717

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/app/legend/qgsapplegendinterface.cpp

+22-4
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,11 @@ void QgsAppLegendInterface::removeGroup( int groupIndex )
7575
parentGroup->removeChildNode( group );
7676
}
7777

78-
void QgsAppLegendInterface::moveLayer( QgsMapLayer * ml, int groupIndex )
78+
void QgsAppLegendInterface::moveLayer( QgsMapLayer *ml, int groupIndex )
7979
{
80+
if ( !ml )
81+
return;
82+
8083
QgsLayerTreeGroup* group = groupIndexToNode( groupIndex );
8184
if ( !group )
8285
return;
@@ -155,14 +158,20 @@ int QgsAppLegendInterface::groupNodeToIndex( QgsLayerTreeGroup* group )
155158
return _groupNodeToIndex( group, mLayerTreeView->layerTreeModel()->rootGroup(), currentIndex );
156159
}
157160

158-
void QgsAppLegendInterface::setLayerVisible( QgsMapLayer * ml, bool visible )
161+
void QgsAppLegendInterface::setLayerVisible( QgsMapLayer *ml, bool visible )
159162
{
163+
if ( !ml )
164+
return;
165+
160166
if ( QgsLayerTreeLayer* nodeLayer = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( ml->id() ) )
161167
nodeLayer->setVisible( visible ? Qt::Checked : Qt::Unchecked );
162168
}
163169

164170
void QgsAppLegendInterface::setLayerExpanded( QgsMapLayer * ml, bool expand )
165171
{
172+
if ( !ml )
173+
return;
174+
166175
if ( QgsLayerTreeLayer* nodeLayer = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( ml->id() ) )
167176
setExpanded( nodeLayer, expand );
168177
}
@@ -247,17 +256,23 @@ bool QgsAppLegendInterface::isGroupVisible( int groupIndex )
247256
return false;
248257
}
249258

250-
bool QgsAppLegendInterface::isLayerExpanded( QgsMapLayer * ml )
259+
bool QgsAppLegendInterface::isLayerExpanded( QgsMapLayer *ml )
251260
{
261+
if ( !ml )
262+
return false;
263+
252264
if ( QgsLayerTreeLayer* nodeLayer = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( ml->id() ) )
253265
return nodeLayer->isExpanded();
254266

255267
return false;
256268
}
257269

258270

259-
bool QgsAppLegendInterface::isLayerVisible( QgsMapLayer * ml )
271+
bool QgsAppLegendInterface::isLayerVisible( QgsMapLayer *ml )
260272
{
273+
if ( !ml )
274+
return false;
275+
261276
if ( QgsLayerTreeLayer* nodeLayer = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( ml->id() ) )
262277
return nodeLayer->isVisible() == Qt::Checked;
263278

@@ -283,6 +298,9 @@ QList< QgsMapLayer * > QgsAppLegendInterface::layers() const
283298

284299
void QgsAppLegendInterface::refreshLayerSymbology( QgsMapLayer *ml )
285300
{
301+
if ( !ml )
302+
return;
303+
286304
mLayerTreeView->refreshLayerSymbology( ml->id() );
287305
}
288306

0 commit comments

Comments
 (0)