Skip to content

Commit 6967381

Browse files
author
Sandro Santilli
committed
Drop special handling of rotation from MapCanvasMap::paint
Stop assuming absence of rotation from MapCanvasItem::setRect, but rather assume that the passed rectangle purely encodes origin and size by only looking at upperLeft corner (xmin,ymax) and width/height of it, scaled by current map resolution. Makes the code simpler (maybe) and still fixes the regression. Also fixes glitches on zoom while map is rotated. Makes glitches on rotation worst, but again that's not a real regression.
1 parent 90db597 commit 6967381

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

src/gui/qgsmapcanvas.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,13 @@ void QgsMapCanvas::rendererJobFinished()
723723

724724
p.end();
725725

726-
QgsRectangle rect = mSettings.visibleExtent();
726+
// This is an hack to pass QgsMapCanvasItem::setRect what it
727+
// expects (encoding of position and size of the item)
728+
const QgsMapToPixel& m2p = mSettings.mapToPixel();
729+
QgsPoint topLeft = m2p.toMapPoint(0,0);
730+
double res = m2p.mapUnitsPerPixel();
731+
QgsRectangle rect(topLeft.x(), topLeft.y(), topLeft.x() + img.width()*res, topLeft.y() - img.height()*res);
732+
727733
mMap->setContent( img, rect );
728734
}
729735

src/gui/qgsmapcanvasitem.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,17 @@ void QgsMapCanvasItem::setRect( const QgsRectangle& rect )
9696
QRectF r; // empty rect by default
9797
if ( !mRect.isEmpty() )
9898
{
99-
r = toCanvasCoordinates( mRect.toRectF() );
100-
r = r.normalized();
99+
// rect encodes origin of the item (xMin,yMax from map to canvas units)
100+
// and size (rect size / map units per pixel)
101+
r.setTopLeft( toCanvasCoordinates( QPointF(mRect.xMinimum(), mRect.yMaximum()) ) );
102+
const QgsMapToPixel* m2p = mMapCanvas->getCoordinateTransform();
103+
double res = m2p->mapUnitsPerPixel();
104+
r.setSize( QSizeF(mRect.width()/res, mRect.height()/res) );
101105
}
102106

103107
// set position in canvas where the item will have coordinate (0,0)
104108
prepareGeometryChange();
105-
setPos( r.topLeft() ); // TODO: compute from (0,0) using toMapCoordinates ?
109+
setPos( r.topLeft() );
106110
mItemSize = QSizeF( r.width() + 2, r.height() + 2 );
107111

108112
// QgsDebugMsg(QString("[%1,%2]-[%3x%4]").arg((int) r.left()).arg((int) r.top()).arg((int) r.width()).arg((int) r.height()));

src/gui/qgsmapcanvasmap.cpp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,7 @@ void QgsMapCanvasMap::paint( QPainter* painter )
5252
QgsDebugMsg( QString( "map paint DIFFERENT SIZE: img %1,%2 item %3,%4" ).arg( mImage.width() ).arg( mImage.height() ).arg( w ).arg( h ) );
5353
}
5454

55-
if ( mMapCanvas->getCoordinateTransform()->mapRotation() )
56-
{
57-
int tX = ( w - mImage.width() ) / 2.0;
58-
int tY = ( h - mImage.height() ) / 2.0;
59-
int fX = 0;
60-
int fY = 0;
61-
int fW = w;
62-
int fH = h;
63-
painter->drawImage( tX, tY, mImage, fX, fY, fW, fH );
64-
}
65-
else
66-
{
67-
painter->drawImage( QRect( 0, 0, w, h ), mImage );
68-
}
55+
painter->drawImage( QRect( 0, 0, w, h ), mImage );
6956

7057
// For debugging:
7158
#if 0

0 commit comments

Comments
 (0)