Skip to content
Permalink
Browse files

Scalebar uses preferred units now

  • Loading branch information
homann committed Sep 4, 2012
1 parent 0a1270b commit 3237577ed116ca345d497fc1210a1b386c17a0ba
Showing with 20 additions and 2 deletions.
  1. +19 −2 src/app/qgsdecorationscalebar.cpp
  2. +1 −0 src/app/qgsdecorationscalebar.h
@@ -23,6 +23,7 @@ email : sbr00pwb@users.sourceforge.net

#include "qgsdecorationscalebardialog.h"

#include "qgis.h"
#include "qgisapp.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
@@ -119,6 +120,7 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
//projections) and that just confuses the rest of the code in this
//function, so force to a positive number.
double myMapUnitsPerPixelDouble = qAbs( canvas->mapUnitsPerPixel() );
double myActualSize = mPreferredSize;

// Exit if the canvas width is 0 or layercount is 0 or QGIS will freeze
int myLayerCount = canvas->layerCount();
@@ -131,9 +133,25 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
// Hard coded sizes
int myMajorTickSize = 8;
int myTextOffsetX = 3;
double myActualSize = mPreferredSize;
int myMargin = 20;

QSettings settings;
QGis::UnitType myPreferredUnits = QGis::fromLiteral( settings.value( "/qgis/measure/displayunits", QGis::toLiteral( QGis::Meters ) ).toString() );
QGis::UnitType myMapUnits = canvas->mapUnits();

// Adjust units meter/feet or vice versa
if ( myMapUnits == QGis::Meters && myPreferredUnits == QGis::Feet )
{
// From meter to feet
myMapUnits = QGis::Feet;
myMapUnitsPerPixelDouble /= 0.3084;
}
else if ( myMapUnits == QGis::Feet && myPreferredUnits == QGis::Meters )
{
// From feet to meter
myMapUnits = QGis::Meters;
myMapUnitsPerPixelDouble *= 0.3084;
}
//Calculate size of scale bar for preferred number of map units
double myScaleBarWidth = mPreferredSize / myMapUnitsPerPixelDouble;

@@ -164,7 +182,6 @@ void QgsDecorationScaleBar::render( QPainter * theQPainter )
}

//Get type of map units and set scale bar unit label text
QGis::UnitType myMapUnits = canvas->mapUnits();
QString myScaleBarUnitLabel;
switch ( myMapUnits )
{
@@ -21,6 +21,7 @@ email : sbr00pwb@users.sourceforge.net
#ifndef QGSCALEBARPLUGIN
#define QGSCALEBARPLUGIN

#include "qgis.h"
#include "qgsdecorationitem.h"

class QPainter;

0 comments on commit 3237577

Please sign in to comment.
You can’t perform that action at this time.