feat: add completed task and project summary
- Add completed timeblock queries and completed project aggregation\n- Add desktop completed summary dialog with range filters, stats, and streak\n- Add medal entry point in the today panel\n- Add Android completed summary menu with local statistics\n- Rebuild AppImage and update validation docs/screenshots
This commit is contained in:
@@ -83,6 +83,8 @@ add_library(schedule_ui STATIC
|
||||
ui/MainWindow.h
|
||||
ui/dialogs/BlockEditDialog.cpp
|
||||
ui/dialogs/BlockEditDialog.h
|
||||
ui/dialogs/CompletedSummaryDialog.cpp
|
||||
ui/dialogs/CompletedSummaryDialog.h
|
||||
ui/dialogs/DailyReviewDialog.cpp
|
||||
ui/dialogs/DailyReviewDialog.h
|
||||
ui/dialogs/ProjectDialog.cpp
|
||||
|
||||
@@ -1422,6 +1422,41 @@ QVector<ScheduleItem> ScheduleService::search(const QString& query, int limit) c
|
||||
return m_store.search(query, limit);
|
||||
}
|
||||
|
||||
QVector<ScheduleItem> ScheduleService::completedItems(const QDate& from, const QDate& to) const
|
||||
{
|
||||
if (!from.isValid() || !to.isValid() || from > to)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
return m_store.completedBlocks(DateTimeUtils::localDayStartUtc(from),
|
||||
DateTimeUtils::localDayEndUtc(to));
|
||||
}
|
||||
|
||||
QVector<Project> ScheduleService::completedProjects(const QDate& from, const QDate& to) const
|
||||
{
|
||||
if (!from.isValid() || !to.isValid() || from > to)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
QVector<Project> result;
|
||||
for (const Project& project : m_store.projects(true))
|
||||
{
|
||||
if (project.status != QStringLiteral("done"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
const QDate completed = project.updatedAt.date();
|
||||
if (completed >= from && completed <= to)
|
||||
{
|
||||
result.append(project);
|
||||
}
|
||||
}
|
||||
std::sort(result.begin(), result.end(), [](const Project& a, const Project& b) {
|
||||
return a.updatedAt > b.updatedAt;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
QString ScheduleService::lastError() const
|
||||
{
|
||||
return m_lastError;
|
||||
|
||||
@@ -77,6 +77,8 @@ public:
|
||||
QVector<ScheduleItem> itemsForRange(const QDate& from, const QDate& to) const;
|
||||
QVector<ScheduleItem> overdueItems(const QDateTime& now = QDateTime::currentDateTime()) const;
|
||||
QVector<ScheduleItem> search(const QString& query, int limit = 100) const;
|
||||
QVector<ScheduleItem> completedItems(const QDate& from, const QDate& to) const;
|
||||
QVector<Project> completedProjects(const QDate& from, const QDate& to) const;
|
||||
QString lastError() const;
|
||||
|
||||
const EnergyProfile& energyProfile() const;
|
||||
|
||||
@@ -1332,6 +1332,41 @@ std::optional<Recurrence> SqliteStore::recurrenceForTask(const QString& taskId)
|
||||
return recurrence;
|
||||
}
|
||||
|
||||
QVector<ScheduleItem> SqliteStore::completedBlocks(const QDateTime& fromUtc,
|
||||
const QDateTime& toUtc) const
|
||||
{
|
||||
m_lastError.clear();
|
||||
QVector<ScheduleItem> items;
|
||||
if (!isOpenInternal())
|
||||
{
|
||||
setError(QStringLiteral("数据库未打开"));
|
||||
return items;
|
||||
}
|
||||
QSqlQuery query(m_database);
|
||||
query.prepare(QStringLiteral(
|
||||
"SELECT %1, %2 FROM timeblock b JOIN task t ON t.id = b.task_id "
|
||||
"WHERE b.status = 'done' "
|
||||
"AND COALESCE(b.done_at, b.end_at) >= :from "
|
||||
"AND COALESCE(b.done_at, b.end_at) < :to "
|
||||
"ORDER BY COALESCE(b.done_at, b.end_at) DESC")
|
||||
.arg(QString::fromLatin1(kBlockColumns), QString::fromLatin1(kTaskColumns)));
|
||||
query.bindValue(QStringLiteral(":from"), DateTimeUtils::toDb(fromUtc));
|
||||
query.bindValue(QStringLiteral(":to"), DateTimeUtils::toDb(toUtc));
|
||||
if (!query.exec())
|
||||
{
|
||||
setError(QStringLiteral("查询已完成日程失败: %1").arg(query.lastError().text()));
|
||||
return items;
|
||||
}
|
||||
while (query.next())
|
||||
{
|
||||
ScheduleItem item;
|
||||
item.block = mapTimeBlock(query, 0);
|
||||
item.task = mapTask(query, 13);
|
||||
items.append(item);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
QVector<ScheduleItem> SqliteStore::search(const QString& query, int limit) const
|
||||
{
|
||||
m_lastError.clear();
|
||||
|
||||
@@ -67,6 +67,7 @@ public:
|
||||
// 已结束但仍未完成、且结束时间在最近 windowDays 内的块。
|
||||
QVector<ScheduleItem> overdueBefore(const QDateTime& nowUtc, int windowDays = 30) const;
|
||||
QVector<ScheduleItem> search(const QString& query, int limit = 100) const;
|
||||
QVector<ScheduleItem> completedBlocks(const QDateTime& fromUtc, const QDateTime& toUtc) const;
|
||||
|
||||
QVector<SyncOutboxItem> outboxBatch(int limit, QString* error = nullptr) const;
|
||||
int outboxCount(QString* error = nullptr) const;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "sync/SyncService.h"
|
||||
#include "ui/MainWindow.h"
|
||||
#include "ui/dialogs/BlockEditDialog.h"
|
||||
#include "ui/dialogs/CompletedSummaryDialog.h"
|
||||
#include "ui/dialogs/DailyReviewDialog.h"
|
||||
#include "ui/dialogs/ProjectDialog.h"
|
||||
#include "ui/dialogs/SettingsDialog.h"
|
||||
@@ -267,6 +268,7 @@ void CompactWindow::connectSignals()
|
||||
}
|
||||
});
|
||||
connect(m_todayPanel, &TodayPanel::reviewRequested, this, &CompactWindow::openDailyReview);
|
||||
connect(m_todayPanel, &TodayPanel::achievementsRequested, this, &CompactWindow::openCompletedSummary);
|
||||
connect(m_todayPanel, &TodayPanel::newProjectRequested, this, &CompactWindow::openNewProject);
|
||||
connect(m_todayPanel, &TodayPanel::editProjectRequested, this, &CompactWindow::openEditProject);
|
||||
connect(m_todayPanel, &TodayPanel::projectStatusRequested, this, [this](const QString& id, const QString& status) {
|
||||
@@ -438,6 +440,13 @@ void CompactWindow::openDailyReview()
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void CompactWindow::openCompletedSummary()
|
||||
{
|
||||
CompletedSummaryDialog dialog(m_scheduleService, m_tokens, this);
|
||||
dialog.moveToCenter();
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void CompactWindow::openNewProject()
|
||||
{
|
||||
ProjectDialog dialog(m_tokens, this);
|
||||
|
||||
@@ -65,6 +65,7 @@ private:
|
||||
void openSchedule();
|
||||
void openSettings();
|
||||
void openDailyReview();
|
||||
void openCompletedSummary();
|
||||
void openNewProject();
|
||||
void openEditProject(const QString& projectId);
|
||||
void openEditDialog(const QString& blockId);
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "services/ScheduleService.h"
|
||||
#include "sync/SyncService.h"
|
||||
#include "ui/dialogs/BlockEditDialog.h"
|
||||
#include "ui/dialogs/CompletedSummaryDialog.h"
|
||||
#include "ui/dialogs/DailyReviewDialog.h"
|
||||
#include "ui/dialogs/ProjectDialog.h"
|
||||
#include "ui/dialogs/SearchDialog.h"
|
||||
@@ -424,6 +425,7 @@ void MainWindow::connectSignals()
|
||||
m_grid->setFocus(Qt::OtherFocusReason);
|
||||
});
|
||||
connect(m_todayPanel, &TodayPanel::reviewRequested, this, &MainWindow::openDailyReview);
|
||||
connect(m_todayPanel, &TodayPanel::achievementsRequested, this, &MainWindow::openCompletedSummary);
|
||||
connect(m_todayPanel, &TodayPanel::newProjectRequested, this, &MainWindow::openNewProject);
|
||||
connect(m_todayPanel, &TodayPanel::editProjectRequested, this, &MainWindow::openEditProject);
|
||||
connect(m_todayPanel, &TodayPanel::projectStatusRequested, this, [this](const QString& id, const QString& status) {
|
||||
@@ -900,6 +902,13 @@ void MainWindow::openDailyReview()
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void MainWindow::openCompletedSummary()
|
||||
{
|
||||
CompletedSummaryDialog dialog(m_scheduleService, m_tokens, this);
|
||||
dialog.moveToCenter();
|
||||
dialog.exec();
|
||||
}
|
||||
|
||||
void MainWindow::openNewProject()
|
||||
{
|
||||
ProjectDialog dialog(m_tokens, this);
|
||||
|
||||
@@ -91,6 +91,7 @@ private:
|
||||
void openEditDialog(const QString& blockId);
|
||||
void openSettings();
|
||||
void openDailyReview();
|
||||
void openCompletedSummary();
|
||||
void openNewProject();
|
||||
void openEditProject(const QString& projectId);
|
||||
void updateOverdueBanner(const QVector<ScheduleItem>& items);
|
||||
|
||||
@@ -0,0 +1,288 @@
|
||||
#include "CompletedSummaryDialog.h"
|
||||
|
||||
#include <QDate>
|
||||
#include <QFrame>
|
||||
#include <QLayoutItem>
|
||||
#include <QSet>
|
||||
#include <QTimer>
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "ElaComboBox.h"
|
||||
#include "ElaPushButton.h"
|
||||
#include "ElaScrollArea.h"
|
||||
#include "ElaText.h"
|
||||
#include "core/DateTimeUtils.h"
|
||||
#include "services/ScheduleService.h"
|
||||
#include "storage/SqliteStore.h"
|
||||
#include "ui/theme/AnimationUtils.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
QString formatMinutes(int minutes)
|
||||
{
|
||||
if (minutes <= 0)
|
||||
{
|
||||
return QStringLiteral("0 分钟");
|
||||
}
|
||||
return DateTimeUtils::formatDuration(minutes);
|
||||
}
|
||||
} // namespace
|
||||
|
||||
CompletedSummaryDialog::CompletedSummaryDialog(ScheduleService& scheduleService,
|
||||
const ThemeTokens& tokens,
|
||||
QWidget* parent)
|
||||
: ElaDialog(parent)
|
||||
, m_scheduleService(scheduleService)
|
||||
, m_tokens(tokens)
|
||||
{
|
||||
setWindowTitle(QStringLiteral("已完成汇总"));
|
||||
setWindowButtonFlags(ElaAppBarType::CloseButtonHint);
|
||||
resize(640, 680);
|
||||
setMinimumWidth(560);
|
||||
|
||||
auto* root = new QVBoxLayout(this);
|
||||
root->setContentsMargins(24, 8, 24, 18);
|
||||
root->setSpacing(10);
|
||||
|
||||
auto* title = new ElaText(QStringLiteral("已完成汇总"), 18, this);
|
||||
QFont titleFont = title->font();
|
||||
titleFont.setWeight(QFont::DemiBold);
|
||||
title->setFont(titleFont);
|
||||
root->addWidget(title);
|
||||
|
||||
auto* subtitle = new ElaText(QStringLiteral("把完成的事情放在一起,看看你已经走了多远。"), 11, this);
|
||||
subtitle->setTextStyle(ElaTextType::Caption);
|
||||
root->addWidget(subtitle);
|
||||
|
||||
auto* rangeRow = new QHBoxLayout();
|
||||
rangeRow->setSpacing(10);
|
||||
auto* rangeLabel = new ElaText(QStringLiteral("范围"), 12, this);
|
||||
m_rangeCombo = new ElaComboBox(this);
|
||||
m_rangeCombo->addItems({QStringLiteral("本周"),
|
||||
QStringLiteral("本月"),
|
||||
QStringLiteral("全部")});
|
||||
m_rangeCombo->setCurrentIndex(2);
|
||||
m_rangeCombo->setFixedSize(130, 32);
|
||||
rangeRow->addWidget(rangeLabel, 0, Qt::AlignVCenter);
|
||||
rangeRow->addWidget(m_rangeCombo, 0, Qt::AlignVCenter);
|
||||
rangeRow->addStretch(1);
|
||||
root->addLayout(rangeRow);
|
||||
|
||||
auto* stats = new QHBoxLayout();
|
||||
stats->setSpacing(28);
|
||||
const auto addStat = [this, stats](const QString& label, ElaText** valueOut) {
|
||||
auto* column = new QVBoxLayout();
|
||||
column->setSpacing(2);
|
||||
auto* title = new ElaText(label, 11, this);
|
||||
title->setTextStyle(ElaTextType::Caption);
|
||||
auto* value = new ElaText(QStringLiteral("0"), 19, this);
|
||||
QFont font = value->font();
|
||||
font.setWeight(QFont::DemiBold);
|
||||
value->setFont(font);
|
||||
column->addWidget(title);
|
||||
column->addWidget(value);
|
||||
stats->addLayout(column);
|
||||
*valueOut = value;
|
||||
};
|
||||
addStat(QStringLiteral("短期任务"), &m_taskStat);
|
||||
addStat(QStringLiteral("专注时长"), &m_focusStat);
|
||||
addStat(QStringLiteral("长期项目"), &m_projectStat);
|
||||
addStat(QStringLiteral("连续完成"), &m_streakStat);
|
||||
root->addLayout(stats);
|
||||
|
||||
auto* divider = new QFrame(this);
|
||||
divider->setFrameShape(QFrame::HLine);
|
||||
divider->setFrameShadow(QFrame::Plain);
|
||||
root->addWidget(divider);
|
||||
|
||||
m_scrollArea = new ElaScrollArea(this);
|
||||
m_scrollArea->setWidgetResizable(true);
|
||||
m_scrollArea->setFrameShape(QFrame::NoFrame);
|
||||
m_scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
m_scrollArea->setStyleSheet(QStringLiteral("QScrollArea{background:transparent;border:none;}"));
|
||||
m_scrollArea->viewport()->setAutoFillBackground(false);
|
||||
m_scrollArea->viewport()->setStyleSheet(QStringLiteral("background:transparent;"));
|
||||
|
||||
m_listWidget = new QWidget(m_scrollArea);
|
||||
m_listWidget->setAutoFillBackground(false);
|
||||
m_listWidget->setStyleSheet(QStringLiteral("background:transparent;"));
|
||||
m_listLayout = new QVBoxLayout(m_listWidget);
|
||||
m_listLayout->setContentsMargins(0, 0, 4, 0);
|
||||
m_listLayout->setSpacing(6);
|
||||
m_listLayout->addStretch(1);
|
||||
m_scrollArea->setWidget(m_listWidget);
|
||||
root->addWidget(m_scrollArea, 1);
|
||||
|
||||
auto* closeRow = new QHBoxLayout();
|
||||
closeRow->addStretch(1);
|
||||
auto* close = new ElaPushButton(QStringLiteral("完成"), this);
|
||||
close->setFixedSize(88, 34);
|
||||
close->setDefault(true);
|
||||
closeRow->addWidget(close);
|
||||
root->addLayout(closeRow);
|
||||
|
||||
connect(close, &ElaPushButton::clicked, this, &CompletedSummaryDialog::accept);
|
||||
connect(m_rangeCombo, &ElaComboBox::currentIndexChanged, this, [this](int) { rebuild(); });
|
||||
rebuild();
|
||||
QTimer::singleShot(0, this, [this]() { AnimationUtils::fadeWindow(this); });
|
||||
}
|
||||
|
||||
void CompletedSummaryDialog::clearLayout(QVBoxLayout* layout)
|
||||
{
|
||||
while (QLayoutItem* item = layout->takeAt(0))
|
||||
{
|
||||
if (QWidget* widget = item->widget())
|
||||
{
|
||||
widget->hide();
|
||||
widget->deleteLater();
|
||||
}
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
|
||||
QString CompletedSummaryDialog::shortRangeStart() const
|
||||
{
|
||||
const QDate today = QDate::currentDate();
|
||||
switch (m_rangeCombo->currentIndex())
|
||||
{
|
||||
case 0:
|
||||
return today.addDays(1 - today.dayOfWeek()).toString(Qt::ISODate);
|
||||
case 1:
|
||||
return QDate(today.year(), today.month(), 1).toString(Qt::ISODate);
|
||||
default:
|
||||
return QDate(2000, 1, 1).toString(Qt::ISODate);
|
||||
}
|
||||
}
|
||||
|
||||
void CompletedSummaryDialog::rebuild()
|
||||
{
|
||||
if (!m_listLayout)
|
||||
{
|
||||
return;
|
||||
}
|
||||
clearLayout(m_listLayout);
|
||||
const QDate today = QDate::currentDate();
|
||||
const QDate start = QDate::fromString(shortRangeStart(), Qt::ISODate);
|
||||
const auto items = m_scheduleService.completedItems(start, today);
|
||||
const auto projects = m_scheduleService.completedProjects(start, today);
|
||||
|
||||
int focusedMinutes = 0;
|
||||
QSet<QDate> completionDays;
|
||||
for (const ScheduleItem& item : items)
|
||||
{
|
||||
focusedMinutes += qMax(0, DateTimeUtils::minutesBetween(item.block.startAt, item.block.endAt));
|
||||
completionDays.insert(item.block.doneAt.has_value() ? item.block.doneAt->date()
|
||||
: item.block.endAt.date());
|
||||
}
|
||||
for (const Project& project : projects)
|
||||
{
|
||||
completionDays.insert(project.updatedAt.date());
|
||||
}
|
||||
|
||||
int streak = 0;
|
||||
QDate cursor = completionDays.contains(today) ? today : today.addDays(-1);
|
||||
while (completionDays.contains(cursor))
|
||||
{
|
||||
++streak;
|
||||
cursor = cursor.addDays(-1);
|
||||
}
|
||||
|
||||
m_taskStat->setText(QString::number(items.size()));
|
||||
m_focusStat->setText(formatMinutes(focusedMinutes));
|
||||
m_projectStat->setText(QString::number(projects.size()));
|
||||
m_streakStat->setText(QStringLiteral("%1 天").arg(streak));
|
||||
|
||||
const auto addSection = [this](const QString& text) {
|
||||
auto* label = new ElaText(text, 13, m_listWidget);
|
||||
QFont font = label->font();
|
||||
font.setWeight(QFont::DemiBold);
|
||||
label->setFont(font);
|
||||
label->setContentsMargins(2, 8, 0, 2);
|
||||
m_listLayout->addWidget(label);
|
||||
};
|
||||
const auto addEmpty = [this](const QString& text) {
|
||||
auto* label = new ElaText(text, 12, m_listWidget);
|
||||
label->setTextStyle(ElaTextType::Caption);
|
||||
label->setContentsMargins(2, 2, 0, 2);
|
||||
m_listLayout->addWidget(label);
|
||||
};
|
||||
if (items.isEmpty() && projects.isEmpty())
|
||||
{
|
||||
addEmpty(QStringLiteral("这个范围内还没有已完成记录。"));
|
||||
m_listLayout->addStretch(1);
|
||||
return;
|
||||
}
|
||||
|
||||
addSection(QStringLiteral("短期任务 · %1").arg(items.size()));
|
||||
if (items.isEmpty())
|
||||
{
|
||||
addEmpty(QStringLiteral("暂无已完成短期任务。"));
|
||||
}
|
||||
int shown = 0;
|
||||
for (const ScheduleItem& item : items)
|
||||
{
|
||||
if (shown++ >= 80)
|
||||
{
|
||||
break;
|
||||
}
|
||||
auto* card = new QFrame(m_listWidget);
|
||||
card->setStyleSheet(
|
||||
QStringLiteral("QFrame{background:%1;border:1px solid %2;border-radius:8px;}")
|
||||
.arg(m_tokens.cardBackground.name(), m_tokens.cardBorder.name()));
|
||||
auto* layout = new QVBoxLayout(card);
|
||||
layout->setContentsMargins(10, 7, 10, 7);
|
||||
layout->setSpacing(2);
|
||||
auto* name = new QLabel(item.task.title, card);
|
||||
name->setStyleSheet(QStringLiteral("background:transparent;border:none;color:%1;font-size:12px;font-weight:600;")
|
||||
.arg(m_tokens.textPrimary.name()));
|
||||
const QDateTime doneAt = item.block.doneAt.value_or(item.block.endAt);
|
||||
auto* detail = new QLabel(
|
||||
QStringLiteral("完成于 %1 · %2–%3")
|
||||
.arg(doneAt.toString(QStringLiteral("MM-dd HH:mm")),
|
||||
item.block.startAt.toString(QStringLiteral("HH:mm")),
|
||||
item.block.endAt.toString(QStringLiteral("HH:mm"))),
|
||||
card);
|
||||
detail->setStyleSheet(QStringLiteral("background:transparent;border:none;color:%1;font-size:11px;")
|
||||
.arg(m_tokens.textMuted.name()));
|
||||
layout->addWidget(name);
|
||||
layout->addWidget(detail);
|
||||
m_listLayout->addWidget(card);
|
||||
}
|
||||
|
||||
addSection(QStringLiteral("长期项目 · %1").arg(projects.size()));
|
||||
if (projects.isEmpty())
|
||||
{
|
||||
addEmpty(QStringLiteral("暂无已完成长期项目。"));
|
||||
}
|
||||
for (const Project& project : projects)
|
||||
{
|
||||
auto* card = new QFrame(m_listWidget);
|
||||
card->setStyleSheet(
|
||||
QStringLiteral("QFrame{background:%1;border:1px solid %2;border-left:3px solid %3;border-radius:8px;}")
|
||||
.arg(m_tokens.cardBackground.name(),
|
||||
m_tokens.cardBorder.name(),
|
||||
m_tokens.success.name()));
|
||||
auto* layout = new QVBoxLayout(card);
|
||||
layout->setContentsMargins(10, 7, 10, 7);
|
||||
layout->setSpacing(2);
|
||||
auto* name = new QLabel(project.title, card);
|
||||
name->setStyleSheet(QStringLiteral("background:transparent;border:none;color:%1;font-size:12px;font-weight:600;")
|
||||
.arg(m_tokens.textPrimary.name()));
|
||||
auto* detail = new QLabel(
|
||||
QStringLiteral("完成于 %1%2")
|
||||
.arg(project.updatedAt.toString(QStringLiteral("MM-dd HH:mm")),
|
||||
project.deadline.has_value()
|
||||
? QStringLiteral(" · 截止 %1").arg(project.deadline->toString(QStringLiteral("yyyy-MM-dd")))
|
||||
: QString()),
|
||||
card);
|
||||
detail->setStyleSheet(QStringLiteral("background:transparent;border:none;color:%1;font-size:11px;")
|
||||
.arg(m_tokens.textMuted.name()));
|
||||
layout->addWidget(name);
|
||||
layout->addWidget(detail);
|
||||
m_listLayout->addWidget(card);
|
||||
}
|
||||
m_listLayout->addStretch(1);
|
||||
AnimationUtils::fadeIn(m_listWidget, 150);
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include "ElaDialog.h"
|
||||
#include "ui/theme/ThemeTokens.h"
|
||||
|
||||
class ElaComboBox;
|
||||
class ElaScrollArea;
|
||||
class ElaText;
|
||||
class QVBoxLayout;
|
||||
class ScheduleService;
|
||||
|
||||
/*
|
||||
* 类名: CompletedSummaryDialog
|
||||
* 功能: 汇总已完成的短期任务与长期项目,展示统计、连续天数和完成记录
|
||||
* 线程安全: 否;UI 线程
|
||||
*/
|
||||
class CompletedSummaryDialog : public ElaDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CompletedSummaryDialog(ScheduleService& scheduleService,
|
||||
const ThemeTokens& tokens,
|
||||
QWidget* parent = nullptr);
|
||||
|
||||
private:
|
||||
void rebuild();
|
||||
static void clearLayout(QVBoxLayout* layout);
|
||||
QString shortRangeStart() const;
|
||||
|
||||
ScheduleService& m_scheduleService;
|
||||
ThemeTokens m_tokens;
|
||||
ElaComboBox* m_rangeCombo = nullptr;
|
||||
ElaText* m_taskStat = nullptr;
|
||||
ElaText* m_focusStat = nullptr;
|
||||
ElaText* m_projectStat = nullptr;
|
||||
ElaText* m_streakStat = nullptr;
|
||||
ElaScrollArea* m_scrollArea = nullptr;
|
||||
QWidget* m_listWidget = nullptr;
|
||||
QVBoxLayout* m_listLayout = nullptr;
|
||||
};
|
||||
@@ -41,6 +41,13 @@ TodayPanel::TodayPanel(QWidget* parent)
|
||||
m_reviewButton->setToolTip(QStringLiteral("今日复盘 (Ctrl+R)"));
|
||||
connect(m_reviewButton, &ElaToolButton::clicked, this, &TodayPanel::reviewRequested);
|
||||
|
||||
m_achievementsButton = new ElaToolButton(this);
|
||||
m_achievementsButton->setIsTransparent(true);
|
||||
m_achievementsButton->setElaIcon(ElaIconType::Medal);
|
||||
m_achievementsButton->setFixedSize(26, 26);
|
||||
m_achievementsButton->setToolTip(QStringLiteral("已完成汇总"));
|
||||
connect(m_achievementsButton, &ElaToolButton::clicked, this, &TodayPanel::achievementsRequested);
|
||||
|
||||
m_newProjectButton = new ElaToolButton(this);
|
||||
m_newProjectButton->setIsTransparent(true);
|
||||
m_newProjectButton->setElaIcon(ElaIconType::FolderPlus);
|
||||
@@ -51,6 +58,7 @@ TodayPanel::TodayPanel(QWidget* parent)
|
||||
header->addWidget(m_titleLabel);
|
||||
header->addStretch(1);
|
||||
header->addWidget(m_countLabel, 0, Qt::AlignVCenter);
|
||||
header->addWidget(m_achievementsButton, 0, Qt::AlignVCenter);
|
||||
header->addWidget(m_newProjectButton, 0, Qt::AlignVCenter);
|
||||
header->addWidget(m_reviewButton, 0, Qt::AlignVCenter);
|
||||
root->addLayout(header);
|
||||
|
||||
@@ -38,6 +38,7 @@ signals:
|
||||
void deleteRequested(const QString& blockId);
|
||||
void focusRequested(const QString& blockId);
|
||||
void reviewRequested();
|
||||
void achievementsRequested();
|
||||
void newProjectRequested();
|
||||
void editProjectRequested(const QString& projectId);
|
||||
void projectStatusRequested(const QString& projectId, const QString& status);
|
||||
@@ -57,6 +58,7 @@ private:
|
||||
ElaText* m_insightLabel = nullptr;
|
||||
ElaToolButton* m_reviewButton = nullptr;
|
||||
ElaToolButton* m_newProjectButton = nullptr;
|
||||
ElaToolButton* m_achievementsButton = nullptr;
|
||||
ElaScrollArea* m_scrollArea = nullptr;
|
||||
QWidget* m_listWidget = nullptr;
|
||||
QVBoxLayout* m_listLayout = nullptr;
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "ui/CompactWindow.h"
|
||||
#include "ui/MainWindow.h"
|
||||
#include "ui/dialogs/BlockEditDialog.h"
|
||||
#include "ui/dialogs/CompletedSummaryDialog.h"
|
||||
#include "ui/dialogs/DailyReviewDialog.h"
|
||||
#include "ui/dialogs/ProjectDialog.h"
|
||||
#include "ui/dialogs/SearchDialog.h"
|
||||
@@ -70,6 +71,7 @@ private slots:
|
||||
void searchDialogFindsSchedules();
|
||||
void repeatDialogShowsOptions();
|
||||
void projectDialogShowsFields();
|
||||
void completedSummaryShowsStats();
|
||||
void aiChatShowsDiffAndAccepts();
|
||||
void aiChatShowsMultiOperationDiff();
|
||||
|
||||
@@ -131,6 +133,19 @@ void TestCompactWindow::createSampleData(ScheduleService& service, const QDate&
|
||||
today.addDays(30),
|
||||
&projectError),
|
||||
qPrintable(projectError));
|
||||
QVERIFY2(service.createProject(QStringLiteral("已完成旧项目"),
|
||||
QStringLiteral("历史项目"),
|
||||
today.addDays(-10),
|
||||
&projectError),
|
||||
qPrintable(projectError));
|
||||
for (const Project& project : service.projects())
|
||||
{
|
||||
if (project.title == QStringLiteral("已完成旧项目"))
|
||||
{
|
||||
service.setProjectStatus(project.id, QStringLiteral("done"), &projectError);
|
||||
break;
|
||||
}
|
||||
}
|
||||
QVERIFY(create(QStringLiteral("团队同步"),
|
||||
QDateTime(today, QTime(10, 0), Qt::LocalTime),
|
||||
QDateTime(today, QTime(11, 0), Qt::LocalTime)));
|
||||
@@ -405,6 +420,27 @@ void TestCompactWindow::projectDialogShowsFields()
|
||||
dialog.accept();
|
||||
}
|
||||
|
||||
void TestCompactWindow::completedSummaryShowsStats()
|
||||
{
|
||||
QTemporaryDir databaseDir;
|
||||
QVERIFY(databaseDir.isValid());
|
||||
SqliteStore store(databaseDir.filePath(QStringLiteral("schedule.db")));
|
||||
QString error;
|
||||
QVERIFY2(store.open(&error), qPrintable(error));
|
||||
|
||||
ThemeManager theme(*m_settings);
|
||||
theme.initialize();
|
||||
ScheduleService service(store, QStringLiteral("summary-test"));
|
||||
createSampleData(service, QDate::currentDate());
|
||||
|
||||
CompletedSummaryDialog dialog(service, theme.tokens());
|
||||
dialog.show();
|
||||
QVERIFY(QTest::qWaitForWindowExposed(&dialog));
|
||||
QTest::qWait(300);
|
||||
saveWindow(&dialog, QStringLiteral("completed-summary.png"));
|
||||
dialog.close();
|
||||
}
|
||||
|
||||
void TestCompactWindow::aiChatShowsDiffAndAccepts()
|
||||
{
|
||||
QTemporaryDir databaseDir;
|
||||
|
||||
@@ -30,6 +30,7 @@ private slots:
|
||||
void createsRecurringSchedules();
|
||||
void startAndLeadReminders();
|
||||
void projectCrudAndPersistence();
|
||||
void completedSummaryQueries();
|
||||
};
|
||||
|
||||
namespace
|
||||
@@ -515,5 +516,36 @@ void TestServices::projectCrudAndPersistence()
|
||||
QVERIFY(!context.service->projectById(id).has_value());
|
||||
}
|
||||
|
||||
void TestServices::completedSummaryQueries()
|
||||
{
|
||||
Context context;
|
||||
QVERIFY(context.open());
|
||||
|
||||
const QDate today = QDate::currentDate();
|
||||
const QDateTime start(today, QTime(9, 0), Qt::LocalTime);
|
||||
QString error;
|
||||
QVERIFY(context.service->createBlock(QStringLiteral("已完成短期任务"),
|
||||
start,
|
||||
start.addSecs(90 * 60),
|
||||
&error));
|
||||
const QString blockId = context.service->itemsForDay(today).first().block.id;
|
||||
QVERIFY2(context.service->setBlockStatus(blockId, QStringLiteral("done"), &error), qPrintable(error));
|
||||
|
||||
QVERIFY(context.service->createProject(QStringLiteral("已完成长期项目"),
|
||||
QStringLiteral("项目说明"),
|
||||
today.addDays(10),
|
||||
&error));
|
||||
const QString projectId = context.service->projects().first().id;
|
||||
QVERIFY2(context.service->setProjectStatus(projectId, QStringLiteral("done"), &error), qPrintable(error));
|
||||
|
||||
const QVector<ScheduleItem> completed = context.service->completedItems(today, today);
|
||||
QCOMPARE(completed.size(), 1);
|
||||
QCOMPARE(completed.first().task.title, QStringLiteral("已完成短期任务"));
|
||||
const QVector<Project> projects = context.service->completedProjects(today, today);
|
||||
QCOMPARE(projects.size(), 1);
|
||||
QCOMPARE(projects.first().title, QStringLiteral("已完成长期项目"));
|
||||
QCOMPARE(context.service->completedItems(today.addDays(1), today.addDays(2)).size(), 0);
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestServices)
|
||||
#include "test_services.moc"
|
||||
|
||||
Reference in New Issue
Block a user