Skip to content

Commit

Permalink
find the QDialog object through iteration by type
Browse files Browse the repository at this point in the history
  • Loading branch information
Gpetrak committed Nov 18, 2024
1 parent d8216e4 commit fa657a7
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/qgis_geonode/gui/geonode_map_layer_config_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit fa657a7

Please sign in to comment.