Skip to content

Commit

Permalink
Fix for ticket #71 (I hope)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
g_j_m committed Apr 15, 2006
1 parent f8228bc commit 69e2ffb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion src/gui/qgsmaprender.cpp
Expand Up @@ -57,6 +57,10 @@ QgsRect QgsMapRender::extent()
return mExtent;
}

void QgsMapRender::updateScale()
{
mScale = mScaleCalculator->calculate(mExtent, mSize.width());
}

bool QgsMapRender::setExtent(const QgsRect& extent)
{
Expand Down Expand Up @@ -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__);
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsmaprender.h
Expand Up @@ -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);

Expand Down

0 comments on commit 69e2ffb

Please sign in to comment.