Files
QT_wuhan_YT/pages/gasdetector.cpp
T
2026-10-16 09:06:03 +08:00

146 lines
4.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "gasdetector.h"
#include "titlebar.h"
#include "statusstrip.h"
#include "datacard.h"
#include "car.h"
#include "confirmdialog.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QPushButton>
#include "global.h"
GasDetectorPage::GasDetectorPage(AppContext* ctx, QWidget* parent)
: BasePage(ctx, parent)
{
QVBoxLayout* root = new QVBoxLayout(this);
root->setContentsMargins(0, 0, 0, 0);
root->setSpacing(0);
m_titleBar = new TitleBar(ctx, this);
m_titleBar->setTitle("气体检测仪");
root->addWidget(m_titleBar);
QHBoxLayout* main = new QHBoxLayout();
main->setContentsMargins(36, 16, 36, 16);
main->setSpacing(32);
// 中央卡片区:左列 底盘/洗消/机械臂 纵向排列,右列由气体检测仪独占并跨满三行
QWidget* center = new QWidget(this);
QGridLayout* grid = new QGridLayout(center);
grid->setSpacing(20);
grid->setContentsMargins(20, 0, 20, 0);
m_chassisCard = new DataCard("底盘", center);
m_chassisCard->addField("电量", "--");
m_chassisCard->addField("电压", "--");
m_washCard = new DataCard("洗消", center);
m_washCard->addField("A液位", "--");
m_washCard->addField("泡沫液位", "--");
m_armCard = new DataCard("机械臂", center);
m_armCard->addField("末端位置", "--");
m_armCard->addField("姿态", "--");
m_gasCard = new DataCard("气体检测仪", center);
m_gasCard->addField("主机状态", "--");
m_gasCard->addField("有毒物种类", "--");
m_gasCard->addField("有毒物等级", "--");
m_gasConcField = m_gasCard->addField("浓度", "--", true);
m_gasCard->setHighlight(true); // 主色描边突出
grid->addWidget(m_chassisCard, 0, 0);
grid->addWidget(m_washCard, 1, 0);
grid->addWidget(m_armCard, 2, 0);
// 本页主角,独占右列:跨 3 行填满
grid->addWidget(m_gasCard, 0, 1, 3, 1);
main->addWidget(center, 1);
// 右侧按钮列(垂直居中 + 平均分布)
QWidget* right = new QWidget(this);
QVBoxLayout* rightLay = new QVBoxLayout(right);
rightLay->setContentsMargins(40, 40, 40, 40);
rightLay->setSpacing(8);
m_start = button("启动", "primary", right);
m_start->setFixedHeight(100);
connect(m_start, &QPushButton::clicked, this, [this]() {
this->ctx()->comm()->sendGasStart();
this->ctx()->gasRunning = true;
updateGating();
});
m_stop = button("停机", "", right);
m_stop->setFixedHeight(100);
connect(m_stop, &QPushButton::clicked, this, [this]() {
this->ctx()->comm()->sendGasStop();
this->ctx()->gasRunning = false;
updateGating();
});
rightLay->addStretch(1);
rightLay->addWidget(m_start);
rightLay->addStretch(1);
rightLay->addWidget(m_stop);
rightLay->addStretch(1);
right->setFixedWidth(360);
main->addWidget(right);
root->addLayout(main, 1);
m_statusStrip = new StatusStrip(ctx, this);
connect(m_statusStrip, &StatusStrip::backClicked, this, [this]() {
if (this->ctx()->gasRunning) {
if (ConfirmDialog::confirm(this, "提示", "检测仍在进行,是否退出?"))
emit navigate(PageJob);
} else {
emit navigate(PageJob);
}
});
root->addWidget(m_statusStrip);
connect(ctx->comm(), &CarCommunication::telemetryUpdated, this, &GasDetectorPage::refresh);
updateGating();
refresh();
}
void GasDetectorPage::updateGating()
{
bool running = ctx()->gasRunning;
m_start->setEnabled(!running);
m_stop->setEnabled(running);
}
void GasDetectorPage::refresh()
{
const Telemetry& t = ctx()->telemetry;
// 同步运行状态(以遥测为准):未收到报文(gasHost 为空)时按未运行处理
ctx()->gasRunning = (t.gasHost == "detecting");
updateGating();
// 未收到对应报文的数值统一显示 "--"(dashIf)
m_chassisCard->setField(0, dashIf(t.hasBattery, QString("%1%").arg(t.soc)));
m_chassisCard->setField(1, dashIf(t.hasBattery, QString("%1V").arg(t.volt, 0, 'f', 0)));
m_chassisCard->setFaults(t.chassisFaults);
m_washCard->setField(0, dashIf(t.hasWash, QString("%1L").arg(t.levelA, 0, 'f', 0)));
m_washCard->setField(1, dashIf(t.hasWash, QString("%1L").arg(t.levelFoam, 0, 'f', 0)));
m_washCard->setAlarm(0, t.levelALow);
m_washCard->setAlarm(1, t.levelBLow);
m_washCard->setFaults(washCardFaults(t));
m_armCard->setField(0, t.pos);
m_armCard->setField(1, t.pose);
m_gasCard->setField(0, gasHostLabel(t));
m_gasCard->setField(1, t.gasType);
m_gasCard->setField(2, t.gasLevel);
m_gasCard->setField(m_gasConcField, dashIf(t.hasGasConc, QString("%1 ppb").arg(t.gasConc, 0, 'f', 0)));
// 主机状态为“故障”与浓度超限是两回事,各自独立闪
m_gasCard->setAlarm(0, t.gasHost == "fault");
m_gasCard->setAlarm(m_gasConcField, t.gasConc > 500.0);
m_gasCard->setFaults(t.detectorFaults);
}