Skip to content
Permalink
Browse files
Add QgsMapToolModifyAnnotation::selectionCleared signal
  • Loading branch information
nyalldawson committed Sep 7, 2021
1 parent ce0d2bd commit d16254e0a3a85d3e06d8a13611973f4297904c26
@@ -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

};
@@ -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;
@@ -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();
@@ -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 );
}


0 comments on commit d16254e

Please sign in to comment.