From fa657a71cf670419884adc655c8928cdb07bde20 Mon Sep 17 00:00:00 2001 From: gpetrak Date: Mon, 18 Nov 2024 15:20:00 +0200 Subject: [PATCH] find the QDialog object through iteration by type --- .../gui/geonode_map_layer_config_widget.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/qgis_geonode/gui/geonode_map_layer_config_widget.py b/src/qgis_geonode/gui/geonode_map_layer_config_widget.py index d21e235..e8a1512 100644 --- a/src/qgis_geonode/gui/geonode_map_layer_config_widget.py +++ b/src/qgis_geonode/gui/geonode_map_layer_config_widget.py @@ -449,10 +449,26 @@ def _show_message( ) -> None: utils.show_message(self.message_bar, message, level, add_loading_widget) + def find_parent_by_type(self, obj, target_type): + # Find the desired object by type + # from a structure: self.parent().parent()... + current_obj = obj + while current_obj is not None: + if isinstance(current_obj, target_type): + return current_obj + if hasattr(current_obj, "parent"): + current_obj = current_obj.parent() + else: + break + return None + def sync_layer_properties(self): # get layer properties dialog - # TODO we have to find a more elegant way to retrieve the properties dialog - properties_dialog = self.parent().parent().parent().parent().parent().parent() + # We need to find QDialog object from a structure like: + # self.parent().parent()... + target_type = QtWidgets.QDialog + obj = self + properties_dialog = self.find_parent_by_type(obj, target_type) # Sync GeoNode's SLD or / and metadata with the layer properties dialog properties_dialog.syncToLayer()