Skip to content
Permalink
Browse files
When grouping layer tree nodes, insert new group at the same position
  • Loading branch information
wonder-sk committed Jul 16, 2014
1 parent 18a1c8a commit c05e5e2825ccf4b8f9a41f3abbfdb0bbfcd6a50a
Showing with 6 additions and 3 deletions.
  1. +6 −3 src/gui/layertree/qgslayertreeviewdefaultactions.cpp
@@ -260,21 +260,24 @@ void QgsLayerTreeViewDefaultActions::makeTopLevel()
void QgsLayerTreeViewDefaultActions::groupSelected()
{
QList<QgsLayerTreeNode*> nodes = mView->selectedNodes( true );
if ( nodes.count() < 2 )
if ( nodes.count() < 2 || ! QgsLayerTree::isGroup( nodes[0]->parent() ) )
return;

QgsLayerTreeGroup* parentGroup = mView->layerTreeModel()->rootGroup();
QgsLayerTreeGroup* parentGroup = QgsLayerTree::toGroup( nodes[0]->parent() );
int insertIdx = parentGroup->children().indexOf( nodes[0] );

QgsLayerTreeGroup* newGroup = new QgsLayerTreeGroup( uniqueGroupName( parentGroup ) );
foreach ( QgsLayerTreeNode* node, nodes )
newGroup->addChildNode( node->clone() );

parentGroup->addChildNode( newGroup );
parentGroup->insertChildNode( insertIdx, newGroup );

foreach ( QgsLayerTreeNode* node, nodes )
{
QgsLayerTreeGroup* group = qobject_cast<QgsLayerTreeGroup*>( node->parent() );
if ( group )
group->removeChildNode( node );
}

mView->setCurrentIndex( mView->layerTreeModel()->node2index( newGroup ) );
}

0 comments on commit c05e5e2

Please sign in to comment.