Commited patch for #3263 with small modifications

git-svn-id: http://svn.osgeo.org/qgis/trunk@15766 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2011-04-19 13:59:39 +00:00
parent fe96d8554c
commit 6e17e93308
2 changed files with 20 additions and 4 deletions

View File

@ -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
@ -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() ) );

View File

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