Skip to content

Commit

Permalink
Patch #2633 by mhugent: adds "snap to background" option when taking …
Browse files Browse the repository at this point in the history
…gcp coordinates from main canvas.

git-svn-id: http://svn.osgeo.org/qgis/trunk@13296 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mmassing committed Apr 11, 2010
1 parent 8b0ba23 commit 3a4b119
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
31 changes: 28 additions & 3 deletions src/plugins/georeferencer/qgsmapcoordsdialog.cpp
Expand Up @@ -17,6 +17,7 @@
#include <QPushButton>

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

#include "qgsgeorefvalidators.h"
#include "qgsmapcoordsdialog.h"
Expand All @@ -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 ) ),
Expand Down Expand Up @@ -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();
}

Expand All @@ -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();
Expand Down
9 changes: 8 additions & 1 deletion src/plugins/georeferencer/qgsmapcoordsdialogbase.ui
Expand Up @@ -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>
Expand Down

0 comments on commit 3a4b119

Please sign in to comment.