round residual plot scale bar to reasonable number

git-svn-id: http://svn.osgeo.org/qgis/trunk@13723 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
mhugent 2010-06-13 08:21:01 +00:00
parent ace4b6e9b5
commit 5d2f0eb02a

View File

@ -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 ) );