Skip to content
Permalink
Browse files

Improve scalebar default settings

  • Loading branch information
Marco Hugentobler
Marco Hugentobler committed Aug 31, 2012
1 parent b1bed9f commit 6028b811911244fbadab0b75099c0af485f31799
Showing with 19 additions and 8 deletions.
  1. +18 −8 src/core/composer/qgscomposerscalebar.cpp
  2. +1 −0 tests/src/core/testqgscomposerscalebar.cpp
@@ -218,7 +218,7 @@ void QgsComposerScaleBar::applyDefaultSettings()
delete mStyle;
mStyle = new QgsSingleBoxScaleBarStyle( this );

mHeight = 5;
mHeight = 3;

mPen = QPen( QColor( 0, 0, 0 ) );
mPen.setWidthF( 1.0 );
@@ -237,14 +237,24 @@ void QgsComposerScaleBar::applyDefaultSize()
{
if ( mComposerMap )
{
//calculate mNumUnitsPerSegment
QgsRectangle composerMapRect = mComposerMap->extent();
setUnits( Meters );
double widthMeter = mapWidth();
int nUnitsPerSegment = widthMeter / 10.0; //default scalebar width equals half the map width
setNumUnitsPerSegment( nUnitsPerSegment );

if( nUnitsPerSegment > 1000 )
{
setNumUnitsPerSegment( (int)( numUnitsPerSegment() / 1000.0 + 0.5 ) * 1000 );
setUnitLabeling( tr("km") );
setNumMapUnitsPerScaleBarUnit( 1000 );
}
else
{
setUnitLabeling( tr("m") );
}

double proposedScaleBarLength = composerMapRect.width() / 4;
int powerOf10 = int ( pow( 10.0, int ( log( proposedScaleBarLength ) / log( 10.0 ) ) ) ); // from scalebar plugin
int nPow10 = proposedScaleBarLength / powerOf10;
mNumSegments = 2;
mNumUnitsPerSegment = ( nPow10 / 2 ) * powerOf10;
setNumSegments( 4 );
setNumSegmentsLeft( 2 );
}

refreshSegmentMillimeters();
@@ -87,6 +87,7 @@ void TestQgsComposerScaleBar::initTestCase()
mComposerScaleBar->setNumUnitsPerSegment( 2000 );
mComposerScaleBar->setNumSegmentsLeft( 0 );
mComposerScaleBar->setNumSegments( 2 );
mComposerScaleBar->setHeight( 5 );
};

void TestQgsComposerScaleBar::cleanupTestCase()

0 comments on commit 6028b81

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