Graphics Reference
In-Depth Information
self.selectStartPointTool = SelectVertexTool(
self.mapCanvas, self.trackLayer,
self.onStartPointSelected)
self.selectEndPointTool = SelectVertexTool(
self.mapCanvas, self.trackLayer,
self.onEndPointSelected)
These two instances of
SelectVertexTool
use different callback methods to respond
when the user clicks on a track vertex. Using these tools, we can now implement the
setStartPoint()
and
setEndPoint()
methods, which were just placeholders un-
til now:
def setStartPoint(self):
if self.actionSetStartPoint.isChecked():
self.mapCanvas.setMapTool(self.selectStartPointTool)
else:
self.setPanMode()
def setEndPoint(self):
if self.actionSetEndPoint.isChecked():
self.mapCanvas.setMapTool(self.selectEndPointTool)
else:
self.setPanMode()
As usual, we activate the map tool when the user clicks on the toolbar action, and switch
back to the pan mode if the user clicks on the action a second time.
All that's left now are the two callback methods,
onStartPointSelected()
and
onEndPointSelected()
. Let's start with the implementation of
onStartPointSelected()
. This method will start by asking the feature's geometry
to return the coordinates of the clicked-on vertex, which we store into
self.curStartPt
:
def onStartPointSelected(self, feature, vertex):
self.curStartPt =
feature.geometry().vertexAt(vertex)