Index: src/app/legend/qgslegend.cpp =================================================================== --- src/app/legend/qgslegend.cpp (revision 15765) +++ src/app/legend/qgslegend.cpp (working copy) @@ -151,14 +151,22 @@ emit currentLayerChanged( layer ); } +int QgsLegend::addGroupToCurrentItem( QString name, bool expand ) + { + QgsDebugMsg( "calledsdsss." ); + QTreeWidgetItem *parent = currentItem(); + addGroup(name, expand, parent); + +} + int QgsLegend::addGroup( QString name, bool expand, QTreeWidgetItem* parent ) { - if ( name.isEmpty() ) - name = tr( "group" ); // some default name if none specified - + if ( name.isEmpty() ) + name = tr( "group" ); // some default name if none specified + QgsLegendGroup *parentGroup = dynamic_cast( parent ); + QgsLegendGroup *group; - QgsLegendGroup *group; if ( parentGroup ) group = new QgsLegendGroup( parentGroup, name ); else @@ -577,7 +585,7 @@ } } - theMenu.addAction( QgisApp::getThemeIcon( "/folder_new.png" ), tr( "&Add group" ), this, SLOT( addGroup() ) ); + theMenu.addAction( QgisApp::getThemeIcon( "/folder_new.png" ), tr( "&Add group" ), this, SLOT( addGroupToCurrentItem() ) ); theMenu.addAction( QgisApp::getThemeIcon( "/mActionExpandTree.png" ), tr( "&Expand all" ), this, SLOT( expandAll() ) ); theMenu.addAction( QgisApp::getThemeIcon( "/mActionCollapseTree.png" ), tr( "&Collapse all" ), this, SLOT( collapseAll() ) ); Index: src/app/legend/qgslegend.h =================================================================== --- src/app/legend/qgslegend.h (revision 15765) +++ src/app/legend/qgslegend.h (working copy) @@ -220,11 +220,21 @@ /*! * Slot called when user wishes to add a new empty layer group to the legend. + * If a the legend has a currentItem() then the new group will be nested into it * The user will be prompted for the name of the newly added group. * @param name name of the new group * @param expand expand the group * @return void */ + int addGroupToCurrentItem( QString name = QString(), bool expand = true); + + /*! + * Slot called when user wishes to add a new empty layer group to the legend. + * The user will be prompted for the name of the newly added group. + * @param name name of the new group + * @param expand expand the group + * @return void + */ int addGroup( QString name = QString(), bool expand = true, QTreeWidgetItem* parent = 0 ); /*!