From b4986c04e14a0e9bc46bd522aab4d03eb89fc7f9 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Thu, 2 Aug 2018 15:09:06 +0200 Subject: [PATCH] more fixes for QGIS 3 --- src/tools/qgepmaptooladdfeature.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/tools/qgepmaptooladdfeature.py b/src/tools/qgepmaptooladdfeature.py index 2a99c495..9e30b304 100644 --- a/src/tools/qgepmaptooladdfeature.py +++ b/src/tools/qgepmaptooladdfeature.py @@ -30,6 +30,7 @@ from builtins import next from builtins import range from qgis.gui import ( + QgsAttributeForm, QgsMapToolAdvancedDigitizing, QgsMapTool, QgsRubberBand, @@ -146,10 +147,10 @@ def right_clicked(self, _): On a right click we create a new feature from the existing rubberband and show the add dialog """ - f = QgsFeature(self.layer.pendingFields()) + f = QgsFeature(self.layer.fields()) f.setGeometry(self.rubberband.asGeometry()) dlg = self.iface.getFeatureForm(self.layer, f) - dlg.setIsAddDialog(True) + dlg.setMode(QgsAttributeForm.AddFeatureMode) dlg.exec_() self.rubberband.reset3D() self.temp_rubberband.reset() @@ -190,10 +191,11 @@ def __init__(self, iface: QgisInterface, layer): assert self.node_layer self.reach_layer = QgepLayerManager.layer('vw_qgep_reach') assert self.reach_layer - self.setMode(QgsMapToolAdvancedDigitizing.CaptureLine) + self.setAdvancedDigitizingAllowed(True) + self.setAutoSnapEnabled(True) - layer_snapping_configs = [{'layer': self.node_layer, 'mode': QgsSnappingConfig.SnapToVertex}, - {'layer': self.reach_layer, 'mode': QgsSnappingConfig.SnapToVertexAndSegment}] + layer_snapping_configs = [{'layer': self.node_layer, 'mode': QgsSnappingConfig.Vertex}, + {'layer': self.reach_layer, 'mode': QgsSnappingConfig.VertexAndSegment}] self.snapping_configs = [] self.snapping_utils = QgsMapCanvasSnappingUtils(self.iface.mapCanvas()) @@ -313,14 +315,14 @@ def right_clicked(self, _): snapping_results = {'from': self.first_snapping_match, 'to': self.last_snapping_match} for dest, match in list(snapping_results.items()): - level_field_index = self.layer.pendingFields().indexFromName('rp_{dest}_level'.format(dest=dest)) + level_field_index = self.layer.fields().indexFromName('rp_{dest}_level'.format(dest=dest)) pt_idx = 0 if dest == 'from' else -1 if match.isValid() and match.layer() in (self.node_layer, self.reach_layer): request = QgsFeatureRequest(match.featureId()) network_element = next(match.layer().getFeatures(request)) assert network_element.isValid() # set the related network element - field = self.layer.pendingFields().indexFromName('rp_{dest}_fk_wastewater_networkelement'.format(dest=dest)) + field = self.layer.fields().indexFromName('rp_{dest}_fk_wastewater_networkelement'.format(dest=dest)) f.setAttribute(field, network_element.attribute('obj_id')) # assign level if the match is a node or if we have 3D from snapping if match.layer() == self.node_layer: @@ -330,7 +332,7 @@ def right_clicked(self, _): f.setAttribute(level_field_index, self.rubberband.points[pt_idx].z()) dlg = self.iface.getFeatureForm(self.layer, f) - dlg.setIsAddDialog(True) + dlg.setMode(QgsAttributeForm.AddFeatureMode) dlg.exec_() self.rubberband.reset3D()