From 69e2ffb9c7d76be5a2b5121f6fea52058f127153 Mon Sep 17 00:00:00 2001 From: g_j_m Date: Sat, 15 Apr 2006 10:27:10 +0000 Subject: [PATCH] Fix for ticket #71 (I hope) Also resolves a long standing issue with the scale units not updating after being changed until the next map redraw (but the fix involves a map redraw). git-svn-id: http://svn.osgeo.org/qgis/trunk@5280 c8812cc2-4d05-0410-92ff-de0c093fc19c --- src/gui/qgsmapcanvas.cpp | 12 ++++++++++++ src/gui/qgsmaprender.cpp | 6 +++++- src/gui/qgsmaprender.h | 3 +++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/gui/qgsmapcanvas.cpp b/src/gui/qgsmapcanvas.cpp index c2df9f1009f..bc5cf087236 100644 --- a/src/gui/qgsmapcanvas.cpp +++ b/src/gui/qgsmapcanvas.cpp @@ -457,6 +457,18 @@ void QgsMapCanvas::mapUnitsChanged() // We assume that if the map units have changed, the changed value // will be accessible from QgsProject. setMapUnits(QgsProject::instance()->mapUnits()); + // Since the map units have changed, force a recalculation of the scale. + mMapRender->updateScale(); + // And then force a redraw of the scale number in the status bar + updateScale(); + // And then redraw the map to force the scale bar to update + // itself. This is less than ideal as the entire map gets redrawn + // just to get the scale bar to redraw itself. If we ask the scale + // bar to redraw itself without redrawing the map, the existing + // scale bar is not removed, and we end up with two scale bars in + // the same location. This can perhaps be fixed when/if the scale + // bar is done as a transparent layer on top of the map canvas. + render(); } void QgsMapCanvas::zoomToSelected() diff --git a/src/gui/qgsmaprender.cpp b/src/gui/qgsmaprender.cpp index 729f95b2882..da25f513599 100644 --- a/src/gui/qgsmaprender.cpp +++ b/src/gui/qgsmaprender.cpp @@ -57,6 +57,10 @@ QgsRect QgsMapRender::extent() return mExtent; } +void QgsMapRender::updateScale() +{ + mScale = mScaleCalculator->calculate(mExtent, mSize.width()); +} bool QgsMapRender::setExtent(const QgsRect& extent) { @@ -163,7 +167,7 @@ void QgsMapRender::adjustExtentToSize() mExtent.setYmax(dymax); // update the scale - mScale = mScaleCalculator->calculate(mExtent, myWidth); + updateScale(); #ifdef QGISDEBUG QgsLogger::debug("Scale (assuming meters as map units) = 1", mScale, 1, __FILE__, __FUNCTION__, __LINE__); diff --git a/src/gui/qgsmaprender.h b/src/gui/qgsmaprender.h index 5a9a7b6f787..c9c5600d059 100644 --- a/src/gui/qgsmaprender.h +++ b/src/gui/qgsmaprender.h @@ -62,6 +62,9 @@ class QgsMapRender : public QObject double scale() const { return mScale; } double mupp() const { return mMupp; } + //! Recalculate the map scale + void updateScale(); + QGis::units mapUnits() const { return mMapUnits; } void setMapUnits(QGis::units u);