Beispiel #1
0
    def testInstance(self):
        """ test retrieving global instance """
        self.assertTrue(QgsRendererRegistry.instance())

        # instance should be initially populated with some default renderers
        self.assertTrue('singleSymbol' in QgsRendererRegistry.instance().renderersList())

        # register a renderer to the singleton, to test that the same instance is always returned
        self.assertFalse('test' in QgsRendererRegistry.instance().renderersList())
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(TestRenderer('test')))
        self.assertTrue('test' in QgsRendererRegistry.instance().renderersList())
Beispiel #2
0
    def testAddRenderer(self):
        """ test adding renderers to registry """
        clearRegistry()

        # add a renderer
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(TestRenderer('test2')))
        self.assertTrue('test2' in QgsRendererRegistry.instance().renderersList())

        # try adding it again - should be rejected due to duplicate name
        self.assertFalse(QgsRendererRegistry.instance().addRenderer(TestRenderer('test2')))
        self.assertTrue('test2' in QgsRendererRegistry.instance().renderersList())
Beispiel #3
0
    def testAddRenderer(self):
        """ test adding renderers to registry """
        clearRegistry()

        # add a renderer
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(TestRenderer('test2')))
        self.assertTrue('test2' in QgsRendererRegistry.instance().renderersList())

        # try adding it again - should be rejected due to duplicate name
        self.assertFalse(QgsRendererRegistry.instance().addRenderer(TestRenderer('test2')))
        self.assertTrue('test2' in QgsRendererRegistry.instance().renderersList())
Beispiel #4
0
    def testInstance(self):
        """ test retrieving global instance """
        self.assertTrue(QgsRendererRegistry.instance())

        # instance should be initially populated with some default renderers
        self.assertTrue('singleSymbol' in QgsRendererRegistry.instance().renderersList())

        # register a renderer to the singleton, to test that the same instance is always returned
        self.assertFalse('test' in QgsRendererRegistry.instance().renderersList())
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(TestRenderer('test')))
        self.assertTrue('test' in QgsRendererRegistry.instance().renderersList())
Beispiel #5
0
    def testRetrieveRenderer(self):
        """ test retrieving renderer by name """
        clearRegistry()

        # try non-existant renderer
        self.assertFalse(QgsRendererRegistry.instance().rendererMetadata('test4'))

        # now add it
        r = TestRenderer('test4')
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r))

        # try retrieving it
        result = QgsRendererRegistry.instance().rendererMetadata('test4')
        self.assertTrue(result)
        self.assertEqual(result.name(), 'test4')
Beispiel #6
0
    def testRetrieveRenderer(self):
        """ test retrieving renderer by name """
        clearRegistry()

        # try non-existant renderer
        self.assertFalse(QgsRendererRegistry.instance().rendererMetadata('test4'))

        # now add it
        r = TestRenderer('test4')
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r))

        # try retrieving it
        result = QgsRendererRegistry.instance().rendererMetadata('test4')
        self.assertTrue(result)
        self.assertEqual(result.name(), 'test4')
Beispiel #7
0
    def testRenderersByLayerType(self):
        """ test retrieving compatible renderers by layer type """
        clearRegistry()

        # add some renderers
        r1 = TestRenderer('test1', QgsRendererAbstractMetadata.PointLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r1))
        r2 = TestRenderer('test2', QgsRendererAbstractMetadata.LineLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r2))
        r3 = TestRenderer('test3', QgsRendererAbstractMetadata.PolygonLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r3))
        r4 = TestRenderer('test4', QgsRendererAbstractMetadata.PointLayer | QgsRendererAbstractMetadata.LineLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r4))

        # make some layers
        point_layer = QgsVectorLayer("Point?field=fldtxt:string",
                                     "pointlayer", "memory")
        line_layer = QgsVectorLayer("LineString?field=fldtxt:string",
                                    "linelayer", "memory")
        polygon_layer = QgsVectorLayer("Polygon?field=fldtxt:string",
                                       "polylayer", "memory")

        # test subsets
        self.assertEqual(QgsRendererRegistry.instance().renderersList(point_layer), ['singleSymbol', 'test1', 'test4'])
        self.assertEqual(QgsRendererRegistry.instance().renderersList(line_layer), ['singleSymbol', 'test2', 'test4'])
        self.assertEqual(QgsRendererRegistry.instance().renderersList(polygon_layer), ['singleSymbol', 'test3'])
    def testRenderersByLayerType(self):
        """ test retrieving compatible renderers by layer type """
        clearRegistry()

        # add some renderers
        r1 = TestRenderer('test1', QgsRendererAbstractMetadata.PointLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r1))
        r2 = TestRenderer('test2', QgsRendererAbstractMetadata.LineLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r2))
        r3 = TestRenderer('test3', QgsRendererAbstractMetadata.PolygonLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r3))
        r4 = TestRenderer(
            'test4', QgsRendererAbstractMetadata.PointLayer
            | QgsRendererAbstractMetadata.LineLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r4))

        # make some layers
        point_layer = QgsVectorLayer("Point?field=fldtxt:string", "pointlayer",
                                     "memory")
        line_layer = QgsVectorLayer("LineString?field=fldtxt:string",
                                    "linelayer", "memory")
        polygon_layer = QgsVectorLayer("Polygon?field=fldtxt:string",
                                       "polylayer", "memory")

        # test subsets
        self.assertEqual(
            QgsRendererRegistry.instance().renderersList(point_layer),
            ['singleSymbol', 'test1', 'test4'])
        self.assertEqual(
            QgsRendererRegistry.instance().renderersList(line_layer),
            ['singleSymbol', 'test2', 'test4'])
        self.assertEqual(
            QgsRendererRegistry.instance().renderersList(polygon_layer),
            ['singleSymbol', 'test3'])
    def testRenderersList(self):
        """ test getting list of renderers from registry """
        clearRegistry()

        self.assertEqual(QgsRendererRegistry.instance().renderersList(),
                         ['singleSymbol'])

        # add some renderers
        r1 = TestRenderer('test1', QgsRendererAbstractMetadata.PointLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r1))
        r2 = TestRenderer('test2', QgsRendererAbstractMetadata.LineLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r2))
        r3 = TestRenderer('test3', QgsRendererAbstractMetadata.PolygonLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r3))
        r4 = TestRenderer(
            'test4', QgsRendererAbstractMetadata.PointLayer
            | QgsRendererAbstractMetadata.LineLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r4))

        self.assertEqual(QgsRendererRegistry.instance().renderersList(),
                         ['singleSymbol', 'test1', 'test2', 'test3', 'test4'])

        # test subsets
        self.assertEqual(
            QgsRendererRegistry.instance().renderersList(
                QgsRendererAbstractMetadata.PointLayer),
            ['singleSymbol', 'test1', 'test4'])
        self.assertEqual(
            QgsRendererRegistry.instance().renderersList(
                QgsRendererAbstractMetadata.LineLayer),
            ['singleSymbol', 'test2', 'test4'])
        self.assertEqual(
            QgsRendererRegistry.instance().renderersList(
                QgsRendererAbstractMetadata.PolygonLayer),
            ['singleSymbol', 'test3'])
        self.assertEqual(
            QgsRendererRegistry.instance().renderersList(
                QgsRendererAbstractMetadata.LineLayer
                | QgsRendererAbstractMetadata.PolygonLayer),
            ['singleSymbol', 'test2', 'test3', 'test4'])
