diff --git a/src/core/qgsmaplayer.cpp b/src/core/qgsmaplayer.cpp index c6dddfdd026b..d1253f2acb6b 100644 --- a/src/core/qgsmaplayer.cpp +++ b/src/core/qgsmaplayer.cpp @@ -1930,18 +1930,21 @@ void QgsMapLayer::setRefreshOnNotifyEnabled( bool enabled ) if ( enabled && !isRefreshOnNotifyEnabled() ) { lDataProvider->setListening( enabled ); - connect( lDataProvider, &QgsVectorDataProvider::notify, this, &QgsMapLayer::onNotifiedTriggerRepaint ); + connect( lDataProvider, &QgsVectorDataProvider::notify, this, &QgsMapLayer::onNotified ); } else if ( !enabled && isRefreshOnNotifyEnabled() ) { // we don't want to disable provider listening because someone else could need it (e.g. actions) - disconnect( lDataProvider, &QgsVectorDataProvider::notify, this, &QgsMapLayer::onNotifiedTriggerRepaint ); + disconnect( lDataProvider, &QgsVectorDataProvider::notify, this, &QgsMapLayer::onNotified ); } mIsRefreshOnNofifyEnabled = enabled; } -void QgsMapLayer::onNotifiedTriggerRepaint( const QString &message ) +void QgsMapLayer::onNotified( const QString &message ) { if ( refreshOnNotifyMessage().isEmpty() || refreshOnNotifyMessage() == message ) + { triggerRepaint(); + emit dataChanged(); + } } diff --git a/src/core/qgsmaplayer.h b/src/core/qgsmaplayer.h index 009ddfdedd5f..5f06443d9f34 100644 --- a/src/core/qgsmaplayer.h +++ b/src/core/qgsmaplayer.h @@ -1427,7 +1427,7 @@ class CORE_EXPORT QgsMapLayer : public QObject private slots: - void onNotifiedTriggerRepaint( const QString &message ); + void onNotified( const QString &message ); protected: diff --git a/tests/src/core/testqgsmaplayer.cpp b/tests/src/core/testqgsmaplayer.cpp index d172aaaf335b..7883434ce282 100644 --- a/tests/src/core/testqgsmaplayer.cpp +++ b/tests/src/core/testqgsmaplayer.cpp @@ -77,6 +77,7 @@ class TestQgsMapLayer : public QObject void styleCategories(); + void notify(); private: QgsVectorLayer *mpLayer = nullptr; @@ -364,5 +365,35 @@ void TestQgsMapLayer::styleCategories() } } +void TestQgsMapLayer::notify() +{ + QgsVectorLayer *vl = new QgsVectorLayer( QStringLiteral( "Point" ), QStringLiteral( "name" ), QStringLiteral( "memory" ) ); + QVERIFY( vl->dataProvider() ); + + QSignalSpy spyRepaint( vl, &QgsMapLayer::repaintRequested ); + QSignalSpy spyDataChanged( vl, &QgsMapLayer::dataChanged ); + + vl->setRefreshOnNotifyEnabled( true ); + emit vl->dataProvider()->notify( "test" ); + QCOMPARE( spyRepaint.count(), 1 ); + QCOMPARE( spyDataChanged.count(), 1 ); + + vl->setRefreshOnNotifyEnabled( false ); + emit vl->dataProvider()->notify( "test" ); + QCOMPARE( spyRepaint.count(), 1 ); + QCOMPARE( spyDataChanged.count(), 1 ); + + vl->setRefreshOnNotifyEnabled( true ); + vl->setRefreshOnNofifyMessage( "test" ); + emit vl->dataProvider()->notify( "test" ); + QCOMPARE( spyRepaint.count(), 2 ); + QCOMPARE( spyDataChanged.count(), 2 ); + + vl->setRefreshOnNofifyMessage( "test" ); + emit vl->dataProvider()->notify( "nottest" ); + QCOMPARE( spyRepaint.count(), 2 ); + QCOMPARE( spyDataChanged.count(), 2 ); +} + QGSTEST_MAIN( TestQgsMapLayer ) #include "testqgsmaplayer.moc"