示例#1
0
 def testHtmlAnnotation(self):
     """ test rendering a html annotation"""
     a = QgsHtmlAnnotation()
     a.setFrameSize(QSizeF(400, 250))
     a.setFrameOffsetFromReferencePoint(QPointF(70, 90))
     html = TEST_DATA_DIR + "/test_html.html"
     a.setSourceFile(html)
     im = self.renderAnnotation(a, QPointF(20, 30))
     self.assertTrue(self.imageCheck('html_annotation', 'html_annotation', im))
示例#2
0
    def testHtmlAnnotation(self):
        """ test rendering a html annotation"""
        a = QgsHtmlAnnotation()
        a.fillSymbol().symbolLayer(0).setStrokeColor(QColor(0, 0, 0))
        a.markerSymbol().symbolLayer(0).setStrokeColor(QColor(0, 0, 0))
        a.setFrameSize(QSizeF(400, 250))
        a.setFrameOffsetFromReferencePoint(QPointF(70, 90))
        html = TEST_DATA_DIR + "/test_html.html"
        a.setSourceFile(html)
        im = self.renderAnnotation(a, QPointF(20, 30))
        self.assertTrue(self.imageCheck('html_annotation', 'html_annotation', im))

        # check clone
        clone = a.clone()
        im = self.renderAnnotation(a, QPointF(20, 30))
        self.assertTrue(self.imageCheck('html_annotation', 'html_annotation', im))
示例#3
0
    def testHtmlAnnotation(self):
        """ test rendering a html annotation"""
        a = QgsHtmlAnnotation()
        a.fillSymbol().symbolLayer(0).setStrokeColor(QColor(0, 0, 0))
        a.markerSymbol().symbolLayer(0).setStrokeColor(QColor(0, 0, 0))
        a.setFrameSize(QSizeF(400, 250))
        a.setFrameOffsetFromReferencePoint(QPointF(70, 90))
        html = TEST_DATA_DIR + "/test_html.html"
        a.setSourceFile(html)
        im = self.renderAnnotation(a, QPointF(20, 30))
        self.assertTrue(
            self.imageCheck('html_annotation', 'html_annotation', im))

        # check clone
        clone = a.clone()
        im = self.renderAnnotation(a, QPointF(20, 30))
        self.assertTrue(
            self.imageCheck('html_annotation', 'html_annotation', im))
示例#4
0
    def testHtmlAnnotationWithFeature(self):
        """ test rendering a html annotation with a feature"""
        layer = QgsVectorLayer("Point?crs=EPSG:3111&field=station:string&field=suburb:string",
                               'test', "memory")

        a = QgsHtmlAnnotation()
        a.setFrameSize(QSizeF(400, 250))
        a.setFrameOffsetFromReferencePoint(QPointF(70, 90))
        a.setMapLayer(layer)
        html = TEST_DATA_DIR + "/test_html_feature.html"
        a.setSourceFile(html)
        im = self.renderAnnotation(a, QPointF(20, 30))
        self.assertTrue(self.imageCheck('html_nofeature', 'html_nofeature', im))
        f = QgsFeature(layer.fields())
        f.setValid(True)
        f.setAttributes(['hurstbridge', 'somewhere'])
        a.setAssociatedFeature(f)
        im = self.renderAnnotation(a, QPointF(20, 30))
        self.assertTrue(self.imageCheck('html_feature', 'html_feature', im))
示例#5
0
    def testHtmlAnnotationWithFeature(self):
        """ test rendering a html annotation with a feature"""
        layer = QgsVectorLayer("Point?crs=EPSG:3111&field=station:string&field=suburb:string",
                               'test', "memory")

        a = QgsHtmlAnnotation()
        a.setFrameSize(QSizeF(400, 250))
        a.setFrameOffsetFromReferencePoint(QPointF(70, 90))
        a.setMapLayer(layer)
        html = TEST_DATA_DIR + "/test_html_feature.html"
        a.setSourceFile(html)
        im = self.renderAnnotation(a, QPointF(20, 30))
        self.assertTrue(self.imageCheck('html_nofeature', 'html_nofeature', im))
        f = QgsFeature(layer.fields())
        f.setValid(True)
        f.setAttributes(['hurstbridge', 'somewhere'])
        a.setAssociatedFeature(f)
        im = self.renderAnnotation(a, QPointF(20, 30))
        self.assertTrue(self.imageCheck('html_feature', 'html_feature', im))
示例#6
0
    def canvasReleaseEvent(self, mouseEvent):
        self.currentMoveAction = QgsMapCanvasAnnotationItem.NoAction
        self.setCursor(self.cursor)

        results = self.identify(mouseEvent.x(), mouseEvent.y(),
                                self.selectionMode, self.VectorLayer)
        for r in results:
            # TODO: filter out features in layers that aren't relevant
            if False:
                continue

            layer = r.mLayer
            feature = r.mFeature

            a = QgsHtmlAnnotation()
            a.setMapLayer(layer)
            html = os.path.join(os.path.dirname(__file__), 'html',
                                'current_predictions_annotation.html')
            a.setSourceFile(html)
            a.setAssociatedFeature(feature)

            # TODO: this size and offset are wack. Can we dynamically calculate from the content somehow?
            a.setFrameSize(QSizeF(270, 160))
            a.setFrameOffsetFromReferencePoint(QPointF(-300, -200))
            a.setMapPosition(feature.geometry().asPoint())
            a.setMapPositionCrs(QgsCoordinateReferenceSystem(layer.crs()))

            # disable its symbol
            for symbol in a.markerSymbol().symbolLayers():
                symbol.setEnabled(False)

            QgsProject.instance().annotationManager().addAnnotation(a)

            # select the just-created annotation to make it easy to move or resize
            item = self.itemForAnnotation(a)
            if item:
                self.canvas.scene().clearSelection()
                item.setSelected(True)
            break