Skip to content
Permalink
Browse files

[composer] Fix incorrect calculation of scale for tick scale bars

QPainter::drawLine(x1,y1,x2,y2) takes int values, so coordinates
were being rounded to the nearest mm. Consequently scale was way
off. Also fixes horizontal line for tick styles being drawn
incorrectly with multiple overlapping segments. (fix #10685)
  • Loading branch information
nyalldawson committed Oct 27, 2014
1 parent 04ed47e commit d2c9ffd86963647bcfa9586aea9303ca5ff3cac1
@@ -434,10 +434,11 @@ void QgsComposerScaleBar::segmentPositions( QList<QPair<double, double> >& 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
@@ -59,8 +59,6 @@ void QgsDoubleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const

bool useColor = true; //alternate brush color/white



QList<QPair<double, double> >::const_iterator segmentIt = segmentInfo.constBegin();
for ( ; segmentIt != segmentInfo.constEnd(); ++segmentIt )
{
@@ -48,7 +48,6 @@ void QgsSingleBoxScaleBarStyle::draw( QPainter* p, double xOffset ) const
p->setRenderHint( QPainter::Antialiasing, true );
p->setPen( mScaleBar->pen() );


QList<QPair<double, double> > segmentInfo;
mScaleBar->segmentPositions( segmentInfo );

@@ -69,26 +69,30 @@ void QgsTicksScaleBarStyle::draw( QPainter* p, double xOffset ) const
QList<QPair<double, double> >::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();
Binary file not shown.

0 comments on commit d2c9ffd

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