Graphics Reference
In-Depth Information
We then set the various instance variables to their initial state, and tell the map tool to use
a cross cursor, which makes it easier for the user to see exactly where they are clicking.
Our next task is to implement the various XXXEvent() methods to respond to the user's
actions. We'll start with canvasReleaseEvent() , which responds to a left-click by
adding a new vertex to the geometry, and to a right-click by finishing off the capture pro-
cess and then adding the geometry to the map layer.
Note
We implement this behavior in the canvasReleaseEvent() method, rather than
canvasPressEvent() , because we want the vertex to be added when the user re-
leases the mouse button, rather than when they initially press it.
Here is the implementation of the canvasReleaseEvent() method. Note that we
make use of several helper methods, which we will define shortly:
def canvasReleaseEvent(self, event):
if event.button() == Qt.LeftButton:
if not self.capturing:
self.startCapturing()
self.addVertex(event.pos())
elif event.button() == Qt.RightButton:
points = self.getCapturedGeometry()
self.stopCapturing()
if points != None:
self.geometryCaptured(points)
Next, we have the canvasMoveEvent() method, which responds to the action of the
user moving the mouse by updating the temporary rubber band to reflect the current
mouse position:
def canvasMoveEvent(self, event):
if self.tempRubberBand != None and self.capturing:
mapPt,layerPt =
self.transformCoordinates(event.pos())
self.tempRubberBand.movePoint(mapPt)
Search WWH ::




Custom Search