Skip to content

Commit d4e1c62

Browse files
author
wonder
committed
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
1 parent c4f55e6 commit d4e1c62

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

python/gui/qgsmapcanvasmap.sip

+4
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,9 @@ class QgsMapCanvasMap : QGraphicsRectItem
4848

4949
QRectF boundingRect() const;
5050

51+
//! Update contents - can be called while drawing to show the status.
52+
//! Added in version 1.2
53+
void updateContents();
54+
5155
};
5256

src/gui/qgsmapcanvas.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ void QgsMapCanvas::updateMap()
391391
{
392392
if ( mMap )
393393
{
394-
mMap->update();
394+
mMap->updateContents();
395395
}
396396
}
397397

src/gui/qgsmapcanvasmap.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ QgsMapCanvasMap::QgsMapCanvasMap( QgsMapCanvas* canvas )
3333
void QgsMapCanvasMap::paint( QPainter* p, const QStyleOptionGraphicsItem*, QWidget* )
3434
{
3535
//refreshes the canvas map with the current offscreen image
36-
if ( mUseQImageToRender )
37-
{
38-
mPixmap = QPixmap::fromImage( mImage );
39-
}
4036
p->drawPixmap( 0, 0, mPixmap );
4137
}
4238

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

72+
// clear the pixmap so that old map won't be displayed while rendering
73+
// TODO: do the canvas updates wisely -> this wouldn't be needed
74+
mPixmap = QPixmap(mImage.size());
75+
mPixmap.fill( mBgColor.rgb() );
76+
7677
QPainter paint;
7778
paint.begin( &mImage );
7879
// Clip drawing to the QImage
@@ -87,7 +88,7 @@ void QgsMapCanvasMap::render()
8788
paint.end();
8889

8990
// convert QImage to QPixmap to acheive faster drawing on screen
90-
//mPixmap = QPixmap::fromImage(image);
91+
mPixmap = QPixmap::fromImage(mImage);
9192
}
9293
else
9394
{
@@ -113,3 +114,13 @@ QPaintDevice& QgsMapCanvasMap::paintDevice()
113114
return mPixmap;
114115
}
115116
}
117+
118+
void QgsMapCanvasMap::updateContents()
119+
{
120+
// make sure we're using current contents
121+
if ( mUseQImageToRender )
122+
mPixmap = QPixmap::fromImage(mImage);
123+
124+
// trigger update of this item
125+
update();
126+
}

src/gui/qgsmapcanvasmap.h

+3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class GUI_EXPORT QgsMapCanvasMap : public QGraphicsRectItem
5858

5959
QRectF boundingRect() const;
6060

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

6265
private:
6366

0 commit comments

Comments
 (0)