[QGIS Commit] r13296 - trunk/qgis/src/plugins/georeferencer

svn_qgis at osgeo.org svn_qgis at osgeo.org
Sun Apr 11 08:44:11 EDT 2010


Author: mmassing
Date: 2010-04-11 08:44:10 -0400 (Sun, 11 Apr 2010)
New Revision: 13296

Modified:
   trunk/qgis/src/plugins/georeferencer/qgsmapcoordsdialog.cpp
   trunk/qgis/src/plugins/georeferencer/qgsmapcoordsdialogbase.ui
Log:
Patch #2633 by mhugent: adds "snap to background" option when taking gcp coordinates from main canvas.

Modified: trunk/qgis/src/plugins/georeferencer/qgsmapcoordsdialog.cpp
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsmapcoordsdialog.cpp	2010-04-11 12:44:00 UTC (rev 13295)
+++ trunk/qgis/src/plugins/georeferencer/qgsmapcoordsdialog.cpp	2010-04-11 12:44:10 UTC (rev 13296)
@@ -17,6 +17,7 @@
 #include <QPushButton>
 
 #include "qgsmapcanvas.h"
+#include "qgsmapcanvassnapper.h"
 
 #include "qgsgeorefvalidators.h"
 #include "qgsmapcoordsdialog.h"
@@ -41,6 +42,9 @@
   mToolEmitPoint = new QgsGeorefMapToolEmitPoint( qgisCanvas );
   mToolEmitPoint->setButton( mPointFromCanvasPushButton );
 
+  QSettings s;
+  mSnapToBackgroundLayerBox->setChecked( s.value( "/Plugin-GeoReferencer/snapToBackgroundLayers", QVariant(false) ).toBool() );
+
   connect( mPointFromCanvasPushButton, SIGNAL( clicked( bool ) ), this, SLOT( setToolEmitPoint( bool ) ) );
 
   connect( mToolEmitPoint, SIGNAL( canvasClicked( const QgsPoint&, Qt::MouseButton ) ),
@@ -81,7 +85,8 @@
     y = dmsToDD( leYCoord->text() );
 
   emit pointAdded( mPixelCoords, QgsPoint( x, y ) );
-
+  QSettings s;
+  s.setValue( "/Plugin-GeoReferencer/snapToBackgroundLayers", mSnapToBackgroundLayerBox->isChecked() );
   close();
 }
 
@@ -90,10 +95,30 @@
   // Only LeftButton should set point
   if ( Qt::LeftButton == button )
   {
+    QgsPoint mapCoordPoint = xy;
+    if ( mQgisCanvas && mSnapToBackgroundLayerBox->isChecked() )
+    {
+      const QgsMapToPixel* mtp = mQgisCanvas->getCoordinateTransform();
+      if ( mtp )
+      {
+        QgsPoint canvasPos = mtp->transform( xy.x(), xy.y() );
+        QPoint snapStartPoint( canvasPos.x(), canvasPos.y() );
+        QgsMapCanvasSnapper snapper( mQgisCanvas );
+        QList<QgsSnappingResult> snapResults;
+        if ( snapper.snapToBackgroundLayers( snapStartPoint, snapResults ) == 0 )
+        {
+          if ( snapResults.size() > 0 )
+          {
+            mapCoordPoint = snapResults.at( 0 ).snappedVertex;
+          }
+        }
+      }
+    }
+
     leXCoord->clear();
     leYCoord->clear();
-    leXCoord->setText( QString::number( xy.x(), 'f', 7 ) );
-    leYCoord->setText( QString::number( xy.y(), 'f', 7 ) );
+    leXCoord->setText( QString::number( mapCoordPoint.x(), 'f', 7 ) );
+    leYCoord->setText( QString::number( mapCoordPoint.y(), 'f', 7 ) );
   }
 
   parentWidget()->showNormal();

Modified: trunk/qgis/src/plugins/georeferencer/qgsmapcoordsdialogbase.ui
===================================================================
--- trunk/qgis/src/plugins/georeferencer/qgsmapcoordsdialogbase.ui	2010-04-11 12:44:00 UTC (rev 13295)
+++ trunk/qgis/src/plugins/georeferencer/qgsmapcoordsdialogbase.ui	2010-04-11 12:44:10 UTC (rev 13296)
@@ -55,7 +55,14 @@
      </item>
     </layout>
    </item>
-   <item row="2" column="0" colspan="2">
+   <item row="2" column="0">
+    <widget class="QCheckBox" name="mSnapToBackgroundLayerBox">
+     <property name="text">
+      <string>Snap to background layers</string>
+     </property>
+    </widget>
+   </item>
+   <item row="3" column="0">
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="standardButtons">
       <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>



More information about the QGIS-commit mailing list