Skip to content

Commit

Permalink
Partial patch #2673 by mhugent:
Browse files Browse the repository at this point in the history
-Configurable GCP labeling
-Ability to generate PDF report of residuals and transform parameters
-Allow resampling to output file even for linear transforms

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13436 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mmassing committed May 7, 2010
1 parent 9342453 commit 873df9b
Show file tree
Hide file tree
Showing 14 changed files with 463 additions and 85 deletions.
3 changes: 2 additions & 1 deletion src/plugins/georeferencer/CMakeLists.txt
Expand Up @@ -15,6 +15,7 @@ SET (GEOREF_SRCS
qgsgeorefvalidators.cpp
qgsleastsquares.cpp
qgsmapcoordsdialog.cpp
qgsresidualplotitem.cpp
qgstransformsettingsdialog.cpp

qgsgcplist.cpp
Expand Down Expand Up @@ -67,7 +68,7 @@ ADD_LIBRARY (georefplugin MODULE ${GEOREF_SRCS} ${GEOREF_MOC_SRCS} ${GEOREF_RCC_
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
../../core ../../core/raster ../../core/renderer ../../core/symbology
../../core ../../core/raster ../../core/renderer ../../core/symbology ../../core/composer
../../gui
..
${GSL_INCLUDE_DIR}
Expand Down
67 changes: 48 additions & 19 deletions src/plugins/georeferencer/qgsgcpcanvasitem.cpp
Expand Up @@ -35,6 +35,12 @@ QgsGCPCanvasItem::QgsGCPCanvasItem( QgsMapCanvas* mapCanvas, const QgsGeorefData

void QgsGCPCanvasItem::paint( QPainter* p )
{
QgsRenderContext context;
if ( !setRenderContextVariables( p, context ) )
{
return;
}

p->setRenderHint( QPainter::Antialiasing );

bool enabled = true;
Expand All @@ -57,29 +63,39 @@ void QgsGCPCanvasItem::paint( QPainter* p )

QSettings s;
bool showIDs = s.value( "/Plugin-GeoReferencer/Config/ShowId" ).toBool();
if ( !showIDs && mIsGCPSource )
bool showCoords = s.value( "/Plugin-GeoReferencer/Config/ShowCoords" ).toBool();

QString msg;
if ( showIDs && showCoords )
{
QString msg = QString( "X %1\nY %2" ).arg( QString::number( worldCoords.x(), 'f' ) ).
arg( QString::number( worldCoords.y(), 'f' ) );
p->setFont( QFont( "helvetica", 9 ) );
QRect textBounds = p->boundingRect( 6, 6, 10, 10, Qt::AlignLeft, msg );
p->setBrush( mLabelBrush );
p->drawRect( textBounds.x() - 2, textBounds.y() - 2, textBounds.width() + 4, textBounds.height() + 4 );
p->drawText( textBounds, Qt::AlignLeft, msg );
mTextBounds = QSizeF( textBounds.width() + 4, textBounds.height() + 4 );
msg = QString( "%1\nX %2\nY %3" ).arg( QString::number( id ) ).arg( QString::number( worldCoords.x(), 'f' ) ).arg( QString::number( worldCoords.y(), 'f' ) );
}
else if ( showIDs )
{
p->setFont( QFont( "helvetica", 12 ) );
QString msg = QString::number( id );
msg = msg = QString::number( id );
}
else if ( showCoords )
{
msg = QString( "X %1\nY %2" ).arg( QString::number( worldCoords.x(), 'f' ) ).arg( QString::number( worldCoords.y(), 'f' ) );
}

if ( !msg.isEmpty() )
{
p->setBrush( mLabelBrush );
p->drawRect( 5, 4, p->fontMetrics().width( msg ) + 2, 14 );
p->drawText( 6, 16, msg );
QFontMetrics fm = p->fontMetrics();
mTextBounds = QSize( fm.width( msg ) + 4, fm.height() + 4 );
QFont textFont( "helvetica" );
textFont.setPixelSize( fontSizePainterUnits( 12, context ) );
p->setFont( textFont );
QRectF textBounds = p->boundingRect( 3 * context.scaleFactor(), 3 * context.scaleFactor(), 5 * context.scaleFactor(), 5 * context.scaleFactor(), Qt::AlignLeft, msg );
mTextBoxRect = QRectF( textBounds.x() - context.scaleFactor() * 1, textBounds.y() - context.scaleFactor() * 1, \
textBounds.width() + 2 * context.scaleFactor(), textBounds.height() + 2 * context.scaleFactor() );
p->drawRect( mTextBoxRect );
p->drawText( textBounds, Qt::AlignLeft, msg );
}

drawResidualArrow( p );
if ( data( 0 ) != "composer" ) //draw residuals only on screen
{
drawResidualArrow( p, context );
}
}

QRectF QgsGCPCanvasItem::boundingRect() const
Expand All @@ -91,6 +107,8 @@ QRectF QgsGCPCanvasItem::boundingRect() const
{
residual = mDataPoint->residual();
}

//only considering screen resolution is ok for the bounding box function
double rf = residualToScreenFactor();

if ( residual.x() > 0 )
Expand All @@ -116,7 +134,12 @@ QRectF QgsGCPCanvasItem::boundingRect() const

QRectF residualArrowRect( QPointF( residualLeft, residualTop ), QPointF( residualRight, residualBottom ) );
QRectF markerRect( -2, -2, mTextBounds.width() + 6, mTextBounds.height() + 6 );
return residualArrowRect.united( markerRect );
QRectF boundingRect = residualArrowRect.united( markerRect );
if ( !mTextBoxRect.isNull() )
{
boundingRect = boundingRect.united( mTextBoxRect );
}
return boundingRect;
}

QPainterPath QgsGCPCanvasItem::shape() const
Expand All @@ -138,9 +161,9 @@ void QgsGCPCanvasItem::updatePosition()
setPos( toCanvasCoordinates( mIsGCPSource ? mDataPoint->pixelCoords() : mDataPoint->mapCoords() ) );
}

void QgsGCPCanvasItem::drawResidualArrow( QPainter* p )
void QgsGCPCanvasItem::drawResidualArrow( QPainter* p, const QgsRenderContext& context )
{
if ( !mDataPoint || !mIsGCPSource )
if ( !mDataPoint || !mIsGCPSource || !mMapCanvas )
{
return;
}
Expand Down Expand Up @@ -188,3 +211,9 @@ void QgsGCPCanvasItem::checkBoundingRectChange()
{
prepareGeometryChange();
}

double QgsGCPCanvasItem::fontSizePainterUnits( double points, const QgsRenderContext& c )
{
return points * 0.3527 * c.scaleFactor();
}

7 changes: 6 additions & 1 deletion src/plugins/georeferencer/qgsgcpcanvasitem.h
Expand Up @@ -49,9 +49,14 @@ class QgsGCPCanvasItem : public QgsMapCanvasItem
bool mIsGCPSource;
QPen mResidualPen;

void drawResidualArrow( QPainter* p );
//text box rect for bounding rect calculation (updated in the paint event)
QRectF mTextBoxRect;

void drawResidualArrow( QPainter* p, const QgsRenderContext& context );
/**Calculates scale factor for residual display*/
double residualToScreenFactor() const;
/**Calculates pixel size for a font point size*/
double fontSizePainterUnits( double points, const QgsRenderContext& c );
};

#endif // QGSGCPCANVASITEM_H
20 changes: 17 additions & 3 deletions src/plugins/georeferencer/qgsgeorefconfigdialog.cpp
Expand Up @@ -54,13 +54,27 @@ void QgsGeorefConfigDialog::readSettings()
{
QSettings s;
if ( s.value( "/Plugin-GeoReferencer/Config/ShowId" ).toBool() )
mShowIDsRadioButton->setChecked( true );
{
mShowIDsCheckBox->setChecked( true );
}
else
{
mShowIDsCheckBox->setChecked( false );
}

if ( s.value( "/Plugin-GeoReferencer/Config/ShowCoords" ).toBool() )
{
mShowCoordsCheckBox->setChecked( true );
}
else
mShowCoordsRadioButton->setChecked( true );
{
mShowCoordsCheckBox->setChecked( false );
}
}

void QgsGeorefConfigDialog::writeSettings()
{
QSettings s;
s.setValue( "/Plugin-GeoReferencer/Config/ShowId", mShowIDsRadioButton->isChecked() );
s.setValue( "/Plugin-GeoReferencer/Config/ShowId", mShowIDsCheckBox->isChecked() );
s.setValue( "/Plugin-GeoReferencer/Config/ShowCoords", mShowCoordsCheckBox->isChecked() );
}
13 changes: 5 additions & 8 deletions src/plugins/georeferencer/qgsgeorefconfigdialogbase.ui
Expand Up @@ -6,32 +6,29 @@
<rect>
<x>0</x>
<y>0</y>
<width>221</width>
<height>102</height>
<width>219</width>
<height>162</height>
</rect>
</property>
<property name="windowTitle">
<string>Configure Georeferencer</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QGroupBox" name="mPointTipGroupBox">
<property name="title">
<string>Point tip</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QRadioButton" name="mShowIDsRadioButton">
<widget class="QCheckBox" name="mShowIDsCheckBox">
<property name="text">
<string>Show IDs</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mShowCoordsRadioButton">
<widget class="QCheckBox" name="mShowCoordsCheckBox">
<property name="text">
<string>Show coords</string>
</property>
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/georeferencer/qgsgeorefdatapoint.cpp
Expand Up @@ -47,6 +47,8 @@ QgsGeorefDataPoint::QgsGeorefDataPoint( const QgsGeorefDataPoint &p )
mPixelCoords = p.pixelCoords();
mMapCoords = p.mapCoords();
mEnabled = p.isEnabled();
mResidual = p.residual();
mId = p.id();
}

QgsGeorefDataPoint::~QgsGeorefDataPoint()
Expand Down
6 changes: 6 additions & 0 deletions src/plugins/georeferencer/qgsgeorefdatapoint.h
Expand Up @@ -13,6 +13,10 @@
* *
***************************************************************************/
/* $Id$ */

#ifndef QGSGEOREFDATAPOINT_H
#define QGSGEOREFDATAPOINT_H

#include "qgsmapcanvasitem.h"

class QgsGCPCanvasItem;
Expand Down Expand Up @@ -66,3 +70,5 @@ class QgsGeorefDataPoint : public QObject
bool mEnabled;
QPointF mResidual;
};

#endif //QGSGEOREFDATAPOINT_H

0 comments on commit 873df9b

Please sign in to comment.