Skip to content

Commit

Permalink
[layouts] Simplify scalebar unit handling
Browse files Browse the repository at this point in the history
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 060270c
Showing 1 changed file with 2 additions and 42 deletions.
44 changes: 2 additions & 42 deletions src/core/layout/qgslayoutitemscalebar.cpp
Expand Up @@ -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 ) );
Expand Down

0 comments on commit 060270c

Please sign in to comment.