mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
View: Tools: Add tree model.
This commit is contained in:
1 parent
ff3b5a320c
commit
288713ce5b
3 files changed
+127
-1
No files matched your search
@@ -185,6 +185,13 @@ class SQLSubModel(PamhyrID):
|
|||||||
else:
|
else:
|
||||||
self._owner_scenario = owner_scenario
|
self._owner_scenario = owner_scenario
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
t = type(self)
|
||||||
|
return (
|
||||||
|
f"'{t.__module__}.{t.__name__}" +
|
||||||
|
f"@{self._pamhyr_id}.{self._owner_scenario}'"
|
||||||
|
)
|
||||||
|
|
||||||
def must_be_saved(self):
|
def must_be_saved(self):
|
||||||
"""Return True if this object MUST be save in the save file.
|
"""Return True if this object MUST be save in the save file.
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ from tools import trace, timer, logger_exception
|
|||||||
|
|
||||||
from View.Tools.PamhyrWindow import PamhyrWindow, PamhyrDialog
|
from View.Tools.PamhyrWindow import PamhyrWindow, PamhyrDialog
|
||||||
from View.Tools.PamhyrWidget import PamhyrWidget
|
from View.Tools.PamhyrWidget import PamhyrWidget
|
||||||
|
from View.Tools.PamhyrTree import (
|
||||||
|
PamhyrModelRoot, PamhyrModelItem, PamhyrModelListItem,
|
||||||
|
)
|
||||||
|
|
||||||
from PyQt5.QtGui import (
|
from PyQt5.QtGui import (
|
||||||
QKeySequence,
|
QKeySequence,
|
||||||
@@ -39,12 +42,26 @@ from PyQt5.QtWidgets import (
|
|||||||
QFileDialog, QTableView, QAbstractItemView,
|
QFileDialog, QTableView, QAbstractItemView,
|
||||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||||
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
|
QComboBox, QVBoxLayout, QHeaderView, QTabWidget,
|
||||||
QGroupBox,
|
QGroupBox, QTreeWidget,
|
||||||
)
|
)
|
||||||
|
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
|
class StricklersModelItem(PamhyrModelItem):
|
||||||
|
def __init__(self, data=None, trad=None, parent=None):
|
||||||
|
super(StricklersModelItem, self).__init__(
|
||||||
|
data=data, trad=trad, parent=parent,
|
||||||
|
)
|
||||||
|
|
||||||
|
def _get_name(self):
|
||||||
|
return str(self._data)
|
||||||
|
|
||||||
|
def _setup_children(self):
|
||||||
|
self.addChild(PamhyrModelItem(data="Minor", parent=self))
|
||||||
|
self.addChild(PamhyrModelItem(data="Medium", parent=self))
|
||||||
|
|
||||||
|
|
||||||
class EnsembleEditDialog(PamhyrDialog):
|
class EnsembleEditDialog(PamhyrDialog):
|
||||||
_pamhyr_ui = "EnsembleEditDialog"
|
_pamhyr_ui = "EnsembleEditDialog"
|
||||||
_pamhyr_name = "Parameters"
|
_pamhyr_name = "Parameters"
|
||||||
@@ -61,7 +78,21 @@ class EnsembleEditDialog(PamhyrDialog):
|
|||||||
self._study = study
|
self._study = study
|
||||||
self._ensemble = ensemble
|
self._ensemble = ensemble
|
||||||
|
|
||||||
|
self._init_tree()
|
||||||
self._init_default_values()
|
self._init_default_values()
|
||||||
|
self._init_connection()
|
||||||
|
|
||||||
|
def _init_tree(self):
|
||||||
|
tree = self.find(QTreeWidget, "treeWidget_target_data")
|
||||||
|
tree.setColumnCount(1)
|
||||||
|
tree.setHeaderLabels(["Name"])
|
||||||
|
|
||||||
|
stricklers = PamhyrModelListItem(
|
||||||
|
name="Stricklers",
|
||||||
|
lst=self._study.river.stricklers,
|
||||||
|
child_item_ctor=StricklersModelItem,
|
||||||
|
parent=tree
|
||||||
|
)
|
||||||
|
|
||||||
def _init_default_values(self):
|
def _init_default_values(self):
|
||||||
self.set_line_edit_text("lineEdit_name", self._ensemble.name)
|
self.set_line_edit_text("lineEdit_name", self._ensemble.name)
|
||||||
@@ -84,6 +115,11 @@ class EnsembleEditDialog(PamhyrDialog):
|
|||||||
|
|
||||||
self._set_widget(self._ensemble.distribution)
|
self._set_widget(self._ensemble.distribution)
|
||||||
|
|
||||||
|
|
||||||
|
def _init_connection(self):
|
||||||
|
self.find(QComboBox, "comboBox_distribution")\
|
||||||
|
.currentTextChanged.connect(self.update_distribution)
|
||||||
|
|
||||||
self.find(QComboBox, "comboBox_distribution")\
|
self.find(QComboBox, "comboBox_distribution")\
|
||||||
.currentTextChanged.connect(self.update_distribution)
|
.currentTextChanged.connect(self.update_distribution)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,83 @@
|
|||||||
|
# PamhyrTree.py -- Pamhyr abstract table model
|
||||||
|
# Copyright (C) 2023-2026 INRAE
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
from tools import trace, timer
|
||||||
|
|
||||||
|
from Model.Except import NotImplementedMethodeError
|
||||||
|
|
||||||
|
from PyQt5.QtCore import (
|
||||||
|
Qt, QVariant, QAbstractItemModel,
|
||||||
|
QCoreApplication, QModelIndex, pyqtSlot,
|
||||||
|
)
|
||||||
|
|
||||||
|
from PyQt5.QtWidgets import (
|
||||||
|
QTreeWidget, QTreeWidgetItem,
|
||||||
|
)
|
||||||
|
|
||||||
|
logger = logging.getLogger()
|
||||||
|
|
||||||
|
|
||||||
|
class PamhyrModelRoot(QTreeWidgetItem):
|
||||||
|
def __init__(self, parent=None):
|
||||||
|
super(PamhyrModelRoot, self).__init__(
|
||||||
|
parent, ["Root"],
|
||||||
|
)
|
||||||
|
|
||||||
|
class PamhyrModelItem(QTreeWidgetItem):
|
||||||
|
def __init__(self, data=None, trad=None, parent=None):
|
||||||
|
self._data = data
|
||||||
|
self._name = self._get_name()
|
||||||
|
|
||||||
|
super(PamhyrModelItem, self).__init__(
|
||||||
|
parent, [self._name],
|
||||||
|
)
|
||||||
|
|
||||||
|
self._setup_children()
|
||||||
|
|
||||||
|
def _get_name(self):
|
||||||
|
return str(self._data)
|
||||||
|
|
||||||
|
def _setup_children(self):
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
class PamhyrModelListItem(QTreeWidgetItem):
|
||||||
|
def __init__(self, name=None, lst=None,
|
||||||
|
child_item_ctor=PamhyrModelItem,
|
||||||
|
trad=None, parent=None):
|
||||||
|
super(PamhyrModelListItem, self).__init__(
|
||||||
|
parent, [name],
|
||||||
|
)
|
||||||
|
|
||||||
|
self._name = name
|
||||||
|
self._lst = lst
|
||||||
|
self._trad = trad
|
||||||
|
self._child_item_ctor = child_item_ctor
|
||||||
|
|
||||||
|
self._setup_children()
|
||||||
|
|
||||||
|
def _setup_children(self):
|
||||||
|
for el in self._lst.lst:
|
||||||
|
self.addChild(
|
||||||
|
self._child_item_ctor(
|
||||||
|
data=el, trad=self._trad, parent=self
|
||||||
|
)
|
||||||
|
)
|
||||||
Reference in new issue
Block a user