Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Convert more code from QgsMapCanvasSnapper to QgsSnappingUtils
  • Loading branch information
wonder-sk committed Jan 20, 2015
1 parent 4b8ea28 commit 1174361
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
12 changes: 6 additions & 6 deletions src/app/qgsmaptoolrotatepointsymbols.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgsmapcanvas.h"
#include "qgspointrotationitem.h"
#include "qgsrendererv2.h"
#include "qgssnappingutils.h"
#include "qgssymbolv2.h"
#include "qgsvectorlayer.h"
#include <QGraphicsPixmapItem>
Expand Down Expand Up @@ -91,15 +92,14 @@ void QgsMapToolRotatePointSymbols::canvasPressEvent( QMouseEvent *e )
}

//find the closest feature to the pressed position
QgsMapCanvasSnapper canvasSnapper( mCanvas );
QList<QgsSnappingResult> snapResults;
if ( canvasSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertex, -1 ) != 0 || snapResults.size() < 1 )
QgsPointLocator::Match m = mCanvas->snappingUtils()->snapToCurrentLayer( e->pos(), QgsPointLocator::Vertex );
if ( !m.isValid() )
{
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 );
return; //error during snapping
}

mFeatureNumber = snapResults.at( 0 ).snappedAtGeometry;
mFeatureNumber = m.featureId();

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

mSnappedPoint = toCanvasCoordinates( snapResults.at( 0 ).snappedVertex );
mSnappedPoint = toCanvasCoordinates( m.point() );

//find out initial arrow direction
QgsFeature pointFeature;
Expand All @@ -131,7 +131,7 @@ void QgsMapToolRotatePointSymbols::canvasPressEvent( QMouseEvent *e )
createPixmapItem( pointFeature );
if ( mRotationItem )
{
mRotationItem->setPointLocation( snapResults.at( 0 ).snappedVertex );
mRotationItem->setPointLocation( m.point() );
}
mCurrentMouseAzimut = calculateAzimut( e->pos() );
setPixmapItemRotation(( int )( mCurrentMouseAzimut ) );
Expand Down
11 changes: 4 additions & 7 deletions src/app/qgsmaptoolsplitfeatures.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgsmapcanvas.h"
#include "qgsmaptoolsplitfeatures.h"
#include "qgsproject.h"
#include "qgssnappingutils.h"
#include "qgsvectorlayer.h"

#include <QMouseEvent>
Expand Down Expand Up @@ -56,17 +57,13 @@ void QgsMapToolSplitFeatures::canvasMapReleaseEvent( QgsMapMouseEvent * e )
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
QList<QgsSnappingResult> snapResults;

//If we snap the first point on a vertex of a line layer, we directly split the feature at this point
if ( vlayer->geometryType() == QGis::Line && points().isEmpty() )
{
if ( mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertex ) == 0 )
QgsPointLocator::Match m = mCanvas->snappingUtils()->snapToCurrentLayer( e->pos(), QgsPointLocator::Vertex );
if ( m.isValid() )
{
if ( snapResults.size() > 0 )
{
split = true;
}
split = true;
}
}

Expand Down
11 changes: 4 additions & 7 deletions src/app/qgsmaptoolsplitparts.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgsmapcanvas.h"
#include "qgsproject.h"
#include "qgsmaptoolsplitparts.h"
#include "qgssnappingutils.h"
#include "qgsvectorlayer.h"

#include <QMouseEvent>
Expand Down Expand Up @@ -55,17 +56,13 @@ void QgsMapToolSplitParts::canvasMapReleaseEvent( QgsMapMouseEvent * e )
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
QList<QgsSnappingResult> snapResults;

//If we snap the first point on a vertex of a line layer, we directly split the feature at this point
if ( vlayer->geometryType() == QGis::Line && points().isEmpty() )
{
if ( mSnapper.snapToCurrentLayer( e->pos(), snapResults, QgsSnapper::SnapToVertex ) == 0 )
QgsPointLocator::Match m = mCanvas->snappingUtils()->snapToCurrentLayer( e->pos(), QgsPointLocator::Vertex );
if ( m.isValid() )
{
if ( snapResults.size() > 0 )
{
split = true;
}
split = true;
}
}

Expand Down

0 comments on commit 1174361

Please sign in to comment.