georefsnap.diff

Marco Hugentobler, 2010-04-07 04:49 AM

Download (3.03 KB)

View differences:

src/plugins/georeferencer/qgsmapcoordsdialog.cpp (working copy)
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 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 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 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();
src/plugins/georeferencer/qgsmapcoordsdialogbase.ui (working copy)
55 55
     </item>
56 56
    </layout>
57 57
   </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">
59 66
    <widget class="QDialogButtonBox" name="buttonBox">
60 67
     <property name="standardButtons">
61 68
      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>