Skip to content
Permalink
Browse files
round residual plot scale bar to reasonable number
git-svn-id: http://svn.osgeo.org/qgis/trunk@13723 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jun 13, 2010
1 parent ace4b6e commit 5d2f0eb02a51a7b9b37f1f4feb915092bd833a9e
Showing with 20 additions and 0 deletions.
  1. +20 −0 src/plugins/georeferencer/qgsresidualplotitem.cpp
@@ -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 ) );

0 comments on commit 5d2f0eb

Please sign in to comment.