diff options
Diffstat (limited to 'src/gui/tasks/table')
-rw-r--r-- | src/gui/tasks/table/widget.py | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/gui/tasks/table/widget.py b/src/gui/tasks/table/widget.py index fe8ea2e..2f3328b 100644 --- a/src/gui/tasks/table/widget.py +++ b/src/gui/tasks/table/widget.py @@ -24,15 +24,12 @@ import service.tasks import util.array import util.range -header_labels = ["Age", "Name", "Duration", "Difficulty", "Priority", "Tag"] - class Widget(QtWidgets.QTableWidget): def __init__( self, parent, on_show: gui.signal.Reload, add_task_signal: gui.tasks.signal.AddTask): - super().__init__(parent) self.init_state() @@ -41,7 +38,7 @@ class Widget(QtWidgets.QTableWidget): self.setSelectionBehavior(QtWidgets.QTableView.SelectRows) self.init_header() self.setRowCount(len(self._tasks)) - self.setColumnCount(len(header_labels)) + self.setColumnCount(len(self.header_labels())) self.setColumnWidth(1, 500) self.update_view() @@ -52,7 +49,6 @@ class Widget(QtWidgets.QTableWidget): self.customContextMenuRequested.connect(lambda position: gui.tasks.table.menu.open(self, self._update_task_signal, position)) self.doubleClicked.connect(lambda index: self.on_double_click(index.row())) - add_task_signal.connect(lambda task, tags: self.insert(task, tags)) self._update_task_signal.connect(lambda row, task, tags: self.update_task(row, task, tags)) on_show.connect(lambda: self.on_show()) @@ -72,13 +68,13 @@ class Widget(QtWidgets.QTableWidget): def init_header(self): - h = QtWidgets.QHeaderView(Qt.Horizontal, self) + self._header_view = QtWidgets.QHeaderView(Qt.Horizontal, self) self._header_model = QtGui.QStandardItemModel() - self._header_model.setHorizontalHeaderLabels(header_labels) - h.setModel(self._header_model) - h.setSectionsClickable(True) - h.sectionClicked.connect(self.on_header_click) - self.setHorizontalHeader(h) + self._header_model.setHorizontalHeaderLabels(self.header_labels()) + self._header_view.setModel(self._header_model) + self._header_view.setSectionsClickable(True) + self._header_view.sectionClicked.connect(self.on_header_click) + self.setHorizontalHeader(self._header_view) # header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents) def on_header_click(self, column): @@ -88,7 +84,7 @@ class Widget(QtWidgets.QTableWidget): self._sort_is_ascending = True self._sort_column = column self.sort() - # self._header_model.setItem(column, QtGui.QStandardItem("Hey!")) + self._header_model.setHorizontalHeaderLabels(self.header_labels()) self.update_view() def sort(self): @@ -206,6 +202,15 @@ class Widget(QtWidgets.QTableWidget): tags = [tt.tag_id for tt in self._task_tags if tt.task_id == task.id] return (task, tags) + def header_labels(self): + labels = ["Age", "Name", "Duration", "Difficulty", "Priority", "Tag"] + if self._sort_is_ascending: + sign = "▼" + else: + sign = "▲" + labels[self._sort_column] = labels[self._sort_column] + " " + sign + return labels + def item(text: str): item = QtWidgets.QTableWidgetItem(text) item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled) |