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

Reload the data source when a dependency layer is changed #37475

Merged
merged 6 commits into from
Jul 10, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 7 additions & 0 deletions python/core/auto_generated/qgsvectorlayer.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -2661,6 +2661,13 @@ Emitted before changes are committed to the data provider.
void beforeRollBack();
%Docstring
Emitted before changes are rolled back.
%End

void afterCommitChanges();
%Docstring
Emitted after changes are commited to the data provider.

.. versionadded:: 3.16
%End

void afterRollBack();
Expand Down
14 changes: 14 additions & 0 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3354,6 +3354,7 @@ bool QgsVectorLayer::commitChanges()
delete mEditBuffer;
mEditBuffer = nullptr;
undoStack()->clear();
emit afterCommitChanges();
emit editingStopped();
}
else
Expand Down Expand Up @@ -5322,6 +5323,17 @@ void QgsVectorLayer::emitDataChanged()
mDataChangedFired = false;
}

void QgsVectorLayer::onAfterCommitChangesDependency()
{
// Refreshing the data provider right away causes problems on a layer dependent on itself.
// In that case two `dataChanged` signals are expected to be emitted when deleting or creating
// a feature, but as the layer is reloaded, the second `dataChanged` is not emitted.
suricactus marked this conversation as resolved.
Show resolved Hide resolved
QTimer::singleShot( 0, this, [ = ]()
{
reload();
} );
}

bool QgsVectorLayer::setDependencies( const QSet<QgsMapLayerDependency> &oDeps )
{
QSet<QgsMapLayerDependency> deps;
Expand All @@ -5345,6 +5357,7 @@ bool QgsVectorLayer::setDependencies( const QSet<QgsMapLayerDependency> &oDeps )
disconnect( lyr, &QgsVectorLayer::geometryChanged, this, &QgsVectorLayer::emitDataChanged );
disconnect( lyr, &QgsVectorLayer::dataChanged, this, &QgsVectorLayer::emitDataChanged );
disconnect( lyr, &QgsVectorLayer::repaintRequested, this, &QgsVectorLayer::triggerRepaint );
disconnect( lyr, &QgsVectorLayer::afterCommitChanges, this, &QgsVectorLayer::onAfterCommitChangesDependency );
}

// assign new dependencies
Expand All @@ -5365,6 +5378,7 @@ bool QgsVectorLayer::setDependencies( const QSet<QgsMapLayerDependency> &oDeps )
connect( lyr, &QgsVectorLayer::geometryChanged, this, &QgsVectorLayer::emitDataChanged );
connect( lyr, &QgsVectorLayer::dataChanged, this, &QgsVectorLayer::emitDataChanged );
connect( lyr, &QgsVectorLayer::repaintRequested, this, &QgsVectorLayer::triggerRepaint );
connect( lyr, &QgsVectorLayer::afterCommitChanges, this, &QgsVectorLayer::onAfterCommitChangesDependency );
}

// if new layers are present, emit a data change
Expand Down
7 changes: 7 additions & 0 deletions src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2482,6 +2482,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
//! Emitted before changes are rolled back.
void beforeRollBack();

/**
* Emitted after changes are commited to the data provider.
* \since QGIS 3.16
*/
void afterCommitChanges();
3nids marked this conversation as resolved.
Show resolved Hide resolved

/**
* Emitted after changes are rolled back.
* \since QGIS 3.4
Expand Down Expand Up @@ -2709,6 +2715,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
void onSymbolsCounted();
void onDirtyTransaction( const QString &sql, const QString &name );
void emitDataChanged();
void onAfterCommitChangesDependency();

private:
void updateDefaultValues( QgsFeatureId fid, QgsFeature feature = QgsFeature() );
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsrelationeditorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -872,6 +872,8 @@ void QgsRelationEditorWidget::toggleEditing( bool state )
if ( mNmRelation.isValid() )
mEditorContext.vectorLayerTools()->stopEditing( mNmRelation.referencedLayer() );
}

updateButtons();
}

void QgsRelationEditorWidget::saveEdits()
Expand Down