Skip to content

Commit 6e17e93

Browse files
author
mhugent
committedApr 19, 2011
Commited patch for #3263 with small modifications
git-svn-id: http://svn.osgeo.org/qgis/trunk@15766 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent fe96d85 commit 6e17e93

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed
 

‎src/app/legend/qgslegend.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
154160
int 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

‎src/app/legend/qgslegend.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,20 @@ class QgsLegend : public QTreeWidget
220220

221221
/*!
222222
* Slot called when user wishes to add a new empty layer group to the legend.
223+
* If a the legend has a currentItem() then the new group will be nested into it
223224
* The user will be prompted for the name of the newly added group.
224225
* @param name name of the new group
225226
* @param expand expand the group
226-
* @return void
227+
* @return index of inserted group
228+
*/
229+
int addGroupToCurrentItem( QString name = QString(), bool expand = true );
230+
231+
/*!
232+
* Slot called when user wishes to add a new empty layer group to the legend.
233+
* The user will be prompted for the name of the newly added group.
234+
* @param name name of the new group
235+
* @param expand expand the group
236+
* @return index of inserted group
227237
*/
228238
int addGroup( QString name = QString(), bool expand = true, QTreeWidgetItem* parent = 0 );
229239

@@ -414,7 +424,7 @@ class QgsLegend : public QTreeWidget
414424

415425
/**Pointer to the main canvas. Used for requiring repaints in case of legend changes*/
416426
QgsMapCanvas* mMapCanvas;
417-
427+
418428
/**Stores the width values of the LegendSymbologyItem pixmaps. The purpose of this is that the legend may automatically change
419429
the global IconWidth when items are added or removed*/
420430
std::multiset<int> mPixmapWidthValues;

0 commit comments

Comments
 (0)
Please sign in to comment.