Skip to content
Permalink
Browse files

Add rotation member to QgsMapCanvasMap, use for handling paint event

Fixes the regression with pre-rendering user feedback for
non-rotated maps. The glitch is still there for rotated maps
but that's not a regression.

See http://hub.qgis.org/issues/11811
  • Loading branch information
Sandro Santilli
Sandro Santilli committed Dec 13, 2014
1 parent fd15a16 commit 05d03066104e429d11e2cb08f8fe02d8b703cae6
Showing with 28 additions and 5 deletions.
  1. +1 −1 src/gui/qgsmapcanvas.cpp
  2. +23 −3 src/gui/qgsmapcanvasmap.cpp
  3. +4 −1 src/gui/qgsmapcanvasmap.h
@@ -724,7 +724,7 @@ void QgsMapCanvas::rendererJobFinished()
p.end();

QgsRectangle rect = mSettings.visibleExtent();
mMap->setContent( img, rect );
mMap->setContent( img, rect, mSettings.rotation() );
}

// now we are in a slot called from mJob - do not delete it immediately
@@ -23,7 +23,7 @@
#include <QPainter>

QgsMapCanvasMap::QgsMapCanvasMap( QgsMapCanvas* canvas )
: QgsMapCanvasItem( canvas )
: QgsMapCanvasItem( canvas ), mRotation(0.0)
{
setZValue( -10 );
}
@@ -32,8 +32,9 @@ QgsMapCanvasMap::~QgsMapCanvasMap()
{
}

void QgsMapCanvasMap::setContent( const QImage& image, const QgsRectangle& rect )
void QgsMapCanvasMap::setContent( const QImage& image, const QgsRectangle& rect, double rotation )
{
mRotation = rotation;
mImage = image;

// For true retro fans: this is approximately how the graphics looked like in 1990
@@ -47,9 +48,28 @@ void QgsMapCanvasMap::setContent( const QImage& image, const QgsRectangle& rect
void QgsMapCanvasMap::paint( QPainter* painter )
{
int w = qRound( boundingRect().width() ) - 2, h = qRound( boundingRect().height() ) - 2; // setRect() makes the size +2 :-(
int wi = mImage.width();
int hi = mImage.height();

double ar = h ? double(w)/h : 0.0; // aspect ratio of bounding rect
double ari = hi ? double(wi)/hi : 0.0; // aspect ratio of image
double ard = fabs(ari-ar); // aspect ratio difference

#if 0
QgsDebugMsg( QString( "XXXX img %1,%2 (%3) item %4,%5 (%6) ardiff %7" )
.arg( wi ).arg( hi ).arg( ari )
.arg( w ).arg( h ).arg( ar )
.arg ( ard )
);
#endif

if ( mImage.size() != QSize( w, h ) )
{
QgsDebugMsg( QString( "map paint DIFFERENT SIZE: img %1,%2 item %3,%4" ).arg( mImage.width() ).arg( mImage.height() ).arg( w ).arg( h ) );
QgsDebugMsg( QString( "map paint DIFFERENT SIZE: img %1,%2 item %3,%4" ).arg( wi ).arg( hi ).arg( w ).arg( h ) );
}

if ( mRotation )
{
int tX = ( w - mImage.width() ) / 2.0;
int tY = ( h - mImage.height() ) / 2.0;
int fX = 0;
@@ -41,7 +41,8 @@ class GUI_EXPORT QgsMapCanvasMap : public QgsMapCanvasItem // public QObject, p
~QgsMapCanvasMap();

//! @note added in 2.4
void setContent( const QImage& image, const QgsRectangle& rect );
//! @note rotation parameter added in 2.8
void setContent( const QImage& image, const QgsRectangle& rect, double rotation=0.0 );

//! @note added in 2.4
QImage contentImage() const { return mImage; }
@@ -75,6 +76,8 @@ class GUI_EXPORT QgsMapCanvasMap : public QgsMapCanvasItem // public QObject, p
private:

QImage mImage;

double mRotation;
};

#endif

0 comments on commit 05d0306

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