Commit 7a7e714e authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

BC: Edit: Add table display mode 'time' and 'date'.

Showing with 16 additions and 10 deletions
+16 -10
...@@ -201,6 +201,7 @@ class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow): ...@@ -201,6 +201,7 @@ class BoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
for row in rows: for row in rows:
win = EditBoundaryConditionWindow( win = EditBoundaryConditionWindow(
data=self._bcs.get(tab, row), data=self._bcs.get(tab, row),
study=self._study,
parent=self parent=self
) )
win.show() win.show()
...@@ -109,10 +109,11 @@ class ExTimeDelegate(QItemDelegate): ...@@ -109,10 +109,11 @@ class ExTimeDelegate(QItemDelegate):
class TableModel(QAbstractTableModel): class TableModel(QAbstractTableModel):
def __init__(self, data=None, undo=None): def __init__(self, data=None, mode="time", undo=None):
super(QAbstractTableModel, self).__init__() super(QAbstractTableModel, self).__init__()
self._headers = data.header self._headers = data.header
self._data = data self._data = data
self._mode = mode
self._undo = undo self._undo = undo
def flags(self, index): def flags(self, index):
...@@ -144,12 +145,13 @@ class TableModel(QAbstractTableModel): ...@@ -144,12 +145,13 @@ class TableModel(QAbstractTableModel):
if self._data.get_type_column(column) == float: if self._data.get_type_column(column) == float:
value = f"{v:.4f}" value = f"{v:.4f}"
elif self._data.header[column] == "time": elif self._data.header[column] == "time":
t0 = datetime.fromtimestamp(0) if self._mode == "time":
t = datetime.fromtimestamp(v) t0 = datetime.fromtimestamp(0)
value = str(t - t0) t = datetime.fromtimestamp(v)
#value = v value = str(t - t0)
else:
value = str(datetime.fromtimestamp(v))
else: else:
# TODO: Time format
value = f"{v}" value = f"{v}"
return value return value
......
...@@ -27,12 +27,14 @@ from View.BoundaryCondition.Edit.Plot import Plot ...@@ -27,12 +27,14 @@ from View.BoundaryCondition.Edit.Plot import Plot
_translate = QCoreApplication.translate _translate = QCoreApplication.translate
class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
def __init__(self, title="Edit BoundaryConditions", data=None, parent=None): def __init__(self, title="Edit BoundaryConditions",
data=None, study=None, parent=None):
super(EditBoundaryConditionWindow, self).__init__( super(EditBoundaryConditionWindow, self).__init__(
name=title, ui="EditBoundaryConditions", parent=parent name=title, ui="EditBoundaryConditions", parent=parent
) )
self._data = data self._data = data
self._study = study
self._title = title self._title = title
self.setup_window() self.setup_window()
...@@ -66,14 +68,15 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow): ...@@ -66,14 +68,15 @@ class EditBoundaryConditionWindow(ASubMainWindow, ListedSubWindow):
table = self.find(QTableView, "tableView") table = self.find(QTableView, "tableView")
self._table = TableModel( self._table = TableModel(
data = self._data, data = self._data,
undo = self._undo_stack undo = self._undo_stack,
mode = self._study.time_system
) )
if self._data.header[0] == "time": if self._data.header[0] == "time":
self._delegate_time = ExTimeDelegate( self._delegate_time = ExTimeDelegate(
data = self._data, data = self._data,
mode = "type", mode = self._study.time_system,
parent=self parent = self
) )
table.setItemDelegateForColumn( table.setItemDelegateForColumn(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment