Skip to content

Commit

Permalink
Simplify the change by not modifing interfaces
Browse files Browse the repository at this point in the history
.. I've found a link from gsMapCanvasMap and the QgsMapToPixel class
  • Loading branch information
Sandro Santilli committed Dec 13, 2014
1 parent 05d0306 commit 90db597
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ void QgsMapCanvas::rendererJobFinished()
p.end();

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

// now we are in a slot called from mJob - do not delete it immediately
Expand Down
24 changes: 4 additions & 20 deletions src/gui/qgsmapcanvasmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <QPainter>

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

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

// For true retro fans: this is approximately how the graphics looked like in 1990
Expand All @@ -48,27 +47,12 @@ 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( wi ).arg( hi ).arg( w ).arg( h ) );
QgsDebugMsg( QString( "map paint DIFFERENT SIZE: img %1,%2 item %3,%4" ).arg( mImage.width() ).arg( mImage.height() ).arg( w ).arg( h ) );
}

if ( mRotation )
if ( mMapCanvas->getCoordinateTransform()->mapRotation() )
{
int tX = ( w - mImage.width() ) / 2.0;
int tY = ( h - mImage.height() ) / 2.0;
Expand Down
5 changes: 1 addition & 4 deletions src/gui/qgsmapcanvasmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ class GUI_EXPORT QgsMapCanvasMap : public QgsMapCanvasItem // public QObject, p
~QgsMapCanvasMap();

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

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

QImage mImage;

double mRotation;
};

#endif

0 comments on commit 90db597

Please sign in to comment.