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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Mar 16 08:59:33 EDT 2010


Author: jef
Date: 2010-03-16 08:59:32 -0400 (Tue, 16 Mar 2010)
New Revision: 13063

Modified:
   trunk/qgis/src/app/legend/qgslegend.cpp
   trunk/qgis/src/app/legend/qgslegend.h
Log:
fix crash when moving layers

Modified: trunk/qgis/src/app/legend/qgslegend.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.cpp	2010-03-16 06:58:07 UTC (rev 13062)
+++ trunk/qgis/src/app/legend/qgslegend.cpp	2010-03-16 12:59:32 UTC (rev 13063)
@@ -540,7 +540,7 @@
 
 void QgsLegend::setMapCanvas( QgsMapCanvas * canvas )
 {
-  if( mMapCanvas ) 
+  if ( mMapCanvas )
   {
     disconnect( mMapCanvas, SIGNAL( layersChanged() ) );
   }
@@ -699,12 +699,18 @@
 
 void QgsLegend::moveLayer( QgsMapLayer * ml, int groupIndex )
 {
+  if ( !ml )
+    return;
+
   QgsLegendLayer *layer = findLegendLayer( ml->getLayerID() );
+  if ( !layer )
+    return;
+
   QgsLegendGroup *group = dynamic_cast<QgsLegendGroup*>( topLevelItem( groupIndex ) );
-  if ( layer && group )
-  {
-    insertItem( layer, group );
-  }
+  if ( !group )
+    return;
+
+  insertItem( layer, group );
 }
 
 void QgsLegend::legendLayerShowProperties()
@@ -1760,16 +1766,16 @@
 
 void QgsLegend::refreshCheckStates()
 {
-  if( !mMapCanvas )
+  if ( !mMapCanvas )
   {
     return;
   }
 
   QList<QgsMapLayer*> lst = mMapCanvas->layers();
-  for ( QTreeWidgetItem* item = firstItem(); item; item = nextItem( item ) ) 
+  for ( QTreeWidgetItem* item = firstItem(); item; item = nextItem( item ) )
   {
     QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( item );
-    if ( ll ) 
+    if ( ll )
     {
       ll->setCheckState( 0, ( lst.contains( ll->layer() ) ? Qt::Checked : Qt::Unchecked ) );
     }

Modified: trunk/qgis/src/app/legend/qgslegend.h
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.h	2010-03-16 06:58:07 UTC (rev 13062)
+++ trunk/qgis/src/app/legend/qgslegend.h	2010-03-16 12:59:32 UTC (rev 13063)
@@ -244,7 +244,7 @@
      * Moves a layer to a group.
      * @param ml the maplayer to move
      * @param groupIndex index of group
-     * @return false if the group does not exist, false otherwise
+     * @note keep in mind that the group's index changes, if the moved layer is above the group.
      */
     void moveLayer( QgsMapLayer* ml, int groupIndex );
 



More information about the QGIS-commit mailing list