Skip to content
Permalink
Browse files

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@13296 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mmassing
mmassing committed Apr 11, 2010
1 parent 8b0ba23 commit 3a4b1192eec1c34c038c987da393b488d50b5fb5
@@ -17,6 +17,7 @@
#include <QPushButton>

#include "qgsmapcanvas.h"
#include "qgsmapcanvassnapper.h"

#include "qgsgeorefvalidators.h"
#include "qgsmapcoordsdialog.h"
@@ -41,6 +42,9 @@ QgsMapCoordsDialog::QgsMapCoordsDialog( QgsMapCanvas* qgisCanvas, QgsPoint pixel
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 @@ void QgsMapCoordsDialog::on_buttonBox_accepted()
y = dmsToDD( leYCoord->text() );

emit pointAdded( mPixelCoords, QgsPoint( x, y ) );

QSettings s;
s.setValue( "/Plugin-GeoReferencer/snapToBackgroundLayers", mSnapToBackgroundLayerBox->isChecked() );
close();
}

@@ -90,10 +95,30 @@ void QgsMapCoordsDialog::maybeSetXY( const QgsPoint & xy, Qt::MouseButton button
// 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();
@@ -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>

0 comments on commit 3a4b119

Please sign in to comment.
You can’t perform that action at this time.