Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mhugent committed Jun 3, 2009
1 parent c3bf9d9 commit d51e423
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
13 changes: 6 additions & 7 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 ||
Expand Down
6 changes: 1 addition & 5 deletions src/core/composer/qgscomposermap.h
Expand Up @@ -22,7 +22,6 @@
#include "qgsrectangle.h"
#include <QGraphicsRectItem>
#include <QObject>
#include <QPixmap>

class QgsComposition;
class QgsMapRenderer;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d51e423

Please sign in to comment.