Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from qgis.core import *
- from qgis.gui import *
- class TestLayer(QgsPluginLayer):
- LAYER_TYPE=u'TestLayer'
- def __init__(self):
- QgsPluginLayer.__init__(self, TestLayer.LAYER_TYPE)
- self.setValid(True)
- def draw(self, rendererContext):
- print("TestLayer::draw")
- return True
- def noise(self):
- print("TestLayer::noise")
- return True
- class TestLayerType(QgsPluginLayerType):
- def __init__(self):
- QgsPluginLayerType.__init__(self, TestLayer.LAYER_TYPE)
- def createLayer(self):
- print("TestLayerType::createLayer")
- return TestLayer()
- registry = QgsPluginLayerRegistry.instance()
- print(registry.removePluginLayerType(TestLayer.LAYER_TYPE))
- print(registry.addPluginLayerType(TestLayerType()))
- print(registry.pluginLayerType(TestLayer.LAYER_TYPE))
- # A TestLayer object should be created but instead a QgsPluginLayer appears
- print(registry.createLayer(TestLayer.LAYER_TYPE))
- # The wrong draw() function is called (from QgsPluginLayer)
- print(registry.createLayer(TestLayer.LAYER_TYPE).draw(QgsRenderContext()))
- # The function noise() of TestLayer is not found
- print(registry.createLayer(TestLayer.LAYER_TYPE).noise())
- """ Output in QGIS 2.8.1 and 2.11 Python console:
- execfile(u'/home/soeren/Dokumente/.../PluginLayerTest.py'.encode('UTF-8'))
- False
- True
- <__console__.TestLayerType object at 0x7febfe2db770>
- TestLayerType::createLayer
- <qgis._core.QgsPluginLayer object at 0x7febfe2db6d8>
- TestLayerType::createLayer
- False
- TestLayerType::createLayer
- Traceback (most recent call last):
- File "<input>", line 1, in <module>
- File "/home/soeren/Dokumente.../PluginLayerTest.py", line 36, in <module>
- print(registry.createLayer(TestLayer.LAYER_TYPE).noise())
- AttributeError: 'QgsPluginLayer' object has no attribute 'noise'
- """
Advertisement
Add Comment
Please, Sign In to add comment