Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/ui/pyqt/task_list.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Model-backed task table with search, filtering, and sorting."""

from typing import ClassVar

from PyQt6.QtCore import (
QAbstractTableModel,
QModelIndex,
Expand All @@ -22,6 +24,8 @@
from logic import local_time
from ui.pyqt.settings_dialog import FILTERS, SORT_FIELDS, UiPreferences

INVALID_MODEL_INDEX = QModelIndex()


class TaskTableModel(QAbstractTableModel):
HEADERS = ("Date", "Time", "Task", "Status", "Created")
Expand All @@ -34,10 +38,10 @@ def __init__(
self.date_format = date_format
self.time_format = time_format

def rowCount(self, parent=QModelIndex()):
def rowCount(self, parent=INVALID_MODEL_INDEX):
return 0 if parent.isValid() else len(self.tasks)

def columnCount(self, parent=QModelIndex()):
def columnCount(self, parent=INVALID_MODEL_INDEX):
return 0 if parent.isValid() else len(self.HEADERS)

def data(self, index, role=Qt.ItemDataRole.DisplayRole):
Expand Down Expand Up @@ -109,7 +113,13 @@ class TaskListWidget(QWidget):
delete_requested = pyqtSignal(object)
complete_requested = pyqtSignal(object)

SORT_COLUMNS = {"date": 0, "time": 1, "text": 2, "status": 3, "created": 4}
SORT_COLUMNS: ClassVar[dict[str, int]] = {
"date": 0,
"time": 1,
"text": 2,
"status": 3,
"created": 4,
}

def __init__(self, scheduler, preferences: UiPreferences, parent=None):
super().__init__(parent)
Expand Down
14 changes: 13 additions & 1 deletion tests/test_pyqt_task_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ui.pyqt.add_dialog import AddTaskDialog, EditTaskDialog
from ui.pyqt.calendar_view import CalendarWorkspace
from ui.pyqt.settings_dialog import SettingsDialog, UiPreferences
from ui.pyqt.task_list import TaskListWidget
from ui.pyqt.task_list import TaskListWidget, TaskTableModel
from ui.pyqt.window import SchedPlusWindow
from updater.config import BuildInfo
from updater.preferences import UpdatePreferences
Expand Down Expand Up @@ -94,6 +94,18 @@ def test_task_workspace_filters_and_searches(app):
assert "1 of 3" in widget.count_label.text()


def test_task_table_model_respects_root_and_child_indexes(app):
model = TaskTableModel([Task(date="2026-08-28", time="09:00", text="Plan")])

assert model.rowCount() == 1
assert model.columnCount() == 5

child_index = model.index(0, 0)
assert child_index.isValid()
assert model.rowCount(child_index) == 0
assert model.columnCount(child_index) == 0


def test_edit_dialog_is_prepopulated(app):
task = Task(date="2026-08-12", time="09:05", text="Plan release")

Expand Down
Loading