[QGIS Commit] r13796 - in branches/threading-branch/src: app app/legend gui

svn_qgis at osgeo.org svn_qgis at osgeo.org
Thu Jun 24 07:27:54 EDT 2010


Author: wonder
Date: 2010-06-24 11:27:54 +0000 (Thu, 24 Jun 2010)
New Revision: 13796

Modified:
   branches/threading-branch/src/app/legend/qgslegend.cpp
   branches/threading-branch/src/app/legend/qgslegend.h
   branches/threading-branch/src/app/legend/qgslegendgroup.cpp
   branches/threading-branch/src/app/legend/qgslegendgroup.h
   branches/threading-branch/src/app/legend/qgslegendlayer.cpp
   branches/threading-branch/src/app/legend/qgslegendlayer.h
   branches/threading-branch/src/app/qgisapp.cpp
   branches/threading-branch/src/gui/qgsmapcanvas.cpp
Log:
Fixed handling of layer/group visibility in legend


Modified: branches/threading-branch/src/app/legend/qgslegend.cpp
===================================================================
--- branches/threading-branch/src/app/legend/qgslegend.cpp	2010-06-24 10:21:11 UTC (rev 13795)
+++ branches/threading-branch/src/app/legend/qgslegend.cpp	2010-06-24 11:27:54 UTC (rev 13796)
@@ -147,29 +147,18 @@
 
 void QgsLegend::selectAll( bool select )
 {
-  if ( !mMapCanvas || mMapCanvas->isDrawing() )
-  {
-    return;
-  }
-
-  // Turn off rendering to improve speed.
-  bool renderFlagState = mMapCanvas->renderFlag();
-  mMapCanvas->setRenderFlag( false );
-
   for ( QTreeWidgetItem* theItem = firstItem(); theItem; theItem = nextItem( theItem ) )
   {
-    QgsLegendItem* litem = dynamic_cast<QgsLegendItem *>( theItem );
-    if ( litem && litem->type() == QgsLegendItem::LEGEND_LAYER )
+    QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( theItem );
+    if ( ll )
     {
-      theItem->setCheckState( 0, ( select ? Qt::Checked : Qt::Unchecked ) );
-      handleItemChange( theItem, 0 );
+      ll->handleCheckStateChange( select ? Qt::Checked : Qt::Unchecked, true );
     }
   }
 
-  // Turn on rendering (if it was on previously)
-  mMapCanvas->setRenderFlag( renderFlagState );
-
   QgsProject::instance()->dirty( true );
+
+  updateMapCanvasLayerSet();
 }
 
 void QgsLegend::removeGroup( int groupIndex )
@@ -1457,17 +1446,16 @@
 }
 
 
-void QgsLegend::handleItemChange( QTreeWidgetItem* item, int row )
+void QgsLegend::handleItemChange( QTreeWidgetItem* item, int column )
 {
   if ( !item )
   {
     return;
   }
 
-  //if the text of a QgsLegendLayer has changed, change the display names of all its maplayers
-  // TODO: is this still necessary?
+  // if the text of a QgsLegendLayer has changed, change the display names of its maplayer
   QgsLegendLayer* theLegendLayer = dynamic_cast<QgsLegendLayer *>( item ); //item is a legend layer
-  if ( theLegendLayer )
+  if ( theLegendLayer && theLegendLayer->layer()->name() != theLegendLayer->text( 0 ) )
   {
     theLegendLayer->layer()->setLayerName( theLegendLayer->text( 0 ) );
   }
@@ -1476,66 +1464,22 @@
   if ( item->data( 0, Qt::UserRole ).toInt() == item->checkState( 0 ) )
     return;
 
-  mMapCanvas->freeze( true );
+  mMapCanvas->cancelRendering();
 
   QgsLegendGroup* lg = dynamic_cast<QgsLegendGroup *>( item ); //item is a legend group
   if ( lg )
   {
-    //set all the child layer files to the new check state
-    std::list<QgsLegendLayer*> subfiles = lg->legendLayers();
-    for ( std::list<QgsLegendLayer*>::iterator iter = subfiles.begin(); iter != subfiles.end(); ++iter )
-    {
-#ifdef QGISDEBUG
-      if ( item->checkState( 0 ) == Qt::Checked )
-      {
-        QgsDebugMsg( "item checked" );
-      }
-      else if ( item->checkState( 0 ) == Qt::Unchecked )
-      {
-        QgsDebugMsg( "item unchecked" );
-      }
-      else if ( item->checkState( 0 ) == Qt::PartiallyChecked )
-      {
-        QgsDebugMsg( "item partially checked" );
-      }
-#endif
-      blockSignals( true );
-      ( *iter )->setCheckState( 0, item->checkState( 0 ) );
-      blockSignals( false );
-      item->setData( 0, Qt::UserRole, item->checkState( 0 ) );
-      if (( *iter )->layer() )
-      {
-        ( *iter )->setVisible( item->checkState( 0 ) == Qt::Checked );
-      }
-    }
-
-    item->setData( 0, Qt::UserRole, item->checkState( 0 ) );
+    // update the group + all its children layers
+    lg->handleCheckStateChange( item->checkState( 0 ) );
   }
 
   QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( item ); //item is a legend layer
   if ( ll )
   {
-    blockSignals( true );
-    ll->setCheckState( 0, item->checkState( 0 ) );
-    blockSignals( false );
-    ll->setData( 0, Qt::UserRole, ll->checkState( 0 ) );
-    if ( ll->layer() )
-    {
-      ll->setVisible( item->checkState( 0 ) == Qt::Checked );
-    }
-
-    if ( ll->parent() )
-    {
-      static_cast<QgsLegendGroup*>( ll->parent() )->updateCheckState();
-      ll->parent()->setData( 0, Qt::UserRole, ll->parent()->checkState( 0 ) );
-    }
-
-    //update check state of the legend group
-    item->setData( 0, Qt::UserRole, item->checkState( 0 ) );
+    // update the visibility + update parent's check state
+    ll->handleCheckStateChange( item->checkState( 0 ), true );
   }
 
-  mMapCanvas->freeze( false );
-
   // update layer set
   updateMapCanvasLayerSet();
 }

