def canvasPressEvent(self, event): ''' Get point and transform to map coordinates ''' # get the current activeVLayer from mainwindow self.activeVLayer = self.mainwindow.activeVLayer if self.activeVLayer == None: return point = event.pos() transform = self.canvas.getCoordinateTransform() # returns a QgsPoint object in map coordinates self.qgsPoint = transform.toMapCoordinates(point.x(), point.y()) print "The point is " + str(self.qgsPoint) # check if the proper editing layer is selected currentLayerName = self.mainwindow.legend.currentItem().canvasLayer.layer().name() if shared.checkSelectedLayer(self.mainwindow, self.mainwindow.scenarioType, currentLayerName) == "Cancel": self.qgsPoint = None return # if wrong edit layer cancel drawing # Check constraints on the added point for the scenario edit type # and prompt the user if constraints are not met. Method returns False # if the constraints are not met. if not shared.checkConstraints(self.mainwindow, self.qgsPoint): self.qgsPoint = None return else: pass # correct editing layer selected and constraints check OK so get the new attributes self.getNewAttributes()
def canvasPressEvent(self, event): ''' Record the mouse down event ''' # set the active vector layer self.activeVLayer = self.mainwindow.activeVLayer if self.activeVLayer == None: return # set the current geometry and some variables for the QgsRubberBand if self.mainwindow.geom: if self.mainwindow.geom == 1: # line self.geom = False else: self.geom = True # polygon # check if the editing layer is selected but only on the first click if self.started == False: currentLayerName = self.mainwindow.legend.currentItem().canvasLayer.layer().name() if shared.checkSelectedLayer(self.mainwindow, self.mainwindow.scenarioType, currentLayerName) == "Cancel": return # return without starting to draw self.down = True # starts the drawing process