Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 committed Jun 14, 2009
1 parent c4f55e6 commit d4e1c62
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
4 changes: 4 additions & 0 deletions python/gui/qgsmapcanvasmap.sip
Expand Up @@ -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();

};

2 changes: 1 addition & 1 deletion src/gui/qgsmapcanvas.cpp
Expand Up @@ -391,7 +391,7 @@ void QgsMapCanvas::updateMap()
{
if ( mMap )
{
mMap->update();
mMap->updateContents();
}
}

Expand Down
21 changes: 16 additions & 5 deletions src/gui/qgsmapcanvasmap.cpp
Expand Up @@ -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 );
}

Expand Down Expand Up @@ -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
Expand All @@ -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
{
Expand All @@ -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();
}
3 changes: 3 additions & 0 deletions src/gui/qgsmapcanvasmap.h
Expand Up @@ -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:

Expand Down

0 comments on commit d4e1c62

Please sign in to comment.