Skip to content

Commit

Permalink
Merge pull request #29 from opengisch/multiedit
Browse files Browse the repository at this point in the history
Dont immediatically get python errors on multiedit
  • Loading branch information
domi4484 authored Dec 5, 2022
2 parents c0859ac + a39a14f commit 00fd2a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ github_deploy_key.out
*.gpkg-shm
*.gpkg-wal
*.qgs~
*.pyproject*
44 changes: 25 additions & 19 deletions linking_relation_editor/gui/linking_relation_editor_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
from qgis.core import (
Qgis,
QgsApplication,
QgsFeature,
QgsFeatureRequest,
QgsGeometry,
QgsIconUtils,
QgsLogger,
QgsMessageLog,
QgsProject,
Expand All @@ -34,7 +36,7 @@
)
from qgis.PyQt.QtCore import QT_VERSION_STR, Qt, QTimer
from qgis.PyQt.QtGui import QIcon
from qgis.PyQt.QtWidgets import QButtonGroup, QSplitter
from qgis.PyQt.QtWidgets import QButtonGroup, QSplitter, QTreeWidgetItem
from qgis.PyQt.uic import loadUiType

from linking_relation_editor.core.plugin_helper import PluginHelper
Expand Down Expand Up @@ -169,6 +171,8 @@ def __init__(self, config, parent):
self.mMapToolDigitize = None
self.mMessageBarItem = None

self.mMultiEditPreviousSelectedItems = list()

# Set initial state for add / remove etc.buttons
self.updateButtons()

Expand Down Expand Up @@ -265,7 +269,7 @@ def updateButtons(self):
selectionNotEmpty = self.mFeatureSelectionMgr.selectedFeatureCount() > 0

if self._multiEditModeActive():
multieditLinkedChildSelected = not self.selectedChildFeatureIds().isEmpty()
multieditLinkedChildSelected = len(self.selectedChildFeatureIds()) != 0

canAddGeometry = False

Expand Down Expand Up @@ -398,10 +402,10 @@ def updateUiMultiEdit(self):
self.mMultiEditInfoLabel.setVisible(True)
self.mStackedWidget.setCurrentWidget(self.mMultiEditStackedWidgetPage)
parentTreeWidgetItems = []
featureIdsMixedValues = []
featureIdsMixedValues = set()
multimapChildFeatures = dict()
self.mMultiEditTreeWidget.clear()
for featureParent in self.mFeatureList:
for featureParent in self._featureList():
treeWidgetItem = self.createMultiEditTreeWidgetItem(
featureParent, self.relation().referencedLayer(), self.MultiEditFeatureType.Parent
)
Expand All @@ -418,7 +422,7 @@ def updateUiMultiEdit(self):
featureChildChild, self.nmRelation().referencedLayer(), self.MultiEditFeatureType.Child
)
treeWidgetItem.addChild(treeWidgetItemChild)
featureIdsMixedValues.insert(featureChildChild.id())
featureIdsMixedValues.add(featureChildChild.id())

if treeWidgetItem in multimapChildFeatures:
multimapChildFeatures[treeWidgetItem].append(featureChildChild.id())
Expand All @@ -430,7 +434,7 @@ def updateUiMultiEdit(self):
featureChild, self.relation().referencingLayer(), self.MultiEditFeatureType.Child
)
treeWidgetItem.addChild(treeWidgetItemChild)
featureIdsMixedValues.insert(featureChild.id())
featureIdsMixedValues.add(featureChild.id())

self.mMultiEditTreeWidget.addTopLevelItem(treeWidgetItem)
treeWidgetItem.setExpanded(True)
Expand Down Expand Up @@ -459,7 +463,7 @@ def updateUiMultiEdit(self):
continue

# Set multiedit info label
if featureIdsMixedValues.isEmpty():
if not featureIdsMixedValues:
icon = QgsApplication.getThemeIcon("/multieditSameValues.svg")
self.mMultiEditInfoLabel.setPixmap(
icon.pixmap(self.mMultiEditInfoLabel.height(), self.mMultiEditInfoLabel.height())
Expand Down Expand Up @@ -657,26 +661,23 @@ def multiEditItemSelectionChanged(self):

# Select all items pointing to the same feature
# but only if we are not deselecting.
if selectedItems.size() == 1 and self.mMultiEditPreviousSelectedItems.size() <= 1:
if len(selectedItems) == 1 and len(self.mMultiEditPreviousSelectedItems) <= 1:
selectedItem = selectedItems[0]
if (
selectedItem.data(0, self.MultiEditTreeWidgetRole.FeatureType).toInt()
== self.MultiEditFeatureType.Child
):
if selectedItem.data(0, self.MultiEditTreeWidgetRole.FeatureType) == self.MultiEditFeatureType.Child:
self.mMultiEditTreeWidget.blockSignals(True)

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

for i in range(self.mMultiEditTreeWidget.childCount()):
treeWidgetItem = self.mMultiEditTreeWidget.child(i)

if (
treeWidgetItem.data(0, self.MultiEditTreeWidgetRole.FeatureType).toInt()
treeWidgetItem.data(0, self.MultiEditTreeWidgetRole.FeatureType)
!= self.MultiEditFeatureType.Child
):
continue

featureIdCurrentItem = treeWidgetItem.data(0, self.MultiEditTreeWidgetRole.FeatureId).toInt()
featureIdCurrentItem = treeWidgetItem.data(0, self.MultiEditTreeWidgetRole.FeatureId)
if self.nmRelation().isValid():
if featureIdSelectedItem == featureIdCurrentItem:
treeWidgetItem.setSelected(True)
Expand All @@ -696,10 +697,7 @@ def selectedChildFeatureIds(self):
if self._multiEditModeActive():
featureIds = set()
for treeWidgetItem in self.mMultiEditTreeWidget.selectedItems():
if (
treeWidgetItem.data(0, self.MultiEditTreeWidgetRole.FeatureType).toInt()
!= self.MultiEditFeatureType.Child
):
if treeWidgetItem.data(0, self.MultiEditTreeWidgetRole.FeatureType) != self.MultiEditFeatureType.Child:
continue

featureIds.insert(treeWidgetItem.data(0, self.MultiEditTreeWidgetRole.FeatureId).toLongLong())
Expand Down Expand Up @@ -831,3 +829,11 @@ def digitizingFinished(self):
self.window().raise_()
self.window().activateWindow()
self.unsetMapTool()

def createMultiEditTreeWidgetItem(self, feature: QgsFeature, layer: QgsVectorLayer, type: MultiEditFeatureType):
treeWidgetItem = QTreeWidgetItem()
treeWidgetItem.setText(0, QgsVectorLayerUtils.getFeatureDisplayString(layer, feature))
treeWidgetItem.setIcon(0, QgsIconUtils.iconForLayer(layer))
treeWidgetItem.setData(0, self.MultiEditTreeWidgetRole.FeatureType, type)
treeWidgetItem.setData(0, self.MultiEditTreeWidgetRole.FeatureId, feature.id())
return treeWidgetItem

0 comments on commit 00fd2a2

Please sign in to comment.