[QGIS Commit] r10880 - trunk/qgis/src/core/composer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Wed Jun 3 09:23:36 EDT 2009


Author: mhugent
Date: 2009-06-03 09:23:36 -0400 (Wed, 03 Jun 2009)
New Revision: 10880

Modified:
   trunk/qgis/src/core/composer/qgscomposermap.cpp
   trunk/qgis/src/core/composer/qgscomposermap.h
Log:
Use QImage as composer map cache because rendering to QPixmap may be slow if antialiasing is turned on

Modified: trunk/qgis/src/core/composer/qgscomposermap.cpp
===================================================================
--- trunk/qgis/src/core/composer/qgscomposermap.cpp	2009-06-03 11:33:58 UTC (rev 10879)
+++ trunk/qgis/src/core/composer/qgscomposermap.cpp	2009-06-03 13:23:36 UTC (rev 10880)
@@ -160,17 +160,16 @@
     h = 5000;
   }
 
-  mCachePixmap = QPixmap( w, h );
+  mCacheImage = QImage( w, h,  QImage::Format_ARGB32);
+  mCacheImage.fill(brush().color().rgb()); //consider the item background brush
   double mapUnitsPerPixel = mExtent.width() / w;
 
   // WARNING: ymax in QgsMapToPixel is device height!!!
   QgsMapToPixel transform( mapUnitsPerPixel, h, mExtent.yMinimum(), mExtent.xMinimum() );
 
-  mCachePixmap.fill( QColor( 255, 255, 255 ) );
+  QPainter p( &mCacheImage );
 
-  QPainter p( &mCachePixmap );
-
-  draw( &p, mExtent, QSize( w, h ), mCachePixmap.logicalDpiX() );
+  draw( &p, mExtent, QSize( w, h ), mCacheImage.logicalDpiX() );
   p.end();
   mCacheUpdated = true;
 }
@@ -206,11 +205,11 @@
     //client functions
 
     // Scale so that the cache fills the map rectangle
-    double scale = 1.0 * QGraphicsRectItem::rect().width() / mCachePixmap.width();
+    double scale = 1.0 * QGraphicsRectItem::rect().width() / mCacheImage.width();
 
     painter->save();
     painter->scale( scale, scale );
-    painter->drawPixmap( mXOffset / scale, mYOffset / scale, mCachePixmap );
+    painter->drawImage( mXOffset / scale, mYOffset / scale, mCacheImage );
     painter->restore();
   }
   else if ( mComposition->plotStyle() == QgsComposition::Print ||

Modified: trunk/qgis/src/core/composer/qgscomposermap.h
===================================================================
--- trunk/qgis/src/core/composer/qgscomposermap.h	2009-06-03 11:33:58 UTC (rev 10879)
+++ trunk/qgis/src/core/composer/qgscomposermap.h	2009-06-03 13:23:36 UTC (rev 10880)
@@ -22,7 +22,6 @@
 #include "qgsrectangle.h"
 #include <QGraphicsRectItem>
 #include <QObject>
-#include <QPixmap>
 
 class QgsComposition;
 class QgsMapRenderer;
@@ -152,10 +151,7 @@
     QgsRectangle mExtent;
 
     // Cache used in composer preview
-    // NOTE:  QCanvasView is slow with bigger images but the spped does not decrease with image size.
-    //        It is very slow, with zoom in in QCanvasView, it seems, that QCanvas is stored as a big image
-    //        with resolution necessary for current zoom and so always a big image mus be redrawn.
-    QPixmap mCachePixmap;
+    QImage mCacheImage;
 
     // Is cache up to date
     bool mCacheUpdated;



More information about the QGIS-commit mailing list