Graphics Reference
In-Depth Information
def deleteVertex(self, feature, vertex):
geometry = feature.geometry()
lineString = geometry.asPolyline()
if len(lineString) <= 2:
return
if geometry.deleteVertex(vertex):
self.layer.changeGeometry(feature.id(),
geometry)
self.onTrackEdited()
With this complex map tool implemented, we can now use it to let the user edit a track.
Back in the forestTrails.py module, add the following to the end of the
setupMapTools() method:
self.editTrackTool = EditTrackTool(self.mapCanvas,
self.trackLayer,
self.onTrackEdited)
self.editTrackTool.setAction(self.actionEditTrack)
We now want to replace our placeholder for the editTrack() method with the follow-
ing:
def editTrack(self):
if self.actionEditTrack.isChecked():
self.mapCanvas.setMapTool(self.editTrackTool)
else:
self.setPanMode()
As with the addTrack() method, we switch to the edit tool when the user clicks on our
action, and switch back to panning mode if the user clicks on the action a second time.
The last thing we need to do is implement the ForestTrailsWin-
dow.onTrackEdited() method to respond when the user makes a change to a track.
Here is this new method:
Search WWH ::




Custom Search