Skip to content

Commit

Permalink
Fix "zoom to" actions fail to correctly set canvas extent when canvas…
Browse files Browse the repository at this point in the history
… has a locked scale
  • Loading branch information
github-actions[bot] authored and nyalldawson committed Mar 25, 2020
1 parent 0f86b77 commit 50c345e
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 21 deletions.
22 changes: 18 additions & 4 deletions python/gui/auto_generated/qgsmapcanvas.sip.in
Expand Up @@ -175,7 +175,15 @@ Returns the combined extent for all layers on the map canvas

void setExtent( const QgsRectangle &r, bool magnified = false );
%Docstring
Sets the extent of the map canvas
Sets the extent of the map canvas to the specified rectangle.

The ``magnified`` argument dictates whether existing canvas constraints such
as a scale lock should be respected or not during the operation. If ``magnified`` is
``True`` then an existing scale lock constraint will be applied. This means that the final
visible canvas extent may not match the specified extent.

If ``magnified`` is ``False`` then scale lock settings will be ignored, and the specified
rectangle will ALWAYS be visible in the canvas.
%End

bool setReferencedExtent( const QgsReferencedRectangle &extent ) throw( QgsCsException );
Expand Down Expand Up @@ -474,16 +482,22 @@ returns current layer (set by legend widget)
Sets wheel zoom factor (should be greater than 1)
%End

void zoomScale( double scale );
void zoomScale( double scale, bool ignoreScaleLock = false );
%Docstring
Zooms the canvas to a specific ``scale``.
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

If ``ignoreScaleLock`` is set to ``True``, then any existing constraint on the map scale
of the canvas will be ignored during the zoom operation.
%End

void zoomByFactor( double scaleFactor, const QgsPointXY *center = 0 );
void zoomByFactor( double scaleFactor, const QgsPointXY *center = 0, bool ignoreScaleLock = false );
%Docstring
Zoom with the factor supplied. Factor > 1 zooms out, interval (0,1) zooms in
If point is given, re-center on it
If point is given, re-center on it.

If ``ignoreScaleLock`` is set to ``True``, then any existing constraint on the map scale
of the canvas will be ignored during the zoom operation.
%End

void zoomWithCenter( int x, int y, bool zoomIn );
Expand Down
2 changes: 1 addition & 1 deletion src/app/gps/qgsgpsinformationwidget.cpp
Expand Up @@ -943,7 +943,7 @@ void QgsGpsInformationWidget::displayGPSInformation( const QgsGpsInformation &in
if ( radRecenterMap->isChecked() ||
( radRecenterWhenNeeded->isChecked() && !myExtentLimit.contains( myPoint ) ) )
{
mMapCanvas->setExtent( myRect );
mMapCanvas->setExtent( myRect, true );
mMapCanvas->refresh();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsidentifyresultsdialog.cpp
Expand Up @@ -1871,7 +1871,7 @@ void QgsIdentifyResultsDialog::zoomToFeature()
rect.scale( 0.5, &c );
}

mCanvas->setExtent( rect );
mCanvas->setExtent( rect, true );
mCanvas->refresh();
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/editorwidgets/qgsrelationreferencewidget.cpp
Expand Up @@ -686,7 +686,7 @@ void QgsRelationReferenceWidget::highlightFeature( QgsFeature f, CanvasExtent ca
{
extent.combineExtentWith( featBBox );
extent.scale( 1.1 );
mCanvas->setExtent( extent );
mCanvas->setExtent( extent, true );
mCanvas->refresh();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/gui/layertree/qgslayertreeviewdefaultactions.cpp
Expand Up @@ -369,7 +369,7 @@ void QgsLayerTreeViewDefaultActions::zoomToLayers( QgsMapCanvas *canvas, const Q
extent.scale( 1.05 );

//zoom to bounding box
canvas->setExtent( extent );
canvas->setExtent( extent, true );
canvas->refresh();
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/layout/qgslayoutmapwidget.cpp
Expand Up @@ -712,7 +712,7 @@ void QgsLayoutMapWidget::viewScaleInCanvas()
}

const double currentScale = mMapItem->scale();
mMapCanvas->zoomScale( currentScale );
mMapCanvas->zoomScale( currentScale, true );
}

void QgsLayoutMapWidget::mXMinLineEdit_editingFinished()
Expand Down
10 changes: 5 additions & 5 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -896,7 +896,7 @@ bool QgsMapCanvas::setReferencedExtent( const QgsReferencedRectangle &extent )
}
}

