[Qgis-developer] symbolForFeature() does not works?

Martin Dobias wonder.sk at gmail.com
Fri Jul 4 02:53:25 PDT 2014

Hi Alex

On Thu, Jul 3, 2014 at 10:53 PM, Alexander Bruy
<alexander.bruy at gmail.com> wrote:
> Hi all,
> seems symbolForFeature() method does not works as expected for most
> renderers:
>  * QgsSingleSymbolRendererV2 — returns feature symbol
>  * QgsCategorizedSymbolRendererV2 — returns None and in debug output
>     I have message saying "there are no hashed symbols!!!"
>  * QgsGraduatedSymbolRendererV2 — just crashes QGIS
>  * QgsRuleBasedRendererV2 — returns None
> All tests made with point shapefile. Here is code snipped I used (load vector
> layer and activate it first):
> layer = iface.mapCanvas().currentLayer()
> feat = layer.getFeatures().next()
> renderer = layer.rendererV2()
> symbol = renderer.symbolForFeature(feat)
> For me this is major issue that makes difficult to develop plugins that works
> with layer symbology (e.g. symbology import/export/conversion)
> Anyone confirms? Should I open a ticket?

Like with renderFeature() call, the symbolForFeature() method must be
called in between startRender()/stopRender() calls, otherwise the
behaviour is undefined. It would be nice though not to crash and emit
a warning instead...


More information about the Qgis-developer mailing list