Skip to content

Commit

Permalink
Commited patch for #3263 with small modifications
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@15766 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 19, 2011
1 parent fe96d85 commit 6e17e93
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/app/legend/qgslegend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QgsLegendGroup *>( parent );

QgsLegendGroup *group;

if ( parentGroup )
group = new QgsLegendGroup( parentGroup, name );
else
Expand Down Expand Up @@ -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() ) );

Expand Down
14 changes: 12 additions & 2 deletions src/app/legend/qgslegend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -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<int> mPixmapWidthValues;
Expand Down

0 comments on commit 6e17e93

Please sign in to comment.