Graphics Reference
In-Depth Information
The Edit Track map tool
Our next task is to implement the Edit Track action. To do this, we'll take EditTool we
defined in Chapter 7 , Selecting and Editing Features in a PyQGIS Application , and modify
it to work specifically with tracks. Fortunately, we only need to support LineString geomet-
ries and can make use of our mixin class, which will simplify the implementation of this
new map tool.
Let's start by adding our new class definition to the mapTools.py module, along with
the __init__() method:
class EditTrackTool(QgsMapTool, MapToolMixin):
def __init__(self, canvas, layer, onTrackEdited):
QgsMapTool.__init__(self, canvas)
self.onTrackEdited = onTrackEdited
self.dragging = False
self.feature = None
self.vertex = None
self.setLayer(layer)
self.setCursor(Qt.CrossCursor)
We now define our canvasPressEvent() method to respond when the user presses
the mouse button over our map canvas:
def canvasPressEvent(self, event):
feature = self.findFeatureAt(event.pos())
if feature == None:
return
vertex = self.findVertexAt(feature, event.pos())
if vertex == None: return
if event.button() == Qt.LeftButton:
# Left click -> move vertex.
self.dragging = True
self.feature = feature
self.vertex = vertex
self.moveVertexTo(event.pos())
Search WWH ::




Custom Search