aboutsummaryrefslogtreecommitdiff
path: root/src/gui/tasks/table
diff options
context:
space:
mode:
authorJoris2020-05-31 17:39:28 +0200
committerJoris2020-05-31 17:39:28 +0200
commit1bed85a9b107d1b03e71b848829cb7b1f33060f4 (patch)
tree7e9bc7dd0813b9426e293dde7913717746a479f8 /src/gui/tasks/table
parenta585e507cbe2c05cc846013cafe433953e514295 (diff)
Prevent removing a tag being used
Diffstat (limited to 'src/gui/tasks/table')
-rw-r--r--src/gui/tasks/table/widget.py25
1 files changed, 15 insertions, 10 deletions
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)):