Skip to content

Commit 05d0306

Browse files
author
Sandro Santilli
committed
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
1 parent fd15a16 commit 05d0306

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

src/gui/qgsmapcanvas.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ void QgsMapCanvas::rendererJobFinished()
724724
p.end();
725725

726726
QgsRectangle rect = mSettings.visibleExtent();
727-
mMap->setContent( img, rect );
727+
mMap->setContent( img, rect, mSettings.rotation() );
728728
}
729729

730730
// now we are in a slot called from mJob - do not delete it immediately

src/gui/qgsmapcanvasmap.cpp

+23-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <QPainter>
2424

2525
QgsMapCanvasMap::QgsMapCanvasMap( QgsMapCanvas* canvas )
26-
: QgsMapCanvasItem( canvas )
26+
: QgsMapCanvasItem( canvas ), mRotation(0.0)
2727
{
2828
setZValue( -10 );
2929
}
@@ -32,8 +32,9 @@ QgsMapCanvasMap::~QgsMapCanvasMap()
3232
{
3333
}
3434

35-
void QgsMapCanvasMap::setContent( const QImage& image, const QgsRectangle& rect )
35+
void QgsMapCanvasMap::setContent( const QImage& image, const QgsRectangle& rect, double rotation )
3636
{
37+
mRotation = rotation;
3738
mImage = image;
3839

3940
// 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
4748
void QgsMapCanvasMap::paint( QPainter* painter )
4849
{
4950
int w = qRound( boundingRect().width() ) - 2, h = qRound( boundingRect().height() ) - 2; // setRect() makes the size +2 :-(
51+
int wi = mImage.width();
52+
int hi = mImage.height();
53+
54+
double ar = h ? double(w)/h : 0.0; // aspect ratio of bounding rect
55+
double ari = hi ? double(wi)/hi : 0.0; // aspect ratio of image
56+
double ard = fabs(ari-ar); // aspect ratio difference
57+
58+
#if 0
59+
QgsDebugMsg( QString( "XXXX img %1,%2 (%3) item %4,%5 (%6) ardiff %7" )
60+
.arg( wi ).arg( hi ).arg( ari )
61+
.arg( w ).arg( h ).arg( ar )
62+
.arg ( ard )
63+
);
64+
#endif
65+
5066
if ( mImage.size() != QSize( w, h ) )
5167
{
52-
QgsDebugMsg( QString( "map paint DIFFERENT SIZE: img %1,%2 item %3,%4" ).arg( mImage.width() ).arg( mImage.height() ).arg( w ).arg( h ) );
68+
QgsDebugMsg( QString( "map paint DIFFERENT SIZE: img %1,%2 item %3,%4" ).arg( wi ).arg( hi ).arg( w ).arg( h ) );
69+
}
70+
71+
if ( mRotation )
72+
{
5373
int tX = ( w - mImage.width() ) / 2.0;
5474
int tY = ( h - mImage.height() ) / 2.0;
5575
int fX = 0;

src/gui/qgsmapcanvasmap.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class GUI_EXPORT QgsMapCanvasMap : public QgsMapCanvasItem // public QObject, p
4141
~QgsMapCanvasMap();
4242

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

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

7778
QImage mImage;
79+
80+
double mRotation;
7881
};
7982

8083
#endif

0 commit comments

Comments
 (0)