Skip to content
Permalink
Browse files

Always use QPixmap when drawing the map in canvas.

This results in faster updates of canvas when rendered map is QImage - e.g. when panning / updating rubber bands.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10926 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder
wonder committed Jun 14, 2009
1 parent c4f55e6 commit d4e1c6206a5cb4d7d7b7648d859b3ab2c1a8d331
Showing with 24 additions and 6 deletions.
  1. +4 −0 python/gui/qgsmapcanvasmap.sip
  2. +1 −1 src/gui/qgsmapcanvas.cpp
  3. +16 −5 src/gui/qgsmapcanvasmap.cpp
  4. +3 −0 src/gui/qgsmapcanvasmap.h
@@ -48,5 +48,9 @@ class QgsMapCanvasMap : QGraphicsRectItem

QRectF boundingRect() const;

//! Update contents - can be called while drawing to show the status.
//! Added in version 1.2
void updateContents();

};

@@ -391,7 +391,7 @@ void QgsMapCanvas::updateMap()
{
if ( mMap )
{
mMap->update();
mMap->updateContents();
}
}

@@ -33,10 +33,6 @@ QgsMapCanvasMap::QgsMapCanvasMap( QgsMapCanvas* canvas )
void QgsMapCanvasMap::paint( QPainter* p, const QStyleOptionGraphicsItem*, QWidget* )
{
//refreshes the canvas map with the current offscreen image
if ( mUseQImageToRender )
{
mPixmap = QPixmap::fromImage( mImage );
}
p->drawPixmap( 0, 0, mPixmap );
}

@@ -73,6 +69,11 @@ void QgsMapCanvasMap::render()
// use temporary image for rendering
mImage.fill( mBgColor.rgb() );

// clear the pixmap so that old map won't be displayed while rendering
// TODO: do the canvas updates wisely -> this wouldn't be needed
mPixmap = QPixmap(mImage.size());
mPixmap.fill( mBgColor.rgb() );

QPainter paint;
paint.begin( &mImage );
// Clip drawing to the QImage
@@ -87,7 +88,7 @@ void QgsMapCanvasMap::render()
paint.end();

// convert QImage to QPixmap to acheive faster drawing on screen
//mPixmap = QPixmap::fromImage(image);
mPixmap = QPixmap::fromImage(mImage);
}
else
{
@@ -113,3 +114,13 @@ QPaintDevice& QgsMapCanvasMap::paintDevice()
return mPixmap;
}
}

void QgsMapCanvasMap::updateContents()
{
// make sure we're using current contents
if ( mUseQImageToRender )
mPixmap = QPixmap::fromImage(mImage);

// trigger update of this item
update();
}
@@ -58,6 +58,9 @@ class GUI_EXPORT QgsMapCanvasMap : public QGraphicsRectItem

QRectF boundingRect() const;

//! Update contents - can be called while drawing to show the status.
//! Added in version 1.2
void updateContents();

private:

0 comments on commit d4e1c62

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