From 093db91552316544ae68f39bbebde986c51bba56 Mon Sep 17 00:00:00 2001 From: timlinux Date: Sun, 27 Jun 2004 00:09:25 +0000 Subject: [PATCH] Made the scale bar units intelligently switch between m and km as appropriate. Made the scale bar max lenght 1/3 screen rather than 1/2 git-svn-id: http://svn.osgeo.org/qgis/trunk@1688 c8812cc2-4d05-0410-92ff-de0c093fc19c --- plugins/scale_bar/plugin.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/scale_bar/plugin.cpp b/plugins/scale_bar/plugin.cpp index a89a67692cc..4b8f404316d 100644 --- a/plugins/scale_bar/plugin.cpp +++ b/plugins/scale_bar/plugin.cpp @@ -84,7 +84,7 @@ qgisMainWindowPointer(theQGisApp), qGisInterface(theQgisInterFace), QgisPlugin(name_,description_,version_,type_) { - mPreferredSize = 100; + mPreferredSize = 30; mPlacement = "Top Left"; mStyle = "Tick Down"; mEnabled = true; @@ -153,7 +153,7 @@ void Plugin::run() int myUnits=qGisInterface->getMapCanvas()->mapUnits(); switch (myUnits) { - case 0: myPluginGui->spnSize->setSuffix(tr(" metres")); break; + case 0: myPluginGui->spnSize->setSuffix(tr(" metres/km")); break; case 1: myPluginGui->spnSize->setSuffix(tr(" feet")); break; case 2: myPluginGui->spnSize->setSuffix(tr(" degrees")); break; default: std::cout << "Error: not picked up map units - actual value = " << myUnits << std::endl; @@ -205,9 +205,9 @@ void Plugin::renderScaleBar(QPainter * theQPainter) }; //if scale bar is more than half the canvas wide keep halving until not - while (myScaleBarWidth > myCanvasWidth/2) + while (myScaleBarWidth > myCanvasWidth/3) { - myScaleBarWidth = myScaleBarWidth /2; + myScaleBarWidth = myScaleBarWidth /3; }; myActualSize = myScaleBarWidth * myMuppDouble; @@ -236,7 +236,13 @@ void Plugin::renderScaleBar(QPainter * theQPainter) case 2: myScaleBarUnitLabel=tr(" degrees"); break; default: std::cout << "Error: not picked up map units - actual value = " << myMapUnits << std::endl; }; - + //use km if units are larget and scale bar width is larger then 1000 + if (myMapUnits==0 && myActualSize > 1000) + { + myScaleBarUnitLabel=tr(" km"); + myActualSize = myActualSize/1000; + + } //Set font and calculate width of unit label int myFontSize = 10; //we use this later for buffering QFont myFont( "helvetica", myFontSize );