diff --git a/src/app/legend/qgslegend.cpp b/src/app/legend/qgslegend.cpp index 630e1cdeeb0..2dc6f11ecac 100644 --- a/src/app/legend/qgslegend.cpp +++ b/src/app/legend/qgslegend.cpp @@ -151,14 +151,20 @@ void QgsLegend::handleCurrentItemChanged( QTreeWidgetItem* current, QTreeWidgetI emit currentLayerChanged( layer ); } +int QgsLegend::addGroupToCurrentItem( QString name, bool expand ) +{ + QTreeWidgetItem *parent = currentItem(); + return 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 *group; + if ( parentGroup ) group = new QgsLegendGroup( parentGroup, name ); else @@ -577,7 +583,7 @@ void QgsLegend::handleRightClickEvent( QTreeWidgetItem* item, const QPoint& posi } } - 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() ) ); diff --git a/src/app/legend/qgslegend.h b/src/app/legend/qgslegend.h index 04be1c262cf..4f21024443c 100644 --- a/src/app/legend/qgslegend.h +++ b/src/app/legend/qgslegend.h @@ -220,10 +220,20 @@ class QgsLegend : public QTreeWidget /*! * 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 + * @return index of inserted group + */ + 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 index of inserted group */ int addGroup( QString name = QString(), bool expand = true, QTreeWidgetItem* parent = 0 ); @@ -414,7 +424,7 @@ class QgsLegend : public QTreeWidget /**Pointer to the main canvas. Used for requiring repaints in case of legend changes*/ QgsMapCanvas* mMapCanvas; - + /**Stores the width values of the LegendSymbologyItem pixmaps. The purpose of this is that the legend may automatically change the global IconWidth when items are added or removed*/ std::multiset mPixmapWidthValues;