Graphics Reference
In-Depth Information
The Pan Tool
To let the user move around the map, we'll make use of the
PanTool
class we implemen-
ted in an earlier chapter. Add the following class definition to the
mapTools.py
module:
class PanTool(QgsMapTool):
def __init__(self, mapCanvas):
QgsMapTool.__init__(self, mapCanvas)
self.setCursor(Qt.OpenHandCursor)
self.dragging = False
def canvasMoveEvent(self, event):
if event.buttons() == Qt.LeftButton:
self.dragging = True
self.canvas().panAction(event)
def canvasReleaseEvent(self, event):
if event.button() == Qt.LeftButton and self.dragging:
self.canvas().panActionEnd(event.pos())
self.dragging = False
Back in our
forestTrails.py
module, add the following new method:
def setupMapTools(self):
self.panTool = PanTool(self.mapCanvas)
self.panTool.setAction(self.actionPan)
This method will initialize the various map tools that our application will use; we'll add to
this method as we go along. For now, add the following to your
main()
function, after the
call to
window.setupRenderers()
:
window.setupMapTools()
We can now replace our dummy implementation of
setPanMode()
with the real thing:
def setPanMode(self):
self.mapCanvas.setMapTool(self.panTool)