Skip to content
Permalink
Browse files

fix extent

  • Loading branch information
pblottiere committed May 12, 2016
1 parent 9a62613 commit b930a4b5e2cb2b5387733597064c073fbdb0ba09
@@ -313,11 +313,16 @@ QgsMapCanvas::~QgsMapCanvas()

void QgsMapCanvas::setMagnificationFactor( double level )
{
QgsRectangle ext = extent();
QgsMapSettings settings = mSettings;
settings.setRotation( 0.0 );

QgsRectangle ext = settings.visibleExtent();
ext.scale( mMagnificationFactor / level );

mMagnificationFactor = level;
mSettings.setExtent( ext );

setExtent( ext, true );

refresh();
}

@@ -880,11 +885,11 @@ QgsRectangle QgsMapCanvas::fullExtent() const
} // extent


void QgsMapCanvas::setExtent( QgsRectangle const & r )
void QgsMapCanvas::setExtent( QgsRectangle const & r, bool magnified )
{
QgsRectangle current = extent();

if ( r == current )
if (( r == current ) && magnified )
return;

if ( r.isEmpty() )
@@ -902,7 +907,11 @@ void QgsMapCanvas::setExtent( QgsRectangle const & r )
}
else
{
mSettings.setExtent( r );
QgsRectangle magnifiedExtent = r;
if ( ! magnified )
magnifiedExtent.scale( 1 / mMagnificationFactor );

mSettings.setExtent( magnifiedExtent );
}
emit extentsChanged();
updateScale();
@@ -943,7 +952,8 @@ void QgsMapCanvas::setCenter( const QgsPoint& center )
QgsRectangle(
x - r.width() / 2.0, y - r.height() / 2.0,
x + r.width() / 2.0, y + r.height() / 2.0
)
),
true
);
} // setCenter

@@ -1515,7 +1525,7 @@ void QgsMapCanvas::zoomWithCenter( int x, int y, bool zoomIn )
QgsPoint center = getCoordinateTransform()->toMapPoint( x, y );
QgsRectangle r = mapSettings().visibleExtent();
r.scale( scaleFactor, &center );
setExtent( r );
setExtent( r, true );
refresh();
}

@@ -1995,7 +2005,7 @@ void QgsMapCanvas::zoomByFactor( double scaleFactor, const QgsPoint* center )
{
QgsRectangle r = mapSettings().extent();
r.scale( scaleFactor, center );
setExtent( r );
setExtent( r, true );
refresh();
}

@@ -216,7 +216,7 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
QgsRectangle fullExtent() const;

//! Set the extent of the map canvas
void setExtent( const QgsRectangle &r );
void setExtent( const QgsRectangle &r, bool magnified = false );

//! Get the current map canvas rotation in clockwise degrees
//! @note added in 2.8
@@ -231,6 +231,24 @@ void TestQgsMapCanvas::testMagnification()
controlImageDir = testDataDir + "control_images/";
checker.setSizeTolerance( 2, 2 );
QCOMPARE( checker.compareImages( "map_magnification_6_5", 100 ), true );

// set magnification factor (auto refresh)
mCanvas->setMagnificationFactor( 1.0 );
QCOMPARE( mCanvas->magnificationFactor(), 1.0 );

// wait for rendering
timer.start( 3000 );
loop.exec();
QCOMPARE( spy.count(), 1 );
spy.clear();

// control image with magnification factor 1.0
mCanvas->saveAsImage( tmpName );

checker.setControlName( "expected_map_magnification" );
checker.setRenderedImage( tmpName );
checker.setSizeTolerance( 2, 2 );
QCOMPARE( checker.compareImages( "map_magnification", 100 ), true );
}

QTEST_MAIN( TestQgsMapCanvas )
Binary file not shown.
Binary file not shown.

0 comments on commit b930a4b

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