Skip to content
Permalink
Browse files

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.
  • Loading branch information
Sandro Santilli
Sandro Santilli committed Dec 13, 2014
1 parent 90db597 commit 696738177f22f81883ee5338bc8a0f39722ab376
Showing with 15 additions and 18 deletions.
  1. +7 −1 src/gui/qgsmapcanvas.cpp
  2. +7 −3 src/gui/qgsmapcanvasitem.cpp
  3. +1 −14 src/gui/qgsmapcanvasmap.cpp
@@ -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 );
}

@@ -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()));
@@ -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

0 comments on commit 6967381

Please sign in to comment.
You can’t perform that action at this time.