Пример #1
0
 def loadSketches(self):
     self.geoSketches = []
     self.annotatatedSketch = None
     if self.sketchFileInfo.exists():
         infile = open(self.sketchFileInfo.filePath(), 'r')
         canvas = self.iface.mapCanvas()
         mapRenderer = canvas.mapRenderer()
         srs=mapRenderer.destinationCrs()
         dumLayer = QgsVectorLayer("Line?crs="+str(srs.authid()), "temporary_lines", "memory")
         self.geoSketches = []
         for line in infile:
             inline = line.split("|")
             sketch=QgsRubberBand(self.iface.mapCanvas(),QGis.Line )
             sketch.setWidth( int(inline[1]) )
             sketch.setColor(QColor(inline[0]))
             sketch.setToGeometry(QgsGeometry.fromWkt(inline[2]),dumLayer)
             if inline[3] != "":
                 annotationText = inline[3].replace("%%N%%","\n")
                 annotationObject = sketchNoteDialog.newPoint(self.iface,QgsGeometry.fromWkt(inline[2]),txt = annotationText)
                 self.annotatatedSketch = True
             else:
                 annotationObject = None
                 annotationText = ""
             self.geoSketches.append([inline[0],inline[1],sketch,annotationObject,annotationText,int(inline[4])])
         self.gestures = int(inline[4])+1
         infile.close()
Пример #2
0
    def canvasReleaseEvent(self, event):
        if event.button() == Qt.RightButton:
            return
        self.pressed=None
        QgsProject.instance().setDirty(True)
        if self.canvasAction == "pen":
            if not self.dragged:
                if self.previousPoint:
                    self.sketch.addPoint(self.previousPoint)
                    self.sketch.addPoint(self.pressedPoint)
                    self.previousPoint = self.pressedPoint
                else:
                    self.previousPoint = self.pressedPoint
                    return
            elif self.previousMoved:
                self.previousMoved = None
                self.sketch.addPoint(self.previousPoint)
                self.sketch.addPoint(self.movedPoint)
                self.previousPoint = self.movedPoint
                
            else:
                self.previousPoint = self.movedPoint
                self.previousMoved = True
            self.geoSketches.append([self.currentColor.name(),str(self.currentWidth),self.sketch,None,"",self.gestures])
            self.points += 1 

        if self.canvasAction == "sketch" and self.noteButton.isChecked():
            if self.points > 0:
                midIdx = -int(self.points/2)
                annotation = sketchNoteDialog.newPoint(self.iface,self.geoSketches[midIdx][2].asGeometry())
                if annotation:
                    self.geoSketches[midIdx][3] = annotation
                    self.geoSketches[midIdx][4] = annotation.document().toPlainText()
                self.annotatatedSketch = True
                self.gestures += 1
Пример #3
0
 def canvasPressEvent(self, event):
     # Press event handler inherited from QgsMapTool used to store the given location in WGS84 long/lat
     if event.button() == Qt.RightButton:
         print "rightbutton"
         if self.noteButton.isChecked():
             midIdx = -int(self.points/2)
             if midIdx == 0:
                 midIdx = -1
             annotation = sketchNoteDialog.newPoint(self.iface,self.geoSketches[midIdx][2].asGeometry())
             if annotation:
                 self.geoSketches[-1][3] = annotation
                 self.geoSketches[-1][4] = annotation.document().toPlainText()
             self.annotatatedSketch = True
         self.gestures += 1
         self.points = 0
         self.penAction()
         self.previousPoint = None
         self.previousMoved = None
         self.movedPoint = None
         self.pressed = None
         self.dragged = None
     else:
         self.pressed=True
         self.dragged = None
         self.movedPoint = None
         self.px = event.pos().x()
         self.py = event.pos().y()
         self.pressedPoint = self.canvas.getCoordinateTransform().toMapCoordinates(self.px, self.py)
         if self.canvasAction == "sketch":
             self.points = 0
         if self.canvasAction == "pen":
             self.snapSys = self.iface.mapCanvas().snappingUtils()
             snappedPoint = self.snapSys.snapToMap(self.pressedPoint)
             if snappedPoint.isValid():
                 self.pressedPoint = snappedPoint.point()
             self.sketch=QgsRubberBand(self.iface.mapCanvas(),QGis.Line )
             self.sketch.setWidth(self.currentWidth)
             self.sketch.setColor(self.currentColor)
             self.sketch.addPoint(self.pressedPoint)
Пример #4
0
 def recoverAllAnnotations(self):
     for sketch in self.geoSketches:
         if sketch[4] != "":
             sketch[3] = sketchNoteDialog.newPoint(self.iface,sketch[2].asGeometry(),txt = sketch[4])