[QGIS Commit] r15766 - trunk/qgis/src/app/legend

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Apr 19 09:59:39 EDT 2011


Author: mhugent
Date: 2011-04-19 06:59:39 -0700 (Tue, 19 Apr 2011)
New Revision: 15766

Modified:
   trunk/qgis/src/app/legend/qgslegend.cpp
   trunk/qgis/src/app/legend/qgslegend.h
Log:
Commited patch for #3263 with small modifications

Modified: trunk/qgis/src/app/legend/qgslegend.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.cpp	2011-04-19 09:46:29 UTC (rev 15765)
+++ trunk/qgis/src/app/legend/qgslegend.cpp	2011-04-19 13:59:39 UTC (rev 15766)
@@ -151,14 +151,20 @@
   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;
 
-  QgsLegendGroup *group;
   if ( parentGroup )
     group = new QgsLegendGroup( parentGroup, name );
   else
@@ -577,7 +583,7 @@
     }
   }
 
-  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() ) );
 

Modified: trunk/qgis/src/app/legend/qgslegend.h
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.h	2011-04-19 09:46:29 UTC (rev 15765)
+++ trunk/qgis/src/app/legend/qgslegend.h	2011-04-19 13:59:39 UTC (rev 15766)
@@ -220,11 +220,21 @@
 
     /*!
      * 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 @@
 
     /**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;



More information about the QGIS-commit mailing list