Skip to content

Commit

Permalink
Enable snapping for select by radius tool
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 20, 2018
1 parent 2b61591 commit fb0529b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 10 additions & 6 deletions src/app/qgsmaptoolselectradius.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -118,6 +117,9 @@ QgsMapToolSelectRadius::~QgsMapToolSelectRadius()

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

if ( !mActive )
return;

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

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

Expand All @@ -149,7 +150,7 @@ void QgsMapToolSelectRadius::canvasReleaseEvent( QgsMapMouseEvent *e )
if ( !mActive )
{
mActive = true;
mRadiusCenter = toMapCoordinates( e->pos() );
mRadiusCenter = e->snapPoint();
createRotationWidget();
}
else
Expand All @@ -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() );
}
Expand All @@ -187,6 +188,9 @@ void QgsMapToolSelectRadius::deactivate()
deleteRotationWidget();
deleteRubberband();
mActive = false;

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

QgsMapTool::deactivate();
}

Expand Down
6 changes: 4 additions & 2 deletions src/app/qgsmaptoolselectradius.h
Expand Up @@ -26,6 +26,7 @@ class QHBoxLayout;
class QgsDoubleSpinBox;
class QgsMapCanvas;
class QgsRubberBand;
class QgsSnapIndicator;

class APP_EXPORT QgsDistanceWidget : public QWidget
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit fb0529b

Please sign in to comment.