Skip to content

Commit 69e2ffb

Browse files
author
g_j_m
committed
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
1 parent f8228bc commit 69e2ffb

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/gui/qgsmapcanvas.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,18 @@ void QgsMapCanvas::mapUnitsChanged()
457457
// We assume that if the map units have changed, the changed value
458458
// will be accessible from QgsProject.
459459
setMapUnits(QgsProject::instance()->mapUnits());
460+
// Since the map units have changed, force a recalculation of the scale.
461+
mMapRender->updateScale();
462+
// And then force a redraw of the scale number in the status bar
463+
updateScale();
464+
// And then redraw the map to force the scale bar to update
465+
// itself. This is less than ideal as the entire map gets redrawn
466+
// just to get the scale bar to redraw itself. If we ask the scale
467+
// bar to redraw itself without redrawing the map, the existing
468+
// scale bar is not removed, and we end up with two scale bars in
469+
// the same location. This can perhaps be fixed when/if the scale
470+
// bar is done as a transparent layer on top of the map canvas.
471+
render();
460472
}
461473

462474
void QgsMapCanvas::zoomToSelected()

src/gui/qgsmaprender.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ QgsRect QgsMapRender::extent()
5757
return mExtent;
5858
}
5959

60+
void QgsMapRender::updateScale()
61+
{
62+
mScale = mScaleCalculator->calculate(mExtent, mSize.width());
63+
}
6064

6165
bool QgsMapRender::setExtent(const QgsRect& extent)
6266
{
@@ -163,7 +167,7 @@ void QgsMapRender::adjustExtentToSize()
163167
mExtent.setYmax(dymax);
164168

165169
// update the scale
166-
mScale = mScaleCalculator->calculate(mExtent, myWidth);
170+
updateScale();
167171

168172
#ifdef QGISDEBUG
169173
QgsLogger::debug("Scale (assuming meters as map units) = 1", mScale, 1, __FILE__, __FUNCTION__, __LINE__);

src/gui/qgsmaprender.h

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ class QgsMapRender : public QObject
6262
double scale() const { return mScale; }
6363
double mupp() const { return mMupp; }
6464

65+
//! Recalculate the map scale
66+
void updateScale();
67+
6568
QGis::units mapUnits() const { return mMapUnits; }
6669
void setMapUnits(QGis::units u);
6770

0 commit comments

Comments
 (0)