Skip to content

Commit

Permalink
legend interface: guard layer dereferences (fixes #13899)
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Nov 29, 2015
1 parent c14352f commit 3b2d717
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/app/legend/qgsapplegendinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ void QgsAppLegendInterface::removeGroup( int groupIndex )
parentGroup->removeChildNode( group );
}

void QgsAppLegendInterface::moveLayer( QgsMapLayer * ml, int groupIndex )
void QgsAppLegendInterface::moveLayer( QgsMapLayer *ml, int groupIndex )
{
if ( !ml )
return;

QgsLayerTreeGroup* group = groupIndexToNode( groupIndex );
if ( !group )
return;
Expand Down Expand Up @@ -155,14 +158,20 @@ int QgsAppLegendInterface::groupNodeToIndex( QgsLayerTreeGroup* group )
return _groupNodeToIndex( group, mLayerTreeView->layerTreeModel()->rootGroup(), currentIndex );
}

void QgsAppLegendInterface::setLayerVisible( QgsMapLayer * ml, bool visible )
void QgsAppLegendInterface::setLayerVisible( QgsMapLayer *ml, bool visible )
{
if ( !ml )
return;

if ( QgsLayerTreeLayer* nodeLayer = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( ml->id() ) )
nodeLayer->setVisible( visible ? Qt::Checked : Qt::Unchecked );
}

void QgsAppLegendInterface::setLayerExpanded( QgsMapLayer * ml, bool expand )
{
if ( !ml )
return;

if ( QgsLayerTreeLayer* nodeLayer = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( ml->id() ) )
setExpanded( nodeLayer, expand );
}
Expand Down Expand Up @@ -247,17 +256,23 @@ bool QgsAppLegendInterface::isGroupVisible( int groupIndex )
return false;
}

bool QgsAppLegendInterface::isLayerExpanded( QgsMapLayer * ml )
bool QgsAppLegendInterface::isLayerExpanded( QgsMapLayer *ml )
{
if ( !ml )
return false;

if ( QgsLayerTreeLayer* nodeLayer = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( ml->id() ) )
return nodeLayer->isExpanded();

return false;
}


bool QgsAppLegendInterface::isLayerVisible( QgsMapLayer * ml )
bool QgsAppLegendInterface::isLayerVisible( QgsMapLayer *ml )
{
if ( !ml )
return false;

if ( QgsLayerTreeLayer* nodeLayer = mLayerTreeView->layerTreeModel()->rootGroup()->findLayer( ml->id() ) )
return nodeLayer->isVisible() == Qt::Checked;

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

void QgsAppLegendInterface::refreshLayerSymbology( QgsMapLayer *ml )
{
if ( !ml )
return;

mLayerTreeView->refreshLayerSymbology( ml->id() );
}

Expand Down

0 comments on commit 3b2d717

Please sign in to comment.