Skip to content

Commit

Permalink
Fix potential crash when adding a group
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Sep 5, 2014
1 parent 86b4fcc commit 0a7ddfa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/gui/layertree/qgslayertreeview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,13 @@ QgsLayerTreeGroup* QgsLayerTreeView::currentGroupNode() const
if ( QgsLayerTree::isGroup( parent ) )
return QgsLayerTree::toGroup( node );
}
// TODO: also handle if symbology is selected?

if ( QgsLayerTreeModelLegendNode* legendNode = layerTreeModel()->index2legendNode( selectionModel()->currentIndex() ) )
{
QgsLayerTreeLayer* parent = legendNode->parent();
if ( QgsLayerTree::isGroup( parent->parent() ) )
return QgsLayerTree::toGroup( parent->parent() );
}

return 0;
}
Expand Down
8 changes: 7 additions & 1 deletion src/gui/layertree/qgslayertreeviewdefaultactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ QAction* QgsLayerTreeViewDefaultActions::actionGroupSelected( QObject* parent )
void QgsLayerTreeViewDefaultActions::addGroup()
{
QgsLayerTreeGroup* group = mView->currentGroupNode();
if ( !group )
group = mView->layerTreeModel()->rootGroup();

QgsLayerTreeGroup* newGroup = group->addGroup( uniqueGroupName( group ) );
mView->edit( mView->layerTreeModel()->node2index( newGroup ) );
Expand Down Expand Up @@ -165,8 +167,12 @@ void QgsLayerTreeViewDefaultActions::zoomToLayer( QgsMapCanvas* canvas )

void QgsLayerTreeViewDefaultActions::zoomToGroup( QgsMapCanvas* canvas )
{
QgsLayerTreeGroup* groupNode = mView->currentGroupNode();
if ( !groupNode )
return;

QList<QgsMapLayer*> layers;
foreach ( QString layerId, mView->currentGroupNode()->findLayerIds() )
foreach ( QString layerId, groupNode->findLayerIds() )
layers << QgsMapLayerRegistry::instance()->mapLayer( layerId );

zoomToLayers( canvas, layers );
Expand Down

0 comments on commit 0a7ddfa

Please sign in to comment.