Index: python/gui/qgslegendinterface.sip =================================================================== --- python/gui/qgslegendinterface.sip (revision 15560) +++ python/gui/qgslegendinterface.sip (working copy) @@ -50,7 +50,8 @@ public slots: //! Add a new group - virtual int addGroup( QString name, bool expand = true ) =0; + //! @note added parent parameter in 1.7 + virtual int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent =0 ) =0; //! Remove group on index virtual void removeGroup( int groupIndex ) =0; Index: src/app/legend/qgsapplegendinterface.h =================================================================== --- src/app/legend/qgsapplegendinterface.h (revision 15560) +++ src/app/legend/qgsapplegendinterface.h (working copy) @@ -65,7 +65,7 @@ public slots: //! Add a new group - int addGroup( QString name, bool expand = true ); + int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent = 0 ); //! Remove all groups with the given name void removeGroup( int groupIndex ); Index: src/app/legend/qgslegend.cpp =================================================================== --- src/app/legend/qgslegend.cpp (revision 15560) +++ src/app/legend/qgslegend.cpp (working copy) @@ -151,16 +151,22 @@ emit currentLayerChanged( layer ); } -int QgsLegend::addGroup( QString name, bool expand ) +int QgsLegend::addGroupToCurrentItem( QString name, bool expand ) { + 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 + + QgsLegendGroup *parentGroup = dynamic_cast( parent ); - QgsLegendGroup *parent = dynamic_cast( currentItem() ); - QgsLegendGroup *group; - if ( parent ) - group = new QgsLegendGroup( parent, name ); + if ( parentGroup ) + group = new QgsLegendGroup( parentGroup, name ); else group = new QgsLegendGroup( this, name ); @@ -577,7 +583,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 15560) +++ src/app/legend/qgslegend.h (working copy) @@ -213,17 +213,27 @@ * @return void */ void selectAll( bool select ); - + /*! * 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 addGroup( QString name = QString(), bool expand = true ); + 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 ); + + /*! * Removes all groups with the given name. * @param name name of the groups to remove * @return void Index: src/app/legend/qgsapplegendinterface.cpp =================================================================== --- src/app/legend/qgsapplegendinterface.cpp (revision 15560) +++ src/app/legend/qgsapplegendinterface.cpp (working copy) @@ -21,6 +21,7 @@ #include "qgslegendlayer.h" #include "qgsmaplayer.h" + QgsAppLegendInterface::QgsAppLegendInterface( QgsLegend * legend ) : mLegend( legend ) { @@ -31,9 +32,9 @@ { } -int QgsAppLegendInterface::addGroup( QString name, bool expand ) +int QgsAppLegendInterface::addGroup( QString name, bool expand, QTreeWidgetItem* parent ) { - return mLegend->addGroup( name, expand ); + return mLegend->addGroup( name, expand, parent ); } void QgsAppLegendInterface::removeGroup( int groupIndex ) Index: src/gui/qgslegendinterface.h =================================================================== --- src/gui/qgslegendinterface.h (revision 15560) +++ src/gui/qgslegendinterface.h (working copy) @@ -23,6 +23,7 @@ #include class QgsMapLayer; +class QTreeWidgetItem; //Information about relationship between groups and layers //key: group name (or null strings for single layers without groups) @@ -80,7 +81,8 @@ public slots: //! Add a new group - virtual int addGroup( QString name, bool expand = true ) = 0; + //! forceAtEnd forces the new group to be created at the end of the legend + virtual int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent = 0 ) = 0; //! Remove group on index virtual void removeGroup( int groupIndex ) = 0;