@@ -151,14 +151,20 @@ void QgsLegend::handleCurrentItemChanged( QTreeWidgetItem* current, QTreeWidgetI
151151 emit currentLayerChanged ( layer );
152152}
153153
154+ int QgsLegend::addGroupToCurrentItem ( QString name, bool expand )
155+ {
156+ QTreeWidgetItem *parent = currentItem ();
157+ return addGroup ( name, expand, parent );
158+ }
159+
154160int QgsLegend::addGroup ( QString name, bool expand, QTreeWidgetItem* parent )
155161{
156162 if ( name.isEmpty () )
157163 name = tr ( " group" ); // some default name if none specified
158164
159165 QgsLegendGroup *parentGroup = dynamic_cast <QgsLegendGroup *>( parent );
160-
161166 QgsLegendGroup *group;
167+
162168 if ( parentGroup )
163169 group = new QgsLegendGroup ( parentGroup, name );
164170 else
@@ -577,7 +583,7 @@ void QgsLegend::handleRightClickEvent( QTreeWidgetItem* item, const QPoint& posi
577583 }
578584 }
579585
580- theMenu.addAction ( QgisApp::getThemeIcon ( " /folder_new.png" ), tr ( " &Add group" ), this , SLOT ( addGroup () ) );
586+ theMenu.addAction ( QgisApp::getThemeIcon ( " /folder_new.png" ), tr ( " &Add group" ), this , SLOT ( addGroupToCurrentItem () ) );
581587 theMenu.addAction ( QgisApp::getThemeIcon ( " /mActionExpandTree.png" ), tr ( " &Expand all" ), this , SLOT ( expandAll () ) );
582588 theMenu.addAction ( QgisApp::getThemeIcon ( " /mActionCollapseTree.png" ), tr ( " &Collapse all" ), this , SLOT ( collapseAll () ) );
583589
0 commit comments