[QGIS Commit] r14716 - docs/trunk/english_us/developer_cookbook/source

svn_qgis at osgeo.org svn_qgis at osgeo.org
Fri Nov 19 12:40:58 EST 2010


Author: wonder
Date: 2010-11-19 09:40:58 -0800 (Fri, 19 Nov 2010)
New Revision: 14716

Added:
   docs/trunk/english_us/developer_cookbook/source/pluginlayer.rst
Modified:
   docs/trunk/english_us/developer_cookbook/source/index.rst
Log:
Basic plugin layer docs. Contributed by Pirmin Kalberer.


Modified: docs/trunk/english_us/developer_cookbook/source/index.rst
===================================================================
--- docs/trunk/english_us/developer_cookbook/source/index.rst	2010-11-19 13:34:55 UTC (rev 14715)
+++ docs/trunk/english_us/developer_cookbook/source/index.rst	2010-11-19 17:40:58 UTC (rev 14716)
@@ -21,6 +21,7 @@
    composer
    expressions
    measure
+   pluginlayer
    plugins
 
 Indices and tables

Added: docs/trunk/english_us/developer_cookbook/source/pluginlayer.rst
===================================================================
--- docs/trunk/english_us/developer_cookbook/source/pluginlayer.rst	                        (rev 0)
+++ docs/trunk/english_us/developer_cookbook/source/pluginlayer.rst	2010-11-19 17:40:58 UTC (rev 14716)
@@ -0,0 +1,52 @@
+
+.. _pluginlayer:
+
+Using Plugin Layers
+===================
+
+If your plugin uses its own methods to render a map layer, writing your own layer type based on QgsPluginLayer might be the best way to implement that.
+
+**TODO:**
+   Check correctness and elaborate on good use cases for QgsPluginLayer, ...
+
+Subclassing QgsPluginLayer
+--------------------------
+
+Below is an example of a minimal QgsPluginLayer implementation. It is an excerpt of the `Watermark example plugin <http://github.com/sourcepole/qgis-watermark-plugin>`_::
+
+  class WatermarkPluginLayer(QgsPluginLayer):
+
+    LAYER_TYPE="watermark"
+
+    def __init__(self):
+      QgsPluginLayer.__init__(self, WatermarkPluginLayer.LAYER_TYPE, "Watermark plugin layer")
+      self.setValid(True)
+
+    def draw(self, rendererContext):
+      image = QImage("myimage.png")
+      painter = rendererContext.painter()
+      painter.save()
+      painter.drawImage(10, 10, image)
+      painter.restore()
+      return True
+
+Methods for reading and writing specific information to the project file can also be added::
+
+    def readXml(self, node):
+
+    def writeXml(self, node, doc):
+
+
+When loading a project containing such a layer, a factory class is needed::
+
+  class WatermarkPluginLayerType(QgsPluginLayerType):
+
+    def __init__(self):
+      QgsPluginLayerType.__init__(self, WatermarkPluginLayer.LAYER_TYPE)
+
+    def createLayer(self):
+      return WatermarkPluginLayer()
+
+You can also add code for displaying custom information in the layer properties::
+
+    def showLayerProperties(self, layer):



More information about the QGIS-commit mailing list