aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/tasks/table/model.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/gui/tasks/table/model.py b/src/gui/tasks/table/model.py
index 8374d03..bf9e386 100644
--- a/src/gui/tasks/table/model.py
+++ b/src/gui/tasks/table/model.py
@@ -79,10 +79,11 @@ class TableModel(QtCore.QAbstractTableModel):
def insert_position(self, header: QtWidgets.QHeaderView, task: Task) -> int:
row = header.sortIndicatorSection()
order = header.sortIndicatorOrder()
+ is_rev = is_reversed(row, order)
return util.array.insert_position(
- sort_key(task, row),
- [sort_key(t, row) for t in self._tasks],
- is_reversed(row, order))
+ sort_key(task, row, is_rev),
+ [sort_key(t, row, is_rev) for t in self._tasks],
+ is_rev)
def update_task(self, header: QtWidgets.QHeaderView, row, task: Task) -> int:
self.delete_task_range(row, 1)
@@ -104,10 +105,11 @@ class TableModel(QtCore.QAbstractTableModel):
def sort(self, row: int, order: Qt.SortOrder):
self.layoutAboutToBeChanged.emit()
+ is_rev = is_reversed(row, order)
self._tasks = sorted(
self._tasks,
- key = lambda task: sort_key(task, row),
- reverse = is_reversed(row, order))
+ key = lambda task: sort_key(task, row, is_rev),
+ reverse = is_rev)
self.layoutChanged.emit()
def age_since(timestamp):
@@ -121,19 +123,25 @@ def age_since(timestamp):
else:
return '1m'
-def sort_key(task: Task, row: int):
+def sort_key(task: Task, row: int, is_reversed: bool):
if row == 0:
return task.created_at
elif row == 1:
return task.name.lower()
elif row == 2:
- return task.duration
+ if is_reversed:
+ return task.duration
+ else:
+ return (task.duration == 0, task.duration)
elif row == 3:
return task.difficulty
elif row == 4:
return task.priority
elif row == 5:
- return task.tag.lower()
+ if is_reversed:
+ return task.tag.lower()
+ else:
+ return (task.tag == '', task.tag.lower())
def is_reversed(row: int, order: Qt.SortOrder) -> bool:
if row == 0: