Index: python/gui/qgslegendinterface.sip =================================================================== --- python/gui/qgslegendinterface.sip (revision 15766) +++ python/gui/qgslegendinterface.sip (working copy) @@ -52,6 +52,10 @@ //! Add a new group //! @note added parent parameter in 1.7 virtual int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent =0 ) = 0; + + //! Add a new group + //! @note added parentIndex parameter in 1.7 + virtual int addGroup( QString name, bool expand, int parentIndex ) = 0; //! Remove group on index virtual void removeGroup( int groupIndex ) =0; Index: src/app/legend/qgsapplegendinterface.h =================================================================== --- src/app/legend/qgsapplegendinterface.h (revision 15766) +++ src/app/legend/qgsapplegendinterface.h (working copy) @@ -66,6 +66,9 @@ //! Add a new group int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent = 0 ); + + //! Add a new group at a specified index + int addGroup( QString name, bool expand, int groupIndex ); //! Remove all groups with the given name void removeGroup( int groupIndex ); Index: src/app/legend/qgslegend.cpp =================================================================== --- src/app/legend/qgslegend.cpp (revision 15766) +++ src/app/legend/qgslegend.cpp (working copy) @@ -159,7 +159,8 @@ int QgsLegend::addGroup( QString name, bool expand, QTreeWidgetItem* parent ) { - if ( name.isEmpty() ) + bool nameEmpty = name.isEmpty(); + if ( nameEmpty ) name = tr( "group" ); // some default name if none specified QgsLegendGroup *parentGroup = dynamic_cast( parent ); @@ -173,10 +174,18 @@ QModelIndex groupIndex = indexFromItem( group ); setExpanded( groupIndex, expand ); setCurrentItem( group ); - openEditor(); + if (nameEmpty) + openEditor(); + return groupIndex.row(); } +int QgsLegend::addGroup( QString name, bool expand, int groupIndex ) +{ + QgsLegendGroup * lg = dynamic_cast( topLevelItem( groupIndex ) ); + return addGroup(name, expand, lg); +} + void QgsLegend::removeAll() { clear(); Index: src/app/legend/qgslegend.h =================================================================== --- src/app/legend/qgslegend.h (revision 15766) +++ src/app/legend/qgslegend.h (working copy) @@ -236,6 +236,15 @@ * @return index of inserted group */ int addGroup( QString name = QString(), bool expand = true, QTreeWidgetItem* parent = 0 ); + + /*! + * Slot called when user wishes to add a new empty layer group to the legend. + * All parameter are mandatory to be used to programatically nest a new group + * @param name name of the new group + * @param expand expand the group + * @return index of inserted group + */ + int addGroup( QString name, bool expand, int parentIndex ); /*! * Removes all groups with the given name. Index: src/app/legend/qgsapplegendinterface.cpp =================================================================== --- src/app/legend/qgsapplegendinterface.cpp (revision 15766) +++ src/app/legend/qgsapplegendinterface.cpp (working copy) @@ -37,6 +37,11 @@ return mLegend->addGroup( name, expand, parent ); } +int QgsAppLegendInterface::addGroup( QString name, bool expand, int parentIndex ) +{ + return mLegend->addGroup( name, expand, parentIndex ); +} + void QgsAppLegendInterface::removeGroup( int groupIndex ) { mLegend->removeGroup( groupIndex ); Index: src/gui/qgslegendinterface.h =================================================================== --- src/gui/qgslegendinterface.h (revision 15766) +++ src/gui/qgslegendinterface.h (working copy) @@ -83,6 +83,10 @@ //! Add a new group //! a parent group can be given to nest the new group in it virtual int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent = 0 ) = 0; + + //! Add a new group + //! a parent group index has to be given to nest the new group in it + virtual int addGroup( QString name, bool expand, int parentIndex ) = 0; //! Remove group on index virtual void removeGroup( int groupIndex ) = 0;