diff --git a/src/Model/BoundaryConditionsAdisTS/BoundaryConditionAdisTS.py b/src/Model/BoundaryConditionsAdisTS/BoundaryConditionAdisTS.py index 94641b65c59aa49a1db56a9327e59ba4413759da..8420e28d38b151420e953cc2d0bdd2ad79d83da5 100644 --- a/src/Model/BoundaryConditionsAdisTS/BoundaryConditionAdisTS.py +++ b/src/Model/BoundaryConditionsAdisTS/BoundaryConditionAdisTS.py @@ -249,6 +249,55 @@ class BoundaryConditionAdisTS(SQLSubModel): return (new_0, new_1) + def add(self, index: int): + value = (self._default_0, self._default_1) + self._data.insert(index, value) + self._status.modified() + return value + def insert(self, index: int, value): self._data.insert(index, value) self._status.modified() + + def delete_i(self, indexes): + self._data = list( + map( + lambda e: e[1], + filter( + lambda e: e[0] not in indexes, + enumerate(self.data) + ) + ) + ) + self._status.modified() + + def sort(self, _reverse=False, key=None): + if key is None: + self._data.sort(reverse=_reverse) + else: + self._data.sort(reverse=_reverse, key=key) + self._status.modified() + + def index(self, bc): + self._data.index(bc) + + def get_i(self, index): + return self.data[index] + + def get_range(self, _range): + lst = [] + for r in _range: + lst.append(r) + return lst + + def _set_i_c_v(self, index, column, value): + v = list(self._data[index]) + v[column] = self._types[column](value) + self._data[index] = tuple(v) + self._status.modified() + + def set_i_0(self, index: int, value): + self._set_i_c_v(index, 0, value) + + def set_i_1(self, index: int, value): + self._set_i_c_v(index, 1, value) diff --git a/src/Model/HydraulicStructures/HydraulicStructures.py b/src/Model/HydraulicStructures/HydraulicStructures.py index 5bb77af0f3a3846e636470ce778c6b70efe671cc..04845d486f11ae281ddd239cf7ec400c0c490383 100644 --- a/src/Model/HydraulicStructures/HydraulicStructures.py +++ b/src/Model/HydraulicStructures/HydraulicStructures.py @@ -155,7 +155,6 @@ class HydraulicStructure(SQLSubModel): return new def _db_save(self, execute, data=None): - print("save hs unit") execute(f"DELETE FROM hydraulic_structures WHERE id = {self.id}") input_reach_id = -1 diff --git a/src/Model/Pollutants/Pollutants.py b/src/Model/Pollutants/Pollutants.py index 645417d433966e548429e4787cd6211165fb71b2..9171aae46aac5ef21e128ed0f2fe2b881522227d 100644 --- a/src/Model/Pollutants/Pollutants.py +++ b/src/Model/Pollutants/Pollutants.py @@ -182,7 +182,6 @@ class Pollutants(SQLSubModel): def new_from_data(self, data): - print("from_data before : ", data) try: new = [int(data[0])] new += [float(d) for d in data[1:]] @@ -190,8 +189,6 @@ class Pollutants(SQLSubModel): logger.error(e) new = None - print("from_data after : ", new) - return new def __len__(self): diff --git a/src/View/BoundaryConditionsAdisTS/Edit/Table.py b/src/View/BoundaryConditionsAdisTS/Edit/Table.py index 3bcb594eb27c256eef73b616219a680e927f4db4..ce4c9318b897104aee084c9e7fb6cfdd646ab9a5 100644 --- a/src/View/BoundaryConditionsAdisTS/Edit/Table.py +++ b/src/View/BoundaryConditionsAdisTS/Edit/Table.py @@ -41,7 +41,7 @@ from PyQt5.QtWidgets import ( ) from View.BoundaryConditionsAdisTS.Edit.UndoCommand import ( - AddCommand, DelCommand, SetDataCommand, PasteCommand, + AddCommand, DelCommand, SetDataCommand, PasteCommand, SortCommand, ) _translate = QCoreApplication.translate @@ -119,6 +119,18 @@ class TableModel(PamhyrTableModel): self.endRemoveRows() + def sort(self, _reverse, parent=QModelIndex()): + self.layoutAboutToBeChanged.emit() + + self._undo.push( + SortCommand( + self._data, _reverse + ) + ) + + self.layoutAboutToBeChanged.emit() + self.update() + def paste(self, row, header, data): if len(data) == 0: return diff --git a/src/View/BoundaryConditionsAdisTS/Edit/UndoCommand.py b/src/View/BoundaryConditionsAdisTS/Edit/UndoCommand.py index 84b031877bc7b922aed0bb1eddd1b4f1d551117b..4d15b496c0e2da8672941945fe133b13eee2fb19 100644 --- a/src/View/BoundaryConditionsAdisTS/Edit/UndoCommand.py +++ b/src/View/BoundaryConditionsAdisTS/Edit/UndoCommand.py @@ -38,29 +38,14 @@ class SetDataCommand(QUndoCommand): self._data = data self._index = index self._column = column - self._old = self._data._data[self._index][self._column] - _type = self._data._types[self._column] - self._new = _type(new_value) + self._old = self._data.get_i(self._index)[self._column] + self._new = new_value def undo(self): - if self._column == 0: - self._data._data[self._index] = ( - self._old, self._data._data[self._index][1] - ) - else: - self._data._data[self._index] = ( - self._data._data[self._index][0], self._old - ) + self._data._set_i_c_v(self._index, self._column, self._old) def redo(self): - if self._column == 0: - self._data._data[self._index] = ( - self._new, self._data._data[self._index][1] - ) - else: - self._data._data[self._index] = ( - self._data._data[self._index][0], self._new - ) + self._data._set_i_c_v(self._index, self._column, self._new) class AddCommand(QUndoCommand): @@ -76,11 +61,11 @@ class AddCommand(QUndoCommand): def redo(self): if self._new is None: - self._new = self._data._data.insert(self._index, ( + self._new = self._data.insert(self._index, ( self._data._types[0](0), self._data._types[1](0.0) )) else: - self._data._data.insert(self._index, self._new) + self._data.insert(self._index, self._new) class DelCommand(QUndoCommand): @@ -97,11 +82,10 @@ class DelCommand(QUndoCommand): def undo(self): for row, el in self._bc: - self._data._data.insert(row, el) + self._data.insert(row, el) def redo(self): - for row in self._rows: - del self._data._data[row] + self._data.delete_i(self._rows) class PasteCommand(QUndoCommand): @@ -121,3 +105,34 @@ class PasteCommand(QUndoCommand): def redo(self): for bc in self._bcs: self._data.insert(self._row, bc) + + +class SortCommand(QUndoCommand): + def __init__(self, data, _reverse): + QUndoCommand.__init__(self) + + self._data = data + self._reverse = _reverse + + self._old = self._data.data + self._indexes = None + + def undo(self): + ll = self._data.data + self._data.sort( + key=lambda x: self._indexes[ll.index(x)] + ) + + def redo(self): + self._data.sort( + _reverse=self._reverse, + key=lambda x: x[0] + ) + if self._indexes is None: + self._indexes = list( + map( + lambda p: self._old.index(p), + self._data.data + ) + ) + self._old = None diff --git a/src/View/BoundaryConditionsAdisTS/Edit/Window.py b/src/View/BoundaryConditionsAdisTS/Edit/Window.py index 3b565cd89d10194974bce637a4d627bc2c05d235..dce2b0336869426b78817a4a7bd509ef9af03738 100644 --- a/src/View/BoundaryConditionsAdisTS/Edit/Window.py +++ b/src/View/BoundaryConditionsAdisTS/Edit/Window.py @@ -143,7 +143,7 @@ class EditBoundaryConditionWindow(PamhyrWindow): def setup_connections(self): self.find(QAction, "action_add").triggered.connect(self.add) self.find(QAction, "action_del").triggered.connect(self.delete) - + self.find(QAction, "action_sort").triggered.connect(self.sort) self._table.dataChanged.connect(self.update) def update(self): diff --git a/src/View/BoundaryConditionsAdisTS/Table.py b/src/View/BoundaryConditionsAdisTS/Table.py index 8b1554970dba01f67ec6db90bb8ef6fc4dd425f5..474771b89441e84434b4e5a203654c69da9e14a2 100644 --- a/src/View/BoundaryConditionsAdisTS/Table.py +++ b/src/View/BoundaryConditionsAdisTS/Table.py @@ -119,17 +119,10 @@ class TableModel(PamhyrTableModel): super(TableModel, self).__init__(trad=trad, **kwargs) - def _setup_lst(self): - self._lst = self._bc_list.lst - def rowCount(self, parent): - return len(self._lst) + return len(self._bc_list) def data(self, index, role): - if len(self._lst) != 0: - data = self._lst - else: - data = [] if role != Qt.ItemDataRole.DisplayRole: return QVariant() @@ -138,12 +131,12 @@ class TableModel(PamhyrTableModel): column = index.column() if self._headers[column] == "type": - n = data[row].type + n = self._bc_list.get(row).type if n is None or n == "": return self._trad["not_associated"] return n elif self._headers[column] == "node": - n = data[row].node + n = self._bc_list.get(row).node if n is None: return self._trad["not_associated"] tmp = next(filter(lambda x: x.id == n, self._data._nodes), None) @@ -152,7 +145,7 @@ class TableModel(PamhyrTableModel): else: return self._trad["not_associated"] elif self._headers[column] == "pol": - n = data[row].pollutant + n = self._bc_list.get(row).pollutant if n is None or n == "not_associated" or n == "": return self._trad["not_associated"] tmp = next(filter(lambda x: x.id == n, @@ -177,20 +170,20 @@ class TableModel(PamhyrTableModel): if self._headers[column] == "type": self._undo.push( SetTypeCommand( - self._lst, row, value + self._bc_list, row, value ) ) elif self._headers[column] == "node": self._undo.push( SetNodeCommand( - self._lst, row, self._data.node(value) + self._bc_list, row, self._data.node(value) ) ) elif self._headers[column] == "pol": if value == self._trad["not_associated"]: self._undo.push( SetPolCommand( - self._lst, row, None + self._bc_list, row, None ) ) else: @@ -199,7 +192,7 @@ class TableModel(PamhyrTableModel): ) self._undo.push( SetPolCommand( - self._lst, row, pol.id + self._bc_list, row, pol.id ) ) except Exception as e: @@ -214,7 +207,7 @@ class TableModel(PamhyrTableModel): self._undo.push( AddCommand( - self._pollutant, self._bc_list, self._lst, row + self._pollutant, self._bc_list, row ) ) @@ -226,7 +219,7 @@ class TableModel(PamhyrTableModel): self._undo.push( DelCommand( - self._lst, rows + self._bc_list, rows ) ) diff --git a/src/View/BoundaryConditionsAdisTS/UndoCommand.py b/src/View/BoundaryConditionsAdisTS/UndoCommand.py index ee0a9f2608ca9d64278f0fff5629035922e51a26..4320a4f81c4e3300664912db18b37242a7ffa78d 100644 --- a/src/View/BoundaryConditionsAdisTS/UndoCommand.py +++ b/src/View/BoundaryConditionsAdisTS/UndoCommand.py @@ -35,14 +35,14 @@ class SetNodeCommand(QUndoCommand): self._bcs = bcs self._index = index - self._old = self._bcs[self._index].node + self._old = self._bcs.get(self._index).node self._new = node.id def undo(self): - self._bcs[self._index].node = self._old + self._bcs.get(self._index).node = self._old def redo(self): - self._bcs[self._index].node = self._new + self._bcs.get(self._index).node = self._new class SetTypeCommand(QUndoCommand): @@ -52,14 +52,14 @@ class SetTypeCommand(QUndoCommand): self._bcs = bcs self._index = index self._type = _type - self._old = self._bcs[self._index].type + self._old = self._bcs.get(self._index).type self._new = self._type def undo(self): - self._bcs[self._index].type = self._old + self._bcs.get(self._index).type = self._old def redo(self): - self._bcs[self._index].type = self._new + self._bcs.get(self._index).type = self._new class SetPolCommand(QUndoCommand): @@ -68,32 +68,31 @@ class SetPolCommand(QUndoCommand): self._bcs = bcs self._index = index - self._old = self._bcs[self._index].pollutant + self._old = self._bcs.get(self._index).pollutant self._new = pollutant def undo(self): - self._bcs[self._index].pollutant = self._old + self._bcs.get(self._index).pollutant = self._old def redo(self): - self._bcs[self._index].pollutant = self._new + self._bcs.get(self._index).pollutant = self._new class AddCommand(QUndoCommand): - def __init__(self, pollutant, bcs_list, bcs, index): + def __init__(self, pollutant, bcs, index): QUndoCommand.__init__(self) self._bcs = bcs - self._bc_list = bcs_list self._pollutant = pollutant self._index = index self._new = None def undo(self): - del self._bcs[self._index] + self._bcs.delete_i([self._index]) def redo(self): if self._new is None: - self._new = self._bc_list.new(self._index, self._pollutant) + self._new = self._bcs.new(self._index, self._pollutant) else: self._bcs.insert(self._index, self._new) @@ -107,7 +106,7 @@ class DelCommand(QUndoCommand): self._bc = [] for row in rows: - self._bc.append((row, self._bcs[row])) + self._bc.append((row, self._bcs.get(row))) self._bc.sort() def undo(self): @@ -115,5 +114,4 @@ class DelCommand(QUndoCommand): self._bcs.insert(row, el) def redo(self): - for row in self._rows: - del self._bcs[row] + self._bcs.delete_i(self._rows) diff --git a/src/View/BoundaryConditionsAdisTS/Window.py b/src/View/BoundaryConditionsAdisTS/Window.py index 1a537856e694ad2bc1d341d1ccf167f14c47b8fe..0d5219db7efedeee08b77d2c5bdaa2f4d4203038 100644 --- a/src/View/BoundaryConditionsAdisTS/Window.py +++ b/src/View/BoundaryConditionsAdisTS/Window.py @@ -180,7 +180,7 @@ class BoundaryConditionAdisTSWindow(PamhyrWindow): def edit(self): rows = self.index_selected_rows() for row in rows: - data = self._bcs.lst[row] + data = self._bcs.get(row) if data.node is None: continue diff --git a/src/View/D90AdisTS/Table.py b/src/View/D90AdisTS/Table.py index 20fa32813a48ced9f96fd8a9939127f264e64220..0fe4d3513a4ed35d00ae8d7555b46bcc56ee5daa 100644 --- a/src/View/D90AdisTS/Table.py +++ b/src/View/D90AdisTS/Table.py @@ -175,7 +175,6 @@ class D90TableModel(PamhyrTableModel): ) ) elif self._headers[column] == "reach": - print(self._river.edge(value).id) self._undo.push( SetCommandSpec( self._lst, row, self._headers[column], diff --git a/src/View/D90AdisTS/Window.py b/src/View/D90AdisTS/Window.py index 822ef4520893fca94e90658eb03966d1b0831111..82a703a8e4b15f881518fc87f9ec1f1ef54f87c2 100644 --- a/src/View/D90AdisTS/Window.py +++ b/src/View/D90AdisTS/Window.py @@ -279,9 +279,7 @@ class D90AdisTSWindow(PamhyrWindow): self._table_spec.add(rows[0]) def delete(self): - print("del") rows = self.index_selected_rows() if len(rows) == 0: - print("len 0") return self._table_spec.delete(rows) diff --git a/src/View/InitialConditions/Window.py b/src/View/InitialConditions/Window.py index 3cab24feb65237c57fc5f35b0455c7921451454f..e671a547fb8fab3ad6b57e9e07a743a8ba97d458 100644 --- a/src/View/InitialConditions/Window.py +++ b/src/View/InitialConditions/Window.py @@ -276,7 +276,6 @@ class InitialConditionsWindow(PamhyrWindow): if filename != "": size = os.stat(filename).st_size # self._table.import_geometry(0, filename) - print(f"filename: {filename}") self._import_from_file(filename) def _import_from_file(self, file_name): diff --git a/src/View/InitialConditionsAdisTS/Table.py b/src/View/InitialConditionsAdisTS/Table.py index 3ea581988c4c1347a6cbd159b8ddfe9b5ba3408c..8201cbf5cf09c9cfd2156e845a484465d2a2fe0b 100644 --- a/src/View/InitialConditionsAdisTS/Table.py +++ b/src/View/InitialConditionsAdisTS/Table.py @@ -194,7 +194,6 @@ class InitialConditionTableModel(PamhyrTableModel): ) ) elif self._headers[column] == "reach": - print(self._river.edge(value).id) self._undo.push( SetCommandSpec( self._lst, row, self._headers[column], diff --git a/src/View/InitialConditionsAdisTS/Window.py b/src/View/InitialConditionsAdisTS/Window.py index a57807e654c176e757f6ba808297f609991c8c47..95755688ced8c141e1d801d7f3cc3b89168b8ea0 100644 --- a/src/View/InitialConditionsAdisTS/Window.py +++ b/src/View/InitialConditionsAdisTS/Window.py @@ -281,9 +281,7 @@ class InitialConditionsAdisTSWindow(PamhyrWindow): self._table_spec.add(rows[0]) def delete(self): - print("del") rows = self.index_selected_rows() if len(rows) == 0: - print("len 0") return self._table_spec.delete(rows) diff --git a/src/View/MainWindow.py b/src/View/MainWindow.py index f5b015fa84ffc81d09605181f6471f355f972007..8da1f0c8d2aa93b5241d58fb43203b30cad6d6ad 100644 --- a/src/View/MainWindow.py +++ b/src/View/MainWindow.py @@ -1319,7 +1319,6 @@ class ApplicationWindow(QMainWindow, ListedSubWindow, WindowToolKit): # self.conf.solvers)) # solver = next(filter(lambda x: x.name == "AdisTS-WC", # self.conf.solvers)) - # print(solver._type) # self.run_solver(solver) run = SelectSolverWindowAdisTS( diff --git a/src/View/ui/EditBoundaryConditions.ui b/src/View/ui/EditBoundaryConditions.ui index f24120f416f464e18bc4200d55e6a877a69aaff5..056c02a831d6aa7450114c2955738161a2fad04d 100644 --- a/src/View/ui/EditBoundaryConditions.ui +++ b/src/View/ui/EditBoundaryConditions.ui @@ -113,7 +113,7 @@ <action name="action_sort"> <property name="icon"> <iconset> - <normaloff>ressources/sort_A-Z.png</normaloff>ressources/sort_A-Z.png</iconset> + <normaloff>ressources/sort_1-9.png</normaloff>ressources/sort_1-9.png</iconset> </property> <property name="text"> <string>Sort</string> diff --git a/src/View/ui/EditBoundaryConditionsAdisTS.ui b/src/View/ui/EditBoundaryConditionsAdisTS.ui index bd55a027cd27a91d93e5e69a8c14396a889e9c92..bec71444f0848b7bfe1243c5ea4bf046b3ff237b 100644 --- a/src/View/ui/EditBoundaryConditionsAdisTS.ui +++ b/src/View/ui/EditBoundaryConditionsAdisTS.ui @@ -72,6 +72,7 @@ </attribute> <addaction name="action_add"/> <addaction name="action_del"/> + <addaction name="action_sort"/> </widget> <action name="action_add"> <property name="checkable"> @@ -106,6 +107,18 @@ <string>Ctrl+D</string> </property> </action> + <action name="action_sort"> + <property name="icon"> + <iconset> + <normaloff>ressources/sort_1-9.png</normaloff>ressources/sort_1-9.png</iconset> + </property> + <property name="text"> + <string>Sort</string> + </property> + <property name="toolTip"> + <string>Sort points</string> + </property> + </action> </widget> <resources/> <connections/>