File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -260,21 +260,24 @@ void QgsLayerTreeViewDefaultActions::makeTopLevel()
260
260
void QgsLayerTreeViewDefaultActions::groupSelected ()
261
261
{
262
262
QList<QgsLayerTreeNode*> nodes = mView ->selectedNodes ( true );
263
- if ( nodes.count () < 2 )
263
+ if ( nodes.count () < 2 || ! QgsLayerTree::isGroup ( nodes[ 0 ]-> parent () ) )
264
264
return ;
265
265
266
- QgsLayerTreeGroup* parentGroup = mView ->layerTreeModel ()->rootGroup ();
266
+ QgsLayerTreeGroup* parentGroup = QgsLayerTree::toGroup ( nodes[0 ]->parent () );
267
+ int insertIdx = parentGroup->children ().indexOf ( nodes[0 ] );
267
268
268
269
QgsLayerTreeGroup* newGroup = new QgsLayerTreeGroup ( uniqueGroupName ( parentGroup ) );
269
270
foreach ( QgsLayerTreeNode* node, nodes )
270
271
newGroup->addChildNode ( node->clone () );
271
272
272
- parentGroup->addChildNode ( newGroup );
273
+ parentGroup->insertChildNode ( insertIdx, newGroup );
273
274
274
275
foreach ( QgsLayerTreeNode* node, nodes )
275
276
{
276
277
QgsLayerTreeGroup* group = qobject_cast<QgsLayerTreeGroup*>( node->parent () );
277
278
if ( group )
278
279
group->removeChildNode ( node );
279
280
}
281
+
282
+ mView ->setCurrentIndex ( mView ->layerTreeModel ()->node2index ( newGroup ) );
280
283
}
You can’t perform that action at this time.
0 commit comments