Skip to content
Permalink
Browse files

Use QImage as composer map cache because rendering to QPixmap may be …

…slow if antialiasing is turned on

git-svn-id: http://svn.osgeo.org/qgis/trunk@10880 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Jun 3, 2009
1 parent dbaf7bd commit 10bd2df721c6c0d5ef7e8abc5f14e80b1286f184
Showing with 7 additions and 12 deletions.
  1. +6 −7 src/core/composer/qgscomposermap.cpp
  2. +1 −5 src/core/composer/qgscomposermap.h
@@ -160,17 +160,16 @@ void QgsComposerMap::cache( void )
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 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
//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 ||
@@ -22,7 +22,6 @@
#include "qgsrectangle.h"
#include <QGraphicsRectItem>
#include <QObject>
#include <QPixmap>

class QgsComposition;
class QgsMapRenderer;
@@ -152,10 +151,7 @@ class CORE_EXPORT QgsComposerMap : /*public QWidget, private Ui::QgsComposerMapB
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;

0 comments on commit 10bd2df

Please sign in to comment.
You can’t perform that action at this time.