Skip to content

Commit

Permalink
Merge pull request #37 from opengisch/check-relations-validity
Browse files Browse the repository at this point in the history
Print a warning when the relations are invalid
  • Loading branch information
domi4484 authored Dec 2, 2024
2 parents 11d4c4b + d0c805d commit 9020bb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
QgsFeature,
QgsFeatureRequest,
QgsIconUtils,
QgsLogger,
QgsVectorLayerUtils,
)
from qgis.gui import QgsAbstractRelationEditorWidget, QgsAttributeDialog, QgsFeatureSelectionDlg
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
QgsExpressionContext,
QgsExpressionContextUtils,
QgsGeometry,
QgsLogger,
QgsProject,
QgsRelation,
QgsSettingsEntryString,
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9020bb7

Please sign in to comment.