Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh snapping index on vector data provider notify #41357

Merged
merged 1 commit into from
Feb 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1971,12 +1971,12 @@ 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;
}
Expand All @@ -1990,8 +1990,11 @@ QgsProject *QgsMapLayer::project() const
return nullptr;
}

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
Original file line number Diff line number Diff line change
Expand Up @@ -1501,7 +1501,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
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class TestQgsMapLayer : public QObject

void styleCategories();

void notify();

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