[QGIS Commit] r11115 - in branches/symbology-ng-branch/src/app: . legend

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Jul 20 10:53:16 EDT 2009


Author: wonder
Date: 2009-07-20 10:53:15 -0400 (Mon, 20 Jul 2009)
New Revision: 11115

Modified:
   branches/symbology-ng-branch/src/app/legend/qgslegendlayer.cpp
   branches/symbology-ng-branch/src/app/legend/qgslegendlayer.h
   branches/symbology-ng-branch/src/app/qgisapp.cpp
Log:
show symbols from rendererV2 in legend


Modified: branches/symbology-ng-branch/src/app/legend/qgslegendlayer.cpp
===================================================================
--- branches/symbology-ng-branch/src/app/legend/qgslegendlayer.cpp	2009-07-20 14:02:24 UTC (rev 11114)
+++ branches/symbology-ng-branch/src/app/legend/qgslegendlayer.cpp	2009-07-20 14:53:15 UTC (rev 11115)
@@ -36,6 +36,9 @@
 #include "qgsvectorlayer.h"
 #include "qgsvectordataprovider.h"
 
+#include "qgsrendererv2.h"
+#include "qgssymbolv2.h"
+
 #include <iostream>
 #include <QAction>
 #include <QCoreApplication>
@@ -271,7 +274,10 @@
   if ( theMapLayer->type() == QgsMapLayer::VectorLayer ) // VECTOR
   {
     QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( theMapLayer );
-    vectorLayerSymbology( vlayer, widthScale ); // get and change symbology
+    if ( vlayer->isUsingRendererV2() )
+      vectorLayerSymbologyV2( vlayer );
+    else
+      vectorLayerSymbology( vlayer, widthScale ); // get and change symbology
   }
   else // RASTER
   {
@@ -388,6 +394,83 @@
   changeSymbologySettings( layer, itemList );
 }
 
+static QPixmap _symbolPreviewPixmap(QgsSymbolV2* sym, QSize iconSize)
+{
+  QPainter p;
+  QPixmap pix(iconSize);
+  pix.fill(Qt::white);
+  p.begin(&pix);
+  sym->drawPreviewIcon(&p, iconSize);
+  p.end();
+  return pix;
+}
+
+void QgsLegendLayer::vectorLayerSymbologyV2( QgsVectorLayer* layer )
+{
+  SymbologyList itemList;
+
+  QSize iconSize(16,16);
+
+  QSettings settings;
+  bool showClassifiers = settings.value( "/qgis/showLegendClassifiers", false ).toBool();
+
+  QgsFeatureRendererV2* renderer = layer->rendererV2();
+  switch (renderer->type())
+  {
+    case QgsFeatureRendererV2::RendererSingleSymbol:
+      {
+        QgsSingleSymbolRendererV2* r = static_cast<QgsSingleSymbolRendererV2*>(renderer);
+        QPixmap pix = _symbolPreviewPixmap(r->symbol(), iconSize);
+
+        itemList.push_back( std::make_pair( "", pix ) );
+      }
+      break;
+    case QgsFeatureRendererV2::RendererCategorizedSymbol:
+      {
+        QgsCategorizedSymbolRendererV2* r = static_cast<QgsCategorizedSymbolRendererV2*>(renderer);
+        if (showClassifiers)
+        {
+          const QgsFieldMap& fields = layer->dataProvider()->fields();
+          QString fieldName = fields[r->attributeIndex()].name();
+          itemList.push_back( std::make_pair( fieldName, QPixmap() ) );
+        }
+
+        int count = r->categories().count();
+        for (int i = 0; i < count; i++)
+        {
+          const QgsRendererCategoryV2& cat = r->categories()[i];
+          QPixmap pix = _symbolPreviewPixmap( cat.symbol(), iconSize );
+          itemList.push_back( std::make_pair( cat.label(), pix ) );
+        }
+      }
+      break;
+    case QgsFeatureRendererV2::RendererGraduatedSymbol:
+      {
+        QgsGraduatedSymbolRendererV2* r = static_cast<QgsGraduatedSymbolRendererV2*>(renderer);
+        if (showClassifiers)
+        {
+          const QgsFieldMap& fields = layer->dataProvider()->fields();
+          QString fieldName = fields[r->attributeIndex()].name();
+          itemList.push_back( std::make_pair( fieldName, QPixmap() ) );
+        }
+
+        int count = r->ranges().count();
+        for (int i = 0; i < count; i++)
+        {
+          const QgsRendererRangeV2& range = r->ranges()[i];
+          QPixmap pix = _symbolPreviewPixmap( range.symbol(), iconSize );
+          itemList.push_back( std::make_pair( range.label(), pix ) );
+        }
+      }
+      break;
+    default:
+      // nothing for unknown renderers
+      break;
+  }
+
+  changeSymbologySettings( layer, itemList );
+}
+
 void QgsLegendLayer::rasterLayerSymbology( QgsRasterLayer* layer )
 {
   SymbologyList itemList;

Modified: branches/symbology-ng-branch/src/app/legend/qgslegendlayer.h
===================================================================
--- branches/symbology-ng-branch/src/app/legend/qgslegendlayer.h	2009-07-20 14:02:24 UTC (rev 11114)
+++ branches/symbology-ng-branch/src/app/legend/qgslegendlayer.h	2009-07-20 14:53:15 UTC (rev 11115)
@@ -96,6 +96,8 @@
     /** Prepare and change symbology for vector layer */
     void vectorLayerSymbology( const QgsVectorLayer* mapLayer, double widthScale = 1.0 );
 
+    void vectorLayerSymbologyV2( QgsVectorLayer* vlayer );
+
     /** Prepare and change symbology for raster layer */
     void rasterLayerSymbology( QgsRasterLayer* mapLayer );
 

Modified: branches/symbology-ng-branch/src/app/qgisapp.cpp
===================================================================
--- branches/symbology-ng-branch/src/app/qgisapp.cpp	2009-07-20 14:02:24 UTC (rev 11114)
+++ branches/symbology-ng-branch/src/app/qgisapp.cpp	2009-07-20 14:53:15 UTC (rev 11115)
@@ -1045,6 +1045,8 @@
   if (!dlg.exec())
     return;
   
+  mMapLegend->refreshLayerSymbology( vlayer->getLayerID(), false );
+
   refreshMapCanvas();
 }
 



More information about the QGIS-commit mailing list