Our first task is to let the user add a new track while in the track editing mode. This involves defining a new map tool, which we will call AddTrackTool
. Before we start implementing the
AddTrackTool
class, however, we're going to create a mixin class that provides various helper methods for our map tools. We'll call this mixin class MapToolMixin
.
Here is our initial implementation of the MapToolMixin
class, which should be placed near the top of your mapTools.py
module:
class MapToolMixin def setLayer(self, layer): self.layer = layer def transformCoordinates(self, screenPt): return (self.toMapCoordinates(screenPt), self.toLayerCoordinates(self.layer, screenPt)) def calcTolerance(self, pos): pt1 = QPoint(pos.x(), pos.y()) pt2 = QPoint(pos.x() + 10, pos.y()) mapPt1,layerPt1 = self.transformCoordinates(pt1) mapPt2,layerPt2 = self.transformCoordinates(pt2) tolerance = layerPt2.x() ...