Skip to content

Commit

Permalink
When grouping layer tree nodes, insert new group at the same position
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Jul 16, 2014
1 parent 18a1c8a commit c05e5e2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/gui/layertree/qgslayertreeviewdefaultactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.