mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
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:
parent
ace4b6e9b5
commit
5d2f0eb02a
@ -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 ) );
|
||||
|
Loading…
x
Reference in New Issue
Block a user