Skip to content

Commit 556210b

Browse files
committed
avoid scaling in painting when possible
not sure how it works internally in Qt, but no need to call epxlicitely on scaling since the image device pixel ratio is set
1 parent ea982fe commit 556210b

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/gui/qgsmapcanvasmap.cpp

+15-9
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,20 @@ QRectF QgsMapCanvasMap::boundingRect() const
6060

6161
void QgsMapCanvasMap::paint( QPainter *painter )
6262
{
63-
int w = std::round( mItemSize.width() ) - 2, h = std::round( mItemSize.height() ) - 2; // setRect() makes the size +2 :-(
64-
if ( mImage.size() != QSize( w, h ) )
63+
// setRect() makes the size +2 :-(
64+
int w = std::round( mItemSize.width() ) - 2;
65+
int h = std::round( mItemSize.height() ) - 2;
66+
67+
bool scale = false;
68+
if ( mImage.size() != QSize( w, h )*mImage.devicePixelRatioF() )
6569
{
66-
QgsDebugMsg( QStringLiteral( "map paint DIFFERENT SIZE: img %1,%2 item %3,%4" ).arg( mImage.width() ).arg( mImage.height() ).arg( w ).arg( h ) );
70+
QgsDebugMsg( QStringLiteral( "map paint DIFFERENT SIZE: img %1,%2 item %3,%4" )
71+
.arg( mImage.width() / mImage.devicePixelRatioF() )
72+
.arg( mImage.height() / mImage.devicePixelRatioF() )
73+
.arg( w ).arg( h ) );
6774
// This happens on zoom events when ::paint is called before
6875
// the renderer has completed
76+
scale = true;
6977
}
7078

7179
/*Offset between 0/0 and mRect.xMinimum/mRect.yMinimum.
@@ -83,12 +91,10 @@ void QgsMapCanvasMap::paint( QPainter *painter )
8391
painter->drawImage( QRectF( ul.x(), ul.y(), lr.x() - ul.x(), lr.y() - ul.y() ), imIt->first, QRect( 0, 0, imIt->first.width(), imIt->first.height() ) );
8492
}
8593

86-
qDebug() << "map painter: " << w << h << mImage.size() << mImage.devicePixelRatioF();
87-
painter->drawImage( QRect( 0, 0, w, h ), mImage );
88-
//Q_ASSERT(mImage.isNull() || mImage.devicePixelRatio()==2);
89-
//QImage img = mImage;
90-
//img.setDevicePixelRatio(2);
91-
//painter->drawImage( 0,0, img );
94+
if ( scale )
95+
painter->drawImage( QRect( 0, 0, w, h ), mImage );
96+
else
97+
painter->drawImage( 0, 0, mImage );
9298

9399
// For debugging:
94100
#if 0

0 commit comments

Comments
 (0)