增加通讯协议
This commit is contained in:
+62
-22
@@ -4,7 +4,8 @@
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include "confirmdialog.h"
|
||||
#include "global.h"
|
||||
|
||||
FaultQueryPage::FaultQueryPage(AppContext* ctx, QWidget* parent)
|
||||
@@ -13,58 +14,98 @@ FaultQueryPage::FaultQueryPage(AppContext* ctx, QWidget* parent)
|
||||
m_categories << "机器人底盘" << "机械臂" << "洗消系统" << "气体检测仪";
|
||||
|
||||
QVBoxLayout* root = new QVBoxLayout(this);
|
||||
root->setContentsMargins(36, 20, 36, 20);
|
||||
root->setSpacing(16);
|
||||
root->setContentsMargins(20, 20, 20, 20);
|
||||
root->setSpacing(30);
|
||||
|
||||
// 顶条:标题 + 汇总数
|
||||
m_title = label("历史故障", 28, C::TEXT, true, this);
|
||||
m_title = label("历史故障", 50, C::TEXT, true, this);
|
||||
root->addWidget(m_title);
|
||||
|
||||
QHBoxLayout* main = new QHBoxLayout();
|
||||
main->setSpacing(28);
|
||||
main->setSpacing(30);
|
||||
|
||||
// 表格
|
||||
m_table = new FaultTable(this);
|
||||
connect(m_table, &FaultTable::rowClicked, this, &FaultQueryPage::onRowClicked);
|
||||
main->addWidget(m_table, 1);
|
||||
|
||||
// 分类按钮列(垂直居中 + 平均分布)
|
||||
// 分类按钮列(左右各留 20px,按钮间距 40px,剩余高度由按钮等分)
|
||||
QWidget* right = new QWidget(this);
|
||||
QVBoxLayout* rightLay = new QVBoxLayout(right);
|
||||
rightLay->setContentsMargins(0, 0, 0, 0);
|
||||
rightLay->setSpacing(8);
|
||||
rightLay->setContentsMargins(80, FaultTable::kHeaderHeight + 10, 30, 80); // 对齐表格内容区后再下移 10px
|
||||
rightLay->setSpacing(60); // 按钮之间的间隔
|
||||
for (const QString& cat : m_categories) {
|
||||
QPushButton* b = button(cat + "故障", "", right);
|
||||
b->setCheckable(true);
|
||||
b->setFixedHeight(110);
|
||||
b->setStyleSheet(QString("font-size:24px;background-color:%1;color:%2;border:1px solid %3;border-radius:12px;")
|
||||
.arg(C::PANEL_HI, C::TEXT, C::BORDER));
|
||||
b->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); // 纵向可拉伸 → 等分剩余空间
|
||||
b->setStyleSheet(QString(
|
||||
"QPushButton{font-size:32px;background-color:%1;color:%2;border:1px solid %3;border-radius:12px;}"
|
||||
"QPushButton:hover,QPushButton:focus,QPushButton:checked"
|
||||
"{background-color:%4;color:#FFFFFF;border:2px solid #8ABFFF;}")
|
||||
.arg(C::PANEL_HI, C::TEXT, C::BORDER, C::PRIMARY));
|
||||
connect(b, &QPushButton::toggled, this, &FaultQueryPage::onCategoryToggled);
|
||||
m_categoryButtons << b;
|
||||
rightLay->addStretch(1);
|
||||
rightLay->addWidget(b);
|
||||
rightLay->addWidget(b, 1);
|
||||
}
|
||||
rightLay->addStretch(1);
|
||||
right->setFixedWidth(360);
|
||||
main->addWidget(right);
|
||||
|
||||
root->addLayout(main, 1);
|
||||
|
||||
// 底部:返回
|
||||
// 底部:返回(预留更大的行高空间)
|
||||
QHBoxLayout* bottomLay = new QHBoxLayout();
|
||||
bottomLay->setContentsMargins(0, 0, 40, 30);
|
||||
bottomLay->addStretch(1);
|
||||
QPushButton* back = button("返回", "", this);
|
||||
back->setFixedSize(144, 76);
|
||||
connect(back, &QPushButton::clicked, this, [this]() { emit navigate(m_returnPage); });
|
||||
bottomLay->addWidget(back);
|
||||
m_back = button("返回", "", this);
|
||||
m_back->setFixedSize(250, 100);
|
||||
m_back->setStyleSheet(cancelButtonStyle(60)); // 选中(悬停/按下/焦点)红底白字
|
||||
connect(m_back, &QPushButton::clicked, this, [this]() { emit navigate(m_returnPage); });
|
||||
bottomLay->addWidget(m_back);
|
||||
root->addLayout(bottomLay);
|
||||
|
||||
// Tab 顺序(循环):表格 → 右侧分类按钮 → 返回 → 上一页 → 下一页 → 回到表格
|
||||
QWidget* first = m_table->view();
|
||||
QWidget* last = first;
|
||||
for (QPushButton* b : m_categoryButtons) {
|
||||
QWidget::setTabOrder(last, b);
|
||||
last = b;
|
||||
}
|
||||
QWidget::setTabOrder(last, m_back);
|
||||
QWidget::setTabOrder(m_back, m_table->prevButton());
|
||||
QWidget::setTabOrder(m_table->prevButton(), m_table->nextButton());
|
||||
QWidget::setTabOrder(m_table->nextButton(), first); // 回到表格,完成循环
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
void FaultQueryPage::showEvent(QShowEvent* ev)
|
||||
{
|
||||
BasePage::showEvent(ev);
|
||||
// 进入页面默认聚焦“分页”(上一页优先;首页禁用时退回下一页,再退回表格)
|
||||
QTimer::singleShot(0, this, [this]() {
|
||||
QWidget* prev = m_table->prevButton();
|
||||
QWidget* next = m_table->nextButton();
|
||||
if (prev->isEnabled()) prev->setFocus();
|
||||
else if (next->isEnabled()) next->setFocus();
|
||||
else m_table->view()->setFocus();
|
||||
});
|
||||
}
|
||||
|
||||
void FaultQueryPage::onCategoryToggled(bool on)
|
||||
{
|
||||
// 单选筛选:确定当前选中的分类
|
||||
// 单选:选中一个分类时,取消其它分类(屏蔽信号,避免它们再触发本函数)
|
||||
QPushButton* src = qobject_cast<QPushButton*>(sender());
|
||||
if (on && src) {
|
||||
for (QPushButton* b : m_categoryButtons) {
|
||||
if (b != src && b->isChecked()) {
|
||||
b->blockSignals(true);
|
||||
b->setChecked(false);
|
||||
b->blockSignals(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 确定当前选中的分类(都没选 = 显示全部)
|
||||
QString selected;
|
||||
for (int i = 0; i < m_categoryButtons.size(); ++i) {
|
||||
if (m_categoryButtons[i]->isChecked()) {
|
||||
@@ -73,7 +114,6 @@ void FaultQueryPage::onCategoryToggled(bool on)
|
||||
}
|
||||
}
|
||||
m_filter = selected;
|
||||
Q_UNUSED(on);
|
||||
refresh();
|
||||
}
|
||||
|
||||
@@ -105,7 +145,7 @@ void FaultQueryPage::onRowClicked(int globalIndex)
|
||||
if (globalIndex < 0 || globalIndex >= data.size())
|
||||
return;
|
||||
const FaultRecord& r = data[globalIndex];
|
||||
QMessageBox::information(this, "故障详情",
|
||||
ConfirmDialog::message(this, "故障详情",
|
||||
QString("故障时间:%1\n分系统:%2\n故障代码:%3\n故障描述:%4")
|
||||
.arg(r.time, r.system, r.code, r.desc));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user