Skip to content

Commit

Permalink
Ensure groups match their original order in QGIS project (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson authored Jun 13, 2024
1 parent cd21c3d commit 7a5c6d7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion felt/core/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ def create_layer_groups(self,
)

group_post_data = [
{'name': g} for g in layer_group_names
{'name': g,
'ordering_key': i} for i, g in enumerate(layer_group_names)
]

return QgsNetworkAccessManager.instance().blockingPost(
Expand Down
14 changes: 13 additions & 1 deletion felt/core/map_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
QgsBlockingNetworkRequest,
QgsReferencedRectangle,
QgsRasterLayer,
QgsLayerTree
QgsLayerTree,
QgsLayerTreeGroup
)
from qgis.utils import iface

Expand Down Expand Up @@ -170,6 +171,12 @@ def __init__(self,
self.error_string: Optional[str] = None
self.feedback: Optional[QgsFeedback] = None
self.was_canceled = False
self.ordered_top_level_groups: List[str] = []
if project:
for child in project.layerTreeRoot().children():
if isinstance(child, QgsLayerTreeGroup):
self.ordered_top_level_groups.append(child.name())
self.ordered_top_level_groups.reverse()

@staticmethod
def layer_and_group(project: QgsProject, layer: QgsMapLayer) \
Expand Down Expand Up @@ -479,6 +486,11 @@ def run(self):
rate_limit_counter = 0

if all_group_names:
# ensure group names match their order in the QGIS project
all_group_names = sorted(
all_group_names,
key=lambda x: self.ordered_top_level_groups.index(x)
)
reply = API_CLIENT.create_layer_groups(
map_id=self.associated_map.id,
layer_group_names=all_group_names
Expand Down

0 comments on commit 7a5c6d7

Please sign in to comment.