Skip to content

Commit

Permalink
fix extent
Browse files Browse the repository at this point in the history
  • Loading branch information
pblottiere committed May 12, 2016
1 parent 9a62613 commit b930a4b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
26 changes: 18 additions & 8 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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() )
Expand All @@ -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();
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/qgsmapcanvas.h
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions tests/src/gui/testqgsmapcanvas.cpp
Expand Up @@ -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 )
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b930a4b

Please sign in to comment.