Skip to content

Commit

Permalink
Fix python error on multiedit tree widget selection
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed Feb 10, 2024
1 parent 7fcb02e commit 467fae6
Showing 1 changed file with 50 additions and 18 deletions.
68 changes: 50 additions & 18 deletions linking_relation_editor/gui/linking_relation_editor_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def __init__(self, config, parent):
self._updateUiTimer.setSingleShot(True)
self._updateUiTimer.timeout.connect(self.updateUiTimeout)

self.mMultiEdit1NJustAddedIds = []

# Ui setup
self.setupUi(self)

Expand Down Expand Up @@ -158,7 +160,7 @@ def __init__(self, config, parent):
self.mViewModeButtonGroup.idClicked.connect(self.setViewMode)
self.mToggleEditingButton.clicked.connect(self.toggleEditing)
self.mSaveEditsButton.clicked.connect(self.saveEdits)
self.mAddFeatureButton.clicked.connect(self.addFeature)
self.mAddFeatureButton.clicked.connect(self.addFeatureClicked)
self.mAddFeatureGeometryButton.clicked.connect(self.addFeatureGeometry)
self.mDuplicateFeatureButton.clicked.connect(self.duplicateSelectedFeatures)
self.mDeleteFeatureButton.clicked.connect(self.deleteSelectedFeatures)
Expand Down Expand Up @@ -296,6 +298,7 @@ def updateButtons(self):
self.mAddFeatureButton.setEnabled(canAdd)
self.mAddFeatureGeometryButton.setEnabled(canAddGeometry)
self.mDuplicateFeatureButton.setEnabled(canEdit and selectionNotEmpty)

self.mLinkFeatureButton.setEnabled(canLink)
self.mDeleteFeatureButton.setEnabled(canRemove)
self.mUnlinkFeatureButton.setEnabled(canUnlink)
Expand Down Expand Up @@ -485,6 +488,31 @@ def updateUiMultiEdit(self):
if featureIdCurrentItem in featureIdsMixedValues:
childItem.setFont(0, fontItalic)

def addFeatureClicked(self):
addedFeatures = self.addFeature()

if not self._multiEditModeActive():
return

self.mMultiEditTreeWidget.blockSignals(True)
self.mMultiEdit1NJustAddedIds = addedFeatures


for indexTopLevelItem in range(self.mMultiEditTreeWidget.topLevelItemCount()):
treeWidgetTopLevelItem = self.mMultiEditTreeWidget.topLevelItem(indexTopLevelItem)

for indexItem in range(treeWidgetTopLevelItem.childCount()):
treeWidgetItem = treeWidgetTopLevelItem.child(indexItem)

if treeWidgetItem.data(0, (self.MultiEditTreeWidgetRole.FeatureId)) in addedFeatures:
treeWidgetItem.setSelected(True)


self.mMultiEditTreeWidget.blockSignals(False)

self.updateUi()
self.updateButtons()

def addFeatureGeometry(self):
if self._multiEditModeActive():
QgsLogger.warning(self.tr("Adding a geometry feature is not supported in multiple edit mode"))
Expand Down Expand Up @@ -665,25 +693,29 @@ def multiEditItemSelectionChanged(self):

featureIdSelectedItem = selectedItem.data(0, self.MultiEditTreeWidgetRole.FeatureId)

for i in range(self.mMultiEditTreeWidget.childCount()):
treeWidgetItem = self.mMultiEditTreeWidget.child(i)
for indexTopLevelItem in range(self.mMultiEditTreeWidget.topLevelItemCount()):
treeWidgetTopLevelItem = self.mMultiEditTreeWidget.topLevelItem(indexTopLevelItem)

if (
treeWidgetItem.data(0, self.MultiEditTreeWidgetRole.FeatureType)
!= self.MultiEditFeatureType.Child
):
continue
for indexItem in range(treeWidgetTopLevelItem.childCount()):
treeWidgetItem = treeWidgetTopLevelItem.child(indexItem)

featureIdCurrentItem = treeWidgetItem.data(0, self.MultiEditTreeWidgetRole.FeatureId)
if self.nmRelation().isValid():
if featureIdSelectedItem == featureIdCurrentItem:
treeWidgetItem.setSelected(True)
else:
if featureIdSelectedItem not in self.mMultiEdit1NJustAddedIds:
break
if (
treeWidgetItem.data(0, self.MultiEditTreeWidgetRole.FeatureType)
!= self.MultiEditFeatureType.Child
):
QgsLogger.warning(self.tr("Not a child item"))
continue

if featureIdCurrentItem not in self.mMultiEdit1NJustAddedIds:
treeWidgetItem.setSelected(True)
featureIdCurrentItem = treeWidgetItem.data(0, self.MultiEditTreeWidgetRole.FeatureId)
if self.nmRelation().isValid():
if featureIdSelectedItem == featureIdCurrentItem:
treeWidgetItem.setSelected(True)
else:
if featureIdSelectedItem not in self.mMultiEdit1NJustAddedIds:
break

if featureIdCurrentItem not in self.mMultiEdit1NJustAddedIds:
treeWidgetItem.setSelected(True)

self.mMultiEditTreeWidget.blockSignals(False)

Expand All @@ -697,7 +729,7 @@ def selectedChildFeatureIds(self):
if treeWidgetItem.data(0, self.MultiEditTreeWidgetRole.FeatureType) != self.MultiEditFeatureType.Child:
continue

featureIds.insert(treeWidgetItem.data(0, self.MultiEditTreeWidgetRole.FeatureId).toLongLong())
featureIds.add(treeWidgetItem.data(0, self.MultiEditTreeWidgetRole.FeatureId))
return featureIds
else:
return self.mFeatureSelectionMgr.selectedFeatureIds()
Expand Down

0 comments on commit 467fae6

Please sign in to comment.