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

svn_qgis at osgeo.org svn_qgis at osgeo.org
Tue Jun 9 18:28:08 EDT 2009


Author: wonder
Date: 2009-06-09 18:28:08 -0400 (Tue, 09 Jun 2009)
New Revision: 10895

Modified:
   trunk/qgis/src/app/legend/qgslegend.cpp
   trunk/qgis/src/app/legend/qgslegendlayer.cpp
   trunk/qgis/src/app/legend/qgslegendlayer.h
Log:
Change layer's icon in legend to reflext that the layer is editable.

Removed duplicate function.


Modified: trunk/qgis/src/app/legend/qgslegend.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegend.cpp	2009-06-09 12:38:11 UTC (rev 10894)
+++ trunk/qgis/src/app/legend/qgslegend.cpp	2009-06-09 22:28:08 UTC (rev 10895)
@@ -506,7 +506,7 @@
   QgsLegendLayer * llayer = new QgsLegendLayer( layer->name() );//generate entry for mStateOfCheckBoxes below
   QgsLegendLayerFileGroup * llfgroup = new QgsLegendLayerFileGroup( llayer, QString( "Files" ) );
   QgsLegendLayerFile * llfile = new QgsLegendLayerFile( llfgroup, QgsLegendLayerFile::nameFromLayer( layer ), layer );
-  llayer->setLayerTypeIcon();
+  llayer->updateIcon();
   llayer->setToolTip( 0, layer->publicSource() );
 
   //set the correct check states
@@ -547,6 +547,10 @@
   setCurrentItem( llayer );
   //make the QTreeWidget item up-to-date
   doItemsLayout();
+
+  // setup connections that will update the layer icons
+  connect(layer, SIGNAL(editingStarted()), llayer, SLOT(updateIcon()));
+  connect(layer, SIGNAL(editingStopped()), llayer, SLOT(updateIcon()));
 }
 
 QgsLegendLayerFile* QgsLegend::currentLayerFile()
@@ -1086,7 +1090,7 @@
           //set the layer type icon if this legendlayerfile is the last in the file group
           if ( child.nextSibling().isNull() )
           {
-            static_cast<QgsLegendLayer*>( theLegendLayerFile->parent()->parent() )->setLayerTypeIcon();
+            static_cast<QgsLegendLayer*>( theLegendLayerFile->parent()->parent() )->updateIcon();
           }
 
           theLegendLayerFile->updateLegendItem();

Modified: trunk/qgis/src/app/legend/qgslegendlayer.cpp
===================================================================
--- trunk/qgis/src/app/legend/qgslegendlayer.cpp	2009-06-09 12:38:11 UTC (rev 10894)
+++ trunk/qgis/src/app/legend/qgslegendlayer.cpp	2009-06-09 22:28:08 UTC (rev 10895)
@@ -84,11 +84,6 @@
   myFont.setBold( true ); //visually differentiate layer labels from the rest
   setFont( 0, myFont );
 }
-void QgsLegendLayer::setLayerTypeIcon()
-{
-  QIcon myIcon( getOriginalPixmap() );
-  setIcon( 0, myIcon );
-}
 
 bool QgsLegendLayer::isLeafNode()
 {
@@ -407,23 +402,28 @@
   if ( mapLayers().size() == 1 )
   {
     //overview
+    // FIXME: overview icon is missing
+    /*
     if ( theFile->isInOverview() )
     {
       // Overlay the overview icon on the default icon
-      QPixmap myPixmap = QgisApp::getThemePixmap( + "mIconOverview.png" );
+      QPixmap myPixmap = QgisApp::getThemePixmap(  "/mIconOverview.png" );
       QPainter p( &newIcon );
       p.drawPixmap( 0, 0, myPixmap );
       p.end();
-    }
+    }*/
 
     //editable
     if ( theLayer->isEditable() )
     {
+      QPixmap myPixmap = QgisApp::getThemePixmap( "/mIconEditable.png" );
+      // use editable icon instead of the layer's type icon
+      newIcon = myPixmap;
+
       // Overlay the editable icon on the default icon
-      QPixmap myPixmap = QgisApp::getThemePixmap( + "mIconEditable.png" );
-      QPainter p( &newIcon );
+      /*QPainter p( &newIcon );
       p.drawPixmap( 0, 0, myPixmap );
-      p.end();
+      p.end();*/
     }
   }
 

Modified: trunk/qgis/src/app/legend/qgslegendlayer.h
===================================================================
--- trunk/qgis/src/app/legend/qgslegendlayer.h	2009-06-09 12:38:11 UTC (rev 10894)
+++ trunk/qgis/src/app/legend/qgslegendlayer.h	2009-06-09 22:28:08 UTC (rev 10895)
@@ -49,9 +49,7 @@
     QgsLegendLayer( QTreeWidget*, QString );
     QgsLegendLayer( QString name );
     ~QgsLegendLayer();
-    /**Sets an icon characterising the type of layer(s) it contains.
-     Note: cannot be in the constructor because layers are added after creation*/
-    void setLayerTypeIcon();
+
     bool isLeafNode();
     QgsLegendItem::DRAG_ACTION accept( LEGEND_ITEM_TYPE type );
     QgsLegendItem::DRAG_ACTION accept( const QgsLegendItem* li ) const;
@@ -70,10 +68,6 @@
     /**Updates symbology of the layer and copies symbology to other layer files in the group*/
     void refreshSymbology( const QString& key, double widthScale = 1.0 );
 
-    /**Goes through all the legendlayerfiles and adds editing/overview pixmaps to the icon. If not all layer files
-    have the same editing/overview state, a tristate is applied*/
-    void updateIcon();
-
     /** called to add appropriate menu items to legend's popup menu */
     void addToPopupMenu( QMenu& theMenu, QAction* toggleEditingAction );
 
@@ -91,6 +85,10 @@
     void saveAsShapefile();
     void saveSelectionAsShapefile();
 
+    /**Goes through all the legendlayerfiles and adds editing/overview pixmaps to the icon. If not all layer files
+    have the same editing/overview state, a tristate is applied*/
+    void updateIcon();
+
   protected:
 
     /** Prepare and change symbology for vector layer */



More information about the QGIS-commit mailing list