Skip to content

Commit

Permalink
Add snap indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 10, 2021
1 parent e0c5cce commit f66eeeb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/gui/annotations/qgsmaptoolmodifyannotation.cpp
Expand Up @@ -26,6 +26,7 @@
#include "qgsannotationitem.h"
#include "qgsannotationitemnode.h"
#include "qgsannotationitemeditoperation.h"
#include "qgssnapindicator.h"
#include "RTree.h"
#include <QTransform>
#include <QWindow>
Expand Down Expand Up @@ -104,6 +105,7 @@ class QgsAnnotationItemNodesSpatialIndex : public RTree<int, float, 2, float>

QgsMapToolModifyAnnotation::QgsMapToolModifyAnnotation( QgsMapCanvas *canvas, QgsAdvancedDigitizingDockWidget *cadDockWidget )
: QgsMapToolAdvancedDigitizing( canvas, cadDockWidget )
, mSnapIndicator( new QgsSnapIndicator( canvas ) )
{

connect( QgsMapToolModifyAnnotation::canvas(), &QgsMapCanvas::mapCanvasRefreshed, this, &QgsMapToolModifyAnnotation::onCanvasRefreshed );
Expand All @@ -113,12 +115,17 @@ QgsMapToolModifyAnnotation::~QgsMapToolModifyAnnotation() = default;

void QgsMapToolModifyAnnotation::deactivate()
{
mSnapIndicator->setMatch( QgsPointLocator::Match() );

clearHoveredItem();
QgsMapToolAdvancedDigitizing::deactivate();
}

void QgsMapToolModifyAnnotation::cadCanvasMoveEvent( QgsMapMouseEvent *event )
{
event->snapPoint();
mSnapIndicator->setMatch( event->mapPointMatch() );

const QgsPointXY mapPoint = event->mapPoint();

switch ( mCurrentAction )
Expand Down Expand Up @@ -417,7 +424,7 @@ void QgsMapToolModifyAnnotation::canvasDoubleClickEvent( QgsMapMouseEvent *event
mCurrentAction = Action::NoAction;
if ( mHoveredItemId == mSelectedItemId && mHoveredItemLayerId == mSelectedItemLayerId )
{
// double click on selected item => add node
// double-click on selected item => add node
if ( QgsAnnotationLayer *layer = annotationLayerFromId( mSelectedItemLayerId ) )
{
const QgsPointXY layerPoint = toLayerCoordinates( layer, event->mapPoint() );
Expand Down
3 changes: 3 additions & 0 deletions src/gui/annotations/qgsmaptoolmodifyannotation.h
Expand Up @@ -29,6 +29,7 @@ class QgsRenderedAnnotationItemDetails;
class QgsAnnotationItem;
class QgsAnnotationLayer;
class QgsAnnotationItemNodesSpatialIndex;
class QgsSnapIndicator;

#define SIP_NO_FILE

Expand Down Expand Up @@ -99,6 +100,8 @@ class GUI_EXPORT QgsMapToolModifyAnnotation : public QgsMapToolAdvancedDigitizin

Action mCurrentAction = Action::NoAction;

std::unique_ptr<QgsSnapIndicator> mSnapIndicator;

QObjectUniquePtr<QgsRubberBand> mHoverRubberBand;
std::vector< QObjectUniquePtr<QgsRubberBand> > mHoveredItemNodeRubberBands;

Expand Down
2 changes: 1 addition & 1 deletion tests/src/app/testqgsmaptooleditannotation.cpp
Expand Up @@ -540,7 +540,7 @@ void TestQgsMapToolEditAnnotation::testAddNode()
QCOMPARE( spy.count(), 1 );
QCOMPARE( spy.at( 0 ).at( 1 ).toString(), i1id );

// double click a segment
// double-click a segment
utils.mouseMove( 5, 3 );
utils.mouseDoubleClick( 5, 3, Qt::LeftButton, Qt::KeyboardModifiers(), true );
// second click isn't selecting an item, so no new signals should be emitted
Expand Down

0 comments on commit f66eeeb

Please sign in to comment.