Skip to content

Commit a9f345f

Browse files
author
mmassing
committed
Partial patch #2673 by mhugent:
-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@13436 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent cca4b0c commit a9f345f

14 files changed

+463
-85
lines changed

src/plugins/georeferencer/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SET (GEOREF_SRCS
1515
qgsgeorefvalidators.cpp
1616
qgsleastsquares.cpp
1717
qgsmapcoordsdialog.cpp
18+
qgsresidualplotitem.cpp
1819
qgstransformsettingsdialog.cpp
1920

2021
qgsgcplist.cpp
@@ -67,7 +68,7 @@ ADD_LIBRARY (georefplugin MODULE ${GEOREF_SRCS} ${GEOREF_MOC_SRCS} ${GEOREF_RCC_
6768
INCLUDE_DIRECTORIES(
6869
${CMAKE_CURRENT_SOURCE_DIR}
6970
${CMAKE_CURRENT_BINARY_DIR}
70-
../../core ../../core/raster ../../core/renderer ../../core/symbology
71+
../../core ../../core/raster ../../core/renderer ../../core/symbology ../../core/composer
7172
../../gui
7273
..
7374
${GSL_INCLUDE_DIR}

src/plugins/georeferencer/qgsgcpcanvasitem.cpp

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ QgsGCPCanvasItem::QgsGCPCanvasItem( QgsMapCanvas* mapCanvas, const QgsGeorefData
3535

3636
void QgsGCPCanvasItem::paint( QPainter* p )
3737
{
38+
QgsRenderContext context;
39+
if ( !setRenderContextVariables( p, context ) )
40+
{
41+
return;
42+
}
43+
3844
p->setRenderHint( QPainter::Antialiasing );
3945

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

5864
QSettings s;
5965
bool showIDs = s.value( "/Plugin-GeoReferencer/Config/ShowId" ).toBool();
60-
if ( !showIDs && mIsGCPSource )
66+
bool showCoords = s.value( "/Plugin-GeoReferencer/Config/ShowCoords" ).toBool();
67+
68+
QString msg;
69+
if ( showIDs && showCoords )
6170
{
62-
QString msg = QString( "X %1\nY %2" ).arg( QString::number( worldCoords.x(), 'f' ) ).
63-
arg( QString::number( worldCoords.y(), 'f' ) );
64-
p->setFont( QFont( "helvetica", 9 ) );
65-
QRect textBounds = p->boundingRect( 6, 6, 10, 10, Qt::AlignLeft, msg );
66-
p->setBrush( mLabelBrush );
67-
p->drawRect( textBounds.x() - 2, textBounds.y() - 2, textBounds.width() + 4, textBounds.height() + 4 );
68-
p->drawText( textBounds, Qt::AlignLeft, msg );
69-
mTextBounds = QSizeF( textBounds.width() + 4, textBounds.height() + 4 );
71+
msg = QString( "%1\nX %2\nY %3" ).arg( QString::number( id ) ).arg( QString::number( worldCoords.x(), 'f' ) ).arg( QString::number( worldCoords.y(), 'f' ) );
7072
}
7173
else if ( showIDs )
7274
{
73-
p->setFont( QFont( "helvetica", 12 ) );
74-
QString msg = QString::number( id );
75+
msg = msg = QString::number( id );
76+
}
77+
else if ( showCoords )
78+
{
79+
msg = QString( "X %1\nY %2" ).arg( QString::number( worldCoords.x(), 'f' ) ).arg( QString::number( worldCoords.y(), 'f' ) );
80+
}
81+
82+
if ( !msg.isEmpty() )
83+
{
7584
p->setBrush( mLabelBrush );
76-
p->drawRect( 5, 4, p->fontMetrics().width( msg ) + 2, 14 );
77-
p->drawText( 6, 16, msg );
78-
QFontMetrics fm = p->fontMetrics();
79-
mTextBounds = QSize( fm.width( msg ) + 4, fm.height() + 4 );
85+
QFont textFont( "helvetica" );
86+
textFont.setPixelSize( fontSizePainterUnits( 12, context ) );
87+
p->setFont( textFont );
88+
QRectF textBounds = p->boundingRect( 3 * context.scaleFactor(), 3 * context.scaleFactor(), 5 * context.scaleFactor(), 5 * context.scaleFactor(), Qt::AlignLeft, msg );
89+
mTextBoxRect = QRectF( textBounds.x() - context.scaleFactor() * 1, textBounds.y() - context.scaleFactor() * 1, \
90+
textBounds.width() + 2 * context.scaleFactor(), textBounds.height() + 2 * context.scaleFactor() );
91+
p->drawRect( mTextBoxRect );
92+
p->drawText( textBounds, Qt::AlignLeft, msg );
8093
}
8194

82-
drawResidualArrow( p );
95+
if ( data( 0 ) != "composer" ) //draw residuals only on screen
96+
{
97+
drawResidualArrow( p, context );
98+
}
8399
}
84100

85101
QRectF QgsGCPCanvasItem::boundingRect() const
@@ -91,6 +107,8 @@ QRectF QgsGCPCanvasItem::boundingRect() const
91107
{
92108
residual = mDataPoint->residual();
93109
}
110+
111+
//only considering screen resolution is ok for the bounding box function
94112
double rf = residualToScreenFactor();
95113

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

117135
QRectF residualArrowRect( QPointF( residualLeft, residualTop ), QPointF( residualRight, residualBottom ) );
118136
QRectF markerRect( -2, -2, mTextBounds.width() + 6, mTextBounds.height() + 6 );
119-
return residualArrowRect.united( markerRect );
137+
QRectF boundingRect = residualArrowRect.united( markerRect );
138+
if ( !mTextBoxRect.isNull() )
139+
{
140+
boundingRect = boundingRect.united( mTextBoxRect );
141+
}
142+
return boundingRect;
120143
}
121144

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

141-
void QgsGCPCanvasItem::drawResidualArrow( QPainter* p )
164+
void QgsGCPCanvasItem::drawResidualArrow( QPainter* p, const QgsRenderContext& context )
142165
{
143-
if ( !mDataPoint || !mIsGCPSource )
166+
if ( !mDataPoint || !mIsGCPSource || !mMapCanvas )
144167
{
145168
return;
146169
}
@@ -188,3 +211,9 @@ void QgsGCPCanvasItem::checkBoundingRectChange()
188211
{
189212
prepareGeometryChange();
190213
}
214+
215+
double QgsGCPCanvasItem::fontSizePainterUnits( double points, const QgsRenderContext& c )
216+
{
217+
return points * 0.3527 * c.scaleFactor();
218+
}
219+

src/plugins/georeferencer/qgsgcpcanvasitem.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,14 @@ class QgsGCPCanvasItem : public QgsMapCanvasItem
4949
bool mIsGCPSource;
5050
QPen mResidualPen;
5151

52-
void drawResidualArrow( QPainter* p );
52+
//text box rect for bounding rect calculation (updated in the paint event)
53+
QRectF mTextBoxRect;
54+
55+
void drawResidualArrow( QPainter* p, const QgsRenderContext& context );
5356
/**Calculates scale factor for residual display*/
5457
double residualToScreenFactor() const;
58+
/**Calculates pixel size for a font point size*/
59+
double fontSizePainterUnits( double points, const QgsRenderContext& c );
5560
};
5661

5762
#endif // QGSGCPCANVASITEM_H

src/plugins/georeferencer/qgsgeorefconfigdialog.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,27 @@ void QgsGeorefConfigDialog::readSettings()
5454
{
5555
QSettings s;
5656
if ( s.value( "/Plugin-GeoReferencer/Config/ShowId" ).toBool() )
57-
mShowIDsRadioButton->setChecked( true );
57+
{
58+
mShowIDsCheckBox->setChecked( true );
59+
}
60+
else
61+
{
62+
mShowIDsCheckBox->setChecked( false );
63+
}
64+
65+
if ( s.value( "/Plugin-GeoReferencer/Config/ShowCoords" ).toBool() )
66+
{
67+
mShowCoordsCheckBox->setChecked( true );
68+
}
5869
else
59-
mShowCoordsRadioButton->setChecked( true );
70+
{
71+
mShowCoordsCheckBox->setChecked( false );
72+
}
6073
}
6174

6275
void QgsGeorefConfigDialog::writeSettings()
6376
{
6477
QSettings s;
65-
s.setValue( "/Plugin-GeoReferencer/Config/ShowId", mShowIDsRadioButton->isChecked() );
78+
s.setValue( "/Plugin-GeoReferencer/Config/ShowId", mShowIDsCheckBox->isChecked() );
79+
s.setValue( "/Plugin-GeoReferencer/Config/ShowCoords", mShowCoordsCheckBox->isChecked() );
6680
}

src/plugins/georeferencer/qgsgeorefconfigdialogbase.ui

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,29 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>221</width>
10-
<height>102</height>
9+
<width>219</width>
10+
<height>162</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>Configure Georeferencer</string>
1515
</property>
16-
<layout class="QGridLayout" name="gridLayout">
16+
<layout class="QGridLayout" name="gridLayout_2">
1717
<item row="0" column="0">
1818
<widget class="QGroupBox" name="mPointTipGroupBox">
1919
<property name="title">
2020
<string>Point tip</string>
2121
</property>
2222
<layout class="QHBoxLayout" name="horizontalLayout">
2323
<item>
24-
<widget class="QRadioButton" name="mShowIDsRadioButton">
24+
<widget class="QCheckBox" name="mShowIDsCheckBox">
2525
<property name="text">
2626
<string>Show IDs</string>
2727
</property>
28-
<property name="checked">
29-
<bool>true</bool>
30-
</property>
3128
</widget>
3229
</item>
3330
<item>
34-
<widget class="QRadioButton" name="mShowCoordsRadioButton">
31+
<widget class="QCheckBox" name="mShowCoordsCheckBox">
3532
<property name="text">
3633
<string>Show coords</string>
3734
</property>

src/plugins/georeferencer/qgsgeorefdatapoint.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ QgsGeorefDataPoint::QgsGeorefDataPoint( const QgsGeorefDataPoint &p )
4747
mPixelCoords = p.pixelCoords();
4848
mMapCoords = p.mapCoords();
4949
mEnabled = p.isEnabled();
50+
mResidual = p.residual();
51+
mId = p.id();
5052
}
5153

5254
QgsGeorefDataPoint::~QgsGeorefDataPoint()

src/plugins/georeferencer/qgsgeorefdatapoint.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
* *
1414
***************************************************************************/
1515
/* $Id$ */
16+
17+
#ifndef QGSGEOREFDATAPOINT_H
18+
#define QGSGEOREFDATAPOINT_H
19+
1620
#include "qgsmapcanvasitem.h"
1721

1822
class QgsGCPCanvasItem;
@@ -66,3 +70,5 @@ class QgsGeorefDataPoint : public QObject
6670
bool mEnabled;
6771
QPointF mResidual;
6872
};
73+
74+
#endif //QGSGEOREFDATAPOINT_H

0 commit comments

Comments
 (0)