Skip to content

Commit d51e423

Browse files
author
mhugent
committed
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/qgis@10880 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c3bf9d9 commit d51e423

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/core/composer/qgscomposermap.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,16 @@ void QgsComposerMap::cache( void )
160160
h = 5000;
161161
}
162162

163-
mCachePixmap = QPixmap( w, h );
163+
mCacheImage = QImage( w, h, QImage::Format_ARGB32);
164+
mCacheImage.fill(brush().color().rgb()); //consider the item background brush
164165
double mapUnitsPerPixel = mExtent.width() / w;
165166

166167
// WARNING: ymax in QgsMapToPixel is device height!!!
167168
QgsMapToPixel transform( mapUnitsPerPixel, h, mExtent.yMinimum(), mExtent.xMinimum() );
168169

169-
mCachePixmap.fill( QColor( 255, 255, 255 ) );
170+
QPainter p( &mCacheImage );
170171

171-
QPainter p( &mCachePixmap );
172-
173-
draw( &p, mExtent, QSize( w, h ), mCachePixmap.logicalDpiX() );
172+
draw( &p, mExtent, QSize( w, h ), mCacheImage.logicalDpiX() );
174173
p.end();
175174
mCacheUpdated = true;
176175
}
@@ -206,11 +205,11 @@ void QgsComposerMap::paint( QPainter* painter, const QStyleOptionGraphicsItem* i
206205
//client functions
207206

208207
// Scale so that the cache fills the map rectangle
209-
double scale = 1.0 * QGraphicsRectItem::rect().width() / mCachePixmap.width();
208+
double scale = 1.0 * QGraphicsRectItem::rect().width() / mCacheImage.width();
210209

211210
painter->save();
212211
painter->scale( scale, scale );
213-
painter->drawPixmap( mXOffset / scale, mYOffset / scale, mCachePixmap );
212+
painter->drawImage( mXOffset / scale, mYOffset / scale, mCacheImage );
214213
painter->restore();
215214
}
216215
else if ( mComposition->plotStyle() == QgsComposition::Print ||

src/core/composer/qgscomposermap.h

+1-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "qgsrectangle.h"
2323
#include <QGraphicsRectItem>
2424
#include <QObject>
25-
#include <QPixmap>
2625

2726
class QgsComposition;
2827
class QgsMapRenderer;
@@ -152,10 +151,7 @@ class CORE_EXPORT QgsComposerMap : /*public QWidget, private Ui::QgsComposerMapB
152151
QgsRectangle mExtent;
153152

154153
// Cache used in composer preview
155-
// NOTE: QCanvasView is slow with bigger images but the spped does not decrease with image size.
156-
// It is very slow, with zoom in in QCanvasView, it seems, that QCanvas is stored as a big image
157-
// with resolution necessary for current zoom and so always a big image mus be redrawn.
158-
QPixmap mCachePixmap;
154+
QImage mCacheImage;
159155

160156
// Is cache up to date
161157
bool mCacheUpdated;

0 commit comments

Comments
 (0)