Skip to content

Commit 845db57

Browse files
author
mmassing
committed
Patch #2633 by mhugent: adds "snap to background" option when taking gcp coordinates from main canvas.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13296 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 87984be commit 845db57

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/plugins/georeferencer/qgsmapcoordsdialog.cpp

+28-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <QPushButton>
1818

1919
#include "qgsmapcanvas.h"
20+
#include "qgsmapcanvassnapper.h"
2021

2122
#include "qgsgeorefvalidators.h"
2223
#include "qgsmapcoordsdialog.h"
@@ -41,6 +42,9 @@ QgsMapCoordsDialog::QgsMapCoordsDialog( QgsMapCanvas* qgisCanvas, QgsPoint pixel
4142
mToolEmitPoint = new QgsGeorefMapToolEmitPoint( qgisCanvas );
4243
mToolEmitPoint->setButton( mPointFromCanvasPushButton );
4344

45+
QSettings s;
46+
mSnapToBackgroundLayerBox->setChecked( s.value( "/Plugin-GeoReferencer/snapToBackgroundLayers", QVariant(false) ).toBool() );
47+
4448
connect( mPointFromCanvasPushButton, SIGNAL( clicked( bool ) ), this, SLOT( setToolEmitPoint( bool ) ) );
4549

4650
connect( mToolEmitPoint, SIGNAL( canvasClicked( const QgsPoint&, Qt::MouseButton ) ),
@@ -81,7 +85,8 @@ void QgsMapCoordsDialog::on_buttonBox_accepted()
8185
y = dmsToDD( leYCoord->text() );
8286

8387
emit pointAdded( mPixelCoords, QgsPoint( x, y ) );
84-
88+
QSettings s;
89+
s.setValue( "/Plugin-GeoReferencer/snapToBackgroundLayers", mSnapToBackgroundLayerBox->isChecked() );
8590
close();
8691
}
8792

@@ -90,10 +95,30 @@ void QgsMapCoordsDialog::maybeSetXY( const QgsPoint & xy, Qt::MouseButton button
9095
// Only LeftButton should set point
9196
if ( Qt::LeftButton == button )
9297
{
98+
QgsPoint mapCoordPoint = xy;
99+
if ( mQgisCanvas && mSnapToBackgroundLayerBox->isChecked() )
100+
{
101+
const QgsMapToPixel* mtp = mQgisCanvas->getCoordinateTransform();
102+
if ( mtp )
103+
{
104+
QgsPoint canvasPos = mtp->transform( xy.x(), xy.y() );
105+
QPoint snapStartPoint( canvasPos.x(), canvasPos.y() );
106+
QgsMapCanvasSnapper snapper( mQgisCanvas );
107+
QList<QgsSnappingResult> snapResults;
108+
if ( snapper.snapToBackgroundLayers( snapStartPoint, snapResults ) == 0 )
109+
{
110+
if ( snapResults.size() > 0 )
111+
{
112+
mapCoordPoint = snapResults.at( 0 ).snappedVertex;
113+
}
114+
}
115+
}
116+
}
117+
93118
leXCoord->clear();
94119
leYCoord->clear();
95-
leXCoord->setText( QString::number( xy.x(), 'f', 7 ) );
96-
leYCoord->setText( QString::number( xy.y(), 'f', 7 ) );
120+
leXCoord->setText( QString::number( mapCoordPoint.x(), 'f', 7 ) );
121+
leYCoord->setText( QString::number( mapCoordPoint.y(), 'f', 7 ) );
97122
}
98123

99124
parentWidget()->showNormal();

src/plugins/georeferencer/qgsmapcoordsdialogbase.ui

+8-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@
5555
</item>
5656
</layout>
5757
</item>
58-
<item row="2" column="0" colspan="2">
58+
<item row="2" column="0">
59+
<widget class="QCheckBox" name="mSnapToBackgroundLayerBox">
60+
<property name="text">
61+
<string>Snap to background layers</string>
62+
</property>
63+
</widget>
64+
</item>
65+
<item row="3" column="0">
5966
<widget class="QDialogButtonBox" name="buttonBox">
6067
<property name="standardButtons">
6168
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>

0 commit comments

Comments
 (0)