Skip to content

Commit 1174361

Browse files
committedJan 20, 2015
Convert more code from QgsMapCanvasSnapper to QgsSnappingUtils
1 parent 4b8ea28 commit 1174361

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed
 

‎src/app/qgsmaptoolrotatepointsymbols.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgsmapcanvas.h"
1919
#include "qgspointrotationitem.h"
2020
#include "qgsrendererv2.h"
21+
#include "qgssnappingutils.h"
2122
#include "qgssymbolv2.h"
2223
#include "qgsvectorlayer.h"
2324
#include <QGraphicsPixmapItem>
@@ -91,15 +92,14 @@ void QgsMapToolRotatePointSymbols::canvasPressEvent( QMouseEvent *e )
9192
}
9293

9394
//find the closest feature to the pressed position
94-
QgsMapCanvasSnapper canvasSnapper( mCanvas );
95-
QList<QgsSnappingResult> snapResults;
96-
if ( canvasSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertex, -1 ) != 0 || snapResults.size() < 1 )
95+
QgsPointLocator::Match m = mCanvas->snappingUtils()->snapToCurrentLayer( e->pos(), QgsPointLocator::Vertex );
96+
if ( !m.isValid() )
9797
{
9898
emit messageEmitted( tr( "No point feature was detected at the clicked position. Please click closer to the feature or enhance the search tolerance under Settings->Options->Digitizing->Serch radius for vertex edits" ), QgsMessageBar::CRITICAL );
9999
return; //error during snapping
100100
}
101101

102-
mFeatureNumber = snapResults.at( 0 ).snappedAtGeometry;
102+
mFeatureNumber = m.featureId();
103103

104104
//get list with renderer rotation attributes
105105
if ( layerRotationAttributes( mActiveLayer, mCurrentRotationAttributes ) != 0 )
@@ -113,7 +113,7 @@ void QgsMapToolRotatePointSymbols::canvasPressEvent( QMouseEvent *e )
113113
return;
114114
}
115115

116-
mSnappedPoint = toCanvasCoordinates( snapResults.at( 0 ).snappedVertex );
116+
mSnappedPoint = toCanvasCoordinates( m.point() );
117117

118118
//find out initial arrow direction
119119
QgsFeature pointFeature;
@@ -131,7 +131,7 @@ void QgsMapToolRotatePointSymbols::canvasPressEvent( QMouseEvent *e )
131131
createPixmapItem( pointFeature );
132132
if ( mRotationItem )
133133
{
134-
mRotationItem->setPointLocation( snapResults.at( 0 ).snappedVertex );
134+
mRotationItem->setPointLocation( m.point() );
135135
}
136136
mCurrentMouseAzimut = calculateAzimut( e->pos() );
137137
setPixmapItemRotation(( int )( mCurrentMouseAzimut ) );

‎src/app/qgsmaptoolsplitfeatures.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgsmapcanvas.h"
1919
#include "qgsmaptoolsplitfeatures.h"
2020
#include "qgsproject.h"
21+
#include "qgssnappingutils.h"
2122
#include "qgsvectorlayer.h"
2223

2324
#include <QMouseEvent>
@@ -56,17 +57,13 @@ void QgsMapToolSplitFeatures::canvasMapReleaseEvent( QgsMapMouseEvent * e )
5657
//add point to list and to rubber band
5758
if ( e->button() == Qt::LeftButton )
5859
{
59-
QList<QgsSnappingResult> snapResults;
60-
6160
//If we snap the first point on a vertex of a line layer, we directly split the feature at this point
6261
if ( vlayer->geometryType() == QGis::Line && points().isEmpty() )
6362
{
64-
if ( mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertex ) == 0 )
63+
QgsPointLocator::Match m = mCanvas->snappingUtils()->snapToCurrentLayer( e->pos(), QgsPointLocator::Vertex );
64+
if ( m.isValid() )
6565
{
66-
if ( snapResults.size() > 0 )
67-
{
68-
split = true;
69-
}
66+
split = true;
7067
}
7168
}
7269

‎src/app/qgsmaptoolsplitparts.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "qgsmapcanvas.h"
1919
#include "qgsproject.h"
2020
#include "qgsmaptoolsplitparts.h"
21+
#include "qgssnappingutils.h"
2122
#include "qgsvectorlayer.h"
2223

2324
#include <QMouseEvent>
@@ -55,17 +56,13 @@ void QgsMapToolSplitParts::canvasMapReleaseEvent( QgsMapMouseEvent * e )
5556
//add point to list and to rubber band
5657
if ( e->button() == Qt::LeftButton )
5758
{
58-
QList<QgsSnappingResult> snapResults;
59-
6059
//If we snap the first point on a vertex of a line layer, we directly split the feature at this point
6160
if ( vlayer->geometryType() == QGis::Line && points().isEmpty() )
6261
{
63-
if ( mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertex ) == 0 )
62+
QgsPointLocator::Match m = mCanvas->snappingUtils()->snapToCurrentLayer( e->pos(), QgsPointLocator::Vertex );
63+
if ( m.isValid() )
6464
{
65-
if ( snapResults.size() > 0 )
66-
{
67-
split = true;
68-
}
65+
split = true;
6966
}
7067
}
7168

0 commit comments

Comments
 (0)
Please sign in to comment.