[QGIS Commit] r9281 - trunk/qgis/src/core/renderer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Sep 7 11:20:14 EDT 2008


Author: mhugent
Date: 2008-09-07 11:20:14 -0400 (Sun, 07 Sep 2008)
New Revision: 9281

Modified:
   trunk/qgis/src/core/renderer/qgsgraduatedsymbolrenderer.cpp
   trunk/qgis/src/core/renderer/qgsrenderer.cpp
   trunk/qgis/src/core/renderer/qgsrenderer.h
   trunk/qgis/src/core/renderer/qgssinglesymbolrenderer.cpp
   trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp
Log:
Scale brush content for printing. Adresses ticket #454. Works for ps, but not for pdf output. A qt bug?

Modified: trunk/qgis/src/core/renderer/qgsgraduatedsymbolrenderer.cpp
===================================================================
--- trunk/qgis/src/core/renderer/qgsgraduatedsymbolrenderer.cpp	2008-09-07 12:42:26 UTC (rev 9280)
+++ trunk/qgis/src/core/renderer/qgsgraduatedsymbolrenderer.cpp	2008-09-07 15:20:14 UTC (rev 9281)
@@ -141,17 +141,28 @@
       QPen pen = theSymbol->pen();
       pen.setWidthF( widthScale * pen.widthF() );
       p->setPen( pen );
-      p->setBrush( theSymbol->brush() );
+
+      if(mVectorType == QGis::Polygon)
+	{
+	  QBrush brush = theSymbol->brush();
+	  scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
+	  p->setBrush(brush);
+	}
     }
     else
     {
       QPen pen = theSymbol->pen();
       pen.setColor( mSelectionColor );
       pen.setWidthF( widthScale * pen.widthF() );
-      QBrush brush = theSymbol->brush();
-      brush.setColor( mSelectionColor );
       p->setPen( pen );
-      p->setBrush( brush );
+
+      if(mVectorType == QGis::Polygon)
+	{
+	  QBrush brush = theSymbol->brush();
+	  scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
+	  brush.setColor( mSelectionColor );
+	  p->setBrush( brush );
+	}
     }
   }
 }

Modified: trunk/qgis/src/core/renderer/qgsrenderer.cpp
===================================================================
--- trunk/qgis/src/core/renderer/qgsrenderer.cpp	2008-09-07 12:42:26 UTC (rev 9280)
+++ trunk/qgis/src/core/renderer/qgsrenderer.cpp	2008-09-07 15:20:14 UTC (rev 9281)
@@ -17,7 +17,9 @@
  ***************************************************************************/
 #include "qgsrenderer.h"
 
+#include <QBrush>
 #include <QColor>
+#include <QMatrix>
 #include <QString>
 
 
@@ -48,3 +50,13 @@
       return false;
   }
 }
+
+void QgsRenderer::scaleBrush(QBrush& b, double rasterScaleFactor) const
+{
+  if(rasterScaleFactor != 1.0)
+    {
+      QMatrix m;
+      m.scale(1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor);
+      b.setMatrix(m);
+    }
+}

Modified: trunk/qgis/src/core/renderer/qgsrenderer.h
===================================================================
--- trunk/qgis/src/core/renderer/qgsrenderer.h	2008-09-07 12:42:26 UTC (rev 9280)
+++ trunk/qgis/src/core/renderer/qgsrenderer.h	2008-09-07 15:20:14 UTC (rev 9281)
@@ -30,6 +30,7 @@
 #include <QList>
 
 class QgsSymbol;
+class QBrush;
 
 typedef QList<int> QgsAttributeList;
 
@@ -93,6 +94,9 @@
 
     /**Layer type*/
     QGis::VectorType mVectorType;
+
+    /**Scales a brush to a given raster scale factor (e.g. for printing)*/
+    void scaleBrush(QBrush& b, double rasterScaleFactor) const;
 };
 
 #endif // QGSRENDERER_H

Modified: trunk/qgis/src/core/renderer/qgssinglesymbolrenderer.cpp
===================================================================
--- trunk/qgis/src/core/renderer/qgssinglesymbolrenderer.cpp	2008-09-07 12:42:26 UTC (rev 9280)
+++ trunk/qgis/src/core/renderer/qgssinglesymbolrenderer.cpp	2008-09-07 15:20:14 UTC (rev 9281)
@@ -125,7 +125,13 @@
       QPen pen = mSymbol->pen();
       pen.setWidthF( widthScale * pen.widthF() );
       p->setPen( pen );
-      p->setBrush( mSymbol->brush() );
+
+      if(mVectorType == QGis::Polygon)
+	{
+	  QBrush brush = mSymbol->brush();
+	  scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
+	  p->setBrush(brush);
+	}
     }
     else
     {
@@ -134,10 +140,15 @@
       // We set pen color in case it is an area with no brush (transparent).
       // Previously, this was only done for lines. Why?
       pen.setColor( mSelectionColor );
-      QBrush brush = mSymbol->brush();
-      brush.setColor( mSelectionColor );
       p->setPen( pen );
-      p->setBrush( brush );
+
+      if(mVectorType == QGis::Polygon)
+	{
+	  QBrush brush = mSymbol->brush();
+	  scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
+	  brush.setColor( mSelectionColor );
+	  p->setBrush( brush );
+	}
     }
   }
 }

Modified: trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp
===================================================================
--- trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp	2008-09-07 12:42:26 UTC (rev 9280)
+++ trunk/qgis/src/core/renderer/qgsuniquevaluerenderer.cpp	2008-09-07 15:20:14 UTC (rev 9281)
@@ -150,17 +150,26 @@
       QPen pen = symbol->pen();
       pen.setWidthF( widthScale * pen.widthF() );
       p->setPen( pen );
-      p->setBrush( symbol->brush() );
+      if(mVectorType == QGis::Polygon)
+	{
+	  QBrush brush = symbol->brush();
+	  scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
+	  p->setBrush(brush);
+	}
     }
     else
     {
       QPen pen = symbol->pen();
       pen.setWidthF( widthScale * pen.widthF() );
       pen.setColor( mSelectionColor );
-      QBrush brush = symbol->brush();
-      brush.setColor( mSelectionColor );
       p->setPen( pen );
-      p->setBrush( brush );
+      if(mVectorType == QGis::Polygon)
+	{
+	  QBrush brush = symbol->brush();
+	  scaleBrush(brush, rasterScaleFactor); //scale brush content for printout
+	  brush.setColor( mSelectionColor );
+	  p->setBrush( brush );
+	}
     }
   }
 }



More information about the QGIS-commit mailing list