diff --git a/src/core/composer/qgscomposerscalebar.cpp b/src/core/composer/qgscomposerscalebar.cpp index 99a6e1cfb2af..6ccd51ea3c7c 100644 --- a/src/core/composer/qgscomposerscalebar.cpp +++ b/src/core/composer/qgscomposerscalebar.cpp @@ -434,10 +434,11 @@ void QgsComposerScaleBar::segmentPositions( QList >& posWi double mCurrentXCoord = mPen.widthF() + mBoxContentSpace; //left segments + double leftSegmentSize = mSegmentMillimeters / mNumSegmentsLeft; for ( int i = 0; i < mNumSegmentsLeft; ++i ) { - posWidthList.push_back( qMakePair( mCurrentXCoord, mSegmentMillimeters / mNumSegmentsLeft ) ); - mCurrentXCoord += mSegmentMillimeters / mNumSegmentsLeft; + posWidthList.push_back( qMakePair( mCurrentXCoord, leftSegmentSize ) ); + mCurrentXCoord += leftSegmentSize; } //right segments diff --git a/src/core/composer/qgsdoubleboxscalebarstyle.cpp b/src/core/composer/qgsdoubleboxscalebarstyle.cpp index 2fa319e8a937..4f50fb2232e6 100755 --- a/src/core/composer/qgsdoubleboxscalebarstyle.cpp +++ b/src/core/composer/qgsdoubleboxscalebarstyle.cpp @@ -59,8 +59,6 @@ void QgsDoubleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const bool useColor = true; //alternate brush color/white - - QList >::const_iterator segmentIt = segmentInfo.constBegin(); for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt ) { diff --git a/src/core/composer/qgssingleboxscalebarstyle.cpp b/src/core/composer/qgssingleboxscalebarstyle.cpp index 590635be9494..1d4d826cec93 100755 --- a/src/core/composer/qgssingleboxscalebarstyle.cpp +++ b/src/core/composer/qgssingleboxscalebarstyle.cpp @@ -48,7 +48,6 @@ void QgsSingleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const p->setRenderHint( QPainter::Antialiasing, true ); p->setPen( mScaleBar->pen() ); - QList > segmentInfo; mScaleBar->segmentPositions( segmentInfo ); diff --git a/src/core/composer/qgsticksscalebarstyle.cpp b/src/core/composer/qgsticksscalebarstyle.cpp old mode 100755 new mode 100644 index ba42a609e65c..4401b5ffe969 --- a/src/core/composer/qgsticksscalebarstyle.cpp +++ b/src/core/composer/qgsticksscalebarstyle.cpp @@ -69,26 +69,30 @@ void QgsTicksScaleBarStyle::draw( QPainter* p, double xOffset ) const QList >::const_iterator segmentIt = segmentInfo.constBegin(); for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt ) { - p->drawLine( segmentIt->first + xOffset, barTopPosition, segmentIt->first + xOffset, barTopPosition + mScaleBar->height() ); + p->drawLine( QLineF( segmentIt->first + xOffset, barTopPosition, segmentIt->first + xOffset, barTopPosition + mScaleBar->height() ) ); + } + + //draw last tick and horizontal line + if ( !segmentInfo.isEmpty() ) + { + double lastTickPositionX = segmentInfo.last().first + mScaleBar->segmentMillimeters() + xOffset; + double verticalPos; switch ( mTickPosition ) { case TicksDown: - p->drawLine( xOffset + segmentIt->first, barTopPosition, xOffset + segmentIt->first + mScaleBar->segmentMillimeters(), barTopPosition ); + verticalPos = barTopPosition; break; case TicksMiddle: - p->drawLine( xOffset + segmentIt->first, middlePosition, xOffset + segmentIt->first + mScaleBar->segmentMillimeters(), middlePosition ); + verticalPos = middlePosition; break; case TicksUp: - p->drawLine( xOffset + segmentIt->first, bottomPosition, xOffset + segmentIt->first + mScaleBar->segmentMillimeters(), bottomPosition ); + verticalPos = bottomPosition; break; } - } - - //draw last tick - if ( !segmentInfo.isEmpty() ) - { - double lastTickPositionX = segmentInfo.last().first + mScaleBar->segmentMillimeters(); - p->drawLine( lastTickPositionX + xOffset, barTopPosition, lastTickPositionX + xOffset, barTopPosition + mScaleBar->height() ); + //horizontal line + p->drawLine( QLineF( xOffset + segmentInfo.at( 0 ).first, verticalPos, lastTickPositionX, verticalPos ) ); + //last vertical line + p->drawLine( QLineF( lastTickPositionX, barTopPosition, lastTickPositionX, barTopPosition + mScaleBar->height() ) ); } p->restore(); diff --git a/tests/testdata/control_images/expected_composerscalebar_tick/expected_composerscalebar_tick.png b/tests/testdata/control_images/expected_composerscalebar_tick/expected_composerscalebar_tick.png index 86317b1add5a..2bb4eecd1579 100644 Binary files a/tests/testdata/control_images/expected_composerscalebar_tick/expected_composerscalebar_tick.png and b/tests/testdata/control_images/expected_composerscalebar_tick/expected_composerscalebar_tick.png differ