Skip to content
Permalink
Browse files

cancel select by radius by pressing ESC

  • Loading branch information
3nids committed Jan 18, 2018
1 parent aca2078 commit 4733bc8210e7e5faf38da31dd5392f75c1396f4a
Showing with 30 additions and 0 deletions.
  1. +23 −0 src/app/qgsmaptoolselectradius.cpp
  2. +7 −0 src/app/qgsmaptoolselectradius.h
@@ -81,6 +81,11 @@ bool QgsDistanceWidget::eventFilter( QObject *obj, QEvent *ev )
if ( obj == mDistanceSpinBox && ev->type() == QEvent::KeyPress )
{
QKeyEvent *event = static_cast<QKeyEvent *>( ev );
if ( event->key() == Qt::Key_Escape )
{
emit distanceEditingCancelled();
return true;
}
if ( event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return )
{
emit distanceEditingFinished( distance(), event->modifiers() );
@@ -185,6 +190,16 @@ void QgsMapToolSelectRadius::deactivate()
QgsMapTool::deactivate();
}

void QgsMapToolSelectRadius::keyReleaseEvent( QKeyEvent *e )
{
if ( mActive && e->key() == Qt::Key_Escape )
{
cancel();
return;
}
QgsMapTool::keyReleaseEvent( e );
}

void QgsMapToolSelectRadius::updateRubberband( const double &radius )
{
mRubberBand->reset( QgsWkbTypes::PolygonGeometry );
@@ -214,6 +229,13 @@ void QgsMapToolSelectRadius::radiusValueEntered( const double &radius, const Qt:
selectFromRubberband( modifiers );
}

void QgsMapToolSelectRadius::cancel()
{
deleteRotationWidget();
deleteRubberband();
mActive = false;
}

void QgsMapToolSelectRadius::deleteRubberband()
{
delete mRubberBand;
@@ -236,6 +258,7 @@ void QgsMapToolSelectRadius::createRotationWidget()

connect( mDistanceWidget, &QgsDistanceWidget::distanceChanged, this, &QgsMapToolSelectRadius::updateRubberband );
connect( mDistanceWidget, &QgsDistanceWidget::distanceEditingFinished, this, &QgsMapToolSelectRadius::radiusValueEntered );
connect( mDistanceWidget, &QgsDistanceWidget::distanceEditingCancelled, this, &QgsMapToolSelectRadius::cancel );
}

void QgsMapToolSelectRadius::deleteRotationWidget()
@@ -44,6 +44,7 @@ class APP_EXPORT QgsDistanceWidget : public QWidget
signals:
void distanceChanged( double distance );
void distanceEditingFinished( double distance, const Qt::KeyboardModifiers &modifiers );
void distanceEditingCancelled();

protected:
bool eventFilter( QObject *obj, QEvent *ev ) override;
@@ -74,6 +75,9 @@ class APP_EXPORT QgsMapToolSelectRadius : public QgsMapTool
//! called when map tool is being deactivated
void deactivate() override;

//! catch escape when active to cancel selection
void keyReleaseEvent( QKeyEvent *e ) override;

private slots:
//! update the rubber band from the input widget
void updateRubberband( const double &radius );
@@ -84,6 +88,9 @@ class APP_EXPORT QgsMapToolSelectRadius : public QgsMapTool
*/
void radiusValueEntered( const double &radius, const Qt::KeyboardModifiers &modifiers );

//! cancel selecting (between two click events)
void cancel();

private:
//! perform selection using radius from rubberband
void selectFromRubberband( const Qt::KeyboardModifiers &modifiers );

0 comments on commit 4733bc8

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