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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Nov 10 13:16:36 EST 2009


Author: jef
Date: 2009-11-10 13:16:35 -0500 (Tue, 10 Nov 2009)
New Revision: 12076

Modified:
   trunk/qgis/src/app/legend/qgslegend.cpp
   trunk/qgis/src/app/legend/qgslegend.h
   trunk/qgis/src/app/legend/qgslegendlayer.cpp
Log:
little legend cleanup: remove member mStateOfCheckBoxes

Modified: trunk/qgis/src/app/legend/qgslegend.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.cpp	2009-11-10 17:46:24 UTC (rev 12075)
+++ trunk/qgis/src/app/legend/qgslegend.cpp	2009-11-10 18:16:35 UTC (rev 12076)
@@ -119,13 +119,12 @@
 void QgsLegend::addGroup()
 {
   QgsLegendGroup* group = new QgsLegendGroup( this, tr( "group" ) );
-  mStateOfCheckBoxes.insert( std::make_pair( group, Qt::Checked ) ); //insert the check state into the map to query for changes later
+  group->setData( 0, Qt::UserRole, Qt::Checked );
   setExpanded( indexFromItem( group ), true );
 }
 
 void QgsLegend::removeAll()
 {
-  mStateOfCheckBoxes.clear();
   clear();
   mPixmapWidthValues.clear();
   mPixmapHeightValues.clear();
@@ -182,8 +181,6 @@
 
       if ( ll && ll->layer() && ll->layer()->getLayerID() == layer_key )
       {
-        //remove the map entry for the checkbox
-        mStateOfCheckBoxes.erase( ll );
         removeItem( ll );
         delete ll;
 
@@ -501,12 +498,12 @@
   if ( llayer->isVisible() )
   {
     llayer->setCheckState( 0, Qt::Checked );
-    mStateOfCheckBoxes.insert( std::make_pair( llayer, Qt::Checked ) );
+    llayer->setData( 0, Qt::UserRole, Qt::Checked );
   }
   else
   {
     llayer->setCheckState( 0, Qt::Unchecked );
-    mStateOfCheckBoxes.insert( std::make_pair( llayer, Qt::Unchecked ) );
+    llayer->setData( 0, Qt::UserRole, Qt::Unchecked );
   }
   blockSignals( false );
 
@@ -909,7 +906,6 @@
   if ( !child.isNull() )
   {
     clear(); //remove all items first
-    mStateOfCheckBoxes.clear();
 
     do
     {
@@ -927,24 +923,24 @@
         if ( checked == "Qt::Checked" )
         {
           theGroup->setCheckState( 0, Qt::Checked );
-          mStateOfCheckBoxes.insert( std::make_pair( theGroup, Qt::Checked ) );
+          theGroup->setData( 0, Qt::UserRole, Qt::Checked );
         }
         else if ( checked == "Qt::Unchecked" )
         {
           theGroup->setCheckState( 0, Qt::Unchecked );
-          mStateOfCheckBoxes.insert( std::make_pair( theGroup, Qt::Unchecked ) );
+          theGroup->setData( 0, Qt::UserRole, Qt::Checked );
         }
         else if ( checked == "Qt::PartiallyChecked" )
         {
           theGroup->setCheckState( 0, Qt::PartiallyChecked );
-          mStateOfCheckBoxes.insert( std::make_pair( theGroup, Qt::PartiallyChecked ) );
+          theGroup->setData( 0, Qt::UserRole, Qt::PartiallyChecked );
         }
         blockSignals( false );
         lastGroup = theGroup;
       }
       else if ( childelem.tagName() == "legendlayer" )
       {
-        bool isOpen; // to recieve info whether the item is open or closed
+        bool isOpen; // to receive info whether the item is open or closed
         lastLayer = readLayerFromXML(childelem, isOpen);
 
         if (lastLayer)
@@ -1039,13 +1035,13 @@
   {
     ll->setVisible(true);
     ll->setCheckState( 0, Qt::Checked );
-    mStateOfCheckBoxes.insert( std::make_pair( ll, Qt::Checked ) );
+    ll->setData( 0, Qt::UserRole, Qt::Checked );
   }
   else if ( checked == "Qt::Unchecked" )
   {
     ll->setVisible(false);
     ll->setCheckState( 0, Qt::Unchecked );
-    mStateOfCheckBoxes.insert( std::make_pair( ll, Qt::Unchecked ) );
+    ll->setData( 0, Qt::UserRole, Qt::Unchecked );
   }
   blockSignals( false );
 
@@ -1336,8 +1332,6 @@
 
 void QgsLegend::updateMapCanvasLayerSet()
 {
-  //std::deque<QString> layers = layerIDs();
-
   QList<QgsMapCanvasLayer> layers;
 
   // create list of the layers
@@ -1484,12 +1478,8 @@
     theLegendLayer->layer()->setLayerName( theLegendLayer->text( 0 ) );
   }
 
-  std::map<QTreeWidgetItem*, Qt::CheckState>::iterator it = mStateOfCheckBoxes.find( item );
-  if ( it == mStateOfCheckBoxes.end() )
-    return;
-
   // has the checkState changed?
-  if ( it->second == item->checkState( 0 ) )
+  if ( item->data(0, Qt::UserRole).toInt() == item->checkState( 0 ) )
     return;
 
   QgsLegendGroup* lg = dynamic_cast<QgsLegendGroup *>( item ); //item is a legend group
@@ -1518,7 +1508,7 @@
       blockSignals( true );
       ( *iter )->setCheckState( 0, item->checkState( 0 ) );
       blockSignals( false );
-      mStateOfCheckBoxes[( *iter )] = item->checkState( 0 );
+      item->setData( 0, Qt::UserRole, item->checkState( 0 ) );
       if (( *iter )->layer() )
       {
         ( *iter )->setVisible( item->checkState( 0 ) == Qt::Checked );
@@ -1529,7 +1519,7 @@
     // off, as turning it on causes a refresh.
     if ( renderFlagState )
       mMapCanvas->setRenderFlag( true );
-    mStateOfCheckBoxes[item] = item->checkState( 0 );
+    item->setData( 0, Qt::UserRole, item->checkState( 0 ) );
   }
 
   QgsLegendLayer* ll = dynamic_cast<QgsLegendLayer *>( item ); //item is a legend layer
@@ -1538,7 +1528,7 @@
     blockSignals( true );
     ll->setCheckState( 0, item->checkState( 0 ) );
     blockSignals( false );
-    mStateOfCheckBoxes[ll] = item->checkState( 0 );
+    ll->setData( 0, Qt::UserRole, ll->checkState( 0 ) );
     if (ll->layer() )
     {
       ll->setVisible( item->checkState( 0 ) == Qt::Checked );
@@ -1547,7 +1537,7 @@
     if ( ll->parent() )
     {
       static_cast<QgsLegendGroup*>( ll->parent() )->updateCheckState();
-      mStateOfCheckBoxes[ll->parent()] = ll->parent()->checkState( 0 );
+      ll->parent()->setData( 0, Qt::UserRole, ll->parent()->checkState( 0 ) );
     }
     // If it was on, turn it back on, otherwise leave it
     // off, as turning it on causes a refresh.
@@ -1557,7 +1547,7 @@
     }
     mMapCanvas->freeze( false );
     //update check state of the legend group
-    mStateOfCheckBoxes[item] = item->checkState( 0 );
+    item->setData( 0, Qt::UserRole, item->checkState( 0 ) );
   }
 
   // update layer set

Modified: trunk/qgis/src/app/legend/qgslegend.h
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.h	2009-11-10 17:46:24 UTC (rev 12075)
+++ trunk/qgis/src/app/legend/qgslegend.h	2009-11-10 18:16:35 UTC (rev 12076)
@@ -169,7 +169,7 @@
     QgsLegendPixmaps& pixmaps() { return mPixmaps; }
 
 
-    void updateCheckStates( QTreeWidgetItem* item, Qt::CheckState state ) {mStateOfCheckBoxes[item] = state;}
+    void updateCheckStates( QTreeWidgetItem* item, Qt::CheckState state ) { item->setData( 0, Qt::UserRole, state ); }
 
   public slots:
 
@@ -404,10 +404,6 @@
     /**Pointer to the main canvas. Used for requiring repaints in case of legend changes*/
     QgsMapCanvas* mMapCanvas;
 
-    /**Map that keeps track of which checkboxes are in which check state. This is necessary because QTreeView does not emit
-       a signal for check state changes*/
-    std::map<QTreeWidgetItem*, Qt::CheckState> mStateOfCheckBoxes;
-
     /**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;

Modified: trunk/qgis/src/app/legend/qgslegendlayer.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegendlayer.cpp	2009-11-10 17:46:24 UTC (rev 12075)
+++ trunk/qgis/src/app/legend/qgslegendlayer.cpp	2009-11-10 18:16:35 UTC (rev 12076)
@@ -385,7 +385,7 @@
     QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( lyr );
 
     // attribute table
-    QAction* tableAction = theMenu.addAction( tr( "&Open attribute table" ), this, SLOT( table() ) );
+    theMenu.addAction( tr( "&Open attribute table" ), this, SLOT( table() ) );
 
     // allow editing
     int cap = vlayer->dataProvider()->capabilities();
@@ -399,7 +399,7 @@
     }
 
     // save as shapefile
-    QAction* saveShpAction = theMenu.addAction( tr( "Save as shapefile..." ), this, SLOT( saveAsShapefile() ) );
+    theMenu.addAction( tr( "Save as shapefile..." ), this, SLOT( saveAsShapefile() ) );
 
     // save selection as shapefile
     QAction* saveSelectionAction = theMenu.addAction( tr( "Save selection as shapefile..." ), this, SLOT( saveSelectionAsShapefile() ) );



More information about the QGIS-commit mailing list