diff options
Diffstat (limited to 'src/gui/tasks/table/model.py')
-rw-r--r-- | src/gui/tasks/table/model.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/gui/tasks/table/model.py b/src/gui/tasks/table/model.py index 90bcc4c..6b8133d 100644 --- a/src/gui/tasks/table/model.py +++ b/src/gui/tasks/table/model.py @@ -7,9 +7,9 @@ import math import util.array import util.range -columns = 3 +columns = 4 -headers = ['Age', 'Name', 'Tag'] +headers = ['Age', 'Name', 'Duration', 'Tag'] default_sort = (0, Qt.AscendingOrder) @@ -31,9 +31,11 @@ class TableModel(QtCore.QAbstractTableModel): task = self._tasks[index.row()] if index.column() == 0: return age_since(task.created_at) - if index.column() == 1: + elif index.column() == 1: return task.name - if index.column() == 2: + elif index.column() == 2: + return pp_duration(task.duration) + elif index.column() == 3: return task.tag else: return QtCore.QVariant() @@ -101,12 +103,22 @@ def age_since(timestamp): else: return '1m' +def pp_duration(minutes: int): + if minutes >= 60 * 24: + return '' + str(math.floor(minutes / 60 / 24)) + 'd' + elif minutes >= 60: + return '' + str(math.floor(minutes / 60)) + 'h' + else: + return '' + str(minutes) + 'm' + def sort_key(task: Task, row: int): if row == 0: return task.created_at elif row == 1: return task.name.lower() elif row == 2: + return task.duration + elif row == 3: return task.tag.lower() def is_reversed(row: int, order: Qt.SortOrder) -> bool: |