Skip to content

Commit

Permalink
Drop special handling of rotation from MapCanvasMap::paint
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Sandro Santilli committed Dec 13, 2014
1 parent 90db597 commit 6967381
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
8 changes: 7 additions & 1 deletion src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,13 @@ void QgsMapCanvas::rendererJobFinished()

p.end();

QgsRectangle rect = mSettings.visibleExtent();
// This is an hack to pass QgsMapCanvasItem::setRect what it
// expects (encoding of position and size of the item)
const QgsMapToPixel& m2p = mSettings.mapToPixel();
QgsPoint topLeft = m2p.toMapPoint(0,0);
double res = m2p.mapUnitsPerPixel();
QgsRectangle rect(topLeft.x(), topLeft.y(), topLeft.x() + img.width()*res, topLeft.y() - img.height()*res);

mMap->setContent( img, rect );
}

Expand Down
10 changes: 7 additions & 3 deletions src/gui/qgsmapcanvasitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,17 @@ void QgsMapCanvasItem::setRect( const QgsRectangle& rect )
QRectF r; // empty rect by default
if ( !mRect.isEmpty() )
{
r = toCanvasCoordinates( mRect.toRectF() );
r = r.normalized();
// rect encodes origin of the item (xMin,yMax from map to canvas units)
// and size (rect size / map units per pixel)
r.setTopLeft( toCanvasCoordinates( QPointF(mRect.xMinimum(), mRect.yMaximum()) ) );
const QgsMapToPixel* m2p = mMapCanvas->getCoordinateTransform();
double res = m2p->mapUnitsPerPixel();
r.setSize( QSizeF(mRect.width()/res, mRect.height()/res) );
}

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

// QgsDebugMsg(QString("[%1,%2]-[%3x%4]").arg((int) r.left()).arg((int) r.top()).arg((int) r.width()).arg((int) r.height()));
Expand Down
15 changes: 1 addition & 14 deletions src/gui/qgsmapcanvasmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,7 @@ void QgsMapCanvasMap::paint( QPainter* painter )
QgsDebugMsg( QString( "map paint DIFFERENT SIZE: img %1,%2 item %3,%4" ).arg( mImage.width() ).arg( mImage.height() ).arg( w ).arg( h ) );
}

if ( mMapCanvas->getCoordinateTransform()->mapRotation() )
{
int tX = ( w - mImage.width() ) / 2.0;
int tY = ( h - mImage.height() ) / 2.0;
int fX = 0;
int fY = 0;
int fW = w;
int fH = h;
painter->drawImage( tX, tY, mImage, fX, fY, fW, fH );
}
else
{
painter->drawImage( QRect( 0, 0, w, h ), mImage );
}
painter->drawImage( QRect( 0, 0, w, h ), mImage );

// For debugging:
#if 0
Expand Down

0 comments on commit 6967381

Please sign in to comment.