Skip to content

Commit

Permalink
more fixes for QGIS 3
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Aug 2, 2018
1 parent 4472799 commit b4986c0
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/tools/qgepmaptooladdfeature.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from builtins import next
from builtins import range
from qgis.gui import (
QgsAttributeForm,
QgsMapToolAdvancedDigitizing,
QgsMapTool,
QgsRubberBand,
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand Down

0 comments on commit b4986c0

Please sign in to comment.