Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] Group selected layers on right click
  • Loading branch information
Arunmozhi authored and NathanW2 committed Feb 15, 2012
1 parent d2775ba commit d2b9e95
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/app/legend/qgslegend.cpp
Expand Up @@ -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() ) );

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

}

3 changes: 3 additions & 0 deletions src/app/legend/qgslegend.h
Expand Up @@ -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.
Expand Down

0 comments on commit d2b9e95

Please sign in to comment.