Beispiel #10
0
    def testRenderersList(self):
        """ test getting list of renderers from registry """
        clearRegistry()

        self.assertEqual(QgsRendererRegistry.instance().renderersList(), ["singleSymbol"])

        # add some renderers
        r1 = TestRenderer("test1", QgsRendererAbstractMetadata.PointLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r1))
        r2 = TestRenderer("test2", QgsRendererAbstractMetadata.LineLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r2))
        r3 = TestRenderer("test3", QgsRendererAbstractMetadata.PolygonLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r3))
        r4 = TestRenderer("test4", QgsRendererAbstractMetadata.PointLayer | QgsRendererAbstractMetadata.LineLayer)
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(r4))

        self.assertEqual(
            QgsRendererRegistry.instance().renderersList(), ["singleSymbol", "test1", "test2", "test3", "test4"]
        )

        # test subsets
        self.assertEqual(
            QgsRendererRegistry.instance().renderersList(QgsRendererAbstractMetadata.PointLayer),
            ["singleSymbol", "test1", "test4"],
        )
        self.assertEqual(
            QgsRendererRegistry.instance().renderersList(QgsRendererAbstractMetadata.LineLayer),
            ["singleSymbol", "test2", "test4"],
        )
        self.assertEqual(
            QgsRendererRegistry.instance().renderersList(QgsRendererAbstractMetadata.PolygonLayer),
            ["singleSymbol", "test3"],
        )
        self.assertEqual(
            QgsRendererRegistry.instance().renderersList(
                QgsRendererAbstractMetadata.LineLayer | QgsRendererAbstractMetadata.PolygonLayer
            ),
            ["singleSymbol", "test2", "test3", "test4"],
        )
Beispiel #11
0
    def testRemoveRenderer(self):
        """ test removing renderers from registry """
        clearRegistry()

        # try removing non-existant renderer
        self.assertFalse(QgsRendererRegistry.instance().removeRenderer('test3'))

        # now add it
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(TestRenderer('test3')))
        self.assertTrue('test3' in QgsRendererRegistry.instance().renderersList())

        # try removing it again - should be ok this time
        self.assertTrue(QgsRendererRegistry.instance().removeRenderer('test3'))
        self.assertFalse('test3' in QgsRendererRegistry.instance().renderersList())

        # try removing it again - should be false since already removed
        self.assertFalse(QgsRendererRegistry.instance().removeRenderer('test3'))
Beispiel #12
0
    def testRemoveRenderer(self):
        """ test removing renderers from registry """
        clearRegistry()

        # try removing non-existant renderer
        self.assertFalse(QgsRendererRegistry.instance().removeRenderer('test3'))

        # now add it
        self.assertTrue(QgsRendererRegistry.instance().addRenderer(TestRenderer('test3')))
        self.assertTrue('test3' in QgsRendererRegistry.instance().renderersList())

        # try removing it again - should be ok this time
        self.assertTrue(QgsRendererRegistry.instance().removeRenderer('test3'))
        self.assertFalse('test3' in QgsRendererRegistry.instance().renderersList())

        # try removing it again - should be false since already removed
        self.assertFalse(QgsRendererRegistry.instance().removeRenderer('test3'))
Beispiel #13
0
def clearRegistry():
    # clear registry to start with
    for r in QgsRendererRegistry.instance().renderersList():
        if r == 'singleSymbol':
            continue
        QgsRendererRegistry.instance().removeRenderer(r)
Beispiel #14
0
def clearRegistry():
    # clear registry to start with
    for r in QgsRendererRegistry.instance().renderersList():
        if r == 'singleSymbol':
            continue
        QgsRendererRegistry.instance().removeRenderer(r)