def testSize(self):
        """ test that map canvas annotation item size is correct """
        a = QgsTextAnnotation()
        a.setFrameSize(QSizeF(300, 200))
        a.setHasFixedMapPosition(False)
        a.setFillSymbol(QgsFillSymbol.createSimple({'color': 'blue', 'width_border': '0'}))

        canvas = QgsMapCanvas()
        canvas.setDestinationCrs(QgsCoordinateReferenceSystem(4326))
        canvas.setFrameStyle(0)
        canvas.resize(600, 400)
        canvas.show()

        canvas.setExtent(QgsRectangle(10, 30, 20, 35))

        i = QgsMapCanvasAnnotationItem(a, canvas)
        self.assertAlmostEqual(i.boundingRect().width(), 300, 1)
        self.assertAlmostEqual(i.boundingRect().height(), 200, 1)

        a.setHasFixedMapPosition(True)
        a.setFrameOffsetFromReferencePoint(QPointF(0, 0))
        self.assertAlmostEqual(i.boundingRect().width(), 300, -1)
        self.assertAlmostEqual(i.boundingRect().height(), 200, -1)
        a.setFrameOffsetFromReferencePoint(QPointF(10, 20))
        self.assertAlmostEqual(i.boundingRect().width(), 310, -1)
        self.assertAlmostEqual(i.boundingRect().height(), 220, -1)
    def testSize(self):
        """ test that map canvas annotation item size is correct """
        a = QgsTextAnnotation()
        a.setFrameSize(QSizeF(300, 200))
        a.setHasFixedMapPosition(False)
        a.setFillSymbol(QgsFillSymbol.createSimple({'color': 'blue', 'width_border': '0'}))

        canvas = QgsMapCanvas()
        canvas.setDestinationCrs(QgsCoordinateReferenceSystem(4326))
        canvas.setFrameStyle(0)
        canvas.resize(600, 400)
        canvas.show()

        canvas.setExtent(QgsRectangle(10, 30, 20, 35))

        i = QgsMapCanvasAnnotationItem(a, canvas)
        self.assertAlmostEqual(i.boundingRect().width(), 300, 1)
        self.assertAlmostEqual(i.boundingRect().height(), 200, 1)

        a.setHasFixedMapPosition(True)
        a.setFrameOffsetFromReferencePoint(QPointF(0, 0))
        self.assertAlmostEqual(i.boundingRect().width(), 300, -1)
        self.assertAlmostEqual(i.boundingRect().height(), 200, -1)
        a.setFrameOffsetFromReferencePoint(QPointF(10, 20))
        self.assertAlmostEqual(i.boundingRect().width(), 310, -1)
        self.assertAlmostEqual(i.boundingRect().height(), 220, -1)
    def testSize(self):
        """ test that map canvas annotation item size is correct """
        a = QgsTextAnnotation()
        a.setFrameSizeMm(QSizeF(300 / 3.7795275, 200 / 3.7795275))
        a.setHasFixedMapPosition(False)
        a.setFillSymbol(QgsFillSymbol.createSimple({'color': 'blue', 'width_border': '0'}))

        canvas = QgsMapCanvas()
        canvas.setDestinationCrs(QgsCoordinateReferenceSystem(4326))
        canvas.setFrameStyle(0)
        canvas.resize(600, 400)
        canvas.show()

        canvas.setExtent(QgsRectangle(10, 30, 20, 35))

        i = QgsMapCanvasAnnotationItem(a, canvas)
        # ugly, but Travis has different default DPI:
        if 299 < i.boundingRect().width() < 301:
            self.assertAlmostEqual(i.boundingRect().width(), 300, 1)
            self.assertAlmostEqual(i.boundingRect().height(), 200, 1)

            a.setHasFixedMapPosition(True)
            a.setFrameOffsetFromReferencePoint(QPointF(0, 0))
            self.assertAlmostEqual(i.boundingRect().width(), 300, -1)
            self.assertAlmostEqual(i.boundingRect().height(), 200, -1)
            a.setFrameOffsetFromReferencePoint(QPointF(10, 20))
            self.assertAlmostEqual(i.boundingRect().width(), 310, -1)
            self.assertAlmostEqual(i.boundingRect().height(), 220, -1)
        else:
            self.assertAlmostEqual(i.boundingRect().width(), 312.5, 1)
            self.assertAlmostEqual(i.boundingRect().height(), 208.33, 1)

            a.setHasFixedMapPosition(True)
            a.setFrameOffsetFromReferencePoint(QPointF(0, 0))
            self.assertAlmostEqual(i.boundingRect().width(), 312.5, -1)
            self.assertAlmostEqual(i.boundingRect().height(), 208.33, -1)
            a.setFrameOffsetFromReferencePoint(QPointF(10, 20))
            self.assertAlmostEqual(i.boundingRect().width(), 322.91, -1)
            self.assertAlmostEqual(i.boundingRect().height(), 229.166, -1)
Esempio n. 4
0
    def testSize(self):
        """ test that map canvas annotation item size is correct """
        a = QgsTextAnnotation()
        a.setFrameSizeMm(QSizeF(300 / 3.7795275, 200 / 3.7795275))
        a.setHasFixedMapPosition(False)
        a.setFillSymbol(
            QgsFillSymbol.createSimple({
                'color': 'blue',
                'width_border': '0'
            }))

        canvas = QgsMapCanvas()
        canvas.setDestinationCrs(QgsCoordinateReferenceSystem(4326))
        canvas.setFrameStyle(0)
        canvas.resize(600, 400)
        canvas.show()

        canvas.setExtent(QgsRectangle(10, 30, 20, 35))

        i = QgsMapCanvasAnnotationItem(a, canvas)
        # ugly, but Travis has different default DPI:
        if 299 < i.boundingRect().width() < 301:
            self.assertAlmostEqual(i.boundingRect().width(), 300, 1)
            self.assertAlmostEqual(i.boundingRect().height(), 200, 1)

            a.setHasFixedMapPosition(True)
            a.setFrameOffsetFromReferencePoint(QPointF(0, 0))
            self.assertAlmostEqual(i.boundingRect().width(), 300, -1)
            self.assertAlmostEqual(i.boundingRect().height(), 200, -1)
            a.setFrameOffsetFromReferencePoint(QPointF(10, 20))
            self.assertAlmostEqual(i.boundingRect().width(), 310, -1)
            self.assertAlmostEqual(i.boundingRect().height(), 220, -1)
        else:
            self.assertAlmostEqual(i.boundingRect().width(), 312.5, 1)
            self.assertAlmostEqual(i.boundingRect().height(), 208.33, 1)

            a.setHasFixedMapPosition(True)
            a.setFrameOffsetFromReferencePoint(QPointF(0, 0))
            self.assertAlmostEqual(i.boundingRect().width(), 312.5, -1)
            self.assertAlmostEqual(i.boundingRect().height(), 208.33, -1)
            a.setFrameOffsetFromReferencePoint(QPointF(10, 20))
            self.assertAlmostEqual(i.boundingRect().width(), 322.91, -1)
            self.assertAlmostEqual(i.boundingRect().height(), 229.166, -1)