Skip to content

Commit

Permalink
Improve scalebar default settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Hugentobler committed Aug 31, 2012
1 parent b1bed9f commit 6028b81
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/core/composer/qgscomposerscalebar.cpp
Expand Up @@ -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 );
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions tests/src/core/testqgscomposerscalebar.cpp
Expand Up @@ -87,6 +87,7 @@ void TestQgsComposerScaleBar::initTestCase()
mComposerScaleBar->setNumUnitsPerSegment( 2000 );
mComposerScaleBar->setNumSegmentsLeft( 0 );
mComposerScaleBar->setNumSegments( 2 );
mComposerScaleBar->setHeight( 5 );
};

void TestQgsComposerScaleBar::cleanupTestCase()
Expand Down

0 comments on commit 6028b81

Please sign in to comment.