Skip to content
Permalink
Browse files

Fix potential crash when adding a group

  • Loading branch information
wonder-sk committed Sep 5, 2014
1 parent 86b4fcc commit 0a7ddfa17049712f88f34d5bfdaebbefe0acc523
Showing with 14 additions and 2 deletions.
  1. +7 −1 src/gui/layertree/qgslayertreeview.cpp
  2. +7 −1 src/gui/layertree/qgslayertreeviewdefaultactions.cpp
@@ -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;
}
@@ -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 ) );
@@ -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 );

0 comments on commit 0a7ddfa

Please sign in to comment.
You can’t perform that action at this time.