17
17
#include < QPushButton>
18
18
19
19
#include " qgsmapcanvas.h"
20
+ #include " qgsmapcanvassnapper.h"
20
21
21
22
#include " qgsgeorefvalidators.h"
22
23
#include " qgsmapcoordsdialog.h"
@@ -41,6 +42,9 @@ QgsMapCoordsDialog::QgsMapCoordsDialog( QgsMapCanvas* qgisCanvas, QgsPoint pixel
41
42
mToolEmitPoint = new QgsGeorefMapToolEmitPoint ( qgisCanvas );
42
43
mToolEmitPoint ->setButton ( mPointFromCanvasPushButton );
43
44
45
+ QSettings s;
46
+ mSnapToBackgroundLayerBox ->setChecked ( s.value ( " /Plugin-GeoReferencer/snapToBackgroundLayers" , QVariant (false ) ).toBool () );
47
+
44
48
connect ( mPointFromCanvasPushButton , SIGNAL ( clicked ( bool ) ), this , SLOT ( setToolEmitPoint ( bool ) ) );
45
49
46
50
connect ( mToolEmitPoint , SIGNAL ( canvasClicked ( const QgsPoint&, Qt::MouseButton ) ),
@@ -81,7 +85,8 @@ void QgsMapCoordsDialog::on_buttonBox_accepted()
81
85
y = dmsToDD ( leYCoord->text () );
82
86
83
87
emit pointAdded ( mPixelCoords , QgsPoint ( x, y ) );
84
-
88
+ QSettings s;
89
+ s.setValue ( " /Plugin-GeoReferencer/snapToBackgroundLayers" , mSnapToBackgroundLayerBox ->isChecked () );
85
90
close ();
86
91
}
87
92
@@ -90,10 +95,30 @@ void QgsMapCoordsDialog::maybeSetXY( const QgsPoint & xy, Qt::MouseButton button
90
95
// Only LeftButton should set point
91
96
if ( Qt::LeftButton == button )
92
97
{
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
+
93
118
leXCoord->clear ();
94
119
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 ) );
97
122
}
98
123
99
124
parentWidget ()->showNormal ();
0 commit comments