Skip to content
Permalink
Browse files

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 a916f7b1c76b03aeb6b317a9573c845edde005c8
Showing with 38 additions and 4 deletions.
  1. +6 −3 src/core/qgsmaplayer.cpp
  2. +1 −1 src/core/qgsmaplayer.h
  3. +31 −0 tests/src/core/testqgsmaplayer.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();
}
}
@@ -1427,7 +1427,7 @@ class CORE_EXPORT QgsMapLayer : public QObject

private slots:

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

protected:

@@ -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"

0 comments on commit a916f7b

Please sign in to comment.