Skip to content

Commit

Permalink
Fix stacktrace issue when switching parent feature and child attribut…
Browse files Browse the repository at this point in the history
…e form is reset (#6)
  • Loading branch information
nirvn authored Nov 23, 2021
1 parent 1eb6c9f commit 5780e67
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ordered_relation_editor/core/ordered_relation_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def reloadData(self):
self._related_features = sorted(self._related_features, key=lambda _f: _f[self._ordering_field])

self.endResetModel()
# emit a currentFeatureChanged signal with an invalid feature to reset the widget
self.currentFeatureChanged.emit(QgsFeature())



Expand Down
5 changes: 3 additions & 2 deletions ordered_relation_editor/gui/ordered_relation_editor_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def parentFormValueChanged(self, attribute, newValue):
if self.attribute_form:
self.attribute_form.parentFormValueChanged(attribute, newValue)

def onCurrentFeatureChanged(self, feature):
def onCurrentFeatureChanged(self, feature = QgsFeature()):
if not self.attribute_form and feature.isValid():
self.attribute_form = QgsAttributeForm(self.relation().referencingLayer(), feature, self.editorContext())
if not self.editorContext().parentContext():
Expand All @@ -115,7 +115,7 @@ def onCurrentFeatureChanged(self, feature):
attribute_editor_scroll_area.setWidget(self.attribute_form)
else:
self.mAttributeFormView.layout().addWidget(self.attribute_form)
else:
elif self.attribute_form:
if self.relation().referencingLayer().isEditable():
if self.attribute_form.save():
self.model.reloadData()
Expand All @@ -124,6 +124,7 @@ def onCurrentFeatureChanged(self, feature):
self.attribute_form.setFeature(feature)
else:
self.attribute_form.deleteLater()
self.attribute_form = None

self.update_buttons()

Expand Down

0 comments on commit 5780e67

Please sign in to comment.