mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
work on hydraulic structures window
This commit is contained in:
1 parent
c17e39e3cf
commit
d73e901a96
14 files changed
+688
-4
No files matched your search
@@ -0,0 +1,208 @@
|
||||
# Window.py -- Pamhyr
|
||||
# Copyright (C) 2023 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
|
||||
|
||||
from tools import timer, trace
|
||||
|
||||
from View.Tools.PamhyrWindow import PamhyrWindow
|
||||
|
||||
from PyQt5 import QtCore
|
||||
from PyQt5.QtCore import (
|
||||
Qt, QVariant, QAbstractTableModel, QCoreApplication,
|
||||
pyqtSlot, pyqtSignal, QItemSelectionModel,
|
||||
)
|
||||
|
||||
from PyQt5.QtWidgets import (
|
||||
QDialogButtonBox, QPushButton, QLineEdit,
|
||||
QFileDialog, QTableView, QAbstractItemView,
|
||||
QUndoStack, QShortcut, QAction, QItemDelegate,
|
||||
QHeaderView, QDoubleSpinBox, QVBoxLayout, QCheckBox
|
||||
)
|
||||
|
||||
from View.HydraulicStructures.Table import (
|
||||
TableModel, ComboBoxDelegate
|
||||
)
|
||||
|
||||
from View.Network.GraphWidget import GraphWidget
|
||||
from View.HydraulicStructures.Translate import HydraulicStructuresTranslate
|
||||
|
||||
_translate = QCoreApplication.translate
|
||||
|
||||
logger = logging.getLogger()
|
||||
|
||||
|
||||
class HydraulicStructuresWindow(PamhyrWindow):
|
||||
_pamhyr_ui = "HydraulicStructures"
|
||||
_pamhyr_name = "Hydraulic Structures"
|
||||
|
||||
def __init__(self, study=None, config=None, parent=None):
|
||||
name = self._pamhyr_name + " - " + study.name
|
||||
|
||||
super(HydraulicStructuresWindow, self).__init__(
|
||||
title=name,
|
||||
study=study,
|
||||
config=config,
|
||||
trad=HydraulicStructuresTranslate(),
|
||||
parent=parent
|
||||
)
|
||||
|
||||
self._hs_lst = self._study.river._hydraulic_structures
|
||||
|
||||
self.setup_table()
|
||||
self.setup_checkbox()
|
||||
self.setup_plots()
|
||||
self.setup_connections()
|
||||
|
||||
def setup_table(self):
|
||||
self._table = None
|
||||
|
||||
self._delegate_reach = ComboBoxDelegate(
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
parent=self,
|
||||
mode = "reaches"
|
||||
)
|
||||
self._delegate_kp = ComboBoxDelegate(
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
parent=self,
|
||||
mode = "kp"
|
||||
)
|
||||
|
||||
table = self.find(QTableView, f"tableView")
|
||||
self._table = TableModel(
|
||||
table_view=table,
|
||||
table_headers=self._trad.get_dict("table_headers"),
|
||||
editable_headers=["name", "reach", "kp"],
|
||||
delegates={
|
||||
"reach": self._delegate_reach,
|
||||
"kp": self._delegate_kp,
|
||||
},
|
||||
trad=self._trad,
|
||||
data=self._study.river,
|
||||
undo=self._undo_stack,
|
||||
)
|
||||
|
||||
selectionModel = table.selectionModel()
|
||||
index = table.model().index(0, 0)
|
||||
|
||||
selectionModel.select(
|
||||
index,
|
||||
QItemSelectionModel.Rows |
|
||||
QItemSelectionModel.ClearAndSelect |
|
||||
QItemSelectionModel.Select
|
||||
)
|
||||
table.scrollTo(index)
|
||||
|
||||
def setup_checkbox(self):
|
||||
self._checkbox = self.find(QCheckBox, f"checkBox")
|
||||
self._set_checkbox_state
|
||||
|
||||
def setup_plots(self):
|
||||
return
|
||||
|
||||
def setup_connections(self):
|
||||
self.find(QAction, "action_add").triggered.connect(self.add)
|
||||
self.find(QAction, "action_delete").triggered.connect(self.delete)
|
||||
self.find(QAction, "action_edit").triggered.connect(self.edit)
|
||||
self._checkbox.stateChanged.connect(self._set_structure_state)
|
||||
|
||||
table = self.find(QTableView, "tableView")
|
||||
table.selectionModel()\
|
||||
.selectionChanged\
|
||||
.connect(self._set_checkbox_state)
|
||||
|
||||
def index_selected_row(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
r = table.selectionModel()\
|
||||
.selectedRows()
|
||||
if len(r)>0:
|
||||
return r[0].row()
|
||||
else:
|
||||
return None
|
||||
|
||||
def index_selected_rows(self):
|
||||
table = self.find(QTableView, "tableView")
|
||||
return list(
|
||||
# Delete duplicate
|
||||
set(
|
||||
map(
|
||||
lambda i: i.row(),
|
||||
table.selectedIndexes()
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def add(self):
|
||||
rows = self.index_selected_rows()
|
||||
if len(self._hs_lst) == 0 or len(rows) == 0:
|
||||
self._table.add(0)
|
||||
else:
|
||||
self._table.add(rows[0])
|
||||
|
||||
def delete(self):
|
||||
rows = self.index_selected_rows()
|
||||
if len(rows) == 0:
|
||||
return
|
||||
|
||||
self._table.delete(rows)
|
||||
|
||||
def _copy(self):
|
||||
logger.info("TODO: copy")
|
||||
|
||||
def _paste(self):
|
||||
logger.info("TODO: paste")
|
||||
|
||||
def _undo(self):
|
||||
self._table.undo()
|
||||
|
||||
def _redo(self):
|
||||
self._table.redo()
|
||||
|
||||
def edit(self):
|
||||
rows = self.index_selected_rows()
|
||||
for row in rows:
|
||||
data = self._hs_lst.get(row)
|
||||
|
||||
if self.sub_window_exists(
|
||||
BasicHydraulicStructuresWindow,
|
||||
data=[self._study, None, data]
|
||||
):
|
||||
continue
|
||||
|
||||
win = BasicHydraulicStructuresWindow(
|
||||
data=data,
|
||||
study=self._study,
|
||||
parent=self
|
||||
)
|
||||
win.show()
|
||||
|
||||
def _set_checkbox_state(self):
|
||||
row = self.index_selected_row()
|
||||
if row is None:
|
||||
self._checkbox.setEnabled(False)
|
||||
self._checkbox.setChecked(True)
|
||||
else:
|
||||
self._checkbox.setEnabled(True)
|
||||
self._checkbox.setChecked(self._hs_lst.get(row).enabled)
|
||||
|
||||
def _set_structure_state(self):
|
||||
row = self.index_selected_row()
|
||||
#self._checkbox.setChecked(self._hs_lst.get(row).enabled)
|
||||
self._hs_lst.get(row).enabled = self._checkbox.isChecked()
|
||||
Reference in new issue
Block a user