Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes #40720 : Refresh snapping index on vector data provider notify
(cherry picked from commit 618734a)
  • Loading branch information
troopa81 authored and nyalldawson committed Feb 19, 2021
1 parent d142b2c commit a916f7b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion src/core/qgsmaplayer.h
Expand Up @@ -1427,7 +1427,7 @@ class CORE_EXPORT QgsMapLayer : public QObject

private slots:

void onNotifiedTriggerRepaint( const QString &message );
void onNotified( const QString &message );

protected:

Expand Down
31 changes: 31 additions & 0 deletions tests/src/core/testqgsmaplayer.cpp
Expand Up @@ -77,6 +77,7 @@ class TestQgsMapLayer : public QObject

void styleCategories();

void notify();

private:
QgsVectorLayer *mpLayer = nullptr;
Expand Down Expand Up @@ -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"

0 comments on commit a916f7b

Please sign in to comment.