Skip to content

Commit

Permalink
Avoid showing first feature by default, defer attribute form creation…
Browse files Browse the repository at this point in the history
… until first feature shown (#5)
  • Loading branch information
nirvn authored Nov 1, 2021
1 parent 96bab29 commit 356e4c9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
31 changes: 19 additions & 12 deletions ordered_relation_editor/gui/ordered_relation_editor_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def __init__(self, config, parent):
# QML display of images
layout = QVBoxLayout()
self.mListView.setLayout(layout)
self.mListView.setMinimumHeight(200)
self.mListView.setMaximumWidth(300)
self.view = QQuickWidget(self.mListView)
self.view.rootContext().setContextProperty("orderedModel", self.model)
self.view.setSource(QUrl.fromLocalFile(os.path.join(os.path.dirname(__file__), '../qml/OrderedImageList.qml')))
Expand Down Expand Up @@ -92,32 +94,37 @@ def updateUiTimeout(self):

self.model.init(self.relation(), self.ordering_field, self.feature(), self.image_path, self.description)

# form view
# we defer attribute form creation on the first valid feature passed on
if self.attribute_form:
self.attribute_form.deleteLater()
self.attribute_form = QgsAttributeForm(self.relation().referencingLayer(), QgsFeature(), self.editorContext())
if not self.editorContext().parentContext():
attribute_editor_scroll_area = QgsScrollArea()
attribute_editor_scroll_area.setWidgetResizable(True)
self.mAttributeFormView.layout().addWidget(attribute_editor_scroll_area)
attribute_editor_scroll_area.setWidget(self.attribute_form)
else:
self.mAttributeFormView.layout().addWidget(self.attribute_form)

self.update_buttons()
self.view.rootObject().setCurrentIndex(0)
self.view.rootObject().setCurrentIndex(-1)

def parentFormValueChanged(self, attribute, newValue):
if self.attribute_form:
self.attribute_form.parentFormValueChanged(attribute, newValue)

def onCurrentFeatureChanged(self, feature):
if self.attribute_form:
if not self.attribute_form and feature.isValid():
self.attribute_form = QgsAttributeForm(self.relation().referencingLayer(), feature, self.editorContext())
if not self.editorContext().parentContext():
attribute_editor_scroll_area = QgsScrollArea()
attribute_editor_scroll_area.setWidgetResizable(True)
self.mAttributeFormView.layout().addWidget(attribute_editor_scroll_area)
attribute_editor_scroll_area.setWidget(self.attribute_form)
else:
self.mAttributeFormView.layout().addWidget(self.attribute_form)
else:
if self.relation().referencingLayer().isEditable():
if self.attribute_form.save():

This comment has been minimized.

Copy link
@3nids

3nids Nov 22, 2021

Member

@nirvn I get a Python crash here after switching parent feature

Traceback (most recent call last):
  File "/Users/denis/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/ordered_relation_editor/gui/ordered_relation_editor_widget.py", line 120, in onCurrentFeatureChanged
    self.model.reloadData()
RuntimeError: wrapped C/C++ object of type QgsAttributeForm has been deleted

how to reproduce:

  1. open support form
  2. click on a frame
  3. switch azimut
  4. click on a frame
self.model.reloadData()

self.attribute_form.setFeature(feature)
if feature.isValid():
self.attribute_form.setFeature(feature)
else:
self.attribute_form.deleteLater()

self.update_buttons()

def deleteSelectedFeature(self):
Expand Down
6 changes: 6 additions & 0 deletions ordered_relation_editor/ui/ordered_relation_editor_widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@
</property>
</widget>
<widget class="QWidget" name="mAttributeFormView" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<property name="leftMargin">
<number>0</number>
Expand Down

0 comments on commit 356e4c9

Please sign in to comment.