diff --git a/CHANGELOG.md b/CHANGELOG.md
index 212c43e..c964ec6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,14 @@
本项目遵循面向用户的变更记录格式。版本号在正式发布前可能继续调整。
+## [0.1.30] - 2026-11-22
+
+### 改进
+
+- 协议解析的左侧数据面板默认收窄,窗口放大时为曲线留出更多空间。拖动分隔条可调整面板宽度,收起面板后继续采集并显示图例。
+- 单模板时设备地址单独显示,多模板时来源同时显示地址和模板名。悬停在当前值上可查看更新时间,拉宽面板可显示时间列。「编辑协议」移至模板列表旁。
+- 曲线区按当前状态提示等待数据或勾选字段。多设备曲线默认以线条显示,便于比较重叠的波形。
+
## [0.1.29] - 2026-11-17
### 新增
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e18ec28..7a2cc78 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.21)
project(
FluentSerialAssistant
- VERSION 0.1.29
+ VERSION 0.1.30
DESCRIPTION "A Fluent Qt serial assistant prototype"
LANGUAGES CXX
)
diff --git a/README.md b/README.md
index 0a6e9eb..18d386c 100644
--- a/README.md
+++ b/README.md
@@ -115,7 +115,7 @@ macOS 版本未经 Apple 公证,首次打开被系统阻止时,请在“系
可上下拖动数据字段调整顺序,载荷偏移随之更新。字段值按“原始值 × 倍率 + 加值”换算,保存后生效。字节图始终显示,字段列表的色块和 HEX 底色与字节图对应;点击字节图或列表中的字段可联动查看属性;新建或切换到没有保存样例的模板、修改协议配置时,会自动生成匹配样例,并重算长度和校验;也可直接粘贴 HEX 或使用“最新接收”分析实际数据;这类样例在修改名称、倍率等配置时保留原始字节,清空样例后继续编辑可恢复自动生成。样例缺少数据时明确显示缺失字节数。
2. 同一总线上有多个设备时,设置地址字节数和地址在整帧中的偏移,解析窗口会按地址的 HEX 字节分组;不区分地址时选择“不区分设备地址”。同一个模板最多定义 32 个载荷字段,未定义时按载荷字节显示 CH1、CH2 等。
3. 勾选左侧协议模板的“启用”即可打开解析窗口;关闭窗口后可点击“解析数据与曲线”再次打开,沿用当前协议和曲线勾选。需要解析多种帧格式时,在窗口中勾选多个模板。
-4. 列表显示各设备字段的当前值和更新时间,勾选“曲线”即可绘制,共用以秒为单位的时间轴。点击窗口顶部“配置”可收起或展开左侧模板与字段列表,收起后继续采集和绘图,并显示图例以区分设备曲线。窗口最多显示 256 个数据字段,同时绘制 32 条曲线;曲线保留最近 12,000 个点。关闭后再次打开或重启应用会保留曲线勾选。
+4. 列表显示设备地址、字段和当前值。勾选多个模板时,来源同时显示地址和模板名。悬停在当前值上可查看更新时间,拉宽左侧面板也可显示时间列。勾选“曲线”即可绘制,共用以秒为单位的时间轴。点击顶部“数据面板”可收起或展开左侧,收起后继续采集和绘图,并显示图例。窗口最多显示 256 个数据字段,同时绘制 32 条曲线;曲线保留最近 12,000 个点。关闭后再次打开或重启应用会保留曲线勾选。
5. 暂停、隐藏、最小化或关闭窗口时停止采集;清空后保留字段和勾选,更改参与解析的模板或保存模板修改后清空历史。校验失败的帧不更新数值,缺少的字段显示“—”。原始串口流按模板长度字段或固定载荷长度重组分批接收的数据;没有长度信息时,请在接收设置中先配置断帧。已断帧的数据块会跳过长度越界的残缺候选,继续解析后续帧;原始流仍等待声明长度,避免误切载荷中的帧头。
### 曲线窗口
diff --git a/README_EN.md b/README_EN.md
index a13ac39..6ec57d6 100644
--- a/README_EN.md
+++ b/README_EN.md
@@ -117,7 +117,7 @@ The macOS build is not notarized by Apple. If macOS blocks it on first launch, c
Drag data rows up or down to reorder fields and update their payload offsets. Values use `raw × scale + add`; save to apply. The byte map stays visible, with matching color swatches and HEX cell backgrounds in the field list. Selecting a byte or row opens its properties. Creating a template, selecting a template without a saved sample, or editing its configuration automatically generates enough payload bytes and recalculates length and checksum. You can also paste HEX or use **Latest received frame** to inspect actual data; these samples retain their original bytes when names, scaling, or other settings change. Clear the sample and continue editing to resume generation. Incomplete samples report the missing byte count.
2. For a bus with multiple devices, set the address size and its byte offset in the whole frame. Data is grouped by the address's HEX bytes. Choose **No device address grouping** to combine frames from a template. Each template supports 32 payload fields; without definitions, payload bytes appear as CH1, CH2, and so on.
3. Check **Enable** in the sidebar to open analysis with the current template. Use **Data and plot analysis** to reopen the window with the same protocol and curve choices. Check additional templates in the window to parse several frame formats.
-4. The list shows current values and update times for each device's fields. Check **Plot** to draw them on a shared time axis in seconds. Use **Configure** in the toolbar to hide or show the template and field list; capture and plotting continue while it is hidden, with a legend identifying each device curve. The window displays up to 256 fields and 32 curves at a time, retaining the latest 12,000 points per curve. Curve choices survive closing the window and restarting the app.
+4. The list shows device addresses, fields, and current values. When multiple templates are checked, it also shows each template name. Hover over a value to see when it was updated, or widen the panel to show the time column. Check **Plot** to draw fields on a shared time axis in seconds. Use **Data panel** to hide or show the left panel. Capture continues and the chart shows a legend when the panel is hidden. The window displays up to 256 fields and 32 curves at a time, retaining the latest 12,000 points per curve. Curve choices survive closing the window and restarting the app.
5. Pausing, hiding, minimizing, or closing the window stops capture. Clearing keeps fields and curve choices; changing enabled templates or saving template changes clears history. Frames with invalid checksums do not update values; missing fields show “—”. Length fields or a fixed payload length let analysis reassemble raw serial reads; configure receive framing first for templates without length information. Within a completed receive block, incomplete length candidates are skipped so later frames can be decoded. Raw streams continue waiting for the declared length, preserving headers that occur inside payloads.
### Plot windows
diff --git a/docs/images/protocol-analysis-en-dark.png b/docs/images/protocol-analysis-en-dark.png
index c18b8ad..0ee1fcd 100644
Binary files a/docs/images/protocol-analysis-en-dark.png and b/docs/images/protocol-analysis-en-dark.png differ
diff --git a/docs/images/protocol-analysis-en-light.png b/docs/images/protocol-analysis-en-light.png
index cb5b678..484d132 100644
Binary files a/docs/images/protocol-analysis-en-light.png and b/docs/images/protocol-analysis-en-light.png differ
diff --git a/docs/images/protocol-analysis-zh-dark.png b/docs/images/protocol-analysis-zh-dark.png
index 41867d0..b675887 100644
Binary files a/docs/images/protocol-analysis-zh-dark.png and b/docs/images/protocol-analysis-zh-dark.png differ
diff --git a/docs/images/protocol-analysis-zh-light.png b/docs/images/protocol-analysis-zh-light.png
index 310719d..46d09f9 100644
Binary files a/docs/images/protocol-analysis-zh-light.png and b/docs/images/protocol-analysis-zh-light.png differ
diff --git a/docs/release-notes/v0.1.30.md b/docs/release-notes/v0.1.30.md
new file mode 100644
index 0000000..4e1bdb9
--- /dev/null
+++ b/docs/release-notes/v0.1.30.md
@@ -0,0 +1,13 @@
+协议解析窗口为实时曲线留出了更多空间。
+
+- 左侧「数据面板」默认收窄,可拖动分隔条调整宽度。收起后曲线占满窗口,继续采集并显示图例。
+- 单模板时显示设备地址,多模板时同时显示模板名。悬停在当前值上可查看更新时间,拉宽面板可显示时间列。「编辑协议」现在位于模板列表旁。
+- 未开始绘图时,曲线区会提示等待数据或勾选字段。多设备曲线默认用线条显示,重叠的波形更容易区分。
+
+## English
+
+The protocol analysis window gives live plots more room.
+
+- The left **Data panel** starts narrower. Drag the divider to resize it. Hiding the panel gives the plot the full width and shows a legend while capture continues.
+- With one template selected, the list shows device addresses. With multiple templates, it also shows their names. Hover over a reading for its update time, or widen the panel to see the time column. **Edit protocol** now sits beside the template list.
+- When there is no plot yet, the chart area shows the next step. The default line display makes overlapping device curves easier to compare.
diff --git a/src/app/resources/i18n/fluentserialassistant.en_US.qm b/src/app/resources/i18n/fluentserialassistant.en_US.qm
index 4f33314..4315add 100644
Binary files a/src/app/resources/i18n/fluentserialassistant.en_US.qm and b/src/app/resources/i18n/fluentserialassistant.en_US.qm differ
diff --git a/src/app/resources/i18n/fluentserialassistant.en_US.ts b/src/app/resources/i18n/fluentserialassistant.en_US.ts
index 04859be..f956f23 100644
--- a/src/app/resources/i18n/fluentserialassistant.en_US.ts
+++ b/src/app/resources/i18n/fluentserialassistant.en_US.ts
@@ -194,16 +194,28 @@ Displayed = raw × %3 + %4
Templates to parse
- 勾选字段即可显示曲线;载荷字段、倍率和设备地址在编辑协议中设置。
- Check fields to plot them. Configure payload fields, scaling, and device addresses in Edit protocol.
+ 数据面板
+ Data panel
- 曲线
- Plot
+ 启用协议解析以接收数据
+ Enable protocol analysis to receive data
+
+
+ 点击“继续”恢复采集
+ Click Resume to continue capturing data
+
+
+ 在数据面板中勾选要解析的模板
+ Check a template in the data panel to parse its frames
+
+
+ 在数据面板中勾选要绘制的字段
+ Check a field in the data panel to plot it
- 模板 / 地址
- Template / address
+ 曲线
+ Plot
更新时间
diff --git a/src/app/resources/i18n/fluentserialassistant.zh_CN.qm b/src/app/resources/i18n/fluentserialassistant.zh_CN.qm
index 5081035..da5070f 100644
Binary files a/src/app/resources/i18n/fluentserialassistant.zh_CN.qm and b/src/app/resources/i18n/fluentserialassistant.zh_CN.qm differ
diff --git a/src/app/resources/i18n/fluentserialassistant.zh_CN.ts b/src/app/resources/i18n/fluentserialassistant.zh_CN.ts
index 5e7572c..5b9eb7a 100644
--- a/src/app/resources/i18n/fluentserialassistant.zh_CN.ts
+++ b/src/app/resources/i18n/fluentserialassistant.zh_CN.ts
@@ -194,16 +194,28 @@
参与解析的模板
- 勾选字段即可显示曲线;载荷字段、倍率和设备地址在编辑协议中设置。
- 勾选字段即可显示曲线;载荷字段、倍率和设备地址在编辑协议中设置。
+ 数据面板
+ 数据面板
- 曲线
- 曲线
+ 启用协议解析以接收数据
+ 启用协议解析以接收数据
+
+
+ 点击“继续”恢复采集
+ 点击“继续”恢复采集
+
+
+ 在数据面板中勾选要解析的模板
+ 在数据面板中勾选要解析的模板
+
+
+ 在数据面板中勾选要绘制的字段
+ 在数据面板中勾选要绘制的字段
- 模板 / 地址
- 模板 / 地址
+ 曲线
+ 曲线
更新时间
diff --git a/src/app/view/protocol_analysis_window.cpp b/src/app/view/protocol_analysis_window.cpp
index 7fccf17..fc5a504 100644
--- a/src/app/view/protocol_analysis_window.cpp
+++ b/src/app/view/protocol_analysis_window.cpp
@@ -2,6 +2,7 @@
#include "app/core/app_i18n.h"
#include "app/core/app_settings.h"
+#include "app/core/font_preferences.h"
#include "app/core/hex_utils.h"
#include "app/view/muted_text.h"
@@ -11,10 +12,12 @@
#include
#include
#include
+#include
#include
#include
#include
#include
+#include
#include
#include
@@ -23,9 +26,33 @@
namespace {
constexpr int MaximumRows = 256;
+constexpr int DefaultPanelWidth = 380;
constexpr auto SelectedTemplatesKey = "protocolAnalysis/templates";
constexpr auto CurveKeysKey = "protocolAnalysis/curves";
+enum ValueColumn
+{
+ CurveColumn,
+ SourceColumn,
+ FieldColumn,
+ ReadingColumn,
+ UpdatedColumn,
+ ValueColumnCount
+};
+
+class AnalysisValuesTable final : public FluentQt::TableWidget
+{
+ public:
+ using TableWidget::TableWidget;
+
+ protected:
+ void resizeEvent(QResizeEvent *event) override
+ {
+ TableWidget::resizeEvent(event);
+ setColumnHidden(UpdatedColumn, width() < 490);
+ }
+};
+
QString channelKey(const QString &templateName, const QString &address, const QString &fieldName)
{
return QString::fromUtf8(
@@ -52,19 +79,16 @@ ProtocolAnalysisWindow::ProtocolAnalysisWindow(QWidget *parent) : QWidget(parent
auto *toolbar = new QHBoxLayout;
m_enabledCheck = new CheckBox(AppI18n::text("启用协议解析"), this);
m_enabledCheck->setObjectName(QStringLiteral("protocolAnalysisEnabled"));
- auto *edit = new PushButton(icon(FluentIcon::Edit), AppI18n::text("编辑协议"), this);
- edit->setObjectName(QStringLiteral("protocolAnalysisEdit"));
m_pauseButton = new PushButton(icon(FluentIcon::Pause), AppI18n::text("暂停"), this);
m_pauseButton->setObjectName(QStringLiteral("protocolAnalysisPause"));
- auto *clear = new PushButton(AppI18n::text("清空"), this);
+ auto *clear = new PushButton(icon(FluentIcon::Broom), AppI18n::text("清空"), this);
clear->setObjectName(QStringLiteral("protocolAnalysisClear"));
- auto *reset = new PushButton(AppI18n::text("复位视图"), this);
- auto *configuration = new ToggleButton(icon(FluentIcon::Setting), AppI18n::text("配置"), this);
+ auto *reset = new PushButton(icon(FluentIcon::FitPage), AppI18n::text("复位视图"), this);
+ auto *configuration = new ToggleButton(icon(FluentIcon::View), AppI18n::text("数据面板"), this);
configuration->setObjectName(QStringLiteral("protocolAnalysisConfigurationToggle"));
configuration->setChecked(true);
toolbar->addWidget(configuration);
toolbar->addWidget(m_enabledCheck);
- toolbar->addWidget(edit);
toolbar->addStretch();
toolbar->addWidget(m_pauseButton);
toolbar->addWidget(clear);
@@ -73,55 +97,70 @@ ProtocolAnalysisWindow::ProtocolAnalysisWindow(QWidget *parent) : QWidget(parent
auto *splitter = new QSplitter(Qt::Horizontal, this);
splitter->setChildrenCollapsible(false);
- auto *panel = new QWidget(splitter);
+ auto *panel = new SimpleCardWidget(splitter);
panel->setObjectName(QStringLiteral("protocolAnalysisConfiguration"));
- panel->setMinimumWidth(500);
+ panel->setMinimumWidth(322);
auto *panelLayout = new QVBoxLayout(panel);
- panelLayout->setContentsMargins(0, 0, 8, 0);
+ panelLayout->setContentsMargins(10, 8, 10, 10);
+ panelLayout->setSpacing(6);
+ auto *templateBar = new QHBoxLayout;
+ auto *templateLabel = new StrongBodyLabel(AppI18n::text("参与解析的模板"), panel);
+ auto *edit = new TransparentPushButton(icon(FluentIcon::Edit), AppI18n::text("编辑协议"), panel);
+ edit->setObjectName(QStringLiteral("protocolAnalysisEdit"));
+ templateBar->addWidget(templateLabel);
+ templateBar->addStretch();
+ templateBar->addWidget(edit);
+ panelLayout->addLayout(templateBar);
+
m_templateTable = new TableWidget(panel);
m_templateTable->setObjectName(QStringLiteral("protocolAnalysisTemplates"));
+ m_templateTable->setAccessibleName(templateLabel->text());
m_templateTable->setColumnCount(1);
- m_templateTable->setHorizontalHeaderLabels({AppI18n::text("参与解析的模板")});
m_templateTable->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
+ m_templateTable->horizontalHeader()->hide();
m_templateTable->verticalHeader()->hide();
- m_templateTable->verticalHeader()->setDefaultSectionSize(36);
+ m_templateTable->verticalHeader()->setDefaultSectionSize(32);
m_templateTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_templateTable->setSelectionBehavior(QAbstractItemView::SelectRows);
m_templateTable->setSelectionMode(QAbstractItemView::SingleSelection);
- m_templateTable->setMinimumHeight(86);
- m_templateTable->setMaximumHeight(140);
+ m_templateTable->setFixedHeight(32);
panelLayout->addWidget(m_templateTable);
- auto *hint =
- new CaptionLabel(AppI18n::text("勾选字段即可显示曲线;载荷字段、倍率和设备地址在编辑协议中设置。"), panel);
- hint->setWordWrap(true);
- AppUi::setMutedTextColor(hint);
- panelLayout->addWidget(hint);
- m_valueTable = new TableWidget(panel);
+
+ panelLayout->addSpacing(4);
+ m_valueTable = new AnalysisValuesTable(panel);
m_valueTable->setObjectName(QStringLiteral("protocolAnalysisValues"));
- m_valueTable->setColumnCount(5);
- m_valueTable->setHorizontalHeaderLabels({AppI18n::text("曲线"), AppI18n::text("模板 / 地址"), AppI18n::text("字段"),
+ m_valueTable->setColumnCount(ValueColumnCount);
+ m_valueTable->setHorizontalHeaderLabels({AppI18n::text("曲线"), AppI18n::text("来源"), AppI18n::text("字段"),
AppI18n::text("当前值"), AppI18n::text("更新时间")});
auto *header = m_valueTable->horizontalHeader();
- header->setSectionResizeMode(0, QHeaderView::Fixed);
- m_valueTable->setColumnWidth(0, 52);
- header->setSectionResizeMode(1, QHeaderView::Stretch);
- header->setSectionResizeMode(2, QHeaderView::Stretch);
- for (int column : {3, 4}) {
- header->setSectionResizeMode(column, QHeaderView::Fixed);
- m_valueTable->setColumnWidth(column, column == 3 ? 92 : 132);
- }
+ header->setSectionResizeMode(QHeaderView::Fixed);
+ header->setSectionResizeMode(SourceColumn, QHeaderView::Stretch);
+ header->setSectionResizeMode(FieldColumn, QHeaderView::Stretch);
+ m_valueTable->setColumnWidth(CurveColumn, 46);
+ m_valueTable->setColumnWidth(ReadingColumn, 102);
+ m_valueTable->setColumnWidth(UpdatedColumn, 118);
+ m_valueTable->setColumnHidden(UpdatedColumn, true);
+ for (int column : {SourceColumn, FieldColumn})
+ m_valueTable->horizontalHeaderItem(column)->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter);
+ const auto cellPadding =
+ QStringLiteral("QTableWidget#protocolAnalysisValues::item { padding-left: 12px; padding-right: 10px; }");
+ FluentStyleSheet::setCustomStyleSheet(m_valueTable, cellPadding, cellPadding);
m_valueTable->verticalHeader()->hide();
- m_valueTable->verticalHeader()->setDefaultSectionSize(36);
+ m_valueTable->verticalHeader()->setDefaultSectionSize(32);
m_valueTable->setEditTriggers(QAbstractItemView::NoEditTriggers);
m_valueTable->setWordWrap(false);
m_valueTable->setSelectionBehavior(QAbstractItemView::SelectRows);
panelLayout->addWidget(m_valueTable, 1);
- m_plot = new RealtimePlotWidget(splitter);
+
+ m_plotStack = new QStackedWidget(splitter);
+ m_plot = new RealtimePlotWidget(m_plotStack);
m_plot->setObjectName(QStringLiteral("protocolAnalysisPlot"));
m_plot->setCapacity(12000);
m_plot->setVisibleSpan(10);
m_plot->setMaximumVisiblePoints(2000);
m_plot->setLegendVisible(false);
+ m_plot->setValueTagsVisible(false);
+ m_plot->setFillVisible(false);
m_plot->setCrosshairVisible(true);
m_plot->setAutoScroll(true);
m_plot->setAutoYRange(true);
@@ -129,15 +168,31 @@ ProtocolAnalysisWindow::ProtocolAnalysisWindow(QWidget *parent) : QWidget(parent
m_refreshRate = m_plot->refreshRate();
m_plot->setRefreshRate(0);
m_plot->setUpdatesEnabled(false);
+ m_plotStack->addWidget(m_plot);
+ auto *emptyPlot = new SimpleCardWidget(m_plotStack);
+ auto *emptyLayout = new QVBoxLayout(emptyPlot);
+ auto *plotIcon = new IconWidget(FluentIcon::Market, emptyPlot);
+ plotIcon->setFixedSize(30, 30);
+ m_plotHint = new BodyLabel(emptyPlot);
+ m_plotHint->setWordWrap(true);
+ m_plotHint->setAlignment(Qt::AlignCenter);
+ AppUi::setMutedTextColor(m_plotHint);
+ emptyLayout->addStretch();
+ emptyLayout->addWidget(plotIcon, 0, Qt::AlignHCenter);
+ emptyLayout->addWidget(m_plotHint);
+ emptyLayout->addStretch();
+ m_plotStack->addWidget(emptyPlot);
+
splitter->addWidget(panel);
- splitter->addWidget(m_plot);
- splitter->setStretchFactor(0, 1);
+ splitter->addWidget(m_plotStack);
+ splitter->setStretchFactor(0, 0);
splitter->setStretchFactor(1, 1);
- splitter->setSizes({570, 680});
+ splitter->setSizes({DefaultPanelWidth, width() - DefaultPanelWidth});
root->addWidget(splitter, 1);
connect(configuration, &PushButton::toggled, this, [this, panel](bool visible) {
panel->setVisible(visible);
m_plot->setLegendVisible(!visible);
+ m_plot->setValueTagsVisible(!visible);
});
m_status = new CaptionLabel(this);
m_status->setObjectName(QStringLiteral("protocolAnalysisStatus"));
@@ -176,7 +231,7 @@ ProtocolAnalysisWindow::ProtocolAnalysisWindow(QWidget *parent) : QWidget(parent
resetChannels();
});
connect(m_valueTable, &TableWidget::itemChanged, this, [this](QTableWidgetItem *item) {
- if (item->column() == 0) {
+ if (item->column() == CurveColumn) {
setCurveVisible(item->row(), item->checkState() == Qt::Checked);
}
});
@@ -203,12 +258,14 @@ void ProtocolAnalysisWindow::setProtocolTemplates(const QListsetFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
name->setCheckState(m_selectedTemplates.contains(item.name) ? Qt::Checked : Qt::Unchecked);
+ name->setToolTip(item.name);
m_templateTable->setItem(row, 0, name);
if (item.name == selectedTemplate) {
m_templateTable->selectRow(row);
}
}
- m_templateTable->setFixedHeight(qBound(86, 36 * (int(m_templates.size()) + 1) + 4, 140));
+ m_templateTable->setFixedHeight(m_templateTable->verticalHeader()->defaultSectionSize() *
+ qBound(1, int(m_templates.size()), 3));
resetChannels();
}
@@ -258,6 +315,16 @@ void ProtocolAnalysisWindow::changeEvent(QEvent *event)
void ProtocolAnalysisWindow::resetChannels()
{
+ const auto isSelected = [this](const auto &item) { return m_selectedTemplates.contains(item.name); };
+ const auto first = std::find_if(m_templates.cbegin(), m_templates.cend(), isSelected);
+ const bool singleTemplate = first != m_templates.cend() && std::none_of(first + 1, m_templates.cend(), isSelected);
+ m_addressOnly = singleTemplate && first->addressSize > 0;
+ m_valueTable->horizontalHeaderItem(SourceColumn)->setText(AppI18n::text(m_addressOnly ? "地址" : "来源"));
+ auto *header = m_valueTable->horizontalHeader();
+ header->setSectionResizeMode(SourceColumn, m_addressOnly ? QHeaderView::Fixed : QHeaderView::Stretch);
+ if (m_addressOnly)
+ m_valueTable->setColumnWidth(SourceColumn, qMax(68, 36 + 21 * first->addressSize));
+
m_channels.clear();
m_channelIndexes.clear();
m_valueTable->setRowCount(0);
@@ -267,7 +334,7 @@ void ProtocolAnalysisWindow::resetChannels()
m_limited = false;
clearData();
for (const auto &item : m_templates) {
- if (m_selectedTemplates.contains(item.name) && item.addressSize == 0) {
+ if (isSelected(item) && item.addressSize == 0) {
for (const auto &field : item.payloadFields) {
channelFor(item.name, {}, field.name);
}
@@ -305,10 +372,10 @@ int ProtocolAnalysisWindow::channelFor(const QString &templateName, const QStrin
return -1;
}
const int row = m_channels.size();
- const QString device = templateName + (address.isEmpty() ? QString() : QStringLiteral(" · ") + address);
+ const QString source = address.isEmpty() ? templateName : address + QStringLiteral(" · ") + templateName;
Channel channel;
channel.key = key;
- channel.label = device + QStringLiteral(" / ") + fieldName;
+ channel.label = source + QStringLiteral(" / ") + fieldName;
channel.value = std::numeric_limits::quiet_NaN();
m_channels.append(channel);
m_channelIndexes.insert(key, row);
@@ -318,14 +385,19 @@ int ProtocolAnalysisWindow::channelFor(const QString &templateName, const QStrin
for (int column = 0; column < m_valueTable->columnCount(); ++column) {
m_valueTable->setItem(row, column, new QTableWidgetItem);
}
- auto *check = m_valueTable->item(row, 0);
+ auto *check = m_valueTable->item(row, CurveColumn);
check->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable);
check->setCheckState(m_curveKeys.contains(key) ? Qt::Checked : Qt::Unchecked);
- m_valueTable->item(row, 1)->setText(device);
- m_valueTable->item(row, 1)->setToolTip(device);
- m_valueTable->item(row, 2)->setText(fieldName);
- m_valueTable->item(row, 2)->setToolTip(fieldName);
- m_valueTable->item(row, 3)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
+ m_valueTable->item(row, SourceColumn)->setText(m_addressOnly ? address : source);
+ m_valueTable->item(row, SourceColumn)->setToolTip(source);
+ m_valueTable->item(row, FieldColumn)->setText(fieldName);
+ m_valueTable->item(row, FieldColumn)->setToolTip(fieldName);
+ QFont numberFont = AppFontPreferences::inputMonospaceFont();
+ numberFont.setPixelSize(13);
+ for (int column : {ReadingColumn, UpdatedColumn}) {
+ m_valueTable->item(row, column)->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
+ m_valueTable->item(row, column)->setFont(numberFont);
+ }
}
if (m_curveKeys.contains(key)) {
setCurveVisible(row, true);
@@ -339,10 +411,10 @@ void ProtocolAnalysisWindow::setCurveVisible(int row, bool visible)
const QSignalBlocker blocker(m_valueTable);
int checked = 0;
for (int index = 0; index < m_valueTable->rowCount(); ++index) {
- checked += m_valueTable->item(index, 0)->checkState() == Qt::Checked;
+ checked += m_valueTable->item(index, CurveColumn)->checkState() == Qt::Checked;
}
if (visible && checked > AppPlot::MaximumChannels) {
- m_valueTable->item(row, 0)->setCheckState(Qt::Unchecked);
+ m_valueTable->item(row, CurveColumn)->setCheckState(Qt::Unchecked);
m_limited = true;
updateStatus();
return;
@@ -359,7 +431,7 @@ void ProtocolAnalysisWindow::setCurveVisible(int row, bool visible)
}
QPixmap swatch(10, 10);
swatch.fill(m_plot->seriesColor(channel.series));
- m_valueTable->item(row, 2)->setIcon(QIcon(swatch));
+ m_valueTable->item(row, FieldColumn)->setIcon(QIcon(swatch));
}
if (channel.series >= 0) {
m_plot->setSeriesVisible(channel.series, visible);
@@ -371,6 +443,7 @@ void ProtocolAnalysisWindow::setCurveVisible(int row, bool visible)
}
AppSettings settings;
settings.setValue(QLatin1String(CurveKeysKey), m_curveKeys.values());
+ updateStatus();
}
void ProtocolAnalysisWindow::appendRecord(const QDateTime ×tamp, const QByteArray &bytes, bool stream)
@@ -439,15 +512,19 @@ void ProtocolAnalysisWindow::appendFrame(const QDateTime ×tamp, const QByte
void ProtocolAnalysisWindow::updateValues()
{
const QSignalBlocker blocker(m_valueTable);
+ const QString updatedLabel = AppI18n::text("更新时间");
for (int row = 0; row < m_channels.size(); ++row) {
const auto &channel = m_channels.at(row);
- m_valueTable->item(row, 3)->setText(std::isfinite(channel.value) ? QString::number(channel.value, 'g', 12)
- : QStringLiteral("—"));
- m_valueTable->item(row, 3)->setToolTip(std::isfinite(channel.value) ? QString::number(channel.value, 'g', 16)
- : QString());
- m_valueTable->item(row, 4)->setText(channel.timestamp.isValid()
- ? channel.timestamp.toString(QStringLiteral("HH:mm:ss.zzz"))
- : QStringLiteral("—"));
+ const bool hasValue = std::isfinite(channel.value);
+ const bool hasTime = channel.timestamp.isValid();
+ const auto time = hasTime ? channel.timestamp.toString(QStringLiteral("HH:mm:ss.zzz")) : QStringLiteral("—");
+ auto *reading = m_valueTable->item(row, ReadingColumn);
+ reading->setText(hasValue ? QString::number(channel.value, 'g', 12) : QStringLiteral("—"));
+ reading->setToolTip(
+ hasTime ? QStringLiteral("%1\n%2 %3")
+ .arg(hasValue ? QString::number(channel.value, 'g', 16) : reading->text(), updatedLabel, time)
+ : QString());
+ m_valueTable->item(row, UpdatedColumn)->setText(time);
}
updateStatus();
}
@@ -459,12 +536,32 @@ void ProtocolAnalysisWindow::updateStatus()
: AppI18n::text("实时");
QString text =
AppI18n::text("%1 · %2 帧 · %3 个数据字段 · 横轴为秒").arg(state).arg(m_frameCount).arg(m_channels.size());
- if (m_channels.isEmpty()) {
- text += QStringLiteral(" · ") + AppI18n::text("等待接收所选协议的数据");
- }
if (m_limited) {
text += QStringLiteral(" · ") +
AppI18n::text("最多显示 %1 个字段,同时绘制 %2 条曲线").arg(MaximumRows).arg(AppPlot::MaximumChannels);
}
m_status->setText(text);
+
+ const bool plotting = m_plot->sampleCount() > 0 &&
+ std::any_of(m_channels.cbegin(), m_channels.cend(),
+ [this](const Channel &channel) { return m_curveKeys.contains(channel.key); });
+ if (plotting) {
+ m_plotStack->setCurrentWidget(m_plot);
+ return;
+ }
+ const bool templateSelected = std::any_of(m_templates.cbegin(), m_templates.cend(), [this](const auto &item) {
+ return m_selectedTemplates.contains(item.name);
+ });
+ if (!m_enabledCheck->isChecked()) {
+ m_plotHint->setText(AppI18n::text("启用协议解析以接收数据"));
+ } else if (m_paused) {
+ m_plotHint->setText(AppI18n::text("点击“继续”恢复采集"));
+ } else if (!templateSelected) {
+ m_plotHint->setText(AppI18n::text("在数据面板中勾选要解析的模板"));
+ } else if (m_frameCount == 0 || m_channels.isEmpty()) {
+ m_plotHint->setText(AppI18n::text("等待接收所选协议的数据"));
+ } else {
+ m_plotHint->setText(AppI18n::text("在数据面板中勾选要绘制的字段"));
+ }
+ m_plotStack->setCurrentWidget(m_plotHint->parentWidget());
}
diff --git a/src/app/view/protocol_analysis_window.h b/src/app/view/protocol_analysis_window.h
index e5e81d7..fda5b91 100644
--- a/src/app/view/protocol_analysis_window.h
+++ b/src/app/view/protocol_analysis_window.h
@@ -7,8 +7,10 @@
#include
#include
+class QStackedWidget;
class QTimer;
namespace FluentQt {
+class BodyLabel;
class CaptionLabel;
class CheckBox;
class PushButton;
@@ -69,7 +71,9 @@ class ProtocolAnalysisWindow : public QWidget
FluentQt::PushButton *m_pauseButton = nullptr;
FluentQt::TableWidget *m_templateTable = nullptr;
FluentQt::TableWidget *m_valueTable = nullptr;
+ QStackedWidget *m_plotStack = nullptr;
FluentQt::RealtimePlotWidget *m_plot = nullptr;
+ FluentQt::BodyLabel *m_plotHint = nullptr;
FluentQt::CaptionLabel *m_status = nullptr;
QTimer *m_valueTimer = nullptr;
QDateTime m_startTime;
@@ -77,6 +81,7 @@ class ProtocolAnalysisWindow : public QWidget
qint64 m_frameCount = 0;
int m_allocatedSeries = 0;
int m_refreshRate = 30;
+ bool m_addressOnly = false;
bool m_paused = false;
bool m_limited = false;
};
diff --git a/tests/tst_protocol_analysis.cpp b/tests/tst_protocol_analysis.cpp
index 9f52c20..5621113 100644
--- a/tests/tst_protocol_analysis.cpp
+++ b/tests/tst_protocol_analysis.cpp
@@ -227,8 +227,8 @@ class ProtocolAnalysisTest : public QObject
QCOMPARE(table->rowCount(), 6);
QTRY_COMPARE(table->item(0, 3)->text(), QStringLiteral("70.33"));
QTRY_COMPARE(table->item(3, 3)->text(), QStringLiteral("-59.04"));
- QVERIFY(table->item(0, 1)->text().endsWith(QStringLiteral("01")));
- QVERIFY(table->item(3, 1)->text().endsWith(QStringLiteral("02")));
+ QCOMPARE(table->item(0, 1)->text(), QStringLiteral("01"));
+ QCOMPARE(table->item(3, 1)->text(), QStringLiteral("02"));
table->item(0, 0)->setCheckState(Qt::Checked);
table->item(3, 0)->setCheckState(Qt::Checked);
QCOMPARE(plot(window)->seriesCount(), 2);
@@ -263,6 +263,8 @@ class ProtocolAnalysisTest : public QObject
QCOMPARE(values(window)->rowCount(), 6);
QTRY_COMPARE(values(window)->item(0, 3)->text(), QStringLiteral("1.23"));
QTRY_COMPARE(values(window)->item(3, 3)->text(), QStringLiteral("4.56"));
+ QCOMPARE(values(window)->item(0, 1)->text(), QStringLiteral("01 · Motors"));
+ QCOMPARE(values(window)->item(3, 1)->text(), QStringLiteral("01 · Sensors"));
templates->item(0, 0)->setCheckState(Qt::Unchecked);
window.appendRecord(now, motorFrame(1));
QCOMPARE(values(window)->rowCount(), 0);
@@ -286,7 +288,7 @@ class ProtocolAnalysisTest : public QObject
bad[bad.size() - 1] ^= 0x01;
window.appendRecord(now, bad + motorFrame(4), true);
QCOMPARE(values(window)->rowCount(), 9);
- QVERIFY(values(window)->item(6, 1)->text().endsWith(QStringLiteral("04")));
+ QCOMPARE(values(window)->item(6, 1)->text(), QStringLiteral("04"));
}
void endedRecordsRecoverAfterAnIncompleteLengthCandidate()