setExtent( canvasExtent );
setExtent( canvasExtent, true );
return true;
}

Expand Down Expand Up @@ -1680,9 +1680,9 @@ void QgsMapCanvas::zoomOut()
zoomByFactor( zoomOutFactor() );
}

void QgsMapCanvas::zoomScale( double newScale )
void QgsMapCanvas::zoomScale( double newScale, bool ignoreScaleLock )
{
zoomByFactor( newScale / scale() );
zoomByFactor( newScale / scale(), nullptr, ignoreScaleLock );
}

void QgsMapCanvas::zoomWithCenter( int x, int y, bool zoomIn )
Expand Down Expand Up @@ -2261,9 +2261,9 @@ void QgsMapCanvas::writeProject( QDomDocument &doc )
// TODO: store only units, extent, projections, dest CRS
}

void QgsMapCanvas::zoomByFactor( double scaleFactor, const QgsPointXY *center )
void QgsMapCanvas::zoomByFactor( double scaleFactor, const QgsPointXY *center, bool ignoreScaleLock )
{
if ( mScaleLocked )
if ( mScaleLocked && !ignoreScaleLock )
{
// zoom map to mouse cursor by magnifying
setMagnificationFactor( mapSettings().magnificationFactor() / scaleFactor );
Expand Down
24 changes: 20 additions & 4 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -207,7 +207,17 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! Returns the combined extent for all layers on the map canvas
QgsRectangle fullExtent() const;

//! Sets the extent of the map canvas
/**
* Sets the extent of the map canvas to the specified rectangle.
*
* The \a magnified argument dictates whether existing canvas constraints such
* as a scale lock should be respected or not during the operation. If \a magnified is
* TRUE then an existing scale lock constraint will be applied. This means that the final
* visible canvas extent may not match the specified extent.
*
* If \a magnified is FALSE then scale lock settings will be ignored, and the specified
* rectangle will ALWAYS be visible in the canvas.
*/
void setExtent( const QgsRectangle &r, bool magnified = false );

/**
Expand Down Expand Up @@ -451,14 +461,20 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
/**
* Zooms the canvas to a specific \a scale.
* The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
* If \a ignoreScaleLock is set to TRUE, then any existing constraint on the map scale
* of the canvas will be ignored during the zoom operation.
*/
void zoomScale( double scale );
void zoomScale( double scale, bool ignoreScaleLock = false );

/**
* Zoom with the factor supplied. Factor > 1 zooms out, interval (0,1) zooms in
* If point is given, re-center on it
* If point is given, re-center on it.
*
* If \a ignoreScaleLock is set to TRUE, then any existing constraint on the map scale
* of the canvas will be ignored during the zoom operation.
*/
void zoomByFactor( double scaleFactor, const QgsPointXY *center = nullptr );
void zoomByFactor( double scaleFactor, const QgsPointXY *center = nullptr, bool ignoreScaleLock = false );

//! Zooms in/out with a given center
void zoomWithCenter( int x, int y, bool zoomIn );
Expand Down
Expand Up @@ -571,7 +571,7 @@ void eVisGenericEventBrowserGui::displayImage()
// only change the extents if the point is beyond the current extents to minimize repaints
if ( !mCanvas->extent().contains( myPoint ) )
{
mCanvas->setExtent( myRect );
mCanvas->setExtent( myRect, true );
}
mCanvas->refresh();
}
Expand Down
Expand Up @@ -411,7 +411,7 @@ void QgsGeometryCheckerResultTab::highlightErrors( bool current )

if ( !totextent.isEmpty() )
{
mIface->mapCanvas()->setExtent( totextent );
mIface->mapCanvas()->setExtent( totextent, true );
}
mIface->mapCanvas()->refresh();
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/topology/checkDock.cpp
Expand Up @@ -205,7 +205,7 @@ void checkDock::errorListClicked( const QModelIndex &index )
QgsRectangle r = mErrorList.at( row )->boundingBox();
r.scale( 1.5 );
QgsMapCanvas *canvas = qgsInterface->mapCanvas();
canvas->setExtent( r );
canvas->setExtent( r, true );
canvas->refresh();

mFixBox->clear();
Expand Down

0 comments on commit 50c345e

Please sign in to comment.