Skip to content

Commit

Permalink
round residual plot scale bar to reasonable number
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13723 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jun 13, 2010
1 parent ef36d7b commit 78fedde
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/plugins/georeferencer/qgsresidualplotitem.cpp
Expand Up @@ -111,6 +111,26 @@ void QgsResidualPlotItem::paint( QPainter* painter, const QStyleOptionGraphicsIt
double initialScaleBarWidth = rect().width() / 5;
double scaleBarWidthUnits = rect().width() / 5 / minMMPixelRatio;

//a simple method to round to next nice number
int nDecPlaces;
if ( scaleBarWidthUnits < 1 )
{
nDecPlaces = -floor( log10( scaleBarWidthUnits ) );
scaleBarWidthUnits *= pow( 10, nDecPlaces );
scaleBarWidthUnits = ( int )( scaleBarWidthUnits + 0.5 );
scaleBarWidthUnits /= pow( 10, nDecPlaces );
}
else
{
nDecPlaces = ( int )log10( scaleBarWidthUnits );
scaleBarWidthUnits /= pow( 10, nDecPlaces );
scaleBarWidthUnits = ( int )( scaleBarWidthUnits + 0.5 );
scaleBarWidthUnits *= pow( 10, nDecPlaces );
}
initialScaleBarWidth = scaleBarWidthUnits * minMMPixelRatio;



painter->setPen( QColor( 0, 0, 0 ) );
painter->drawLine( QPointF( 5, rect().height() - 5 ), QPointF( 5 + initialScaleBarWidth, rect().height() - 5 ) );
painter->drawLine( QPointF( 5, rect().height() - 5 ), QPointF( 5, rect().height() - 7 ) );
Expand Down

0 comments on commit 78fedde

Please sign in to comment.