Skip to content

Commit

Permalink
Add QgsMapToolModifyAnnotation::selectionCleared signal
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Sep 7, 2021
1 parent ce0d2bd commit d16254e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
Expand Up @@ -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

};
Expand Down
17 changes: 13 additions & 4 deletions src/gui/annotations/qgsmaptoolmodifyannotation.cpp
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions src/gui/annotations/qgsmaptoolmodifyannotation.h
Expand Up @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions tests/src/app/testqgsmaptooleditannotation.cpp
Expand Up @@ -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 );
}


Expand Down

0 comments on commit d16254e

Please sign in to comment.