コード例 #1
0
    def testScaledGeometry(self):
        """
        Test scaling geometry
        """
        shape = QgsLegendPatchShape(
            QgsSymbol.Line, QgsGeometry.fromWkt('LineString(5 5, 1 2)'))

        self.assertEqual(
            shape.scaledGeometry(QSizeF(20, 30)).asWkt(1),
            'LineString (20 7.5, 0 22.5)')
        self.assertEqual(
            shape.scaledGeometry(QSizeF(200, 300)).asWkt(1),
            'LineString (200 75, 0 225)')
        shape.setScaleToOutputSize(False)
        self.assertEqual(
            shape.scaledGeometry(QSizeF(20, 30)).asWkt(1),
            'LineString (5 5, 1 2)')
        self.assertEqual(
            shape.scaledGeometry(QSizeF(200, 300)).asWkt(1),
            'LineString (5 5, 1 2)')
コード例 #2
0
    def testBasic(self):
        shape = QgsLegendPatchShape(
            QgsSymbol.Line, QgsGeometry.fromWkt('LineString( 0 0, 1 1)'),
            False)
        self.assertFalse(shape.isNull())
        self.assertEqual(shape.symbolType(), QgsSymbol.Line)
        self.assertEqual(shape.geometry().asWkt(), 'LineString (0 0, 1 1)')
        self.assertFalse(shape.preserveAspectRatio())

        shape.setSymbolType(QgsSymbol.Marker)
        self.assertEqual(shape.symbolType(), QgsSymbol.Marker)

        shape.setGeometry(QgsGeometry.fromWkt('Multipoint( 1 1, 2 2)'))
        self.assertEqual(shape.geometry().asWkt(), 'MultiPoint ((1 1),(2 2))')

        shape.setPreserveAspectRatio(True)
        self.assertTrue(shape.preserveAspectRatio())

        self.assertTrue(shape.scaleToOutputSize())
        shape.setScaleToOutputSize(False)
        self.assertFalse(shape.scaleToOutputSize())