Skip to content
Permalink
Browse files

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

 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.
  • Loading branch information
suricactus committed Jul 10, 2020
1 parent b6a9cce commit b7d36375c207a028e4e993be20b4be1fc0e525fb
@@ -2672,6 +2672,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();
@@ -3367,6 +3367,7 @@ bool QgsVectorLayer::commitChanges()
delete mEditBuffer;
mEditBuffer = nullptr;
undoStack()->clear();
emit afterCommitChanges();
emit editingStopped();
}
else
@@ -5335,6 +5336,12 @@ void QgsVectorLayer::emitDataChanged()
mDataChangedFired = false;
}

void QgsVectorLayer::onAfterCommitChangesDependency()
{
mDataChangedFired = true;
reload();
}

bool QgsVectorLayer::setDependencies( const QSet<QgsMapLayerDependency> &oDeps )
{
QSet<QgsMapLayerDependency> deps;
@@ -5358,6 +5365,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
@@ -5378,6 +5386,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
@@ -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();

/**
* Emitted after changes are rolled back.
* \since QGIS 3.4
@@ -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() );
@@ -872,6 +872,8 @@ void QgsRelationEditorWidget::toggleEditing( bool state )
if ( mNmRelation.isValid() )
mEditorContext.vectorLayerTools()->stopEditing( mNmRelation.referencedLayer() );
}

updateButtons();
}

void QgsRelationEditorWidget::saveEdits()

0 comments on commit b7d3637

Please sign in to comment.
You can’t perform that action at this time.