aboutsummaryrefslogtreecommitdiff
path: root/src/gui/tasks/table
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/tasks/table')
-rw-r--r--src/gui/tasks/table/menu.py3
-rw-r--r--src/gui/tasks/table/widget.py30
2 files changed, 21 insertions, 12 deletions
diff --git a/src/gui/tasks/table/menu.py b/src/gui/tasks/table/menu.py
index db89551..0ad9857 100644
--- a/src/gui/tasks/table/menu.py
+++ b/src/gui/tasks/table/menu.py
@@ -3,10 +3,11 @@ from typing import List
import db.tasks
import gui.tasks.dialog
+from model.status import Status
from model.task import Task, ValidTaskForm
from model.tag import Tag
-def open(table, update_task_signal, position):
+def open(table: QtWidgets.QTableWidget, status: Status, update_task_signal, position):
rows = set([index.row() for index in table.selectedIndexes()])
menu = QtWidgets.QMenu(table)
diff --git a/src/gui/tasks/table/widget.py b/src/gui/tasks/table/widget.py
index 2f3328b..14806fa 100644
--- a/src/gui/tasks/table/widget.py
+++ b/src/gui/tasks/table/widget.py
@@ -10,6 +10,7 @@ from model.priority import Priority
from model.tag import Tag
from model.task import Task
from model.task_tag import TaskTag
+from model.status import Status
import database
import db.tags
import db.task_tags
@@ -29,10 +30,11 @@ class Widget(QtWidgets.QTableWidget):
self,
parent,
on_show: gui.signal.Reload,
- add_task_signal: gui.tasks.signal.AddTask):
+ add_task_signal: gui.tasks.signal.AddTask,
+ status: Status):
super().__init__(parent)
- self.init_state()
+ self.init_state(status)
self.sort()
self.setSelectionBehavior(QtWidgets.QTableView.SelectRows)
@@ -46,27 +48,23 @@ class Widget(QtWidgets.QTableWidget):
# Menu
self.setContextMenuPolicy(Qt.CustomContextMenu)
- self.customContextMenuRequested.connect(lambda position: gui.tasks.table.menu.open(self, self._update_task_signal, position))
+ self.customContextMenuRequested.connect(lambda position: gui.tasks.table.menu.open(self, status, 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())
- def on_show(self):
- self._tags = db.tags.get(database.cursor())
- self.update_view()
-
- def init_state(self):
+ def init_state(self, status: Status):
self._update_task_signal = gui.tasks.signal.UpdateTask()
cursor = database.cursor()
- self._tasks = service.tasks.get(cursor)
+ self._status = status
+ self._tasks = service.tasks.get(cursor, self._status)
self._task_tags = db.task_tags.get(cursor)
self._tags = db.tags.get(cursor)
self._sort_column = 0
self._sort_is_ascending = True
-
def init_header(self):
self._header_view = QtWidgets.QHeaderView(Qt.Horizontal, self)
self._header_model = QtGui.QStandardItemModel()
@@ -75,7 +73,15 @@ class Widget(QtWidgets.QTableWidget):
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_show(self):
+ cursor = database.cursor()
+ self._tasks = service.tasks.get(cursor, self._status)
+ self._task_tags = db.task_tags.get(cursor)
+ self._tags = db.tags.get(cursor)
+ self.setRowCount(len(self._tasks))
+ self.sort()
+ self.update_view()
def on_header_click(self, column):
if self._sort_column == column:
@@ -138,6 +144,7 @@ class Widget(QtWidgets.QTableWidget):
self.insertRow(row)
self.update_row(row)
self._task_tags += [TaskTag(task_id=task.id, tag_id=tag_id) for tag_id in tags]
+ self.setRowCount(len(self._tasks))
return row
def is_reversed(self) -> bool:
@@ -189,6 +196,7 @@ class Widget(QtWidgets.QTableWidget):
self._task_tags = [tt for tt in self._task_tags if tt.task_id in [t.id for t in self._tasks]]
for row in sorted(rows, reverse=True):
self.removeRow(row)
+ self.setRowCount(len(self._tasks))
def get_selected_rows(self):
return list(set([index.row() for index in self.selectedIndexes()]))