Modified: branches/threading-branch/src/app/legend/qgslegend.h
===================================================================
--- branches/threading-branch/src/app/legend/qgslegend.h	2010-06-24 10:21:11 UTC (rev 13795)
+++ branches/threading-branch/src/app/legend/qgslegend.h	2010-06-24 11:27:54 UTC (rev 13796)
@@ -364,7 +364,7 @@
     /**Sets all listview items to closed*/
     void collapseAll();
     /**Just for a test*/
-    void handleItemChange( QTreeWidgetItem* item, int row );
+    void handleItemChange( QTreeWidgetItem* item, int column );
     /** delegates current layer to map canvas */
     void handleCurrentItemChanged( QTreeWidgetItem* current, QTreeWidgetItem* previous );
     /**Calls openPersistentEditor for the current item*/

Modified: branches/threading-branch/src/app/legend/qgslegendgroup.cpp
===================================================================
--- branches/threading-branch/src/app/legend/qgslegendgroup.cpp	2010-06-24 10:21:11 UTC (rev 13795)
+++ branches/threading-branch/src/app/legend/qgslegendgroup.cpp	2010-06-24 11:27:54 UTC (rev 13796)
@@ -145,5 +145,20 @@
     treeWidget()->blockSignals( true );
     setCheckState( 0, theState );
     treeWidget()->blockSignals( false );
+
+    setData( 0, Qt::UserRole, theState );
   }
 }
+
+void QgsLegendGroup::handleCheckStateChange( Qt::CheckState state )
+{
+  //set all the child layer files to the new check state
+  std::list<QgsLegendLayer*> subfiles = legendLayers();
+  for ( std::list<QgsLegendLayer*>::iterator iter = subfiles.begin(); iter != subfiles.end(); ++iter )
+  {
+    // update the children (but don't let them update the parent)
+    ( *iter )->handleCheckStateChange( state, false );
+  }
+
+  setData( 0, Qt::UserRole, state );
+}

Modified: branches/threading-branch/src/app/legend/qgslegendgroup.h
===================================================================
--- branches/threading-branch/src/app/legend/qgslegendgroup.h	2010-06-24 10:21:11 UTC (rev 13795)
+++ branches/threading-branch/src/app/legend/qgslegendgroup.h	2010-06-24 11:27:54 UTC (rev 13796)
@@ -45,6 +45,9 @@
     std::list<QgsLegendLayer*> legendLayers();
     /**Goes through all the legendlayers and sets check state to checked/partially checked/unchecked*/
     void updateCheckState();
+
+    /** called when the legend group gets checked/unchecked to check/uncheck also its children */
+    void handleCheckStateChange( Qt::CheckState state );
 };
 
 #endif

