Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
3nids committed Oct 19, 2018
1 parent ea982fe commit 556210b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/gui/qgsmapcanvasmap.cpp
Expand Up @@ -60,12 +60,20 @@ QRectF QgsMapCanvasMap::boundingRect() const

void QgsMapCanvasMap::paint( QPainter *painter )
{
int w = std::round( mItemSize.width() ) - 2, h = std::round( mItemSize.height() ) - 2; // setRect() makes the size +2 :-(
if ( mImage.size() != QSize( w, h ) )
// setRect() makes the size +2 :-(
int w = std::round( mItemSize.width() ) - 2;
int h = std::round( mItemSize.height() ) - 2;

bool scale = false;
if ( mImage.size() != QSize( w, h )*mImage.devicePixelRatioF() )
{
QgsDebugMsg( QStringLiteral( "map paint DIFFERENT SIZE: img %1,%2 item %3,%4" ).arg( mImage.width() ).arg( mImage.height() ).arg( w ).arg( h ) );
QgsDebugMsg( QStringLiteral( "map paint DIFFERENT SIZE: img %1,%2 item %3,%4" )
.arg( mImage.width() / mImage.devicePixelRatioF() )
.arg( mImage.height() / mImage.devicePixelRatioF() )
.arg( w ).arg( h ) );
// This happens on zoom events when ::paint is called before
// the renderer has completed
scale = true;
}

/*Offset between 0/0 and mRect.xMinimum/mRect.yMinimum.
Expand All @@ -83,12 +91,10 @@ void QgsMapCanvasMap::paint( QPainter *painter )
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() ) );
}

qDebug() << "map painter: " << w << h << mImage.size() << mImage.devicePixelRatioF();
painter->drawImage( QRect( 0, 0, w, h ), mImage );
//Q_ASSERT(mImage.isNull() || mImage.devicePixelRatio()==2);
//QImage img = mImage;
//img.setDevicePixelRatio(2);
//painter->drawImage( 0,0, img );
if ( scale )
painter->drawImage( QRect( 0, 0, w, h ), mImage );
else
painter->drawImage( 0, 0, mImage );

// For debugging:
#if 0
Expand Down

0 comments on commit 556210b

Please sign in to comment.