Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[FEATURE] Group selected layers on right click

  • Loading branch information...
commit d2b9e95b6677e17dda68f480c3e452befe23f1d7 1 parent d2775ba
Arunmozhi authored February 13, 2012 NathanW2 committed February 15, 2012
46  src/app/legend/qgslegend.cpp
@@ -628,9 +628,17 @@ void QgsLegend::handleRightClickEvent( QTreeWidgetItem* item, const QPoint& posi
628 628
     {
629 629
       theMenu.addAction( tr( "Re&name" ), this, SLOT( openEditor() ) );
630 630
     }
  631
+    //
  632
+    // Option to group layers, if the selection is more than one
  633
+    //
  634
+    if( selectedLayers().length() > 1 )
  635
+    {
  636
+      theMenu.addAction( tr( "&Group selected" ), this, SLOT( groupSelectedLayers() ) );
  637
+    }
  638
+    // ends here
631 639
   }
632 640
 
633  
-  theMenu.addAction( QgisApp::getThemeIcon( "/folder_new.png" ), tr( "&Add group" ), this, SLOT( addGroupToCurrentItem() ) );
  641
+  theMenu.addAction( QgisApp::getThemeIcon( "/folder_new.png" ), tr( "&Add new group" ), this, SLOT( addGroupToCurrentItem() ) );
634 642
   theMenu.addAction( QgisApp::getThemeIcon( "/mActionExpandTree.png" ), tr( "&Expand all" ), this, SLOT( expandAll() ) );
635 643
   theMenu.addAction( QgisApp::getThemeIcon( "/mActionCollapseTree.png" ), tr( "&Collapse all" ), this, SLOT( collapseAll() ) );
636 644
 
@@ -2401,3 +2409,39 @@ void QgsLegend::toggleDrawingOrderUpdate()
2401 2409
 {
2402 2410
   setUpdateDrawingOrder( !mUpdateDrawingOrder );
2403 2411
 }
  2412
+
  2413
+void QgsLegend::groupSelectedLayers()
  2414
+{
  2415
+  //avoid multiple refreshes of map canvas because of itemChanged signal
  2416
+  blockSignals( true );
  2417
+
  2418
+  QTreeWidgetItem * parent;
  2419
+  foreach( QTreeWidgetItem* item, selectedItems() )
  2420
+  {
  2421
+    parent = item->parent();
  2422
+  }
  2423
+  QgsLegendGroup *group;
  2424
+
  2425
+  if( parent )
  2426
+  {
  2427
+    group = new QgsLegendGroup( parent, tr( "sub-group" ) );
  2428
+  }
  2429
+  else
  2430
+  {
  2431
+    group = new QgsLegendGroup( this, tr( "group" ) );
  2432
+  }
  2433
+
  2434
+  foreach( QTreeWidgetItem * item, selectedItems() )
  2435
+  {
  2436
+    QgsLegendLayer* layer = dynamic_cast<QgsLegendLayer *>( item );
  2437
+    if ( layer )
  2438
+    {
  2439
+      insertItem( item, group );
  2440
+    }
  2441
+  }
  2442
+  editItem( group, 0 );
  2443
+
  2444
+  blockSignals( false );
  2445
+
  2446
+}
  2447
+
3  src/app/legend/qgslegend.h
@@ -313,6 +313,9 @@ class QgsLegend : public QTreeWidget
313 313
     /** Update drawing order */
314 314
     void unsetUpdateDrawingOrder( bool dontUpdateDrawingOrder ) { setUpdateDrawingOrder( !dontUpdateDrawingOrder ); }
315 315
 
  316
+    /** Create a new group for the selected items **/
  317
+    void groupSelectedLayers();
  318
+
316 319
   protected:
317 320
 
318 321
     /*!Event handler for mouse movements.

0 notes on commit d2b9e95

Please sign in to comment.
Something went wrong with that request. Please try again.