diff --git a/python/gui/auto_generated/annotations/qgsmaptoolmodifyannotation.sip.in b/python/gui/auto_generated/annotations/qgsmaptoolmodifyannotation.sip.in index fe12e70bcc4d..6d7c49575f40 100644 --- a/python/gui/auto_generated/annotations/qgsmaptoolmodifyannotation.sip.in +++ b/python/gui/auto_generated/annotations/qgsmaptoolmodifyannotation.sip.in @@ -42,6 +42,11 @@ Constructor for QgsMapToolModifyAnnotation void itemSelected( QgsAnnotationLayer *layer, const QString &itemId ); %Docstring Emitted when the selected item is changed. +%End + + void selectionCleared(); +%Docstring +Emitted when the selected item is cleared; %End }; diff --git a/src/gui/annotations/qgsmaptoolmodifyannotation.cpp b/src/gui/annotations/qgsmaptoolmodifyannotation.cpp index bd6d36eded02..eb09c49c0274 100644 --- a/src/gui/annotations/qgsmaptoolmodifyannotation.cpp +++ b/src/gui/annotations/qgsmaptoolmodifyannotation.cpp @@ -187,10 +187,7 @@ void QgsMapToolModifyAnnotation::cadCanvasPressEvent( QgsMapMouseEvent *event ) if ( mHoveredItemId.isEmpty() || !mHoverRubberBand ) { - if ( mSelectedRubberBand ) - mSelectedRubberBand->hide(); - mSelectedItemId.clear(); - mSelectedItemLayerId.clear(); + clearSelectedItem(); } else if ( mHoveredItemId != mSelectedItemId || mHoveredItemLayerId != mSelectedItemLayerId ) { @@ -330,6 +327,18 @@ void QgsMapToolModifyAnnotation::clearHoveredItem() mHoveredItemNodesSpatialIndex.reset(); } +void QgsMapToolModifyAnnotation::clearSelectedItem() +{ + if ( mSelectedRubberBand ) + mSelectedRubberBand->hide(); + + const bool hadSelection = !mSelectedItemId.isEmpty(); + mSelectedItemId.clear(); + mSelectedItemLayerId.clear(); + if ( hadSelection ) + emit selectionCleared(); +} + void QgsMapToolModifyAnnotation::createHoverBand() { const double scaleFactor = canvas()->fontMetrics().xHeight() * .2; diff --git a/src/gui/annotations/qgsmaptoolmodifyannotation.h b/src/gui/annotations/qgsmaptoolmodifyannotation.h index e616f99fd0b5..834e51289f24 100644 --- a/src/gui/annotations/qgsmaptoolmodifyannotation.h +++ b/src/gui/annotations/qgsmaptoolmodifyannotation.h @@ -58,8 +58,14 @@ class GUI_EXPORT QgsMapToolModifyAnnotation : public QgsMapToolAdvancedDigitizin */ void itemSelected( QgsAnnotationLayer *layer, const QString &itemId ); + /** + * Emitted when the selected item is cleared; + */ + void selectionCleared(); + private: void clearHoveredItem(); + void clearSelectedItem(); void createHoverBand(); void createHoveredNodeBand(); void createSelectedItemBand(); diff --git a/tests/src/app/testqgsmaptooleditannotation.cpp b/tests/src/app/testqgsmaptooleditannotation.cpp index 22a41a55140b..749980d22224 100644 --- a/tests/src/app/testqgsmaptooleditannotation.cpp +++ b/tests/src/app/testqgsmaptooleditannotation.cpp @@ -139,6 +139,13 @@ void TestQgsMapToolEditAnnotation::testSelectItem() utils.mouseClick( 7.5, 1.5, Qt::LeftButton, Qt::KeyboardModifiers(), true ); QCOMPARE( spy.count(), 3 ); QCOMPARE( spy.at( 2 ).at( 1 ).toString(), i3id ); + + // click on no item - should clear selection + QSignalSpy selectionClearedSpy( &tool, &QgsMapToolModifyAnnotation::selectionCleared ); + utils.mouseMove( 9.5, 9.5 ); + utils.mouseClick( 9.5, 9.5, Qt::LeftButton, Qt::KeyboardModifiers(), true ); + QCOMPARE( spy.count(), 3 ); + QCOMPARE( selectionClearedSpy.count(), 1 ); }