Skip to content
Permalink
Browse files
Fix bug with georef pdf report scale bar units
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13719 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Jun 12, 2010
1 parent d25700e commit cda4fc9a870b62c9c12b3ff8a829d4cbc250040c
@@ -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 );
@@ -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 )
{

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

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

0 comments on commit cda4fc9

Please sign in to comment.