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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sat Apr 16 09:58:57 EDT 2011


Author: alexbruy
Date: 2011-04-16 06:58:57 -0700 (Sat, 16 Apr 2011)
New Revision: 15727

Modified:
   trunk/qgis/src/app/legend/qgsapplegendinterface.cpp
   trunk/qgis/src/app/legend/qgslegend.cpp
   trunk/qgis/src/app/legend/qgslegend.h
Log:
more robust fix for #2762 as suggested by Martin


Modified: trunk/qgis/src/app/legend/qgsapplegendinterface.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgsapplegendinterface.cpp	2011-04-16 13:23:14 UTC (rev 15726)
+++ trunk/qgis/src/app/legend/qgsapplegendinterface.cpp	2011-04-16 13:58:57 UTC (rev 15727)
@@ -119,18 +119,7 @@
 
 QList< QgsMapLayer * > QgsAppLegendInterface::layers() const
 {
-  QList< QgsMapLayer * > items;
-  QTreeWidgetItemIterator it( mLegend );
-  while ( *it )
-  {
-    QgsLegendLayer *llayer = dynamic_cast<QgsLegendLayer *>( *it );
-    if ( llayer )
-      items.append( llayer->layer() );
-
-    ++it;
-  }
-
-  return items;
+  return mLegend->layers();
 }
 
 void QgsAppLegendInterface::refreshLayerSymbology( QgsMapLayer *ml )

Modified: trunk/qgis/src/app/legend/qgslegend.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.cpp	2011-04-16 13:23:14 UTC (rev 15726)
+++ trunk/qgis/src/app/legend/qgslegend.cpp	2011-04-16 13:58:57 UTC (rev 15727)
@@ -649,7 +649,7 @@
   updateMapCanvasLayerSet();
 
   // first layer?
-  if ( QgsMapLayerRegistry::instance()->count() == 1 )
+  if ( layers().count() == 1 )
   {
     mMapCanvas->zoomToFullExtent();
     mMapCanvas->clearExtentHistory();
@@ -716,6 +716,22 @@
   return layers;
 }
 
+QList<QgsMapLayer *> QgsLegend::layers()
+{
+  QList< QgsMapLayer * > items;
+  QTreeWidgetItemIterator it( this );
+  while ( *it )
+  {
+    QgsLegendLayer *llayer = dynamic_cast<QgsLegendLayer *>( *it );
+    if ( llayer )
+      items.append( llayer->layer() );
+
+    ++it;
+  }
+
+  return items;
+}
+
 bool QgsLegend::setCurrentLayer( QgsMapLayer *layer )
 {
   QgsLegendLayer *ll = findLegendLayer( layer );

Modified: trunk/qgis/src/app/legend/qgslegend.h
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.h	2011-04-16 13:23:14 UTC (rev 15726)
+++ trunk/qgis/src/app/legend/qgslegend.h	2011-04-16 13:58:57 UTC (rev 15727)
@@ -112,6 +112,10 @@
     Else, an empty list is returned.*/
     QList<QgsMapLayer *> selectedLayers();
 
+    /*!Returns all layers loaded in QgsMapCanvas.
+    Else, an empty list is returned.*/
+    QList<QgsMapLayer *> layers();
+
     /*!set the current layer
     returns true if the layer exists, false otherwise*/
     bool setCurrentLayer( QgsMapLayer *layer );
@@ -410,7 +414,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