Skip to content

Commit

Permalink
Fix bug with georef pdf report scale bar units
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@13719 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jun 12, 2010
1 parent d22834a commit 57caf4c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 31 deletions.
11 changes: 2 additions & 9 deletions src/plugins/georeferencer/qgsgeorefplugingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,15 +1403,8 @@ bool QgsGeorefPluginGui::writePDFReportFile( const QString& fileName, const QgsG
resPlotItem->setExtent( composerMap->extent() );
resPlotItem->setGCPList( mPoints );

//convert residual scale bar plot to map units if scaling is equal in x- and y-direction (e.g. helmert)
if ( wldTransform )
{
if ( doubleNear( scaleX, scaleX ) )
{
resPlotItem->setPixelToMapUnits( scaleX );
resPlotItem->setConvertScaleToMapUnits( true );
}
}
//necessary for the correct scale bar unit label
resPlotItem->setConvertScaleToMapUnits( residualUnits == tr( "map units" ) );

QgsComposerTextTable* gcpTable = new QgsComposerTextTable( composition );
gcpTable->setHeaderFont( tableHeaderFont );
Expand Down
23 changes: 6 additions & 17 deletions src/plugins/georeferencer/qgsresidualplotitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#include <math.h>
#endif

QgsResidualPlotItem::QgsResidualPlotItem( QgsComposition* c ): QgsComposerItem( c ), mConvertScaleToMapUnits( false ), mPixelToMapUnits( 1.0 )
QgsResidualPlotItem::QgsResidualPlotItem( QgsComposition* c ): QgsComposerItem( c ), mConvertScaleToMapUnits( false )
{

}
Expand Down Expand Up @@ -109,32 +109,21 @@ void QgsResidualPlotItem::paint( QPainter* painter, const QStyleOptionGraphicsIt

//draw scale bar
double initialScaleBarWidth = rect().width() / 5;
int nUnits;
double scaleBarWidth;
if ( mConvertScaleToMapUnits ) //map units
{
nUnits = initialScaleBarWidth / minMMPixelRatio * mPixelToMapUnits;
scaleBarWidth = nUnits * minMMPixelRatio / mPixelToMapUnits;
}
else //pixels
{
nUnits = initialScaleBarWidth / minMMPixelRatio;
scaleBarWidth = nUnits * minMMPixelRatio;
}
double scaleBarWidthUnits = rect().width() / 5 / minMMPixelRatio;

painter->setPen( QColor( 0, 0, 0 ) );
painter->drawLine( QPointF( 5, rect().height() - 5 ), QPointF( 5 + scaleBarWidth, rect().height() - 5 ) );
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 ) );
painter->drawLine( QPointF( 5 + scaleBarWidth, rect().height() - 5 ), QPointF( 5 + scaleBarWidth, rect().height() - 7 ) );
painter->drawLine( QPointF( 5 + initialScaleBarWidth, rect().height() - 5 ), QPointF( 5 + initialScaleBarWidth, rect().height() - 7 ) );
QFont scaleBarFont;
scaleBarFont.setPointSize( 9 );
if ( mConvertScaleToMapUnits )
{
drawText( painter, 5, rect().height() - 4 + fontAscentMillimeters( scaleBarFont ), QString( "%1 map units" ).arg( nUnits ), QFont() );
drawText( painter, 5, rect().height() - 4 + fontAscentMillimeters( scaleBarFont ), QString( "%1 map units" ).arg( scaleBarWidthUnits ), QFont() );
}
else
{
drawText( painter, 5, rect().height() - 4 + fontAscentMillimeters( scaleBarFont ), QString( "%1 pixels" ).arg( nUnits ), QFont() );
drawText( painter, 5, rect().height() - 4 + fontAscentMillimeters( scaleBarFont ), QString( "%1 pixels" ).arg( scaleBarWidthUnits ), QFont() );
}

drawFrame( painter );
Expand Down
5 changes: 0 additions & 5 deletions src/plugins/georeferencer/qgsresidualplotitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ class QgsResidualPlotItem: public QgsComposerItem
void setExtent( const QgsRectangle& rect ) { mExtent = rect;}
QgsRectangle extent() const { return mExtent; }

void setPixelToMapUnits( double d ) { mPixelToMapUnits = d; }
double pixelToMapUnits() const { return mPixelToMapUnits; }

void setConvertScaleToMapUnits( bool convert ) { mConvertScaleToMapUnits = convert; }
bool convertScaleToMapUnits() const { return mConvertScaleToMapUnits; }

Expand All @@ -55,8 +52,6 @@ class QgsResidualPlotItem: public QgsComposerItem
QgsRectangle mExtent;
/**True if the scale bar units should be converted to map units. This can be done for transformation where the scaling in all directions is the same (helmert)*/
bool mConvertScaleToMapUnits;
/**Scale factor from pixels to map units*/
double mPixelToMapUnits;

/**Calculates maximal possible mm to pixel ratio such that the residual arrow is still inside the frame*/
double maxMMToPixelRatioForGCP( const QgsGeorefDataPoint* p, double pixelXMM, double pixelYMM );
Expand Down

0 comments on commit 57caf4c

Please sign in to comment.