Dear devs,
I'm trying to apply a symbology on a mesh when loading the layer at the end of
an alg.
```
def _apply_mesh_symbology(layer: QgsMeshLayer) -> None:
"""Default display for the output mesh: native mesh frame (edges), no
colouring.
MDAL loads a Selafin showing the placeholder ``BOTTOM`` scalar dataset
coloured; this turns scalar/vector colouring off, enables the native mesh
frame.
"""
settings = layer.rendererSettings()
settings.setActiveScalarDatasetGroup(-1) # no BOTTOM colouring
settings.setActiveVectorDatasetGroup(-1)
edge = settings.edgeMeshSettings()
edge.setEnabled(True) # draw the mesh edges
settings.setEdgeMeshSettings(edge)
native = settings.nativeMeshSettings()
native.setEnabled(True) # draw the native mesh (edges)
triangular = settings.triangularMeshSettings()
triangular.setEnabled(True) # draw the triangular mesh frame
settings.setTriangularMeshSettings(triangular)
settings.setNativeMeshSettings(native)
layer.setRendererSettings(settings)
layer.triggerRepaint()
class _MeshLayerPostProcessor(QgsProcessingLayerPostProcessorInterface):
"""Finalize the Selafin mesh layer loaded on completion: CRS + default
symbology."""
instance = None
def __init__(self, crs):
super().__init__()
self._crs = crs
#
https://github.com/QuickOSM/QuickOSM/blob/7ddeb32239e96394335babbb50ca728e6a48e4ee/QuickOSM/quick_osm_processing/advanced/decorate_output.py#L151-L156
@staticmethod
def create(crs) -> "_MeshLayerPostProcessor":
_MeshLayerPostProcessor.instance = _MeshLayerPostProcessor(crs)
return _MeshLayerPostProcessor.instance
def postProcessLayer(self, layer, context, feedback): # noqa: ARG002 -
QGIS API signature
if layer is None:
return
if self._crs is not None and self._crs.isValid():
layer.setCrs(self._crs)
if isinstance(layer, QgsMeshLayer):
_apply_mesh_symbology(layer)
```
The layer is loaded with correct CRS, with scalar coloring OFF but the native
mesh rendering remains OFF.
I'm wondering if I'm doing something wrong...
Once the layer is loaded, I can activate native mesh rendering using python
console without issues:
```
l = iface.activeLayer()
r = l.rendererSettings()
n = r.nativeMeshSettings()
n.setEnabled(True)
r.setNativeMeshSettings(n)
l.setRendererSettings(r)
```
Any hints?
Kind regards,
Nicolas
_______________________________________________
QGIS-Developer mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer