Skip to content

Commit

Permalink
Always create new subgroup for a new output name
Browse files Browse the repository at this point in the history
  • Loading branch information
Huite committed Oct 30, 2023
1 parent f904411 commit a2aac91
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 43 deletions.
3 changes: 2 additions & 1 deletion plugin/qgistim/widgets/compute_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ def finished(self, result):
self.parent.set_interpreter_interaction(True)
if result:
self.push_success_message()
self.parent.clear_outdated_output(self.data["path"])
path = self.data["path"]
output = self.data["output_options"]
name = f"{Path(path).stem}"
self.parent.parent.create_output_group(name=f"{name} output")
if output.head_observations or output.discharge:
self.parent.load_vector_result(path)
if output.mesh:
Expand Down
16 changes: 7 additions & 9 deletions plugin/qgistim/widgets/dataset_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,17 +372,16 @@ def add_selection_to_qgis(self) -> None:
self.add_item_to_qgis(item)
return

def load_geopackage(
self, input_group: str = None, output_group: str = None
) -> None:
def load_geopackage(self, input_group: str = None) -> None:
"""
Load the layers of a GeoPackage into the Layers Panel
"""
self.dataset_tree.clear()

name = str(Path(self.path).stem)
self.parent.create_input_group(name, input_group)
self.parent.create_output_group(name, output_group)
if input_group is None:
name = str(Path(self.path).stem)
input_group = f"{name} input"
self.parent.create_input_group(input_group)

elements = load_elements_from_geopackage(self.path)
for element in elements:
Expand Down Expand Up @@ -469,7 +468,7 @@ def restore_geopackage(self) -> None:
if not success:
self.parent.message_bar.pushMessage(
title="Error",
text="Could not find a QGIS-Tim GeoPackage in this QGS Project.",
text="Could not find a QGIS-Tim GeoPackage in this QGIS Project.",
level=Qgis.Critical,
)
return
Expand All @@ -482,9 +481,8 @@ def restore_geopackage(self) -> None:
)

input_group_name, _ = qgs_project.readEntry("qgistim", "input_group")
output_group_name, _ = qgs_project.readEntry("qgistim", "output_group")
self.dataset_line_edit.setText(geopackage_path)
self.load_geopackage(input_group_name, output_group_name)
self.load_geopackage(input_group_name)
return

def remove_geopackage_layer(self) -> None:
Expand Down
57 changes: 24 additions & 33 deletions plugin/qgistim/widgets/tim_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
connection to the QGIS Layers Panel, and ensures there is a group for the Tim
layers there.
"""
from typing import Any, Dict, Optional, Union
from typing import Any, Dict, Union

from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import (
Expand All @@ -15,13 +15,7 @@
QVBoxLayout,
QWidget,
)
from qgis.core import (
QgsApplication,
QgsEditFormConfig,
QgsLayerTreeGroup,
QgsMapLayer,
QgsProject,
)
from qgis.core import QgsApplication, QgsEditFormConfig, QgsMapLayer, QgsProject
from qgistim.core.server_handler import ServerHandler
from qgistim.core.task import BaseServerTask
from qgistim.widgets.compute_widget import ComputeWidget
Expand All @@ -38,19 +32,17 @@ def __init__(
self,
root,
name: str,
group_name: Optional[QgsLayerTreeGroup] = None,
):
self.name = name
self.root = root
self.subgroups = {}
self.create_group(group_name)

def _create_group(self, group_name: str):
if group_name is not None:
self.group = self.root.findGroup(group_name)
if self.group is not None:
self.group.removeAllChildren()
return
self.create_group()

def _create_group(self):
self.group = self.root.findGroup(self.name)
if self.group is not None:
self.group.removeAllChildren()
return
self.group = self.root.addGroup(self.name)
return

Expand Down Expand Up @@ -160,15 +152,21 @@ def add_layer(


class InputGroup(LayersPanelGroup):
def create_group(self, group=None):
def create_group(self) -> None:
QgsProject.instance().writeEntry("qgistim", "input_group", self.name)
self._create_group(group)
self._create_group()
self.create_subgroup("timml")
self.create_subgroup("ttim")
return


class OutputGroup(LayersPanelGroup):
def create_group(self, group=None):
QgsProject.instance().writeEntry("qgistim", "output_group", self.name)
self._create_group(group)
def create_group(self) -> None:
self._create_group()
self.create_subgroup("vector")
self.create_subgroup("mesh")
self.create_subgroup("raster")
return


class StartTask(BaseServerTask):
Expand Down Expand Up @@ -322,19 +320,12 @@ def add_element(self, element: Any):

# QGIS layers
# -----------
def create_input_group(self, name: str, group: str = None) -> None:
def create_input_group(self, name: str) -> None:
root = self.qgs_project.layerTreeRoot()
self.input_group = InputGroup(root, f"{name} input", group)
self.input_group.create_subgroup("timml")
self.input_group.create_subgroup("ttim")
self.input_group = InputGroup(root, name)
return

def create_output_group(self, name: str, group: str = None) -> None:
def create_output_group(self, name: str) -> None:
root = self.qgs_project.layerTreeRoot()
self.output_group = OutputGroup(root, f"{name} output", group)
# Pre-create the groups here to make sure the vector group ends up on top.
# Apparently moving it destroys the group?
self.output_group.create_subgroup("vector")
self.output_group.create_subgroup("mesh")
self.output_group.create_subgroup("raster")
self.output_group = OutputGroup(root, name)
return

0 comments on commit a2aac91

Please sign in to comment.