| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205 |
- #include "createtaskdialog.h"
- #include "ui_createtaskdialog.h"
- #include "appconfig.h"
- #include "localplans.h"
- #include <QCheckBox>
- #include <QDialog>
- #include <QDialogButtonBox>
- #include <QDragEnterEvent>
- #include <QDropEvent>
- #include <QFile>
- #include <QColor>
- #include <QDebug>
- #include <QFont>
- #include <QFrame>
- #include <QGraphicsDropShadowEffect>
- #include <QGridLayout>
- #include <QGroupBox>
- #include <QGuiApplication>
- #include <QHBoxLayout>
- #include <QIntValidator>
- #include <QJsonArray>
- #include <QJsonDocument>
- #include <QJsonObject>
- #include <QLabel>
- #include <QLineEdit>
- #include <QListWidget>
- #include <QListWidgetItem>
- #include <QMimeData>
- #include <QPushButton>
- #include <QScreen>
- #include <QTabWidget>
- #include <QTimer>
- #include <QToolButton>
- #include <QVBoxLayout>
- #include <functional>
- namespace {
- const char *const kTaskMime = "application/x-slt-task";
- const char *const kKeys[] = {
- "mem vdd", "mem vddq", "tCL", "tRCD", "tRP", "tRAS",
- "tRFC", "tRTP", "trrd_l", "tWTR_S", "tWTR_L", "tWR",
- "tCCD_L", "trefi", "tRFCsb",
- };
- const int kKeyCount = int(sizeof(kKeys) / sizeof(kKeys[0]));
- // config.json 的 memoryParams,作为没有本地计划时的默认值
- QJsonObject configMemoryParams()
- {
- const QString path = appConfigPath(QStringLiteral("config.json"));
- if (path.isEmpty())
- return QJsonObject();
- QFile f(path);
- if (!f.open(QIODevice::ReadOnly))
- return QJsonObject();
- return QJsonDocument::fromJson(f.readAll()).object()
- .value(QStringLiteral("memoryParams")).toObject();
- }
- // 算法清单每行放一个真正的 QCheckBox(setItemWidget):点击由控件自己处理,
- // 不经过 QAbstractItemView 的双击判定,快速连点不会漏一次。
- QList<QCheckBox *> algoChecks(QListWidget *list)
- {
- QList<QCheckBox *> out;
- for (int i = 0; i < list->count(); ++i)
- if (QCheckBox *cb = qobject_cast<QCheckBox *>(list->itemWidget(list->item(i))))
- out << cb;
- return out;
- }
- QStringList checkedItems(const QListWidget *list)
- {
- QStringList out;
- for (int i = 0; i < list->count(); ++i)
- if (QCheckBox *cb = qobject_cast<QCheckBox *>(list->itemWidget(list->item(i))))
- if (cb->isChecked())
- out << cb->text();
- return out;
- }
- QJsonArray toArray(const QStringList &items)
- {
- QJsonArray a;
- for (const QString &s : items)
- a.append(s);
- return a;
- }
- QStringList fromArray(const QJsonValue &v)
- {
- QStringList out;
- const QJsonArray a = v.toArray();
- for (const QJsonValue &x : a)
- out << x.toString();
- return out;
- }
- // 阶段对象:保留 efi_path / config_path / test_command 等既有键,
- // 只覆盖 selected(勾选项)与 enabled(= 至少勾了一项)。
- QJsonObject withSelection(const QJsonObject &base, const QStringList &selected)
- {
- QJsonObject o = base;
- o.insert(QStringLiteral("selected"), toArray(selected));
- o.insert(QStringLiteral("enabled"), !selected.isEmpty());
- o.remove(QStringLiteral("only_tests"));
- o.remove(QStringLiteral("skip_tests"));
- return o;
- }
- QStringList allItems(QListWidget *list)
- {
- QStringList out;
- for (QCheckBox *cb : algoChecks(list))
- out << cb->text();
- return out;
- }
- void ensureDefaultSelection(QJsonObject &cfg, const QString &key, const QStringList &all)
- {
- QJsonObject sec = cfg.value(key).toObject();
- if (sec.contains(QStringLiteral("selected")))
- return;
- // 尊重 config.json 里显式配置的 enabled=false(如默认不开启 RMT/AMT 时,不能强行全选)
- if (sec.contains(QStringLiteral("enabled")) && !sec.value(QStringLiteral("enabled")).toBool(true)) {
- sec.insert(QStringLiteral("selected"), QJsonArray());
- sec.insert(QStringLiteral("enabled"), false);
- cfg.insert(key, sec);
- return;
- }
- sec.insert(QStringLiteral("selected"), toArray(all));
- sec.insert(QStringLiteral("enabled"), !all.isEmpty());
- cfg.insert(key, sec);
- }
- // 旧版存档的 memory_params 没有目标温度和 ecc / debuglog:补齐默认
- void ensureMemoryDefaults(QJsonObject &cfg)
- {
- QJsonObject mem = cfg.value(QStringLiteral("memory_params")).toObject();
- if (!mem.contains(QStringLiteral("target_temp")))
- mem.insert(QStringLiteral("target_temp"), 70);
- const char *const checks[] = {"errhandle", "ap", "ecc", "debuglog"};
- for (const char *k : checks) {
- const QString key = QString::fromLatin1(k);
- if (!mem.contains(key))
- mem.insert(key, false);
- }
- cfg.insert(QStringLiteral("memory_params"), mem);
- }
- // 任务池:拖出时只带任务 id,不放 Qt 默认的 model 数据。
- class TaskSourceList : public QListWidget
- {
- public:
- explicit TaskSourceList(QWidget *parent = nullptr) : QListWidget(parent) {}
- protected:
- QStringList mimeTypes() const override
- {
- return QStringList() << QString::fromLatin1(kTaskMime);
- }
- // Qt 5 的这个虚函数是「按值传参」,Qt 6 才改成 const 引用。
- // 写成引用等于没覆盖,拖出去的会是 Qt 默认 MIME,任务框就收不到了。
- #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
- QMimeData *mimeData(const QList<QListWidgetItem *> &items) const override
- #else
- QMimeData *mimeData(const QList<QListWidgetItem *> items) const override
- #endif
- {
- QMimeData *m = new QMimeData();
- if (!items.isEmpty() && items.first())
- m->setData(QString::fromLatin1(kTaskMime),
- QByteArray::number(items.first()->data(Qt::UserRole).toInt()));
- return m;
- }
- };
- // 机台里的「任务框」:接住拖来的任务 id。
- class TaskDropZone : public QFrame
- {
- public:
- explicit TaskDropZone(QWidget *parent = nullptr) : QFrame(parent)
- {
- setAcceptDrops(true);
- }
- std::function<void(int)> onTaskDropped;
- std::function<bool()> canDrop; // 机台离线时返回 false,任务拖不进来
- std::function<bool(int)> canDropTask; // 这条任务本身不许拖入(例如正在执行中)
- protected:
- void dragEnterEvent(QDragEnterEvent *e) override
- {
- if (!e->mimeData()->hasFormat(QString::fromLatin1(kTaskMime)))
- return;
- // 这个机台显示「控制台离线」时不接收任务:直接忽略,鼠标会显示禁止图标
- if (canDrop && !canDrop())
- return;
- // 执行中的任务不允许再添加:拖过来的 mimeData 里就是任务 id,
- // 在 enter 阶段拒掉,鼠标直接显示禁止,不用等松手再弹提示。
- if (canDropTask) {
- const QByteArray b = e->mimeData()->data(QString::fromLatin1(kTaskMime));
- bool ok = false;
- const int taskId = b.toInt(&ok);
- if (ok && !canDropTask(taskId))
- return;
- }
- e->acceptProposedAction();
- setProperty("dragOver", true);
- style()->polish(this);
- }
- void dragLeaveEvent(QDragLeaveEvent *e) override
- {
- Q_UNUSED(e)
- setProperty("dragOver", false);
- style()->polish(this);
- }
- void dropEvent(QDropEvent *e) override
- {
- setProperty("dragOver", false);
- style()->polish(this);
- const QByteArray b = e->mimeData()->data(QString::fromLatin1(kTaskMime));
- bool ok = false;
- const int taskId = b.toInt(&ok);
- e->acceptProposedAction();
- if (ok && onTaskDropped)
- onTaskDropped(taskId);
- }
- };
- // 删除类操作的确认框。样式跟项目其它弹窗一致:白底圆角卡片 + 蓝色主按钮,
- // 不用系统 QMessageBox(灰底 + 系统图标,和蓝白扁平界面不搭)。
- bool confirmRemove(QWidget *parent, const QString &title, const QString &detail,
- bool showCancel = true)
- {
- QDialog dlg(parent);
- dlg.setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
- dlg.setAttribute(Qt::WA_TranslucentBackground); // 圆角外透出底下的界面,不留一圈灰底
- dlg.setWindowTitle(title);
- dlg.setFixedWidth(420);
- QVBoxLayout *outer = new QVBoxLayout(&dlg);
- outer->setContentsMargins(20, 20, 20, 20); // 给阴影留绘制空间
- QFrame *card = new QFrame(&dlg);
- card->setObjectName(QStringLiteral("confirmCard"));
- card->setStyleSheet(QStringLiteral(
- "QFrame#confirmCard { background:#ffffff; border:1px solid #d3dde9; border-radius:10px; }"
- "QLabel#confirmTitle { color:#20323f; font-size:19px; font-weight:600; }"
- "QLabel#confirmDetail { color:#5b7183; font-size:15px; }"));
- outer->addWidget(card);
- // 和 ResultToast 一样的柔和投影,让卡片从背景里浮起来
- QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(card);
- shadow->setBlurRadius(32);
- shadow->setOffset(0, 8);
- shadow->setColor(QColor(31, 56, 82, 95));
- card->setGraphicsEffect(shadow);
- QVBoxLayout *body = new QVBoxLayout(card);
- body->setContentsMargins(24, 22, 24, 18);
- body->setSpacing(18);
- QLabel *titleLabel = new QLabel(title, card);
- titleLabel->setObjectName(QStringLiteral("confirmTitle"));
- QLabel *detailLabel = new QLabel(detail, card);
- detailLabel->setObjectName(QStringLiteral("confirmDetail"));
- detailLabel->setWordWrap(true);
- body->addWidget(titleLabel);
- body->addWidget(detailLabel);
- QHBoxLayout *foot = new QHBoxLayout();
- foot->setContentsMargins(0, 0, 0, 0);
- foot->setSpacing(10);
- foot->addStretch(1);
- QPushButton *cancel = nullptr;
- if (showCancel) {
- cancel = new QPushButton(QStringLiteral("取消"), card);
- cancel->setStyleSheet(QStringLiteral(
- "QPushButton { color:#2f7fc1; background:#ffffff; border:1px solid #cdd7e1;"
- " border-radius:4px; padding:5px 16px; font-size:14px; }"
- "QPushButton:hover { background:#eef4fa; border-color:#b9cfe2; }"));
- cancel->setCursor(Qt::PointingHandCursor);
- foot->addWidget(cancel);
- QObject::connect(cancel, &QPushButton::clicked, &dlg, &QDialog::reject);
- }
- QPushButton *ok = new QPushButton(
- showCancel ? QStringLiteral("确定") : QStringLiteral("知道了"), card);
- ok->setStyleSheet(QStringLiteral(
- "QPushButton { color:#ffffff; background:#2f7fc1; border:1px solid #2f7fc1;"
- " border-radius:4px; padding:5px 16px; font-size:14px; }"
- "QPushButton:hover { background:#2a72ad; border-color:#2a72ad; }"));
- ok->setDefault(true);
- ok->setCursor(Qt::PointingHandCursor);
- foot->addWidget(ok);
- body->addLayout(foot);
- QObject::connect(ok, &QPushButton::clicked, &dlg, &QDialog::accept);
- return dlg.exec() == QDialog::Accepted;
- }
- // 只给一条说明、不需要用户做「确定/取消」的判断(例如执行中任务禁止删除)。
- void showNotice(QWidget *parent, const QString &title, const QString &detail)
- {
- confirmRemove(parent, title, detail, false);
- }
- // 输入任务名字的小弹窗。样式跟 confirmRemove / ResultToast 一套:
- // 白底圆角卡片 + 蓝色主按钮,不用系统 QInputDialog 的灰底。
- bool promptTaskName(QWidget *parent, const QString &defaultName,
- const QStringList &existingNames, QString *out)
- {
- QDialog dlg(parent);
- dlg.setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint);
- dlg.setAttribute(Qt::WA_TranslucentBackground);
- dlg.setWindowTitle(QStringLiteral("创建任务"));
- dlg.setFixedWidth(420);
- QVBoxLayout *outer = new QVBoxLayout(&dlg);
- outer->setContentsMargins(20, 20, 20, 20);
- QFrame *card = new QFrame(&dlg);
- card->setObjectName(QStringLiteral("nameCard"));
- card->setStyleSheet(QStringLiteral(
- "QFrame#nameCard { background:#ffffff; border:1px solid #d3dde9; border-radius:10px; }"
- "QLabel#nameTitle { color:#20323f; font-size:19px; font-weight:600; }"
- "QLabel#nameLabel { color:#5b7183; font-size:15px; }"));
- outer->addWidget(card);
- QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(card);
- shadow->setBlurRadius(32);
- shadow->setOffset(0, 8);
- shadow->setColor(QColor(31, 56, 82, 95));
- card->setGraphicsEffect(shadow);
- QVBoxLayout *body = new QVBoxLayout(card);
- body->setContentsMargins(24, 22, 24, 18);
- body->setSpacing(12);
- QLabel *title = new QLabel(QStringLiteral("创建任务"), card);
- title->setObjectName(QStringLiteral("nameTitle"));
- QLabel *label = new QLabel(QStringLiteral("任务名:"), card);
- label->setObjectName(QStringLiteral("nameLabel"));
- QLineEdit *edit = new QLineEdit(card);
- edit->setText(defaultName);
- edit->selectAll();
- edit->setStyleSheet(QStringLiteral(
- "QLineEdit { background:#ffffff; border:1px solid #d7e0ea; border-radius:4px;"
- " color:#33465a; font-size:16px; padding:6px 10px; }"
- "QLineEdit:focus { border-color:#6ba6d8; }"));
- body->addWidget(title);
- body->addWidget(label);
- body->addWidget(edit);
- QLabel *err = new QLabel(card);
- err->setObjectName(QStringLiteral("nameError"));
- err->setStyleSheet(QStringLiteral("QLabel#nameError { color:#c92f2f; font-size:13px; }"));
- err->setWordWrap(true);
- err->hide();
- body->addWidget(err);
- QHBoxLayout *foot = new QHBoxLayout();
- foot->setContentsMargins(0, 0, 0, 0);
- foot->setSpacing(10);
- foot->addStretch(1);
- QPushButton *cancel = new QPushButton(QStringLiteral("取消"), card);
- cancel->setStyleSheet(QStringLiteral(
- "QPushButton { color:#2f7fc1; background:#ffffff; border:1px solid #cdd7e1;"
- " border-radius:4px; padding:5px 16px; font-size:14px; }"
- "QPushButton:hover { background:#eef4fa; border-color:#b9cfe2; }"));
- QPushButton *ok = new QPushButton(QStringLiteral("确定"), card);
- ok->setStyleSheet(QStringLiteral(
- "QPushButton { color:#ffffff; background:#2f7fc1; border:1px solid #2f7fc1;"
- " border-radius:4px; padding:5px 16px; font-size:14px; }"
- "QPushButton:hover { background:#2a72ad; border-color:#2a72ad; }"));
- ok->setDefault(true);
- cancel->setCursor(Qt::PointingHandCursor);
- ok->setCursor(Qt::PointingHandCursor);
- foot->addWidget(cancel);
- foot->addWidget(ok);
- body->addLayout(foot);
- QObject::connect(cancel, &QPushButton::clicked, &dlg, &QDialog::reject);
- // 任务名不能重复:重名时就在输入框下方红字提示,不关窗、让用户直接改。
- QObject::connect(ok, &QPushButton::clicked, &dlg, [&]() {
- const QString name = edit->text().trimmed();
- if (name.isEmpty()) {
- dlg.reject();
- return;
- }
- if (existingNames.contains(name)) {
- err->setText(QStringLiteral("任务名「%1」已存在,请换一个名字").arg(name));
- err->show();
- edit->setFocus();
- edit->selectAll();
- return;
- }
- dlg.accept();
- });
- QObject::connect(edit, &QLineEdit::textChanged, err, &QLabel::hide);
- QObject::connect(edit, &QLineEdit::returnPressed, ok, &QPushButton::click);
- edit->setFocus();
- if (dlg.exec() != QDialog::Accepted)
- return false;
- const QString name = edit->text().trimmed();
- if (name.isEmpty())
- return false;
- *out = name;
- return true;
- }
- } // namespace
- CreateTaskDialog::CreateTaskDialog(QWidget *parent)
- : QDialog(parent)
- , ui(new Ui::createTaskDialog)
- , m_stationTaskIds(4, QVector<int>())
- {
- ui->setupUi(this);
- // 这个窗口沿用旧版紧凑字体:全局基准是 11.25pt,这里回到 9pt。
- // QSS 里写了 font-size 的控件由 app.qss 末尾的 #createTaskDialog 覆盖规则接手。
- QFont dlgFont = font();
- dlgFont.setPointSizeF(11.25);
- setFont(dlgFont);
- if (QWidget *bar = findChild<QWidget *>(QStringLiteral("targetTempBar")))
- bar->setAttribute(Qt::WA_StyledBackground, true);
- // 参数输入框:只收数字,数字靠左显示
- for (int i = 0; i < kKeyCount; ++i) {
- QLineEdit *ed = findChild<QLineEdit *>(QStringLiteral("paramEdit_%1").arg(i));
- if (!ed)
- continue;
- ed->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
- ed->setValidator(new QIntValidator(0, 99999999, ed));
- }
- // 三组算法清单:每行一个真正的 QCheckBox
- auto setupAlgoList = [this](QListWidget *list, QLabel *badge, QLabel *foot,
- QToolButton *all, QToolButton *none) {
- list->setSelectionMode(QAbstractItemView::NoSelection);
- list->setFocusPolicy(Qt::NoFocus);
- for (int i = 0; i < list->count(); ++i) {
- QListWidgetItem *it = list->item(i);
- const QString text = it->text();
- it->setText(QString());
- it->setFlags(Qt::ItemIsEnabled);
- QCheckBox *cb = new QCheckBox(text, list);
- cb->setProperty("role", "algoCheck");
- cb->setFocusPolicy(Qt::NoFocus);
- cb->setChecked(true);
- it->setSizeHint(QSize(it->sizeHint().width(), cb->sizeHint().height()));
- list->setItemWidget(it, cb);
- }
- auto refresh = [list, badge, foot]() {
- const QList<QCheckBox *> cbs = algoChecks(list);
- int sel = 0;
- for (QCheckBox *cb : cbs)
- if (cb->isChecked())
- ++sel;
- badge->setText(QStringLiteral("%1/%2").arg(sel).arg(cbs.size()));
- foot->setText(QStringLiteral("共 %1 项 · 已选 %2 项").arg(cbs.size()).arg(sel));
- };
- for (QCheckBox *cb : algoChecks(list))
- connect(cb, &QCheckBox::toggled, this, refresh);
- connect(all, &QToolButton::clicked, this, [list]() {
- for (QCheckBox *cb : algoChecks(list))
- cb->setChecked(true);
- });
- connect(none, &QToolButton::clicked, this, [list]() {
- for (QCheckBox *cb : algoChecks(list))
- cb->setChecked(false);
- });
- refresh();
- };
- setupAlgoList(ui->algoList, ui->mtBadge, ui->mtFoot, ui->mtAll, ui->mtNone);
- setupAlgoList(ui->amtList, ui->amtBadge, ui->amtFoot, ui->amtAll, ui->amtNone);
- setupAlgoList(ui->rmtList, ui->rmtBadge, ui->rmtFoot, ui->rmtAll, ui->rmtNone);
- // 卡头的「14/14」计数徽标按需求去掉(三组都一样),只留「全选 / 清空」。
- // 刷新逻辑照旧写文字,只是标签不可见,不影响勾选统计。
- ui->mtBadge->setVisible(false);
- ui->amtBadge->setVisible(false);
- ui->rmtBadge->setVisible(false);
- // 在 MT 算法卡片底部增加 ADDRLIMLO / ADDRLIMHI 区间配置行(支持快速短区间测试与自定义内存范围)
- if (QVBoxLayout *mtLay = qobject_cast<QVBoxLayout *>(ui->mtBox->layout())) {
- QHBoxLayout *rangeRow = new QHBoxLayout();
- rangeRow->setSpacing(6);
- m_mtCustomRange = new QCheckBox(QStringLiteral("限制地址"), ui->mtBox);
- m_mtCustomRange->setProperty("role", "paramCheck");
- m_mtCustomRange->setToolTip(QStringLiteral("勾选后下发 ADDRLIMLO / ADDRLIMHI(如 0x10000000 ~ 0x14000000)"));
- m_mtAddrLoEdit = new QLineEdit(ui->mtBox);
- m_mtAddrLoEdit->setProperty("role", "paramEdit");
- m_mtAddrLoEdit->setPlaceholderText(QStringLiteral("0x10000000"));
- m_mtAddrLoEdit->setMinimumWidth(96);
- QLabel *dash = new QLabel(QStringLiteral("~"), ui->mtBox);
- m_mtAddrHiEdit = new QLineEdit(ui->mtBox);
- m_mtAddrHiEdit->setProperty("role", "paramEdit");
- m_mtAddrHiEdit->setPlaceholderText(QStringLiteral("0x14000000"));
- m_mtAddrHiEdit->setMinimumWidth(96);
- auto syncRangeEnabled = [this](bool on) {
- if (m_mtAddrLoEdit) m_mtAddrLoEdit->setEnabled(on);
- if (m_mtAddrHiEdit) m_mtAddrHiEdit->setEnabled(on);
- };
- connect(m_mtCustomRange, &QCheckBox::toggled, this, syncRangeEnabled);
- syncRangeEnabled(false);
- rangeRow->addWidget(m_mtCustomRange);
- rangeRow->addWidget(m_mtAddrLoEdit, 1);
- rangeRow->addWidget(dash);
- rangeRow->addWidget(m_mtAddrHiEdit, 1);
- const int insertAt = qMax(0, mtLay->count() - 1);
- mtLay->insertLayout(insertAt, rangeRow);
- }
- // 适配小分辨率/高 DPI 桌面(1366x768 或 1080p @ 125%/150%):约束弹窗不超出屏幕可用区域
- if (QScreen *sc = (parent && parent->screen()) ? parent->screen() : QGuiApplication::primaryScreen()) {
- const QRect avail = sc->availableGeometry();
- if (avail.width() > 320 && avail.height() > 240
- && (width() > avail.width() - 24 || height() > avail.height() - 24)) {
- ui->algoList->setMinimumHeight(200);
- ui->amtList->setMinimumHeight(200);
- ui->rmtList->setMinimumHeight(140);
- resize(qMin(width(), qMax(900, avail.width() - 32)),
- qMin(height(), qMax(620, avail.height() - 32)));
- }
- }
- // 「创建任务」/「关闭」按钮。点创建任务只生成任务,不写文件、不关窗。
- QPushButton *ok = ui->buttonBox->button(QDialogButtonBox::Ok);
- ok->setText(QStringLiteral("创建任务"));
- ok->setStyleSheet(QStringLiteral(
- "QPushButton { color:#ffffff; background:#2f7fc1; border:1px solid #2f7fc1;"
- " border-radius:4px; padding:6px 20px; font-size:16px; }"
- "QPushButton:hover { background:#2a72ad; border-color:#2a72ad; }"
- "QPushButton:pressed { background:#256394; }"));
- QPushButton *cancel = ui->buttonBox->button(QDialogButtonBox::Cancel);
- cancel->setText(QStringLiteral("关闭"));
- cancel->setStyleSheet(QStringLiteral(
- "QPushButton { color:#2f7fc1; background:#ffffff; border:1px solid #cdd7e1;"
- " border-radius:4px; padding:6px 20px; font-size:16px; }"
- "QPushButton:hover { background:#eef4fa; border-color:#b9cfe2; }"
- "QPushButton:pressed { background:#e6f2fc; }"));
- connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &CreateTaskDialog::createTask);
- connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
- // 「任务分配」页不需要底部的「创建任务 / 关闭」:只有「创建任务」页(index 0)显示。
- // 切页时同步;分配页仍可用右上角 X(或 Esc)关窗。
- auto syncFooter = [this](int index) {
- ui->buttonBox->setVisible(index == 0);
- };
- connect(ui->taskTabs, &QTabWidget::currentChanged, this, syncFooter);
- syncFooter(ui->taskTabs->currentIndex());
- ui->targetTempEdit->setValidator(new QIntValidator(1, 254, ui->targetTempEdit));
- // 配置页的初始值取 S1 已存配置(不再按工位分别维护一份)
- m_baseCfg = LocalPlans::stationConfig(0);
- ensureMemoryDefaults(m_baseCfg);
- ensureDefaultSelection(m_baseCfg, QStringLiteral("mt"), allItems(ui->algoList));
- ensureDefaultSelection(m_baseCfg, QStringLiteral("amt"), allItems(ui->amtList));
- ensureDefaultSelection(m_baseCfg, QStringLiteral("rmt"), allItems(ui->rmtList));
- loadUiFrom(m_baseCfg);
- buildAssignTab();
- // 从 qt-plans.json 恢复各机台已分配的任务:任务拖拽时已经落盘,
- // 重开软件不能让机台框显示成空的。同名任务在任务池里复用同一个 id。
- for (int s = 0; s < m_stationTaskIds.size(); ++s) {
- const QJsonArray arr = LocalPlans::stationConfig(s)
- .value(QStringLiteral("tasks")).toArray();
- for (const QJsonValue &v : arr) {
- const QJsonObject item = v.toObject();
- const QString name = item.value(QStringLiteral("name")).toString();
- const QJsonObject cfg = item.value(QStringLiteral("config")).toObject();
- if (name.isEmpty() || cfg.isEmpty())
- continue;
- int id = -1;
- for (const SltTask &t : m_tasks)
- if (t.name == name) { id = t.id; break; }
- if (id < 0) {
- SltTask t;
- t.id = m_nextTaskId++;
- t.name = name;
- t.cfg = cfg;
- m_tasks.append(t);
- id = t.id;
- }
- if (!m_stationTaskIds[s].contains(id))
- m_stationTaskIds[s].append(id);
- }
- }
- refreshTaskList();
- refreshStationBoxes();
- }
- CreateTaskDialog::~CreateTaskDialog()
- {
- delete ui;
- }
- // ---------------------------------------------------------------------------
- // 「任务分配」页:左侧任务池 + 右侧四个机台的任务框
- // ---------------------------------------------------------------------------
- void CreateTaskDialog::buildAssignTab()
- {
- QVBoxLayout *root = ui->assignLayout;
- QHBoxLayout *row = new QHBoxLayout();
- row->setSpacing(12);
- // 左:任务池
- QGroupBox *poolBox = new QGroupBox(QStringLiteral("已创建任务"), ui->assignTab);
- poolBox->setProperty("role", "algoBox");
- QVBoxLayout *poolLay = new QVBoxLayout(poolBox);
- poolLay->setContentsMargins(10, 10, 10, 10);
- poolLay->setSpacing(8);
- QHBoxLayout *poolTools = new QHBoxLayout();
- QLabel *poolHint = new QLabel(QStringLiteral("拖到右侧机台"), poolBox);
- poolHint->setProperty("role", "taskHint");
- QToolButton *delBtn = new QToolButton(poolBox);
- delBtn->setText(QStringLiteral("删除选中"));
- delBtn->setCursor(Qt::PointingHandCursor);
- delBtn->setProperty("role", "algoMini");
- poolTools->addWidget(poolHint);
- poolTools->addStretch(1);
- poolTools->addWidget(delBtn);
- poolLay->addLayout(poolTools);
- m_taskList = new TaskSourceList(poolBox);
- m_taskList->setObjectName(QStringLiteral("taskPool"));
- m_taskList->setProperty("role", "taskPool");
- m_taskList->setSelectionMode(QAbstractItemView::SingleSelection);
- // 不要焦点:否则选中项会被 Qt 画一圈点状虚线框,任务名看起来像被框住了
- m_taskList->setFocusPolicy(Qt::NoFocus);
- m_taskList->setDragEnabled(true);
- m_taskList->setDragDropMode(QAbstractItemView::DragOnly);
- m_taskList->setDefaultDropAction(Qt::CopyAction);
- m_taskList->setMinimumWidth(300);
- poolLay->addWidget(m_taskList, 1);
- connect(delBtn, &QToolButton::clicked, this, &CreateTaskDialog::deleteSelectedTask);
- row->addWidget(poolBox, 2);
- // 右:四个机台
- QGroupBox *stationBox = new QGroupBox(QStringLiteral("机台任务分配"), ui->assignTab);
- stationBox->setProperty("role", "algoBox");
- QGridLayout *grid = new QGridLayout(stationBox);
- grid->setContentsMargins(10, 10, 10, 10);
- grid->setSpacing(12);
- for (int i = 0; i < 4; ++i) {
- QFrame *card = new QFrame(stationBox);
- card->setProperty("role", "stationCard");
- card->setAttribute(Qt::WA_StyledBackground, true);
- QVBoxLayout *cardLay = new QVBoxLayout(card);
- cardLay->setContentsMargins(12, 10, 12, 12);
- cardLay->setSpacing(8);
- QHBoxLayout *head = new QHBoxLayout();
- QLabel *title = new QLabel(QStringLiteral("SLT-HT-%1").arg(i + 1, 3, 10, QLatin1Char('0')), card);
- title->setProperty("role", "stationTitle");
- // 标题右边的在线/离线标签,口径跟主界面卡片上的状态完全一致
- QLabel *status = new QLabel(card);
- status->setProperty("role", "stationStatus");
- m_stationStatus.append(status);
- QToolButton *clear = new QToolButton(card);
- clear->setText(QStringLiteral("清空"));
- clear->setCursor(Qt::PointingHandCursor);
- clear->setProperty("role", "algoMini");
- m_stationClearBtns.append(clear);
- head->addWidget(title);
- head->addWidget(status);
- head->addStretch(1);
- head->addWidget(clear);
- cardLay->addLayout(head);
- TaskDropZone *zone = new TaskDropZone(card);
- zone->setProperty("role", "taskDrop");
- zone->setAttribute(Qt::WA_StyledBackground, true);
- zone->setMinimumHeight(76);
- QVBoxLayout *zoneLay = new QVBoxLayout(zone);
- zoneLay->setContentsMargins(10, 8, 10, 8);
- zoneLay->setSpacing(4);
- m_stationChipLays.append(zoneLay); // 任务条由 refreshStationBoxes 动态重建
- connect(clear, &QToolButton::clicked, this, [this, i]() { clearStation(i); });
- zone->onTaskDropped = [this, i](int taskId) { assignTask(i, taskId); };
- zone->canDrop = [this, i]() { return m_onlineProbe ? m_onlineProbe(i) : true; };
- // 执行中的任务鼠标直接显示禁止图标,松手也不会被添加
- zone->canDropTask = [this](int taskId) { return !isTaskRunning(taskId); };
- cardLay->addWidget(zone);
- grid->addWidget(card, i / 2, i % 2);
- }
- row->addWidget(stationBox, 5);
- root->addLayout(row, 1);
- refreshStationBoxes();
- // 机台的在线/离线状态跟着后端走,每秒刷一次标签(后端 state 随时在变)
- QTimer *statusTimer = new QTimer(this);
- statusTimer->setInterval(1000);
- connect(statusTimer, &QTimer::timeout, this, &CreateTaskDialog::refreshStationStatus);
- statusTimer->start();
- refreshStationStatus();
- }
- // ---------------------------------------------------------------------------
- // 点「创建任务」:把配置页当前内容变成一条任务,切到第二个页签
- // ---------------------------------------------------------------------------
- void CreateTaskDialog::createTask()
- {
- // 先问任务名字:取消或留空都不建任务,也不占用编号。
- // 把已有任务名传进去,重名直接在输入框里红字提示,不生成第二条同名任务。
- QStringList existingNames;
- existingNames.reserve(m_tasks.size());
- for (const SltTask &t : m_tasks)
- existingNames.append(t.name);
- QString taskName;
- if (!promptTaskName(this, QStringLiteral("高温标参"), existingNames, &taskName))
- return;
- SltTask t;
- t.id = m_nextTaskId++;
- t.name = taskName;
- t.cfg = currentConfig();
- m_tasks.append(t);
- refreshTaskList();
- ui->taskTabs->setCurrentIndex(1); // 切到任务分配页,底部按钮随之隐藏
- }
- void CreateTaskDialog::refreshTaskList()
- {
- if (!m_taskList)
- return;
- m_taskList->clear();
- // 任务池里只显示任务名字,不铺温度、算法数等摘要
- for (const SltTask &t : m_tasks) {
- QListWidgetItem *it = new QListWidgetItem(m_taskList);
- it->setText(t.name);
- it->setSizeHint(QSize(240, 32));
- it->setData(Qt::UserRole, t.id);
- it->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
- it->setToolTip(QStringLiteral("拖到右侧机台的任务框里完成分配"));
- }
- }
- void CreateTaskDialog::deleteSelectedTask()
- {
- if (!m_taskList || !m_taskList->currentItem())
- return;
- const int id = m_taskList->currentItem()->data(Qt::UserRole).toInt();
- // 执行中的任务不能删:删了会让本地队列和 qt-plans.json 对不上
- if (isTaskRunning(id)) {
- showNotice(this, QStringLiteral("任务执行中"),
- QStringLiteral("「%1」正在执行中,不能删除。请等本轮结束后再操作。")
- .arg(taskNameOf(id)));
- return;
- }
- const QString name = m_taskList->currentItem()->text();
- if (!confirmRemove(this, QStringLiteral("删除任务"),
- QStringLiteral("确定删除任务「%1」吗?\n"
- "已分配到机台的这条任务也会一并移除。").arg(name)))
- return;
- for (int i = 0; i < m_tasks.size(); ++i) {
- if (m_tasks.at(i).id == id) {
- m_tasks.removeAt(i);
- break;
- }
- }
- // 已经挂到机台的任务也要从各机台列表里摘掉并重写该工位 JSON
- for (int s = 0; s < m_stationTaskIds.size(); ++s) {
- if (m_stationTaskIds[s].removeAll(id) > 0) {
- m_saved = saveStationTasks(s);
- emit configsSaved(m_saved, s, QStringLiteral("删除"));
- }
- }
- refreshTaskList();
- refreshStationBoxes();
- }
- void CreateTaskDialog::refreshStationStatus()
- {
- for (int s = 0; s < m_stationStatus.size(); ++s) {
- QLabel *label = m_stationStatus.at(s);
- const bool online = m_onlineProbe ? m_onlineProbe(s) : true;
- const QString text = online ? QStringLiteral("在线") : QStringLiteral("离线");
- const QString state = online ? QStringLiteral("online") : QStringLiteral("offline");
- if (label->text() == text && label->property("state").toString() == state)
- continue;
- label->setText(text);
- label->setProperty("state", state);
- label->style()->unpolish(label);
- label->style()->polish(label);
- }
- // 「执行中」状态随时会变(任务起跑 / 跑完),每秒同步一次「清空」按钮,
- // 免得按钮还停留在上一次的状态。逻辑层 clearStation() 也实时兜底拦截。
- for (int s = 0; s < m_stationClearBtns.size(); ++s) {
- QToolButton *btn = m_stationClearBtns.at(s);
- if (!btn)
- continue;
- const bool locked = stationHasRunningTask(s);
- btn->setEnabled(!locked);
- btn->setToolTip(locked ? QStringLiteral("有任务执行中,不能清空") : QString());
- }
- }
- void CreateTaskDialog::refreshStationBoxes()
- {
- for (int s = 0; s < m_stationChipLays.size(); ++s) {
- QVBoxLayout *lay = m_stationChipLays.at(s);
- QWidget *host = lay->parentWidget();
- QLayoutItem *child = nullptr;
- while ((child = lay->takeAt(0)) != nullptr) {
- if (QWidget *w = child->widget())
- delete w;
- delete child;
- }
- const QVector<int> &ids = m_stationTaskIds.at(s);
- if (ids.isEmpty()) {
- // 空框只留虚线框,不写「把任务拖到这里」的提示字(末尾的 addStretch 负责撑开)
- } else {
- // 按拖入顺序一条一行地列出任务名,像队列一样,不显示「已分配」这类状态字
- for (int n = 0; n < ids.size(); ++n) {
- const int id = ids.at(n);
- QString name;
- for (const SltTask &t : m_tasks)
- if (t.id == id) { name = t.name; break; }
- if (name.isEmpty())
- name = QStringLiteral("已删除任务");
- QFrame *chip = new QFrame(host);
- chip->setProperty("role", "taskChip");
- chip->setAttribute(Qt::WA_StyledBackground, true);
- QHBoxLayout *chipLay = new QHBoxLayout(chip);
- chipLay->setContentsMargins(8, 3, 4, 3);
- chipLay->setSpacing(6);
- const bool running = isTaskRunning(id);
- QLabel *label = new QLabel(QStringLiteral("%1. %2").arg(n + 1).arg(name), chip);
- label->setProperty("role", "taskName");
- if (running)
- label->setToolTip(QStringLiteral("任务执行中,暂不能移除"));
- QToolButton *close = new QToolButton(chip);
- close->setText(QStringLiteral("×"));
- close->setCursor(Qt::PointingHandCursor);
- close->setFocusPolicy(Qt::NoFocus); // 同理,点完不留焦点虚框
- close->setProperty("role", "algoMini");
- close->setEnabled(!running);
- close->setToolTip(running ? QStringLiteral("任务执行中,不能移除")
- : QStringLiteral("从该机台移除这条任务"));
- chipLay->addWidget(label);
- chipLay->addStretch(1);
- chipLay->addWidget(close);
- connect(close, &QToolButton::clicked, this,
- [this, s, id]() { removeTask(s, id); });
- lay->addWidget(chip);
- }
- }
- lay->addStretch(1);
- }
- refreshStationStatus(); // 重铺后立刻同步「清空」按钮的可用状态
- }
- // 把该机台当前的任务列表写进 qt-plans.json:
- // stations.Sn.tasks = [{name, config}, ...],一个机台可以挂多条;
- // 同时保留扁平的 memory_params / rmt / amt / mt(取最后一条任务),
- // 让详情页、stationConfig() 等旧链路照常工作。
- bool CreateTaskDialog::saveStationTasks(int station)
- {
- if (station < 0 || station >= m_stationTaskIds.size())
- return false;
- QJsonArray arr;
- QJsonObject flat;
- for (int id : m_stationTaskIds.at(station)) {
- for (const SltTask &t : m_tasks) {
- if (t.id != id)
- continue;
- QJsonObject item;
- item.insert(QStringLiteral("name"), t.name);
- item.insert(QStringLiteral("config"), t.cfg);
- arr.append(item);
- flat = t.cfg;
- break;
- }
- }
- QJsonObject stationCfg = LocalPlans::stationConfig(station);
- if (!flat.isEmpty()) {
- const QStringList keys = flat.keys();
- for (const QString &k : keys)
- stationCfg.insert(k, flat.value(k));
- }
- stationCfg.insert(QStringLiteral("tasks"), arr);
- QJsonObject one;
- one.insert(QStringLiteral("S%1").arg(station + 1), stationCfg);
- qInfo().noquote() << "[plans] 写工位" << (station + 1) << "任务数 =" << arr.size();
- return LocalPlans::saveStations(one);
- }
- // 拖入机台:追加一条任务(同一任务不重复挂),立刻写该工位 JSON
- void CreateTaskDialog::setOnlineProbe(std::function<bool(int)> probe)
- {
- m_onlineProbe = std::move(probe);
- }
- void CreateTaskDialog::setRunningProbe(std::function<bool(const QString &)> probe)
- {
- m_runningProbe = std::move(probe);
- }
- QString CreateTaskDialog::taskNameOf(int taskId) const
- {
- for (const SltTask &t : m_tasks)
- if (t.id == taskId)
- return t.name;
- return QString();
- }
- bool CreateTaskDialog::isTaskRunning(int taskId) const
- {
- // 任务名是唯一键(创建时已禁止重名),主窗口按「当前工位正在跑的那条任务名」判定。
- const QString name = taskNameOf(taskId);
- return !name.isEmpty() && m_runningProbe && m_runningProbe(name);
- }
- bool CreateTaskDialog::stationHasRunningTask(int station) const
- {
- if (station < 0 || station >= m_stationTaskIds.size())
- return false;
- for (int id : m_stationTaskIds.at(station))
- if (isTaskRunning(id))
- return true;
- return false;
- }
- void CreateTaskDialog::assignTask(int station, int taskId)
- {
- if (station < 0 || station >= m_stationTaskIds.size())
- return;
- // 执行中的任务不能再挂到任何机台。dragEnter 已挡一层,这里再兜底:
- // 拖拽过程中该任务可能刚好开始跑。
- if (isTaskRunning(taskId)) {
- showNotice(this, QStringLiteral("任务执行中"),
- QStringLiteral("「%1」正在执行中,不能添加到任务框。请等本轮结束后再操作。")
- .arg(taskNameOf(taskId)));
- return;
- }
- // 机台显示「控制台离线」时不接收任务(拖拽时已被 dragEnterEvent 拒了,这里双保险)
- if (m_onlineProbe && !m_onlineProbe(station))
- return;
- bool exists = false;
- for (const SltTask &t : m_tasks)
- if (t.id == taskId) { exists = true; break; }
- if (!exists || m_stationTaskIds.at(station).contains(taskId))
- return;
- m_stationTaskIds[station].append(taskId);
- m_saved = saveStationTasks(station);
- refreshStationBoxes();
- // 不再有顶部文字反馈:拖进去之后机台框里直接出现任务条,那就是反馈。
- // 也避免连续拖多条时被弹窗 / 提示打断。
- emit configsSaved(m_saved, station, QStringLiteral("分配"));
- }
- void CreateTaskDialog::removeTask(int station, int taskId)
- {
- if (station < 0 || station >= m_stationTaskIds.size())
- return;
- if (!m_stationTaskIds.at(station).contains(taskId))
- return;
- if (isTaskRunning(taskId)) {
- showNotice(this, QStringLiteral("任务执行中"),
- QStringLiteral("「%1」正在执行中,不能从任务框移除。请等本轮结束后再操作。")
- .arg(taskNameOf(taskId)));
- return;
- }
- QString name;
- for (const SltTask &t : m_tasks)
- if (t.id == taskId) { name = t.name; break; }
- const QString dev = QStringLiteral("SLT-HT-%1").arg(station + 1, 3, 10, QLatin1Char('0'));
- if (!confirmRemove(this, QStringLiteral("移除任务"),
- QStringLiteral("确定从 %1 移除「%2」吗?\n其它机台不受影响。")
- .arg(dev, name)))
- return;
- m_stationTaskIds[station].removeAll(taskId);
- m_saved = saveStationTasks(station);
- refreshStationBoxes();
- emit configsSaved(m_saved, station, QStringLiteral("移除"));
- }
- void CreateTaskDialog::clearStation(int station)
- {
- if (station < 0 || station >= m_stationTaskIds.size())
- return;
- if (m_stationTaskIds.at(station).isEmpty())
- return;
- // 框里只要有一条执行中的任务就整框拒绝清空,避免连正在跑的那条一起删掉
- if (stationHasRunningTask(station)) {
- showNotice(this, QStringLiteral("有任务执行中"),
- QStringLiteral("该机台有正在执行的任务,不能清空。请等本轮结束后再操作。"));
- return;
- }
- const QString dev = QStringLiteral("SLT-HT-%1").arg(station + 1, 3, 10, QLatin1Char('0'));
- if (!confirmRemove(this, QStringLiteral("清空任务"),
- QStringLiteral("确定清空 %1 任务框里的全部 %2 条任务吗?")
- .arg(dev).arg(m_stationTaskIds.at(station).size())))
- return;
- m_stationTaskIds[station].clear();
- m_saved = saveStationTasks(station);
- refreshStationBoxes();
- emit configsSaved(m_saved, station, QStringLiteral("清空"));
- }
- // ---------------------------------------------------------------------------
- // 配置页 ↔ JSON
- // ---------------------------------------------------------------------------
- QJsonObject CreateTaskDialog::currentConfig() const
- {
- QJsonObject cfg = m_baseCfg;
- const QJsonObject mem = params();
- cfg.insert(QStringLiteral("memory_params"), mem);
- QJsonObject mtObj = withSelection(cfg.value(QStringLiteral("mt")).toObject(), algorithms());
- mtObj.insert(QStringLiteral("ecc"), mem.value(QStringLiteral("ecc")).toBool());
- mtObj.insert(QStringLiteral("debuglog"), mem.value(QStringLiteral("debuglog")).toBool());
- if (m_mtCustomRange && m_mtCustomRange->isChecked()) {
- const QString lo = m_mtAddrLoEdit ? m_mtAddrLoEdit->text().trimmed() : QString();
- const QString hi = m_mtAddrHiEdit ? m_mtAddrHiEdit->text().trimmed() : QString();
- if (!lo.isEmpty() || !hi.isEmpty()) {
- mtObj.insert(QStringLiteral("memory_range"), QStringLiteral("custom"));
- if (!lo.isEmpty())
- mtObj.insert(QStringLiteral("addr_lim_lo"), lo);
- else
- mtObj.remove(QStringLiteral("addr_lim_lo"));
- if (!hi.isEmpty())
- mtObj.insert(QStringLiteral("addr_lim_hi"), hi);
- else
- mtObj.remove(QStringLiteral("addr_lim_hi"));
- } else {
- mtObj.insert(QStringLiteral("memory_range"), QStringLiteral("all"));
- mtObj.remove(QStringLiteral("addr_lim_lo"));
- mtObj.remove(QStringLiteral("addr_lim_hi"));
- }
- } else {
- mtObj.insert(QStringLiteral("memory_range"), QStringLiteral("all"));
- mtObj.remove(QStringLiteral("addr_lim_lo"));
- mtObj.remove(QStringLiteral("addr_lim_hi"));
- }
- mtObj.remove(QStringLiteral("ADDRLIMLO"));
- mtObj.remove(QStringLiteral("ADDRLIMHI"));
- mtObj.remove(QStringLiteral("addr_lo"));
- mtObj.remove(QStringLiteral("addr_hi"));
- cfg.insert(QStringLiteral("mt"), mtObj);
- cfg.insert(QStringLiteral("amt"),
- withSelection(cfg.value(QStringLiteral("amt")).toObject(), amtAlgorithms()));
- cfg.insert(QStringLiteral("rmt"),
- withSelection(cfg.value(QStringLiteral("rmt")).toObject(), rmtAlgorithms()));
- return cfg;
- }
- void CreateTaskDialog::loadUiFrom(const QJsonObject &cfg)
- {
- QJsonObject p = cfg.value(QStringLiteral("memory_params")).toObject();
- if (p.isEmpty())
- p = configMemoryParams();
- for (int i = 0; i < kKeyCount; ++i) {
- QLineEdit *ed = findChild<QLineEdit *>(QStringLiteral("paramEdit_%1").arg(i));
- if (!ed)
- continue;
- const int v = p.value(QString::fromLatin1(kKeys[i])).toInt();
- ed->setText(v > 0 ? QString::number(v) : QString());
- }
- ui->errBox->setChecked(p.value(QStringLiteral("errhandle")).toBool());
- ui->apBox->setChecked(p.value(QStringLiteral("ap")).toBool());
- ui->eccBox->setChecked(p.value(QStringLiteral("ecc")).toBool());
- ui->debuglogBox->setChecked(p.value(QStringLiteral("debuglog")).toBool());
- ui->targetTempEdit->setText(QString::number(p.value(QStringLiteral("target_temp")).toInt(70)));
- auto apply = [](QListWidget *list, const QJsonObject &sec) {
- if (!sec.contains(QStringLiteral("selected")))
- return;
- QStringList sel = fromArray(sec.value(QStringLiteral("selected")));
- for (QString &s : sel) {
- if (s == QLatin1String("Adress test, walking ones, 1 CPU"))
- s = QStringLiteral("Address test, walking ones, 1 CPU");
- }
- const QList<QCheckBox *> cbs = algoChecks(list);
- // 存档里的名字一个都对不上当前清单 = 清单换过版,按全选处理,
- // 避免整组显示 0/N 把该阶段静默关掉。空数组是用户主动清空,照旧全不选。
- if (!sel.isEmpty()) {
- bool matched = false;
- for (QCheckBox *cb : cbs) {
- if (sel.contains(cb->text())) {
- matched = true;
- break;
- }
- }
- if (!matched) {
- for (QCheckBox *cb : cbs)
- cb->setChecked(true);
- return;
- }
- }
- for (QCheckBox *cb : cbs)
- cb->setChecked(sel.contains(cb->text()));
- };
- const QJsonObject mtCfg = cfg.value(QStringLiteral("mt")).toObject();
- apply(ui->algoList, mtCfg);
- apply(ui->amtList, cfg.value(QStringLiteral("amt")).toObject());
- apply(ui->rmtList, cfg.value(QStringLiteral("rmt")).toObject());
- if (m_mtCustomRange && m_mtAddrLoEdit && m_mtAddrHiEdit) {
- QString lo = mtCfg.value(QStringLiteral("addr_lim_lo")).toString().trimmed();
- if (lo.isEmpty()) lo = mtCfg.value(QStringLiteral("ADDRLIMLO")).toString().trimmed();
- QString hi = mtCfg.value(QStringLiteral("addr_lim_hi")).toString().trimmed();
- if (hi.isEmpty()) hi = mtCfg.value(QStringLiteral("ADDRLIMHI")).toString().trimmed();
- const bool custom = (mtCfg.value(QStringLiteral("memory_range")).toString() == QLatin1String("custom"))
- || !lo.isEmpty() || !hi.isEmpty();
- m_mtCustomRange->setChecked(custom);
- m_mtAddrLoEdit->setText(lo);
- m_mtAddrHiEdit->setText(hi);
- }
- refreshAll();
- }
- void CreateTaskDialog::refreshAll()
- {
- auto upd = [](QListWidget *list, QLabel *badge, QLabel *foot) {
- const QList<QCheckBox *> cbs = algoChecks(list);
- int sel = 0;
- for (QCheckBox *cb : cbs)
- if (cb->isChecked())
- ++sel;
- badge->setText(QStringLiteral("%1/%2").arg(sel).arg(cbs.size()));
- foot->setText(QStringLiteral("共 %1 项 · 已选 %2 项").arg(cbs.size()).arg(sel));
- };
- upd(ui->algoList, ui->mtBadge, ui->mtFoot);
- upd(ui->amtList, ui->amtBadge, ui->amtFoot);
- upd(ui->rmtList, ui->rmtBadge, ui->rmtFoot);
- }
- QJsonObject CreateTaskDialog::params() const
- {
- // 保留后端 0.8.1.19 支持的扩展 ICT 目录参数(最多 224 项)。
- // 当前表单只编辑常用快捷项,其余已从 config.json / qt-plans.json 载入的键
- // 必须原样留在任务配置里,不能在创建任务时被空对象覆盖掉。
- QJsonObject o = m_baseCfg.value(QStringLiteral("memory_params")).toObject();
- if (o.isEmpty())
- o = configMemoryParams();
- for (int i = 0; i < kKeyCount; ++i) {
- const QString key = QString::fromLatin1(kKeys[i]);
- QLineEdit *ed = findChild<QLineEdit *>(QStringLiteral("paramEdit_%1").arg(i));
- if (!ed)
- continue;
- const QString txt = ed->text().trimmed();
- if (txt.isEmpty()) {
- o.remove(key);
- continue;
- }
- const int v = txt.toInt();
- if (v > 0)
- o.insert(key, v);
- else
- o.remove(key);
- }
- o.insert(QStringLiteral("errhandle"), ui->errBox->isChecked());
- o.insert(QStringLiteral("ap"), ui->apBox->isChecked());
- o.insert(QStringLiteral("ecc"), ui->eccBox->isChecked());
- o.insert(QStringLiteral("debuglog"), ui->debuglogBox->isChecked());
- const int targetTemp = ui->targetTempEdit->text().trimmed().toInt();
- if (targetTemp > 0)
- o.insert(QStringLiteral("target_temp"), targetTemp);
- return o;
- }
- QStringList CreateTaskDialog::algorithms() const
- {
- return checkedItems(ui->algoList);
- }
- QStringList CreateTaskDialog::amtAlgorithms() const
- {
- return checkedItems(ui->amtList);
- }
- QStringList CreateTaskDialog::rmtAlgorithms() const
- {
- return checkedItems(ui->rmtList);
- }
|