Skip to content

Commit

Permalink
Fix #47810 - zoom last and next with rotated map looses scale
Browse files Browse the repository at this point in the history
  • Loading branch information
Djedouas authored and troopa81 committed Aug 30, 2022
1 parent 92ee41e commit 047f072
Showing 2 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
@@ -1405,9 +1405,9 @@ void QgsMapCanvas::setExtent( const QgsRectangle &r, bool magnified )
mLastExtent.removeAt( i );
}

if ( !mLastExtent.isEmpty() && mLastExtent.last() != extent() )
if ( !mLastExtent.isEmpty() && mLastExtent.last() != mSettings.extent() )
{
mLastExtent.append( extent() );
mLastExtent.append( mSettings.extent() );
}

// adjust history to no more than 100
@@ -1553,7 +1553,7 @@ void QgsMapCanvas::zoomToNextExtent()
void QgsMapCanvas::clearExtentHistory()
{
mLastExtent.clear(); // clear the zoom history list
mLastExtent.append( extent() ) ; // set the current extent in the list
mLastExtent.append( mSettings.extent() ) ; // set the current extent in the list
mLastExtentIndex = mLastExtent.size() - 1;
// update controls' enabled state
emit zoomLastStatusChanged( mLastExtentIndex > 0 );
17 changes: 17 additions & 0 deletions tests/src/gui/testqgsmapcanvas.cpp
Original file line number Diff line number Diff line change
@@ -80,6 +80,7 @@ class TestQgsMapCanvas : public QObject
void testZoomResolutions();
void testTooltipEvent();
void testMapLayers();
void testExtentHistory();

private:
QgsMapCanvas *mCanvas = nullptr;
@@ -587,5 +588,21 @@ void TestQgsMapCanvas::testMapLayers()
QCOMPARE( canvas->layer( QStringLiteral( "xxx" ) ), nullptr );
}

void TestQgsMapCanvas::testExtentHistory()
{
QgsRectangle initialExtent;
const QList<double> rotations = QList<double>() << 0.0 << 30.0;
for ( double rotation : rotations )
{
mCanvas->setRotation( rotation );
mCanvas->clearExtentHistory();
mCanvas->setExtent( QgsRectangle( 0, 0, 10, 10 ) );
initialExtent = mCanvas->extent();
mCanvas->setExtent( QgsRectangle( 100, 100, 110, 110 ) );
mCanvas->zoomToPreviousExtent();
QCOMPARE( mCanvas->extent(), initialExtent );
}
}

QGSTEST_MAIN( TestQgsMapCanvas )
#include "testqgsmapcanvas.moc"

0 comments on commit 047f072

Please sign in to comment.