From 1bed85a9b107d1b03e71b848829cb7b1f33060f4 Mon Sep 17 00:00:00 2001 From: Joris Date: Sun, 31 May 2020 17:39:28 +0200 Subject: Prevent removing a tag being used --- src/gui/tasks/table/widget.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) (limited to 'src/gui/tasks/table') diff --git a/src/gui/tasks/table/widget.py b/src/gui/tasks/table/widget.py index 0a8d216..82c0456 100644 --- a/src/gui/tasks/table/widget.py +++ b/src/gui/tasks/table/widget.py @@ -99,16 +99,21 @@ class Widget(QtWidgets.QTableWidget): reverse = is_rev) def update_task(self, row, task: Task, tags: List[int]): - # TODO: just update if sort order is not impacted - # self._tasks[row] = task - # task_ids = [t.id for t in self._tasks] - # filtred_task_tags = [tt for tt in self._task_tags if tt.task_id in task_ids] - # new_task_tags = [TaskTag(task_id=task.id, tag_id=tag_id) for tag_id in tags] - # self._task_tags = filtred_task_tags + new_task_tags - # self.update_row(row) - self.delete_rows([row]) - row = self.insert(task, tags) - self.selectRow(row) + self._tasks[row] = task + filtred_task_tags = [tt for tt in self._task_tags if tt.task_id in [t.id for t in self._tasks if t.id != task.id]] + new_task_tags = [TaskTag(task_id=task.id, tag_id=tag_id) for tag_id in tags] + self._task_tags = filtred_task_tags + new_task_tags + + # Update task in table + self.sort() + row_after_sort = [i for i in range(len(self._tasks)) if self._tasks[i].id == task.id][0] + if row_after_sort == row: + self.update_row(row) + else: + self.removeRow(row) + self.insertRow(row_after_sort) + self.update_row(row_after_sort) + self.selectRow(row_after_sort) def update_view(self): for row in range(len(self._tasks)): -- cgit v1.2.3