diff --git a/src/dx_productivity/trial_task_center/ui/task_list.py b/src/dx_productivity/trial_task_center/ui/task_list.py index 645f4d3..8cca088 100644 --- a/src/dx_productivity/trial_task_center/ui/task_list.py +++ b/src/dx_productivity/trial_task_center/ui/task_list.py @@ -79,6 +79,10 @@ class TaskList(QWidget): self.recycle_button = QPushButton('回收站', objectName='taskRecycleBin') self.recycle_button.setCheckable(True) self.count = QLabel(objectName='taskCount') + self.empty_hint = QLabel(objectName='taskEmptyHint') + self.empty_hint.setTextFormat(Qt.TextFormat.PlainText) + self.empty_hint.setWordWrap(True) + self.empty_hint.hide() self.filter = QComboBox(objectName="taskFilter") for label, key, picture in (('全部任务', 'all', 'grid'), ('未完成', 'unfinished', 'clock'), ('待开始', 'pending', 'clock'), ('执行中', 'running', 'clock'), @@ -146,6 +150,7 @@ class TaskList(QWidget): layout.addWidget(self.filter) layout.addLayout(batch) layout.addLayout(selection) + layout.addWidget(self.empty_hint) layout.addWidget(self.list, 1) layout.addWidget(self.queue_button) layout.addLayout(footer) @@ -254,6 +259,17 @@ class TaskList(QWidget): if getattr(task, "task_id") == selected: self.list.setCurrentItem(item) hidden = selected and self.current_task_id() is None - self.count.setText(f'{len(tasks)} / {len(self._tasks)} 个任务' + (' · 当前任务已隐藏' if hidden else '')) + if not tasks: + category_text = self.filter.currentText() if category != 'all' and not self.recycle_button.isChecked() else '' + if not self._tasks: + hint = '回收站为空。' if self.recycle_button.isChecked() else '暂无任务,点击“新建任务”导入工程。' + elif query: + scope = f'“{category_text}”中' if category_text else '' + hint = f'{scope}未找到与“{self.search.text().strip()}”匹配的任务。' + else: + hint = f'暂无“{category_text}”任务。' + self.empty_hint.setText(hint) + self.empty_hint.setVisible(not tasks) + self.count.setText(f'匹配 {len(tasks)} / 共 {len(self._tasks)} 个任务' + (' · 当前任务已隐藏' if hidden else '')) self._update_selection_state() self.view_changed.emit() diff --git a/tests/ui/test_task_categories.py b/tests/ui/test_task_categories.py index 4ada517..4e4b97a 100644 --- a/tests/ui/test_task_categories.py +++ b/tests/ui/test_task_categories.py @@ -27,6 +27,26 @@ def visible_ids(panel): return [panel.list.item(index).data(Qt.ItemDataRole.UserRole) for index in range(panel.list.count())] +def test_empty_list_explains_search_filter_and_initial_state(navigation, qtbot): + panel, tasks, opened = navigation + panel.populate(tasks[:1]) + qtbot.keyClicks(panel.search, 'zzzz_no_match') + assert panel.empty_hint.isVisible() + assert 'zzzz_no_match' in panel.empty_hint.text() + assert '匹配 0 / 共 1 个任务' in panel.count.text() + panel.filter.setCurrentIndex(panel.filter.findData('completed')) + assert '已完成' in panel.empty_hint.text() and 'zzzz_no_match' in panel.empty_hint.text() + panel.search.clear() + assert '已完成' in panel.empty_hint.text() + panel.filter.setCurrentIndex(panel.filter.findData('all')) + assert not panel.empty_hint.isVisible() and len(visible_ids(panel)) == 1 + panel.populate(()) + assert '新建任务' in panel.empty_hint.text() + panel.recycle_button.setChecked(True) + panel.populate(()) + assert '回收站' in panel.empty_hint.text() + + @pytest.mark.parametrize(('category','expected'),[ ('all',['draft','ready','running','paused','completed','failed','blocked']), ('unfinished',['draft','ready','running','paused','failed','blocked']),