Graphics Reference
In-Depth Information
Using this renderer will cause the various point geometries to be displayed in alternating
colors, for example:
Let's take a closer look at how this class was implemented, and what the various methods
do:
•
__init__()
: This is your standard Python initializer. Notice how we have to
provide a unique name for the renderer when calling the
QgsFeatureRender-
erV2.__init__()
method; this is used to keep track of the various renderers
within QGIS itself.
•
clone()
: This creates a copy of this renderer. If your renderer uses properties to
control how it works, this method should copy those properties into the new ren-
derer object.
•
symbolForFeature()
: This returns the symbol to use for drawing the given
feature.
•
startRender()
: This gives you the opportunity to prepare your renderer and
any symbols you use before the features are rendered. Note that you must call the
startRender()
method on each symbol that your renderer uses; as the ren-
derer can make use of multiple symbols, you need to implement this so that your
symbols are also given a chance to prepare for rendering.
•
stopRender()
: This finishes rendering the features. Once again, you need to
implement this so that your symbols can have a chance to clean up once the ren-
dering process has finished.
•
usedAttributes()
: This method should be implemented to return the list of
feature attributes that the renderer makes use of. If your renderer does not use at-
tributes to choose between the various symbols, then you do not need to imple-
ment this method.
If you wish, you can also implement your own widget that lets the user change the way
the renderer works. This is done by subclassing
QgsRendererV2Widget
and setting
up the widget to edit the renderer's various properties in the same way that we implemen-
ted a subclass of
QgsSymbolLayerV2Widget
to edit the properties for a symbol lay-