|
24 | 24 | #include "qgsmapcanvas.h"
|
25 | 25 | #include "qgsproject.h"
|
26 | 26 | #include "qgsrubberband.h"
|
| 27 | +#include "qgssnappingutils.h" |
27 | 28 | #include "qgsvectorlayer.h"
|
28 | 29 |
|
29 | 30 | #include <QMouseEvent>
|
30 | 31 | #include <QRubberBand>
|
31 | 32 |
|
| 33 | +//! Match filter that does not accept only one particular point |
| 34 | +struct QgsExcludePointFilter : public QgsPointLocator::MatchFilter |
| 35 | +{ |
| 36 | + QgsExcludePointFilter( const QgsPoint& exclPoint ) : mExclPoint( exclPoint ) {} |
| 37 | + bool acceptMatch( const QgsPointLocator::Match& match ) { return match.point() != mExclPoint; } |
| 38 | + QgsPoint mExclPoint; |
| 39 | +}; |
| 40 | + |
| 41 | + |
32 | 42 | QgsMapToolNodeTool::QgsMapToolNodeTool( QgsMapCanvas* canvas )
|
33 | 43 | : QgsMapToolVertexEdit( canvas )
|
34 | 44 | , mSelectedFeature( 0 )
|
@@ -256,26 +266,22 @@ void QgsMapToolNodeTool::canvasMoveEvent( QMouseEvent * e )
|
256 | 266 | }
|
257 | 267 | createMovingRubberBands();
|
258 | 268 |
|
259 |
| - QList<QgsSnappingResult> snapResults; |
260 |
| - QgsPoint posMapCoord = snapPointFromResults( snapResults, e->pos() ); |
261 |
| - mPosMapCoordBackup = posMapCoord; |
| 269 | + mPosMapCoordBackup = toMapCoordinates( e->pos() ); |
262 | 270 | }
|
263 | 271 | else
|
264 | 272 | {
|
265 | 273 | // move rubberband
|
266 |
| - QList<QgsSnappingResult> snapResults; |
267 |
| - mSnapper.snapToBackgroundLayers( e->pos(), snapResults, QList<QgsPoint>() << mClosestMapVertex ); |
268 |
| - |
269 |
| - // get correct coordinates to move to |
270 |
| - QgsPoint posMapCoord = snapPointFromResults( snapResults, e->pos() ); |
271 |
| - |
272 |
| - QgsPoint pressMapCoords; |
273 |
| - if ( snapResults.size() > 0 ) |
| 274 | + QgsPoint posMapCoord, pressMapCoords; |
| 275 | + QgsExcludePointFilter excludePointFilter( mClosestMapVertex ); |
| 276 | + QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToMap( e->pos(), &excludePointFilter ); |
| 277 | + if ( match.isValid() ) |
274 | 278 | {
|
| 279 | + posMapCoord = match.point(); |
275 | 280 | pressMapCoords = mClosestMapVertex;
|
276 | 281 | }
|
277 | 282 | else
|
278 | 283 | {
|
| 284 | + posMapCoord = toMapCoordinates( e->pos() ); |
279 | 285 | pressMapCoords = toMapCoordinates( mPressCoordinates );
|
280 | 286 | }
|
281 | 287 |
|
@@ -544,27 +550,33 @@ void QgsMapToolNodeTool::canvasReleaseEvent( QMouseEvent * e )
|
544 | 550 | if ( mMoving )
|
545 | 551 | {
|
546 | 552 | mMoving = false;
|
| 553 | + QgsPoint releaseMapCoords, pressMapCoords; |
547 | 554 |
|
548 |
| - QList<QgsSnappingResult> snapResults; |
549 |
| - mSnapper.snapToBackgroundLayers( e->pos(), snapResults, QList<QgsPoint>() << mClosestMapVertex ); |
550 |
| - |
551 |
| - QgsPoint releaseLayerCoords = toLayerCoordinates( vlayer, snapPointFromResults( snapResults, e->pos() ) ); |
| 555 | + QgsExcludePointFilter excludePointFilter( mClosestMapVertex ); |
| 556 | + QgsPointLocator::Match match = mCanvas->snappingUtils()->snapToMap( e->pos(), &excludePointFilter ); |
552 | 557 |
|
553 |
| - QgsPoint pressLayerCoords; |
554 |
| - if ( snapResults.size() > 0 ) |
| 558 | + if ( match.isValid() ) |
| 559 | + { |
| 560 | + releaseMapCoords = match.point(); |
| 561 | + pressMapCoords = mClosestMapVertex; |
| 562 | + } |
| 563 | + else |
555 | 564 | {
|
556 |
| - pressLayerCoords = toLayerCoordinates( vlayer, mClosestMapVertex ); |
| 565 | + releaseMapCoords = toMapCoordinates( e->pos() ); |
| 566 | + pressMapCoords = toMapCoordinates( mPressCoordinates ); |
| 567 | + } |
557 | 568 |
|
| 569 | + QgsPoint releaseLayerCoords = toLayerCoordinates( vlayer, releaseMapCoords ); |
| 570 | + QgsPoint pressLayerCoords = toLayerCoordinates( vlayer, pressMapCoords ); |
| 571 | + |
| 572 | + if ( match.isValid() ) |
| 573 | + { |
558 | 574 | int topologicalEditing = QgsProject::instance()->readNumEntry( "Digitizing", "/TopologicalEditing", 0 );
|
559 | 575 | if ( topologicalEditing )
|
560 | 576 | {
|
561 |
| - insertSegmentVerticesForSnap( snapResults, vlayer ); |
| 577 | + addTopologicalPoints( QList<QgsPoint>() << releaseMapCoords ); |
562 | 578 | }
|
563 | 579 | }
|
564 |
| - else |
565 |
| - { |
566 |
| - pressLayerCoords = toLayerCoordinates( vlayer, mPressCoordinates ); |
567 |
| - } |
568 | 580 |
|
569 | 581 | mSelectedFeature->moveSelectedVertexes( releaseLayerCoords - pressLayerCoords );
|
570 | 582 | mCanvas->refresh();
|
|
0 commit comments