Skip to content

Commit

Permalink
Always use QPixmap when drawing the map in canvas.
Browse files Browse the repository at this point in the history
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@10926 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jun 14, 2009
1 parent 6e1f579 commit a4ac4f8
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 a4ac4f8

Please sign in to comment.