fix extent

This commit is contained in:
Blottiere Paul 2016-05-12 14:41:34 +02:00
parent 9a62613b6b
commit b930a4b5e2
5 changed files with 37 additions and 9 deletions

View File

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

View File

@ -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

View File

@ -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.

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB