Skip to content
Permalink
Browse files
[FEATURE] Group selected layers on right click
  • Loading branch information
tecoholic authored and NathanW2 committed Feb 15, 2012
1 parent d2775ba commit d2b9e95b6677e17dda68f480c3e452befe23f1d7
Showing with 48 additions and 1 deletion.
  1. +45 −1 src/app/legend/qgslegend.cpp
  2. +3 −0 src/app/legend/qgslegend.h
@@ -628,9 +628,17 @@ void QgsLegend::handleRightClickEvent( QTreeWidgetItem* item, const QPoint& posi
{
theMenu.addAction( tr( "Re&name" ), this, SLOT( openEditor() ) );
}
//
// Option to group layers, if the selection is more than one
//
if( selectedLayers().length() > 1 )
{
theMenu.addAction( tr( "&Group selected" ), this, SLOT( groupSelectedLayers() ) );
}
// ends here
}

theMenu.addAction( QgisApp::getThemeIcon( "/folder_new.png" ), tr( "&Add group" ), this, SLOT( addGroupToCurrentItem() ) );
theMenu.addAction( QgisApp::getThemeIcon( "/folder_new.png" ), tr( "&Add new 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() ) );

@@ -2401,3 +2409,39 @@ void QgsLegend::toggleDrawingOrderUpdate()
{
setUpdateDrawingOrder( !mUpdateDrawingOrder );
}

void QgsLegend::groupSelectedLayers()
{
//avoid multiple refreshes of map canvas because of itemChanged signal
blockSignals( true );

QTreeWidgetItem * parent;
foreach( QTreeWidgetItem* item, selectedItems() )
{
parent = item->parent();
}
QgsLegendGroup *group;

if( parent )
{
group = new QgsLegendGroup( parent, tr( "sub-group" ) );
}
else
{
group = new QgsLegendGroup( this, tr( "group" ) );
}

foreach( QTreeWidgetItem * item, selectedItems() )
{
QgsLegendLayer* layer = dynamic_cast<QgsLegendLayer *>( item );
if ( layer )
{
insertItem( item, group );
}
}
editItem( group, 0 );

blockSignals( false );

}

@@ -313,6 +313,9 @@ class QgsLegend : public QTreeWidget
/** Update drawing order */
void unsetUpdateDrawingOrder( bool dontUpdateDrawingOrder ) { setUpdateDrawingOrder( !dontUpdateDrawingOrder ); }

/** Create a new group for the selected items **/
void groupSelectedLayers();

protected:

/*!Event handler for mouse movements.

0 comments on commit d2b9e95

Please sign in to comment.