129 lines
4.0 KiB
C++
129 lines
4.0 KiB
C++
#include "VersionsPanel.h"
|
|
|
|
#include <QHeaderView>
|
|
#include <QLabel>
|
|
#include <QTreeWidget>
|
|
#include <QTreeWidgetItem>
|
|
#include <QVBoxLayout>
|
|
|
|
VersionsPanel::VersionsPanel(QWidget *parent) : QWidget(parent)
|
|
{
|
|
auto *layout = new QVBoxLayout(this);
|
|
layout->setContentsMargins(4, 4, 4, 4);
|
|
layout->setSpacing(6);
|
|
|
|
m_deviceNameLabel = new QLabel("Not connected", this);
|
|
m_deviceNameLabel->setStyleSheet("font-size: 13pt; font-weight: bold; padding: 4px;");
|
|
layout->addWidget(m_deviceNameLabel);
|
|
|
|
m_table = new QTreeWidget(this);
|
|
m_table->setColumnCount(3);
|
|
m_table->setHeaderLabels({"Board", "Firmware Version", "Hardware UID"});
|
|
m_table->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
|
m_table->header()->setSectionResizeMode(1, QHeaderView::Stretch);
|
|
m_table->header()->setSectionResizeMode(2, QHeaderView::Stretch);
|
|
m_table->setAlternatingRowColors(true);
|
|
m_table->setRootIsDecorated(false);
|
|
m_table->setUniformRowHeights(true);
|
|
layout->addWidget(m_table, 1);
|
|
|
|
m_statusLabel = new QLabel("Waiting for data...", this);
|
|
m_statusLabel->setStyleSheet("color: gray; font-size: 9pt; padding: 2px;");
|
|
layout->addWidget(m_statusLabel);
|
|
}
|
|
|
|
void VersionsPanel::reset()
|
|
{
|
|
m_table->clear();
|
|
m_rowIndex.clear();
|
|
m_deviceName.clear();
|
|
m_rnpCount = -1;
|
|
m_collected = 0;
|
|
m_deviceNameLabel->setText("Not connected");
|
|
m_statusLabel->setText("Waiting for data...");
|
|
}
|
|
|
|
void VersionsPanel::setDeviceName(const QString &name)
|
|
{
|
|
m_deviceName = name;
|
|
m_deviceNameLabel->setText(name);
|
|
|
|
// Update master row label if it already exists
|
|
if (m_rowIndex.contains("M")) {
|
|
int idx = m_rowIndex["M"];
|
|
auto *item = m_table->topLevelItem(idx);
|
|
if (item) item->setText(0, QString("Master (%1)").arg(name));
|
|
}
|
|
}
|
|
|
|
void VersionsPanel::setRnpCount(int count)
|
|
{
|
|
m_rnpCount = count;
|
|
m_collected = 0;
|
|
|
|
// Pre-allocate master row at index 0 if not already present
|
|
if (!m_rowIndex.contains("M")) {
|
|
auto *master = new QTreeWidgetItem();
|
|
master->setText(0, QString("Master (%1)").arg(m_deviceName));
|
|
QFont f = master->font(0);
|
|
f.setBold(true);
|
|
for (int c = 0; c < 3; ++c) master->setFont(c, f);
|
|
m_table->insertTopLevelItem(0, master);
|
|
m_rowIndex["M"] = 0;
|
|
}
|
|
|
|
// Pre-allocate one row per slave panel IN ORDER
|
|
for (int i = 0; i < count; ++i) {
|
|
const QString id = QString::number(i);
|
|
if (!m_rowIndex.contains(id)) {
|
|
auto *item = new QTreeWidgetItem();
|
|
item->setText(0, QString("Panel %1").arg(i));
|
|
m_table->addTopLevelItem(item);
|
|
// Master is always index 0; slaves start at 1
|
|
m_rowIndex[id] = 1 + i;
|
|
}
|
|
}
|
|
|
|
updateStatus();
|
|
}
|
|
|
|
void VersionsPanel::setVersion(const QString &boardId, const QString &version)
|
|
{
|
|
// If master row doesn't exist yet (NAM/VER arrive before RNP), create it
|
|
if (boardId == "M" && !m_rowIndex.contains("M")) {
|
|
auto *master = new QTreeWidgetItem();
|
|
master->setText(0, QString("Master (%1)").arg(m_deviceName));
|
|
QFont f = master->font(0);
|
|
f.setBold(true);
|
|
for (int c = 0; c < 3; ++c) master->setFont(c, f);
|
|
m_table->insertTopLevelItem(0, master);
|
|
m_rowIndex["M"] = 0;
|
|
}
|
|
|
|
if (!m_rowIndex.contains(boardId)) return;
|
|
auto *item = m_table->topLevelItem(m_rowIndex[boardId]);
|
|
if (item) item->setText(1, version);
|
|
}
|
|
|
|
void VersionsPanel::setUid(const QString &boardId, const QString &uid)
|
|
{
|
|
if (!m_rowIndex.contains(boardId)) return;
|
|
auto *item = m_table->topLevelItem(m_rowIndex[boardId]);
|
|
if (item) item->setText(2, uid);
|
|
|
|
if (boardId != "M") {
|
|
++m_collected;
|
|
updateStatus();
|
|
}
|
|
}
|
|
|
|
void VersionsPanel::updateStatus()
|
|
{
|
|
if (m_rnpCount < 0) {
|
|
m_statusLabel->setText("Waiting for panel count (RNP)...");
|
|
return;
|
|
}
|
|
m_statusLabel->setText(
|
|
QString("Panels: %1 / %2 collected").arg(m_collected).arg(m_rnpCount));
|
|
}
|