The Delete Track map tool
We now want to implement the Delete Track action. Fortunately, the map tool for doing is very simple, thanks to our mixin class. Add the following class definition to the mapTools.py
module:
class DeleteTrackTool(QgsMapTool, MapToolMixin): def __init__(self, canvas, layer, onTrackDeleted): QgsMapTool.__init__(self, canvas) self.onTrackDeleted = onTrackDeleted self.feature = None self.setLayer(layer) self.setCursor(Qt.CrossCursor) def canvasPressEvent(self, event): self.feature = self.findFeatureAt(event.pos()) def canvasReleaseEvent(self, event): feature = self.findFeatureAt(event.pos()) if feature != None and feature.id() == self.feature.id(): self.layer.deleteFeature(self.feature.id()) self.onTrackDeleted()
Then, back in the forestTrails.py
module, add the following to the end of the setupMapTools()
method:
self.deleteTrackTool = DeleteTrackTool( ...