-
Pierre-Antoine Rouby authored8d3bfa4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# -*- coding: utf-8 -*-
from View.ASubWindow import ASubMainWindow
from View.ListedSubWindow import ListedSubWindow
from PyQt5.QtCore import (
Qt, QVariant, QAbstractTableModel,
QCoreApplication,
)
from PyQt5.QtWidgets import (
QDialogButtonBox, QPushButton, QLineEdit,
QFileDialog, QTableView, QAbstractItemView,
)
from View.BoundaryCondition.EditBoundaryConditionWindow import EditBoundaryConditionWindow
_translate = QCoreApplication.translate
long_types = {
"PC": _translate("BoundaryCondition", "Ponctual contribution"),
"TZ": _translate("BoundaryCondition", "Time over Z"),
"TD": _translate("BoundaryCondition", "Time over Debit"),
"ZD": _translate("BoundaryCondition", "Z over Debit"),
}
table_headers = {
"name": _translate("BoundaryCondition", "Name"),
"type": _translate("BoundaryCondition", "Type"),
"node": _translate("BoundaryCondition", "Node")
}
class TableModel(QAbstractTableModel):
def __init__(self, data=None):
super(QAbstractTableModel, self).__init__()
self._headers = list(table_headers.keys())
self._data = data
self._lst = self._data.boundary_condition
def flags(self, index):
options = Qt.ItemIsEnabled | Qt.ItemIsSelectable
options |= Qt.ItemIsEditable
return options
def rowCount(self, parent):
return len(self._lst)
def columnCount(self, parent):
return len(self._headers)
def data(self, index, role):
if role != Qt.ItemDataRole.DisplayRole:
return QVariant()
row = index.row()
column = index.column()
if self._headers[column] == "name":
return self.lst[row].name
elif self._headers[column] == "type":
t = self.lst[row].bctype
return long_types[t]
elif self._headers[column] == "node":
n = self.lst[row].node
if n is None:
return "-"
return n.name
return QVariant()
def headerData(self, section, orientation, role):
if role == Qt.ItemDataRole.DisplayRole and orientation == Qt.Orientation.Horizontal:
return table_headers[self._headers[section]]
return QVariant()
def setData(self, index, value, role=Qt.EditRole):
if not index.isValid() or role != Qt.EditRole:
return False
row = index.row()
column = index.column()
if self._headers[column] == "name":
self.lst[row].name = value
elif self._headers[column] == "type":
self.lst[row].bctype = value
elif self._headers[column] == "node":
self.lst[row].node = value
self.dataChanged.emit(index, index)
return True
class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
def __init__(self, title="BoundaryConditions", study=None, parent=None):
super(BoundaryConditionWindow, self).__init__(
name=title, ui="BoundaryConditions", parent=parent
)
self._study = study
table = self.find(QTableView, "tableView")
self._table = TableModel(
data = self._study.river
)
table.setModel(self._table)
self.ui.setWindowTitle(title)
def edit(self):
win = EditBoundaryConditionWindow(data=None, parent=self)
win.show()