Skip to content

Commit

Permalink
Add rotation member to QgsMapCanvasMap, use for handling paint event
Browse files Browse the repository at this point in the history
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 committed Dec 13, 2014
1 parent fd15a16 commit 05d0306
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/gui/qgsmapcanvas.cpp
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions src/gui/qgsmapcanvasmap.cpp
Expand Up @@ -23,7 +23,7 @@
#include <QPainter>

QgsMapCanvasMap::QgsMapCanvasMap( QgsMapCanvas* canvas )
: QgsMapCanvasItem( canvas )
: QgsMapCanvasItem( canvas ), mRotation(0.0)
{
setZValue( -10 );
}
Expand All @@ -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
Expand All @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/gui/qgsmapcanvasmap.h
Expand Up @@ -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; }
Expand Down Expand Up @@ -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.