[QGIS-Developer] QgsRenderCategory with or without uuid?
Raymond Nijssen
r.nijssen at terglobo.nl
Wed Mar 12 08:10:34 PDT 2025
Hi developers,
We recently bumped into an issue which took quite some to solve The
QgsRenderCategory objects we created in python resulted in a layer with
incorrectly working "layer legend". When unchecking and checking the
categories in that layer legend, it's always the first category being
turned off/on. It appears to be related to the uuid. Here's the code for
the fix:
https://gitlab.com/terglobo/qgis_dso_plugin/-/commit/f2e492e69f19f426bbe43355d18821ce4807ab5c
After clicking around a bit, opening the layer style panel too,
something gets updated and everything starts working correctly. Saving
the style to .qml also seems to trigger an update.
My question is, should the old way of creating an empty
QgsRenderCategory and setting the value, label and symbol later, not be
used anymore? In that case, the python cookbook needs to be updated.
Or is this a bug that needs to be fixed?
Since QGIS can somehow fix this internaly, it would be nice if the
QgsRenderCategory constructor would simply create and set a uuid
automatically, or otherwise get an updateUuid() method. Instead of
importing uuid and putting uuid=str(uuid.uuid4()) in your python code.
Regards,
Raymond (and Richard)
api docs:
https://qgis.org/pyqgis/master/core/QgsRendererCategory.html
cookbook:
https://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/vector.html#categorized-symbol-renderer
More information about the QGIS-Developer
mailing list