Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[FEATURE] Group selected layers on right click

  • Loading branch information...
commit d2b9e95b6677e17dda68f480c3e452befe23f1d7 1 parent d2775ba
@tecoholic tecoholic authored NathanW2 committed
Showing with 48 additions and 1 deletion.
  1. +45 −1 src/app/legend/qgslegend.cpp
  2. +3 −0  src/app/legend/qgslegend.h
View
46 src/app/legend/qgslegend.cpp
@@ -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 );
+
+}
+
View
3  src/app/legend/qgslegend.h
@@ -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.
Please sign in to comment.
Something went wrong with that request. Please try again.