Skip to content
Permalink
Browse files

Enable snapping for select by radius tool

  • Loading branch information
nyalldawson committed Jan 19, 2018
1 parent 2b61591 commit fb0529bb56bea0d9ad027dc4945b58852aa84e14
Showing with 14 additions and 8 deletions.
  1. +10 −6 src/app/qgsmaptoolselectradius.cpp
  2. +4 −2 src/app/qgsmaptoolselectradius.h
@@ -29,6 +29,7 @@ email : jpalmer at linz dot govt dot nz
#include "qgis.h"
#include "qgslogger.h"
#include "qgsdoublespinbox.h"
#include "qgssnapindicator.h"


const int RADIUS_SEGMENTS = 80;
@@ -103,11 +104,9 @@ void QgsDistanceWidget::distanceSpinBoxValueChanged( double distance )

QgsMapToolSelectRadius::QgsMapToolSelectRadius( QgsMapCanvas *canvas )
: QgsMapTool( canvas )
, mSnapIndicator( new QgsSnapIndicator( canvas ) )
{
mRubberBand = nullptr;
mCursor = Qt::ArrowCursor;
mFillColor = QColor( 254, 178, 76, 63 );
mStrokeColor = QColor( 254, 58, 29, 100 );
}

QgsMapToolSelectRadius::~QgsMapToolSelectRadius()
@@ -118,6 +117,9 @@ QgsMapToolSelectRadius::~QgsMapToolSelectRadius()

void QgsMapToolSelectRadius::canvasMoveEvent( QgsMapMouseEvent *e )
{
QgsPointXY radiusEdge = e->snapPoint();
mSnapIndicator->setMatch( e->mapPointMatch() );

if ( !mActive )
return;

@@ -128,7 +130,6 @@ void QgsMapToolSelectRadius::canvasMoveEvent( QgsMapMouseEvent *e )
mRubberBand->setStrokeColor( mStrokeColor );
}

QgsPointXY radiusEdge = toMapCoordinates( e->pos() );
updateRadiusFromEdge( radiusEdge );
}

@@ -149,7 +150,7 @@ void QgsMapToolSelectRadius::canvasReleaseEvent( QgsMapMouseEvent *e )
if ( !mActive )
{
mActive = true;
mRadiusCenter = toMapCoordinates( e->pos() );
mRadiusCenter = e->snapPoint();
createRotationWidget();
}
else
@@ -160,7 +161,7 @@ void QgsMapToolSelectRadius::canvasReleaseEvent( QgsMapMouseEvent *e )
mRubberBand->setFillColor( mFillColor );
mRubberBand->setStrokeColor( mStrokeColor );
}
QgsPointXY radiusEdge = toMapCoordinates( QPoint( e->pos().x() + 1, e->pos().y() + 1 ) );
QgsPointXY radiusEdge = e->snapPoint();
updateRadiusFromEdge( radiusEdge );
selectFromRubberband( e->modifiers() );
}
@@ -187,6 +188,9 @@ void QgsMapToolSelectRadius::deactivate()
deleteRotationWidget();
deleteRubberband();
mActive = false;

mSnapIndicator->setMatch( QgsPointLocator::Match() );

QgsMapTool::deactivate();
}

@@ -26,6 +26,7 @@ class QHBoxLayout;
class QgsDoubleSpinBox;
class QgsMapCanvas;
class QgsRubberBand;
class QgsSnapIndicator;

class APP_EXPORT QgsDistanceWidget : public QWidget
{
@@ -104,14 +105,15 @@ class APP_EXPORT QgsMapToolSelectRadius : public QgsMapTool

//! used for storing all of the maps point for the polygon
QgsRubberBand *mRubberBand = nullptr;
std::unique_ptr<QgsSnapIndicator> mSnapIndicator;

//! Center point for the radius
QgsPointXY mRadiusCenter;

bool mActive = false;

QColor mFillColor;
QColor mStrokeColor;
QColor mFillColor = QColor( 254, 178, 76, 63 );
QColor mStrokeColor = QColor( 254, 58, 29, 100 );

//! Shows current angle value and allows numerical editing
QgsDistanceWidget *mDistanceWidget = nullptr;

0 comments on commit fb0529b

Please sign in to comment.
You can’t perform that action at this time.