From b58f7de29dde604a16432f7306f0647cb45d5cf4 Mon Sep 17 00:00:00 2001 From: mba Date: Tue, 29 Jun 2021 22:03:15 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Gestion=20valeur=20g=C3=A9n=C3=A9r=C3=A9es?= =?UTF-8?q?=20en=20BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Historisation/maplayer.py | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/Historisation/maplayer.py b/Historisation/maplayer.py index a526b14..a40a41a 100644 --- a/Historisation/maplayer.py +++ b/Historisation/maplayer.py @@ -71,8 +71,18 @@ def setListenToCommit(self, listen: bool): if listen: self.getVectorLayer().beforeCommitChanges.connect(self.onBeforeCommitChanges) + self.getVectorLayer().committedFeaturesAdded.connect(self.onCommittedFeaturesAdded) + self.getVectorLayer().committedAttributeValuesChanges.connect(self.onCommittedAttributeValuesChanges) + self.getVectorLayer().committedGeometriesChanges.connect(self.onCommittedGeometriesChanges) + self.getVectorLayer().committedFeaturesRemoved.connect(self.onCommittedFeaturesRemoved) + self.getVectorLayer().afterCommitChanges.connect(self.onAfterCommitChanges) else: self.getVectorLayer().beforeCommitChanges.disconnect(self.onBeforeCommitChanges) + self.getVectorLayer().committedFeaturesAdded.disconnect(self.onCommittedFeaturesAdded) + self.getVectorLayer().committedAttributeValuesChanges.disconnect(self.onCommittedAttributeValuesChanges) + self.getVectorLayer().committedGeometriesChanges.disconnect(self.onCommittedGeometriesChanges) + self.getVectorLayer().committedFeaturesRemoved.disconnect(self.onCommittedFeaturesRemoved) + self.getVectorLayer().afterCommitChanges.disconnect(self.onAfterCommitChanges) def historizeTable(self, displayField: str, idField: str): now = QDateTime.currentDateTime() @@ -99,17 +109,31 @@ def historizeTable(self, displayField: str, idField: str): self.histoLayer.initializeTable(now, eventId, self.valueMaps) def onBeforeCommitChanges(self): - # Get modifications - editBuffer = self.getVectorLayer().editBuffer() + self.added = [] + self.modifiedGeometries = [] + self.modifiedAttributes = [] + self.deletedIds = [] + + def onCommittedFeaturesAdded(self, layerId, addedFeatures): + self.added = addedFeatures + + def onCommittedAttributeValuesChanges(self, layerId, changedAttributesValues): + self.modifiedAttributes = changedAttributesValues - added = list(editBuffer.addedFeatures().values()) + def onCommittedGeometriesChanges(self, layerId, changedGeometries): + self.modifiedGeometries = changedGeometries + + def onCommittedFeaturesRemoved(self, layerId, deletedFeatureIds): + self.deletedIds = deletedFeatureIds + + def onAfterCommitChanges(self): + # Get modifications + added = list(self.added) - modifiedGeometries = editBuffer.changedGeometries() - modifiedAttributes = editBuffer.changedAttributeValues() - modifiedIds = list(set(list(modifiedGeometries)+list(modifiedAttributes))) + modifiedIds = list(set(list(self.modifiedGeometries)+list(self.modifiedAttributes))) modified = [] if len(modifiedIds) == 0 else list(self.getFeatures(QgsFeatureRequest(modifiedIds))) - deletedIds = editBuffer.deletedFeatureIds() + deletedIds = list(self.deletedIds) deleted = [] if len(deletedIds) == 0 else list(self.getDatabaseFeatures(QgsFeatureRequest(deletedIds))) # Get user events From fa23aa4e751667ce0a61c411ede9877924e05077 Mon Sep 17 00:00:00 2001 From: mba Date: Tue, 13 Jul 2021 13:06:37 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Fix=20valeurs=20autog=C3=A9n=C3=A9r=C3=A9es?= =?UTF-8?q?=20si=20ce=20n'est=20pas=20la=20PK?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Historisation/maplayer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Historisation/maplayer.py b/Historisation/maplayer.py index a40a41a..185b37b 100644 --- a/Historisation/maplayer.py +++ b/Historisation/maplayer.py @@ -128,7 +128,8 @@ def onCommittedFeaturesRemoved(self, layerId, deletedFeatureIds): def onAfterCommitChanges(self): # Get modifications - added = list(self.added) + addedIds = list(map(lambda x: x.id(), self.added)) + added = [] if len(addedIds) == 0 else list(self.getFeatures(QgsFeatureRequest(addedIds))) modifiedIds = list(set(list(self.modifiedGeometries)+list(self.modifiedAttributes))) modified = [] if len(modifiedIds) == 0 else list(self.getFeatures(QgsFeatureRequest(modifiedIds))) From 664b29e355e55be36796742486f7d151dadcf0de Mon Sep 17 00:00:00 2001 From: mba Date: Tue, 13 Jul 2021 13:18:21 +0200 Subject: [PATCH 3/3] Fix deleted objects --- Historisation/maplayer.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Historisation/maplayer.py b/Historisation/maplayer.py index 185b37b..53e4038 100644 --- a/Historisation/maplayer.py +++ b/Historisation/maplayer.py @@ -74,14 +74,12 @@ def setListenToCommit(self, listen: bool): self.getVectorLayer().committedFeaturesAdded.connect(self.onCommittedFeaturesAdded) self.getVectorLayer().committedAttributeValuesChanges.connect(self.onCommittedAttributeValuesChanges) self.getVectorLayer().committedGeometriesChanges.connect(self.onCommittedGeometriesChanges) - self.getVectorLayer().committedFeaturesRemoved.connect(self.onCommittedFeaturesRemoved) self.getVectorLayer().afterCommitChanges.connect(self.onAfterCommitChanges) else: self.getVectorLayer().beforeCommitChanges.disconnect(self.onBeforeCommitChanges) self.getVectorLayer().committedFeaturesAdded.disconnect(self.onCommittedFeaturesAdded) self.getVectorLayer().committedAttributeValuesChanges.disconnect(self.onCommittedAttributeValuesChanges) self.getVectorLayer().committedGeometriesChanges.disconnect(self.onCommittedGeometriesChanges) - self.getVectorLayer().committedFeaturesRemoved.disconnect(self.onCommittedFeaturesRemoved) self.getVectorLayer().afterCommitChanges.disconnect(self.onAfterCommitChanges) def historizeTable(self, displayField: str, idField: str): @@ -109,10 +107,15 @@ def historizeTable(self, displayField: str, idField: str): self.histoLayer.initializeTable(now, eventId, self.valueMaps) def onBeforeCommitChanges(self): + # For added and modified, process after commit for DB default values self.added = [] self.modifiedGeometries = [] self.modifiedAttributes = [] - self.deletedIds = [] + + # For deleted, process before commit + editBuffer = self.getVectorLayer().editBuffer() + deletedIds = editBuffer.deletedFeatureIds() + self.deleted = [] if len(deletedIds) == 0 else list(self.getDatabaseFeatures(QgsFeatureRequest(deletedIds))) def onCommittedFeaturesAdded(self, layerId, addedFeatures): self.added = addedFeatures @@ -123,9 +126,6 @@ def onCommittedAttributeValuesChanges(self, layerId, changedAttributesValues): def onCommittedGeometriesChanges(self, layerId, changedGeometries): self.modifiedGeometries = changedGeometries - def onCommittedFeaturesRemoved(self, layerId, deletedFeatureIds): - self.deletedIds = deletedFeatureIds - def onAfterCommitChanges(self): # Get modifications addedIds = list(map(lambda x: x.id(), self.added)) @@ -134,8 +134,7 @@ def onAfterCommitChanges(self): modifiedIds = list(set(list(self.modifiedGeometries)+list(self.modifiedAttributes))) modified = [] if len(modifiedIds) == 0 else list(self.getFeatures(QgsFeatureRequest(modifiedIds))) - deletedIds = list(self.deletedIds) - deleted = [] if len(deletedIds) == 0 else list(self.getDatabaseFeatures(QgsFeatureRequest(deletedIds))) + deleted = list(self.deleted) # Get user events dlg = SaveManagementToolDialog(self.getVectorLayer().name(), self.uri.table(), self.histoParamTable, self.histoEventTypeTable, added, modified, deleted)