diff options
author | Joris | 2020-05-10 15:34:45 +0200 |
---|---|---|
committer | Joris | 2020-05-10 15:34:45 +0200 |
commit | 45414a031909a360a025048592566e14cd71e5be (patch) | |
tree | 564ec179daa618ecb36670b95ebca913e2e21b62 | |
parent | 0863478038df43d5ab3de734263b5b2f4b224984 (diff) |
Sort empty fields as last results
-rw-r--r-- | src/gui/tasks/table/model.py | 24 |
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: |