Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Prevent crash when model is not set
  • Loading branch information
elpaso committed May 10, 2017
1 parent 8309c3c commit 6649825
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/gui/layertree/qgslayertreeview.cpp
Expand Up @@ -253,18 +253,22 @@ void QgsLayerTreeView::updateExpandedStateFromNode( QgsLayerTreeNode* node )

QgsMapLayer* QgsLayerTreeView::layerForIndex( const QModelIndex& index ) const
{
QgsLayerTreeNode* node = layerTreeModel()->index2node( index );
if ( node )
// Check if model has been set and index is valid
if ( layerTreeModel() && index.isValid( ) )
{
if ( QgsLayerTree::isLayer( node ) )
return QgsLayerTree::toLayer( node )->layer();
}
else
{
// possibly a legend node
QgsLayerTreeModelLegendNode* legendNode = layerTreeModel()->index2legendNode( index );
if ( legendNode )
return legendNode->layerNode()->layer();
QgsLayerTreeNode* node = layerTreeModel()->index2node( index );
if ( node )
{
if ( QgsLayerTree::isLayer( node ) )
return QgsLayerTree::toLayer( node )->layer();
}
else
{
// possibly a legend node
QgsLayerTreeModelLegendNode* legendNode = layerTreeModel()->index2legendNode( index );
if ( legendNode )
return legendNode->layerNode()->layer();
}
}

return nullptr;
Expand Down

0 comments on commit 6649825

Please sign in to comment.