From d0c805dfebcd2ae9101cfb57565bea4e7c4bbfcd Mon Sep 17 00:00:00 2001 From: Damiano Lombardi Date: Wed, 20 Nov 2024 22:01:35 +0100 Subject: [PATCH] Print a warning when the relations are invalid --- .../gui/relation_editor_document_side_widget.py | 11 ++++++++--- .../gui/relation_editor_feature_side_widget.py | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/document_management_system/gui/relation_editor_document_side_widget.py b/document_management_system/gui/relation_editor_document_side_widget.py index bde0cd4..6c7229f 100644 --- a/document_management_system/gui/relation_editor_document_side_widget.py +++ b/document_management_system/gui/relation_editor_document_side_widget.py @@ -22,6 +22,7 @@ QgsFeature, QgsFeatureRequest, QgsIconUtils, + QgsLogger, QgsVectorLayerUtils, ) from qgis.gui import QgsAbstractRelationEditorWidget, QgsAttributeDialog, QgsFeatureSelectionDlg @@ -245,13 +246,17 @@ def updateUiManyToManyPolymorphic(self): def afterSetRelations(self): self._nmRelation = QgsProject.instance().relationManager().relation(str(self.nmRelationId())) + if not self.relation().isValid(): + QgsLogger.warning(self.tr(f"Invalid relation set, relation id: '{self.relation().id()}'")) + self.updateButtons() + return + self._setCardinality() self._checkTransactionGroup() - if self.relation().isValid(): - self.relation().referencingLayer().editingStopped.connect(self.updateButtons) - self.relation().referencingLayer().editingStarted.connect(self.updateButtons) + self.relation().referencingLayer().editingStopped.connect(self.updateButtons) + self.relation().referencingLayer().editingStarted.connect(self.updateButtons) if self.nmRelation().isValid(): self.nmRelation().referencedLayer().editingStarted.connect(self.updateButtons) diff --git a/document_management_system/gui/relation_editor_feature_side_widget.py b/document_management_system/gui/relation_editor_feature_side_widget.py index 2baff41..359eb9e 100644 --- a/document_management_system/gui/relation_editor_feature_side_widget.py +++ b/document_management_system/gui/relation_editor_feature_side_widget.py @@ -20,6 +20,7 @@ QgsExpressionContext, QgsExpressionContextUtils, QgsGeometry, + QgsLogger, QgsProject, QgsRelation, QgsSettingsEntryString, @@ -203,11 +204,15 @@ def updateButtons(self): def afterSetRelations(self): self._nmRelation = QgsProject.instance().relationManager().relation(str(self.nmRelationId())) + if not self.relation().isValid(): + QgsLogger.warning(self.tr(f"Invalid relation set, relation id: '{self.relation().id()}'")) + self.updateButtons() + return + self._checkTransactionGroup() - if self.relation().isValid(): - self.relation().referencingLayer().editingStopped.connect(self.updateButtons) - self.relation().referencingLayer().editingStarted.connect(self.updateButtons) + self.relation().referencingLayer().editingStopped.connect(self.updateButtons) + self.relation().referencingLayer().editingStarted.connect(self.updateButtons) if self.nmRelation().isValid(): self.nmRelation().referencedLayer().editingStarted.connect(self.updateButtons)