Skip to content

Commit

Permalink
List on the logs the list layers/groups when counting
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Dec 18, 2023
1 parent 4b023dd commit deee046
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
13 changes: 8 additions & 5 deletions lizmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,22 +843,25 @@ def project_saved(self):
return

# Check the number of layers between the project and the Lizmap configuration file.
count_cfg = len(self.layerList.keys())
count_qgs = count_legend_items(self.project.layerTreeRoot(), self.project, 0)
if count_cfg != count_qgs:
list_cfg = list(self.layerList.keys())
list_qgs = count_legend_items(self.project.layerTreeRoot(), self.project, [])
if len(list_cfg) != len(list_qgs):
self.iface.messageBar().pushMessage(
'Lizmap',
tr(
'The project has {count_qgs} items in the legend, while the Lizmap configuration has {count_cfg} '
'items. Please open the plugin to sync the "{layer_tab}" tab.'
).format(
count_qgs=count_qgs,
count_cfg=count_cfg,
count_qgs=len(list_qgs),
count_cfg=len(list_cfg),
layer_tab=self.dlg.mOptionsListWidget.item(Panels.Layers).text()
),
Qgis.Warning,
duration=DURATION_WARNING_BAR,
)
LOGGER.debug(
"Difference in counts between CFG and QGS\n\nList in CFG : {}\nList in QGS : {}".format(
','.join(list_cfg), ','.join(list_qgs)))

def filename_changed(self):
""" When the current project has been renamed. """
Expand Down
10 changes: 5 additions & 5 deletions lizmap/project_checker_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,19 +325,19 @@ def project_trust_layer_metadata(project: QgsProject, fix: bool = False) -> bool
return True


def count_legend_items(layer_tree: QgsLayerTreeNode, project, count: int) -> int:
def count_legend_items(layer_tree: QgsLayerTreeNode, project, list_qgs: list) -> list:
""" Count all items in the project legend. """
for child in layer_tree.children():
# noinspection PyArgumentList
if QgsLayerTree.isLayer(child):
count += 1
list_qgs.append(child.name())
else:
child = cast_to_group(child)
count += 1
list_qgs.append(child.name())
# Recursive call
count = count_legend_items(child, project, count)
list_qgs = count_legend_items(child, project, list_qgs)

return count
return list_qgs


def trailing_layer_group_name(layer_tree: QgsLayerTreeNode, project, results: List) -> List:
Expand Down

0 comments on commit deee046

Please sign in to comment.