Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Standardize UX for measure tool/measure angle tools with other map tools
- Measure tool: pressing "escape" cancels the measure
- Measure angle tool: right click cancels the measure, unless its the
  final point in which case the angle is locked in (like
digitizing/measure distance tools)
- Measure angle tool: backspace/del removes last point
- Measure angle tool: escape cancels the measure
  • Loading branch information
nyalldawson committed Jun 15, 2021
1 parent 5770019 commit 51c0886
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 9 deletions.
35 changes: 35 additions & 0 deletions src/app/qgsmaptoolmeasureangle.cpp
Expand Up @@ -86,6 +86,13 @@ void QgsMapToolMeasureAngle::canvasMoveEvent( QgsMapMouseEvent *e )

void QgsMapToolMeasureAngle::canvasReleaseEvent( QgsMapMouseEvent *e )
{
// if we clicked the right button we cancel the operation, unless it's the "final" click
if ( e->button() == Qt::RightButton && mAnglePoints.size() != 2 )
{
stopMeasuring();
return;
}

//add points until we have three
if ( mAnglePoints.size() == 3 )
{
Expand All @@ -112,6 +119,34 @@ void QgsMapToolMeasureAngle::canvasReleaseEvent( QgsMapMouseEvent *e )
}
}

void QgsMapToolMeasureAngle::keyPressEvent( QKeyEvent *e )
{
if ( e->key() == Qt::Key_Escape )
{
stopMeasuring();
}
else if ( ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) )
{
if ( !mAnglePoints.empty() && mRubberBand )
{
if ( mAnglePoints.size() == 1 )
{
//removing first point, so restart everything
stopMeasuring();
}
else
{
//remove second last point from line band, and last point from points band
mRubberBand->removePoint( -2, true );
mAnglePoints.removeLast();
}
}

// Override default shortcut management in MapCanvas
e->ignore();
}
}

void QgsMapToolMeasureAngle::stopMeasuring()
{
delete mRubberBand;
Expand Down
9 changes: 1 addition & 8 deletions src/app/qgsmaptoolmeasureangle.h
Expand Up @@ -34,17 +34,10 @@ class APP_EXPORT QgsMapToolMeasureAngle: public QgsMapTool
~QgsMapToolMeasureAngle() override;

Flags flags() const override { return QgsMapTool::AllowZoomRect; }

//! Mouse move event for overriding
void canvasMoveEvent( QgsMapMouseEvent *e ) override;

//! Mouse release event for overriding
void canvasReleaseEvent( QgsMapMouseEvent *e ) override;

//! called when set as currently active map tool
void keyPressEvent( QKeyEvent *e ) override;
void activate() override;

//! called when map tool is being deactivated
void deactivate() override;

private:
Expand Down
6 changes: 5 additions & 1 deletion src/app/qgsmeasuretool.cpp
Expand Up @@ -252,7 +252,11 @@ void QgsMeasureTool::undo()

void QgsMeasureTool::keyPressEvent( QKeyEvent *e )
{
if ( ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) )
if ( e->key() == Qt::Key_Escape )
{
mDialog->restart();
}
else if ( ( e->key() == Qt::Key_Backspace || e->key() == Qt::Key_Delete ) )
{
if ( !mDone )
{
Expand Down

0 comments on commit 51c0886

Please sign in to comment.