Skip to content
Permalink
Browse files

[layouts] Simplify scalebar unit handling

Instead of auto setting the units to meters/feet, and then using
the label multiplier setting to obtain a scalebar in km/miles,
instead we always keep auto-set label multipliers at 1 and just
always keep the users explicitly set scale bar units.

This should help avoid the complexity of layout scale bars, while
still keeping flexibility if someone does need custom units.
  • Loading branch information
nyalldawson committed Nov 24, 2017
1 parent b7ef3d3 commit 060270c0be14bc4492df5698782840e309ae10f7
Showing with 2 additions and 42 deletions.
  1. +2 −42 src/core/layout/qgslayoutitemscalebar.cpp
@@ -400,48 +400,8 @@ void QgsLayoutItemScaleBar::applyDefaultSize( QgsUnitTypes::DistanceUnit units )
double initialUnitsPerSegment = widthInSelectedUnits / 10.0; //default scalebar width equals half the map width
mSettings.setUnitsPerSegment( initialUnitsPerSegment );

switch ( units )
{
case QgsUnitTypes::DistanceUnknownUnit:
{
upperMagnitudeMultiplier = 1.0;
setUnitLabel( tr( "units" ) );
break;
}
case QgsUnitTypes::DistanceMeters:
{
if ( initialUnitsPerSegment > 1000.0 )
{
upperMagnitudeMultiplier = 1000.0;
setUnitLabel( tr( "km" ) );
}
else
{
upperMagnitudeMultiplier = 1.0;
setUnitLabel( tr( "m" ) );
}
break;
}
case QgsUnitTypes::DistanceFeet:
{
if ( initialUnitsPerSegment > 5419.95 )
{
upperMagnitudeMultiplier = 5419.95;
setUnitLabel( tr( "miles" ) );
}
else
{
upperMagnitudeMultiplier = 1.0;
setUnitLabel( tr( "ft" ) );
}
break;
}

default:
setUnitLabel( QgsUnitTypes::toAbbreviatedString( units ) );
upperMagnitudeMultiplier = 1;
break;
}
setUnitLabel( QgsUnitTypes::toAbbreviatedString( units ) );
upperMagnitudeMultiplier = 1;

double segmentWidth = initialUnitsPerSegment / upperMagnitudeMultiplier;
int segmentMagnitude = std::floor( std::log10( segmentWidth ) );

0 comments on commit 060270c

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