Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing Layer groups removed when no layers left in them #97

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions libqfieldsync/offline_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
QgsRasterLayer,
QgsValueRelationFieldFormatter,
QgsVectorLayer,
QgsLayerTreeGroup,
)
from qgis.PyQt.QtCore import QCoreApplication, QObject, pyqtSignal

Expand Down Expand Up @@ -279,6 +280,8 @@ def _convert(self, project: QgsProject) -> None:
elif layer_action == SyncAction.REMOVE:
project.removeMapLayer(layer)

self.remove_empty_groups_from_layer_tree_group(project.layerTreeRoot())

export_project_filename = self._export_filename

# save the original project path
Expand Down Expand Up @@ -346,6 +349,22 @@ def _convert(self, project: QgsProject) -> None:
QgsProject.instance().write(str(export_project_filename))
project.writeProject.disconnect(on_original_project_write)

def remove_empty_groups_from_layer_tree_group(
self, group: QgsLayerTreeGroup
) -> None:
"""
Recursively removes any empty groups from the given layer tree group.
"""
for child in group.children():
if not isinstance(child, QgsLayerTreeGroup):
continue

# remove recursively
self.remove_empty_groups_from_layer_tree_group(child)

if not child.children():
group.removeChildNode(child)

def post_process_offline_layers(self):
project = QgsProject.instance()
project.setEvaluateDefaultValues(False)
Expand Down
Loading