From 4b5466ea1500a1991ee38f6af3f291d6b12724c5 Mon Sep 17 00:00:00 2001 From: gpetrak Date: Mon, 25 Nov 2024 16:16:24 +0200 Subject: [PATCH 1/2] QGIS crashes during the loading of SLD --- src/qgis_geonode/styles.py | 6 ++++++ src/qgis_geonode/utils.py | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/qgis_geonode/styles.py b/src/qgis_geonode/styles.py index f8f80601..4759c09c 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_sld_comments 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_sld_comments(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 473e1554..f29635f3 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_sld_comments(element): + child = element.firstChild() + while not child.isNull(): + if child.isComment(): + element.removeChild(child) + else: + if child.isElement(): + remove_sld_comments(child) + child = child.nextSibling() From a55a7b719686cfaeb2226dbde754c24d6266e9f1 Mon Sep 17 00:00:00 2001 From: gpetrak Date: Mon, 25 Nov 2024 16:23:41 +0200 Subject: [PATCH 2/2] rename the remove_sld_comments --- src/qgis_geonode/styles.py | 4 ++-- src/qgis_geonode/utils.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/qgis_geonode/styles.py b/src/qgis_geonode/styles.py index 4759c09c..3cc0b9e2 100644 --- a/src/qgis_geonode/styles.py +++ b/src/qgis_geonode/styles.py @@ -4,7 +4,7 @@ from qgis.PyQt import QtXml from . import network -from .utils import remove_sld_comments +from .utils import remove_comments_from_sld def deserialize_sld_doc( @@ -22,7 +22,7 @@ def deserialize_sld_doc( # 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_sld_comments(root) + remove_comments_from_sld(root) if not root.isNull(): sld_named_layer = root.firstChildElement("NamedLayer") diff --git a/src/qgis_geonode/utils.py b/src/qgis_geonode/utils.py index f29635f3..2298e622 100644 --- a/src/qgis_geonode/utils.py +++ b/src/qgis_geonode/utils.py @@ -39,12 +39,12 @@ def show_message( message_bar.pushWidget(message_item, level=level) -def remove_sld_comments(element): +def remove_comments_from_sld(element): child = element.firstChild() while not child.isNull(): if child.isComment(): element.removeChild(child) else: if child.isElement(): - remove_sld_comments(child) + remove_comments_from_sld(child) child = child.nextSibling()