[QGIS Commit] r15787 - in trunk/qgis: python/gui src/app/legend src/gui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Apr 21 03:43:44 EDT 2011


Author: mhugent
Date: 2011-04-21 00:43:44 -0700 (Thu, 21 Apr 2011)
New Revision: 15787

Modified:
   trunk/qgis/python/gui/qgslegendinterface.sip
   trunk/qgis/src/app/legend/qgsapplegendinterface.cpp
   trunk/qgis/src/app/legend/qgsapplegendinterface.h
   trunk/qgis/src/app/legend/qgslegend.cpp
   trunk/qgis/src/app/legend/qgslegend.h
   trunk/qgis/src/gui/qgslegendinterface.h
Log:
Improve python bindings for adding legend groups (#3263). Patch from Marco Bernasocchi 

Modified: trunk/qgis/python/gui/qgslegendinterface.sip
===================================================================
--- trunk/qgis/python/gui/qgslegendinterface.sip	2011-04-20 21:42:44 UTC (rev 15786)
+++ trunk/qgis/python/gui/qgslegendinterface.sip	2011-04-21 07:43:44 UTC (rev 15787)
@@ -52,6 +52,10 @@
     //! Add a new group
     //! @note added parent parameter in 1.7
     virtual int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent =0 ) = 0;
+    
+    //! Add a new group
+    //! @note added parentIndex parameter in 1.7
+    virtual int addGroup( QString name, bool expand, int parentIndex ) = 0;
 
     //! Remove group on index
     virtual void removeGroup( int groupIndex ) =0;

Modified: trunk/qgis/src/app/legend/qgsapplegendinterface.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgsapplegendinterface.cpp	2011-04-20 21:42:44 UTC (rev 15786)
+++ trunk/qgis/src/app/legend/qgsapplegendinterface.cpp	2011-04-21 07:43:44 UTC (rev 15787)
@@ -37,6 +37,11 @@
   return mLegend->addGroup( name, expand, parent );
 }
 
+int QgsAppLegendInterface::addGroup( QString name, bool expand, int parentIndex )
+{
+  return mLegend->addGroup( name, expand, parentIndex );
+}
+
 void QgsAppLegendInterface::removeGroup( int groupIndex )
 {
   mLegend->removeGroup( groupIndex );

Modified: trunk/qgis/src/app/legend/qgsapplegendinterface.h
===================================================================
--- trunk/qgis/src/app/legend/qgsapplegendinterface.h	2011-04-20 21:42:44 UTC (rev 15786)
+++ trunk/qgis/src/app/legend/qgsapplegendinterface.h	2011-04-21 07:43:44 UTC (rev 15787)
@@ -67,6 +67,9 @@
     //! Add a new group
     int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent = 0 );
 
+    //! Add a new group at a specified index
+    int addGroup( QString name, bool expand, int groupIndex );
+
     //! Remove all groups with the given name
     void removeGroup( int groupIndex );
 

Modified: trunk/qgis/src/app/legend/qgslegend.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.cpp	2011-04-20 21:42:44 UTC (rev 15786)
+++ trunk/qgis/src/app/legend/qgslegend.cpp	2011-04-21 07:43:44 UTC (rev 15787)
@@ -159,7 +159,8 @@
 
 int QgsLegend::addGroup( QString name, bool expand, QTreeWidgetItem* parent )
 {
-  if ( name.isEmpty() )
+  bool nameEmpty = name.isEmpty();
+  if ( nameEmpty )
     name = tr( "group" ); // some default name if none specified
 
   QgsLegendGroup *parentGroup = dynamic_cast<QgsLegendGroup *>( parent );
@@ -173,10 +174,18 @@
   QModelIndex groupIndex = indexFromItem( group );
   setExpanded( groupIndex, expand );
   setCurrentItem( group );
-  openEditor();
+  if ( nameEmpty )
+    openEditor();
+
   return groupIndex.row();
 }
 
+int QgsLegend::addGroup( QString name, bool expand, int groupIndex )
+{
+  QgsLegendGroup * lg = dynamic_cast<QgsLegendGroup *>( topLevelItem( groupIndex ) );
+  return addGroup( name, expand, lg );
+}
+
 void QgsLegend::removeAll()
 {
   clear();

Modified: trunk/qgis/src/app/legend/qgslegend.h
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.h	2011-04-20 21:42:44 UTC (rev 15786)
+++ trunk/qgis/src/app/legend/qgslegend.h	2011-04-21 07:43:44 UTC (rev 15787)
@@ -238,6 +238,15 @@
     int addGroup( QString name = QString(), bool expand = true, QTreeWidgetItem* parent = 0 );
 
     /*!
+     * Slot called when user wishes to add a new empty layer group to the legend.
+     * All parameter are mandatory to be used to programatically nest a new group
+     * @param name name of the new group
+     * @param expand expand the group
+     * @return index of inserted group
+     */
+    int addGroup( QString name, bool expand, int parentIndex );
+
+    /*!
      * Removes all groups with the given name.
      * @param name name of the groups to remove
      * @return void

Modified: trunk/qgis/src/gui/qgslegendinterface.h
===================================================================
--- trunk/qgis/src/gui/qgslegendinterface.h	2011-04-20 21:42:44 UTC (rev 15786)
+++ trunk/qgis/src/gui/qgslegendinterface.h	2011-04-21 07:43:44 UTC (rev 15787)
@@ -84,6 +84,10 @@
     //! a parent group can be given to nest the new group in it
     virtual int addGroup( QString name, bool expand = true, QTreeWidgetItem* parent = 0 ) = 0;
 
+    //! Add a new group
+    //! a parent group index has to be given to nest the new group in it
+    virtual int addGroup( QString name, bool expand, int parentIndex ) = 0;
+
     //! Remove group on index
     virtual void removeGroup( int groupIndex ) = 0;
 



More information about the QGIS-commit mailing list