Skip to content

Commit

Permalink
Add check for empty baselayers group in the legend fix #540
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Dec 18, 2023
1 parent deee046 commit 120a27b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lizmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@
from lizmap.table_manager.dataviz import TableManagerDataviz
from lizmap.table_manager.layouts import TableManagerLayouts
from lizmap.tools import cast_to_group, cast_to_layer
from lizmap.widgets.project_tools import is_layer_wms_excluded
from lizmap.widgets.project_tools import (
empty_baselayers,
is_layer_wms_excluded,
)

try:
from lizmap.plugin_manager import QgisPluginManager
Expand Down Expand Up @@ -3168,6 +3171,11 @@ def project_config_file(
self.dlg.check_results.add_error(Error(Path(self.project.fileName()).name, checks.TrustProject))
self.dlg.enabled_trust_project(True)

if empty_baselayers(self.project):
self.dlg.check_results.add_error(
Error(Path(self.project.fileName()).name, checks.EmptyBaseLayersGroup)
)

# Not blocking, we change it in the background
if self.project.readNumEntry("WMSMaxAtlasFeatures", '')[0] <= 0:
LOGGER.info("The maximum atlas features was less than '1'. We set it to '1' to at least have a value.")
Expand Down
17 changes: 17 additions & 0 deletions lizmap/widgets/check_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,23 @@ def __init__(self):
Severities().blocking if qgis_version() >= 32200 else Severities().important,
QIcon(':/images/themes/default/mIconQgsProjectFile.svg'),
)
self.EmptyBaseLayersGroup = Check(
'empty_baselayers_group',
tr('Empty "baselayers" group'),
tr('The group "baselayers" cannot be empty.'),
(
'<ul>'
'<li>{}</li>'
'<li>{}</li>'
'</ul>'.format(
tr("Either add some layers in it"),
tr('Or remove it.'),
)
),
Levels.Project,
Severities().blocking,
QIcon(':/images/themes/default/mIconQgsProjectFile.svg'),
)
self.LeadingTrailingSpaceLayerGroupName = Check(
'leading_trailing_space',
tr('Leading/trailing space in layer/group name'),
Expand Down
13 changes: 12 additions & 1 deletion lizmap/widgets/project_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__license__ = 'GPL version 3'
__email__ = '[email protected]'

from qgis.core import QgsProject
from qgis.core import QgsLayerTreeGroup, QgsProject


def is_layer_wms_excluded(project: QgsProject, name: str) -> bool:
Expand All @@ -12,3 +12,14 @@ def is_layer_wms_excluded(project: QgsProject, name: str) -> bool:
"""
server_wms_excluded_list, server_exclude = project.readListEntry('WMSRestrictedLayers', '')
return server_exclude and name in server_wms_excluded_list


def empty_baselayers(project: QgsProject) -> bool:
""" Check if the "baselayers" group is empty or not. """
root_group = project.layerTreeRoot()
groups = root_group.findGroups()
for qgis_group in groups:
qgis_group: QgsLayerTreeGroup
if qgis_group.name() == 'baselayers':
return len(qgis_group.children()) == 0
return False

0 comments on commit 120a27b

Please sign in to comment.