diff --git a/src/qgis_geonode/styles.py b/src/qgis_geonode/styles.py index f8f8060..3cc0b9e 100644 --- a/src/qgis_geonode/styles.py +++ b/src/qgis_geonode/styles.py @@ -4,6 +4,7 @@ from qgis.PyQt import QtXml from . import network +from .utils import remove_comments_from_sld def deserialize_sld_doc( @@ -18,6 +19,11 @@ def deserialize_sld_doc( named_layer_element = None if sld_loaded: root = sld_doc.documentElement() + + # We remove all the comments from the SLD since they cause a QGIS crash + # during the SLD serialization (serialize_sld_named_layer, save() method) + remove_comments_from_sld(root) + if not root.isNull(): sld_named_layer = root.firstChildElement("NamedLayer") if not sld_named_layer.isNull(): diff --git a/src/qgis_geonode/utils.py b/src/qgis_geonode/utils.py index 473e155..2298e62 100644 --- a/src/qgis_geonode/utils.py +++ b/src/qgis_geonode/utils.py @@ -37,3 +37,14 @@ def show_message( progress_bar.setMaximum(0) message_item.layout().addWidget(progress_bar) message_bar.pushWidget(message_item, level=level) + + +def remove_comments_from_sld(element): + child = element.firstChild() + while not child.isNull(): + if child.isComment(): + element.removeChild(child) + else: + if child.isElement(): + remove_comments_from_sld(child) + child = child.nextSibling()