Skip to content

Commit

Permalink
Scalebar uses preferred units now
Browse files Browse the repository at this point in the history
  • Loading branch information
homann committed Sep 4, 2012
1 parent 0a1270b commit 3237577
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/app/qgsdecorationscalebar.cpp
Expand Up @@ -23,6 +23,7 @@ email : sbr00pwb@users.sourceforge.net

#include "qgsdecorationscalebardialog.h"

#include "qgis.h"
#include "qgisapp.h"
#include "qgslogger.h"
#include "qgsmapcanvas.h"
Expand Down Expand Up @@ -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();
Expand All @@ -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;

Expand Down Expand Up @@ -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 )
{
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsdecorationscalebar.h
Expand Up @@ -21,6 +21,7 @@ email : sbr00pwb@users.sourceforge.net
#ifndef QGSCALEBARPLUGIN
#define QGSCALEBARPLUGIN

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

class QPainter;
Expand Down

0 comments on commit 3237577

Please sign in to comment.