Modified: branches/threading-branch/src/app/legend/qgslegendlayer.cpp
===================================================================
--- branches/threading-branch/src/app/legend/qgslegendlayer.cpp	2010-06-24 10:21:11 UTC (rev 13795)
+++ branches/threading-branch/src/app/legend/qgslegendlayer.cpp	2010-06-24 11:27:54 UTC (rev 13796)
@@ -22,6 +22,7 @@
 #include "qgisapp.h"
 #include "qgslegend.h"
 #include "qgslegendlayer.h"
+#include "qgslegendgroup.h"
 #include "qgslegendsymbologyitem.h"
 #include "qgslogger.h"
 
@@ -499,3 +500,21 @@
   QString name = mLyr.layer()->name();
   setText( 0, name );
 }
+
+void QgsLegendLayer::handleCheckStateChange( Qt::CheckState state, bool updateParentGroup )
+{
+  treeWidget()->blockSignals( true );
+  setCheckState( 0, state );
+  treeWidget()->blockSignals( false );
+
+  setData( 0, Qt::UserRole, state );
+  if ( layer() )
+  {
+    setVisible( state == Qt::Checked );
+  }
+
+  if ( updateParentGroup && parent() )
+  {
+    static_cast<QgsLegendGroup*>( parent() )->updateCheckState();
+  }
+}

Modified: branches/threading-branch/src/app/legend/qgslegendlayer.h
===================================================================
--- branches/threading-branch/src/app/legend/qgslegendlayer.h	2010-06-24 10:21:11 UTC (rev 13795)
+++ branches/threading-branch/src/app/legend/qgslegendlayer.h	2010-06-24 11:27:54 UTC (rev 13796)
@@ -54,8 +54,6 @@
     /**Returns the map layer associated the item*/
     QgsMapLayer* layer();
     QgsMapCanvasLayer& canvasLayer();
-    /**Goes through all the legendlayerfiles and sets check state to checked/partially checked/unchecked*/
-    //void updateCheckState();
 
     /**Updates symbology of the layer and copies symbology to other layer files in the group*/
     void refreshSymbology( const QString& key, double widthScale = 1.0 );
@@ -72,6 +70,9 @@
     /**Determines whether there are layers in overview*/
     bool isInOverview();
 
+    /** called when the legend layer gets checked/unchecked */
+    void handleCheckStateChange( Qt::CheckState state, bool updateParentGroup );
+
     /**Returns a label for a layer. Is static such that
      the name can be passed to the constructor of QgsLegendLayer*/
     static QString nameFromLayer( QgsMapLayer* layer );

Modified: branches/threading-branch/src/app/qgisapp.cpp
===================================================================
--- branches/threading-branch/src/app/qgisapp.cpp	2010-06-24 10:21:11 UTC (rev 13795)
+++ branches/threading-branch/src/app/qgisapp.cpp	2010-06-24 11:27:54 UTC (rev 13796)
@@ -3507,11 +3507,11 @@
       // showMaxmized() is a work-around. Turn off rendering for this as it
       // would otherwise cause two re-renders of the map, which can take a
       // long time.
-      bool renderFlag = mapCanvas()->renderFlag();
-      mapCanvas()->setRenderFlag( false );
+      mapCanvas()->freeze();
       showNormal();
       showMaximized();
-      mapCanvas()->setRenderFlag( renderFlag );
+      mapCanvas()->freeze(false);
+      mapCanvas()->refresh();
       mPrevScreenModeMaximized = false;
     }
     else

Modified: branches/threading-branch/src/gui/qgsmapcanvas.cpp
===================================================================
--- branches/threading-branch/src/gui/qgsmapcanvas.cpp	2010-06-24 10:21:11 UTC (rev 13795)
+++ branches/threading-branch/src/gui/qgsmapcanvas.cpp	2010-06-24 11:27:54 UTC (rev 13796)
@@ -227,11 +227,8 @@
 
 void QgsMapCanvas::setLayerSet( QList<QgsMapCanvasLayer> &layers )
 {
-  if ( isDrawing() )
-  {
-    QgsDebugMsg("ignored - drawing!" );
-    return;
-  }
+  // make sure we're not rendering
+  cancelRendering();
 
   // create layer set
   QStringList layerSet, layerSetOverview;
@@ -363,7 +360,10 @@
 void QgsMapCanvas::refresh()
 {
   if ( !mRenderFlag || mFrozen )
+  {
+    QgsDebugMsg("REFRESH ignored: canvas frozen");
     return;
+  }
 
   cancelRendering();
 



More information about the QGIS-commit mailing list