Skip to content

Commit

Permalink
Merge pull request #298 from GeoNode/ISSUE_297
Browse files Browse the repository at this point in the history
QGIS crashes during the loading of SLD
  • Loading branch information
giohappy authored Nov 27, 2024
2 parents 83da353 + 57c70eb commit 571d5e6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/qgis_geonode/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from qgis.PyQt import QtXml

from . import network
from .utils import remove_comments_from_sld


def deserialize_sld_doc(
Expand All @@ -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():
Expand Down
11 changes: 11 additions & 0 deletions src/qgis_geonode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 571d5e6

Please sign in to comment.