mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-28 11:19:24 +08:00
修改设备显示信息的寄存器地址配置文件,修改服务端界面
This commit is contained in:
@@ -7,12 +7,16 @@
|
||||
#include "app/Station.h"
|
||||
#include "protocol/MqttEntity.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QWHome::QWHome(QWidget* parent) : MyWidget(parent)
|
||||
{
|
||||
this->setObjectName("workspace");
|
||||
this->setStyleSheet("#workspace { background-color:rgba(100,100,100,50); }");
|
||||
this->setObjectName("home");
|
||||
this->setStyleSheet("#home { background-color:rgba(100,100,100,50); }");
|
||||
|
||||
int x = 10, y = 10;
|
||||
int x = 10, y = 0;
|
||||
{
|
||||
this->groupSys = MyQUI::GroupBox(this, x, y, 1190, 120, "系统");
|
||||
auto pw = groupSys.get();
|
||||
@@ -21,54 +25,29 @@ QWHome::QWHome(QWidget* parent) : MyWidget(parent)
|
||||
x = 10, y += 130;
|
||||
this->groupHttp = MyQUI::GroupBox(this, x, y, 390, 120, "HTTP");
|
||||
auto pw = groupHttp.get();
|
||||
MyQUI::PairLine(pw, 20, 20, "服务类型: ", "服务端");
|
||||
MyQUI::PairLine(pw, 20, 50, "服务端口: ", Utils::toStr(Config::option.http.port));
|
||||
MyQUI::PairLine(pw, 20, 80, "服务状态: ", "运行");
|
||||
this->addPair("http-t", pw, 20, 20, "服务类型: ", "服务端");
|
||||
this->addPair("http-p", pw, 20, 50, "服务端口: ", Utils::toStr(Config::option.http.port));
|
||||
this->addPair("http-s", pw, 20, 80, "服务状态: ", "运行");
|
||||
}
|
||||
{
|
||||
x += 400;
|
||||
this->groupMqtt = MyQUI::GroupBox(this, x, y, 390, 120, "MQTT");
|
||||
auto pw = groupMqtt.get();
|
||||
MyQUI::PairLine(pw, 20, 20, "服务类型: ", "客户端");
|
||||
MyQUI::PairLine(pw, 20, 50, "服务地址: ", Config::option.mqtt.host);
|
||||
MyQUI::PairLine(pw, 20, 80, "服务状态: ", "---");
|
||||
this->addPair("mqtt-t", pw, 20, 20, "服务类型: ", "客户端");
|
||||
this->addPair("mqtt-h", pw, 20, 50, "服务地址: ", Config::option.mqtt.host);
|
||||
this->addPair("mqtt-s", pw, 20, 80, "服务状态: ", "---");
|
||||
}
|
||||
{
|
||||
x += 400;
|
||||
this->groupDB = MyQUI::GroupBox(this, x, y, 390, 120, "数据库");
|
||||
auto pw = groupDB.get();
|
||||
MyQUI::PairLine(pw, 20, 20, "数据库名: ", Config::option.database.dbname);
|
||||
MyQUI::PairLine(pw, 20, 50, "主机地址: ", Config::option.database.host);
|
||||
MyQUI::PairLine(pw, 20, 80, "用 户 名: ", Config::option.database.user);
|
||||
this->addPair("db-n", pw, 20, 20, "数据库名: ", Config::option.database.dbname);
|
||||
this->addPair("db-h", pw, 20, 50, "主机地址: ", Config::option.database.host);
|
||||
this->addPair("db-u", pw, 20, 80, "用 户 名: ", Config::option.database.user);
|
||||
|
||||
|
||||
const std::string QSS_TABLE = // 表格整体样式
|
||||
"QTableWidget {"
|
||||
" background-color: transparent;" // 背景色
|
||||
" gridline-color: #C0C0C0;" // 网格线颜色
|
||||
" border: 1px solid gray;" // 边框
|
||||
" color: white;" // 文字颜色
|
||||
"}"
|
||||
// 表头样式
|
||||
"QHeaderView::section {"
|
||||
" background-color: #404040;" // 表头背景
|
||||
" padding: 4px;" // 内边距
|
||||
" border: 1px solid #505050;" // 边框
|
||||
" min-height: 25px;" // 最小高度
|
||||
"}"
|
||||
// 单元格样式
|
||||
"QTableWidget::item {"
|
||||
" padding-left: 5px;"
|
||||
" border-bottom: 1px solid gray;" // 底部边框
|
||||
"}"
|
||||
// 选中状态
|
||||
"QTableWidget::item:selected {"
|
||||
" background-color: #B8D6FF;" // 选中背景色
|
||||
" color: black;" // 选中文字颜色
|
||||
"}";
|
||||
|
||||
table = std::make_shared<QTableWidget>(this);
|
||||
table->setGeometry(10, y += 130, 1190, 300);
|
||||
table->setGeometry(10, y += 130, 1190, 265);
|
||||
table->setStyleSheet(QSS_TABLE.c_str());
|
||||
table->horizontalHeader()->setStretchLastSection(true); // 最后一列占满
|
||||
table->verticalHeader()->setVisible(false); // 不显示垂直表头
|
||||
@@ -92,36 +71,55 @@ QWHome::QWHome(QWidget* parent) : MyWidget(parent)
|
||||
table->setColumnWidth(1, 120);
|
||||
table->setColumnWidth(2, 50);
|
||||
table->setColumnWidth(4, 80);
|
||||
|
||||
}
|
||||
|
||||
textLog = std::make_shared<QTextEdit>(this);
|
||||
textLog->setGeometry(10, y += 310, 1190, 280);
|
||||
textLog->setStyleSheet("background-color: transparent; border: 1px solid gray; font-weight: 400;");
|
||||
textLog->setReadOnly(true);
|
||||
logFilter = MyQUI::PairLine(this, 10, y += 270, "日志过滤: ", "", false);
|
||||
btnLogClean = std::make_shared<QPushButton>("清除", this);
|
||||
btnLogClean->setGeometry(400, y, 80, 26);
|
||||
connect(btnLogClean.get(), &QPushButton::clicked, this, [=]() { texteditLog->clear(); });
|
||||
|
||||
texteditLog = std::make_shared<QTextEdit>(this);
|
||||
texteditLog->setGeometry(10, y += 30, 1190, 280);
|
||||
texteditLog->setStyleSheet("background-color: transparent; border: 1px solid gray; font-weight: 400;");
|
||||
texteditLog->setReadOnly(true);
|
||||
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// QT显示spdlog: 方法一
|
||||
// 第二个参数是方法函数名称,即调用 QTextEdit的appeng函数;
|
||||
auto qtSink = std::make_shared<spdlog::sinks::qt_sink_mt>(textLog.get(), "append");
|
||||
spdlog::default_logger()->sinks().push_back(qtSink);
|
||||
//auto qtSink = std::make_shared<spdlog::sinks::qt_sink_mt>(textLog.get(), "append");
|
||||
//spdlog::default_logger()->sinks().push_back(qtSink);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// QT显示spdlog: 方法二, 自定义实现 QtLogSink
|
||||
myqtSink = std::make_shared<QtLogSink>(this);
|
||||
spdlog::default_logger()->sinks().push_back(myqtSink);
|
||||
//auto logger = std::make_shared<spdlog::logger>("custom_logger", myqtSink);
|
||||
//spdlog::register_logger(logger);
|
||||
|
||||
// 连接信号和槽,使用Qt::QueuedConnection确保线程安全
|
||||
connect(myqtSink.get(), &QtLogSink::logMessageReceived, this, &QWHome::onLogMessageReceived, Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
|
||||
void QWHome::setTableCell(int row, int col, std::string text, std::string style /*= ""*/)
|
||||
QWHome::~QWHome()
|
||||
{
|
||||
auto item = table->item(row, col);
|
||||
if (!item)
|
||||
{
|
||||
item = new QTableWidgetItem();
|
||||
table->setItem(row, col, item);
|
||||
}
|
||||
item->setText(text.c_str());
|
||||
if (style == "OK") { item->setForeground(QBrush(Qt::green)); }
|
||||
else if (style == "ERR") { item->setForeground(QBrush(Qt::red)); }
|
||||
table->clear();
|
||||
mapPairs.clear();
|
||||
}
|
||||
|
||||
void QWHome::addPair(string name, QWidget* parent, int x, int y, string k, string v, bool readonly /*= true*/)
|
||||
{
|
||||
if (name.empty()) name = k;
|
||||
mapPairs[name] = MyQUI::PairLine(parent, x, y, k, v);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void QWHome::onTimer()
|
||||
{
|
||||
if (!this->isVisible()) { return; }
|
||||
|
||||
auto& appdata = Application().data();
|
||||
int rowNo = 0;
|
||||
int tsNow = Utils::time();
|
||||
@@ -135,27 +133,46 @@ void QWHome::onTimer()
|
||||
bool isOpen = station->status > 0;
|
||||
bool isConnected = station->mqttCli->isConnected;
|
||||
|
||||
setTableCell(rowNo, 0, std::to_string(station->stationId));
|
||||
setTableCell(rowNo, 1, station->name);
|
||||
setTableCell(rowNo, 2, station->code);
|
||||
setTableCell(rowNo, 3, isOpen ? "启用" : "未启用", isOpen ? "OK" : "ERR");
|
||||
setTableCell(rowNo, 4, isConnected ? "连接成功" : "未连接", isConnected ? "OK" : "ERR");
|
||||
MyQUI::setTableCell(table, rowNo, 0, std::to_string(station->stationId));
|
||||
MyQUI::setTableCell(table, rowNo, 1, station->name);
|
||||
MyQUI::setTableCell(table, rowNo, 2, station->code);
|
||||
MyQUI::setTableCell(table, rowNo, 3, isOpen ? "启用" : "未启用", isOpen ? "OK" : "ERR");
|
||||
MyQUI::setTableCell(table, rowNo, 4, isConnected ? "连接成功" : "未连接", isConnected ? "OK" : "ERR");
|
||||
|
||||
int tsPolling = station->getPollingTS();
|
||||
setTableCell(rowNo, 5, tsPolling > 0 ? std::to_string(tsNow - tsPolling) + "/" + std::to_string(Config::option.mqtt.interval) : "--");
|
||||
MyQUI::setTableCell(table, rowNo, 5, tsPolling > 0 ? std::to_string(tsNow - tsPolling) + "/" + std::to_string(Config::option.mqtt.interval) : "--");
|
||||
|
||||
setTableCell(rowNo, 6, Utils::toStr(station->statData.dayElectIn, 0));
|
||||
setTableCell(rowNo, 7, Utils::toStr(station->statData.dayElectOut, 0));
|
||||
setTableCell(rowNo, 8, Utils::toStr(station->statData.totalElectIn, 0));
|
||||
setTableCell(rowNo, 9, Utils::toStr(station->statData.totalElectOut, 0));
|
||||
setTableCell(rowNo, 10, Utils::toStr(station->statData.dayFeeIn, 0));
|
||||
setTableCell(rowNo, 11, Utils::toStr(station->statData.dayFeeOut, 0));
|
||||
setTableCell(rowNo, 12, Utils::toStr(station->statData.totalFeeIn, 0));
|
||||
setTableCell(rowNo, 13, Utils::toStr(station->statData.totalFeeOut, 0));
|
||||
setTableCell(rowNo, 14, Utils::toStr(station->statData.dayIncome, 0));
|
||||
setTableCell(rowNo, 15, Utils::toStr(station->statData.totalIncome, 0));
|
||||
setTableCell(rowNo, 16, station->statData.ts > 0 ? Utils::timeStr(station->statData.ts) : "--");
|
||||
MyQUI::setTableCell(table, rowNo, 6, Utils::toStr(station->statData.dayElectIn, 0));
|
||||
MyQUI::setTableCell(table, rowNo, 7, Utils::toStr(station->statData.dayElectOut, 0));
|
||||
MyQUI::setTableCell(table, rowNo, 8, Utils::toStr(station->statData.totalElectIn, 0));
|
||||
MyQUI::setTableCell(table, rowNo, 9, Utils::toStr(station->statData.totalElectOut, 0));
|
||||
MyQUI::setTableCell(table, rowNo, 10, Utils::toStr(station->statData.dayFeeIn, 0));
|
||||
MyQUI::setTableCell(table, rowNo, 11, Utils::toStr(station->statData.dayFeeOut, 0));
|
||||
MyQUI::setTableCell(table, rowNo, 12, Utils::toStr(station->statData.totalFeeIn, 0));
|
||||
MyQUI::setTableCell(table, rowNo, 13, Utils::toStr(station->statData.totalFeeOut, 0));
|
||||
MyQUI::setTableCell(table, rowNo, 14, Utils::toStr(station->statData.dayIncome, 0));
|
||||
MyQUI::setTableCell(table, rowNo, 15, Utils::toStr(station->statData.totalIncome, 0));
|
||||
MyQUI::setTableCell(table, rowNo, 16, station->statData.ts > 0 ? Utils::timeStr(station->statData.ts) : "--");
|
||||
|
||||
rowNo++;
|
||||
}
|
||||
}
|
||||
|
||||
void QWHome::onLogMessageReceived(const QString& message)
|
||||
{
|
||||
if (!this->isVisible()) { return; }
|
||||
|
||||
bool show = true;
|
||||
if (logFilter.second)
|
||||
{
|
||||
auto filter = logFilter.second->text();
|
||||
if (!filter.isEmpty() && !message.contains(filter))
|
||||
{
|
||||
show = false;
|
||||
}
|
||||
}
|
||||
if (show)
|
||||
{
|
||||
texteditLog->append(message.trimmed());
|
||||
}
|
||||
}
|
||||
@@ -6,23 +6,54 @@
|
||||
#include <QTableWidget>
|
||||
|
||||
|
||||
#include <spdlog/sinks/base_sink.h>
|
||||
#include <QObject>
|
||||
|
||||
class QtLogSink : public QObject, public spdlog::sinks::base_sink<std::mutex>
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QtLogSink(QObject* parent = nullptr) : QObject(parent) {}
|
||||
|
||||
protected:
|
||||
void sink_it_(const spdlog::details::log_msg& msg) override {
|
||||
spdlog::memory_buf_t formatted;
|
||||
spdlog::sinks::base_sink<std::mutex>::formatter_->format(msg, formatted);
|
||||
QString logMessage = QString::fromStdString(fmt::to_string(formatted));
|
||||
// 发射信号,传递日志消息
|
||||
emit logMessageReceived(logMessage);
|
||||
}
|
||||
|
||||
void flush_() override {}
|
||||
|
||||
signals:
|
||||
void logMessageReceived(const QString& message);
|
||||
};
|
||||
|
||||
|
||||
class QWHome : public MyWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QWHome(QWidget* parent);
|
||||
~QWHome();
|
||||
|
||||
void addPair(string name, QWidget* parent, int x, int y, string k, string v, bool readonly = true);
|
||||
|
||||
|
||||
// 创建自定义sink
|
||||
//std::shared_ptr<QtTextSink> qtSink;
|
||||
|
||||
std::map<string, MyPairLabelLine> mapPairs;
|
||||
std::shared_ptr<QGroupBox> groupSys;
|
||||
std::shared_ptr<QGroupBox> groupHttp;
|
||||
std::shared_ptr<QGroupBox> groupMqtt;
|
||||
std::shared_ptr<QGroupBox> groupDB;
|
||||
std::shared_ptr<QTableWidget> table {};
|
||||
std::shared_ptr<QTextEdit> textLog;
|
||||
std::shared_ptr<QTextEdit> texteditLog;
|
||||
MyPairLabelLine logFilter {};
|
||||
std::shared_ptr<QPushButton> btnLogClean;
|
||||
std::shared_ptr<QtLogSink> myqtSink;
|
||||
|
||||
void onTimer() override;
|
||||
void setTableCell(int row, int col, std::string text, std::string style = "");
|
||||
void onLogMessageReceived(const QString& message);
|
||||
};
|
||||
@@ -0,0 +1,218 @@
|
||||
#include "QWMonitor.h"
|
||||
|
||||
#include "app/Application.h"
|
||||
#include "app/AppData.h"
|
||||
#include "app/Station.h"
|
||||
#include "app/Device.h"
|
||||
#include "common/Utils.h"
|
||||
#include "app/DataStruct.h"
|
||||
|
||||
QWMonitor::QWMonitor(QWidget* parent) : MyWidget(parent)
|
||||
{
|
||||
//this->setStyleSheet("background-color: red;");
|
||||
int x = 10, y = 10;
|
||||
for (auto& iter: Application::data().mapStation)
|
||||
{
|
||||
auto station = iter.second;
|
||||
auto btn = make_shared<QPushButton>(station->name.c_str(), this);
|
||||
btn->setGeometry(x, y, 120, 36);
|
||||
btn->setStyleSheet(QSS_BTN.c_str());
|
||||
x += 130;
|
||||
|
||||
if (!curActiveBtn)
|
||||
{
|
||||
curActiveBtn = btn;
|
||||
curActiveBtn->setStyleSheet(QSS_BTN_ACTIVE.c_str());
|
||||
}
|
||||
mapBtnStation[btn] = station;
|
||||
|
||||
connect(btn.get(), &QPushButton::clicked, this, [=]()
|
||||
{
|
||||
if (btn != curActiveBtn)
|
||||
{
|
||||
if (curActiveBtn) { curActiveBtn->setStyleSheet(QSS_BTN.c_str()); }
|
||||
if (btn) { btn->setStyleSheet(QSS_BTN_ACTIVE.c_str()); }
|
||||
curActiveBtn = btn;
|
||||
this->initStation(station);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
table = std::make_shared<QTableWidget>(this);
|
||||
table->setGeometry(10, y += 50, 700, 800);
|
||||
table->setStyleSheet(QSS_TABLE.c_str());
|
||||
table->horizontalHeader()->setStretchLastSection(true); // 最后一列占满
|
||||
table->verticalHeader()->setVisible(false); // 不显示垂直表头
|
||||
table->setEditTriggers(QAbstractItemView::NoEditTriggers); // 单元格不可编辑
|
||||
table->setSelectionMode(QAbstractItemView::SingleSelection); // 设置为单选模式
|
||||
table->setSelectionBehavior(QAbstractItemView::SelectRows); // 设置为整行选中
|
||||
table->horizontalHeader()->setFixedHeight(50);
|
||||
table->horizontalHeader()->setDefaultSectionSize(60);
|
||||
|
||||
QTableWidgetItem* headerItem;
|
||||
QStringList headerText_Row, headerText_Col;
|
||||
headerText_Row << "ID" << "类型ID" << "类型名称" << "设备名称" << "编号" << "状态" << "通讯\n状态" << "工作\n状态" << "故障\n状态";
|
||||
|
||||
// 设置为水平表头
|
||||
table->setColumnCount(headerText_Row.size());
|
||||
table->setHorizontalHeaderLabels(headerText_Row);
|
||||
table->setColumnWidth(0, 50);
|
||||
table->setColumnWidth(1, 60);
|
||||
table->setColumnWidth(2, 120);
|
||||
table->setColumnWidth(3, 160);
|
||||
|
||||
connect(table.get(), &QTableWidget::currentCellChanged, this, &QWMonitor::onCurrentCellChanged);
|
||||
|
||||
if (curActiveBtn)
|
||||
{
|
||||
this->initStation(mapBtnStation[curActiveBtn]);
|
||||
}
|
||||
|
||||
this->groupStation = MyQUI::GroupBox(this, 730, y, 480, 800, "设备信息");
|
||||
|
||||
labDeviceInfo = std::make_shared<QLabel>(groupStation.get());
|
||||
labDeviceInfo->setGeometry(10, 20, 400, 26);
|
||||
|
||||
// 将内容widget设置为滚动区域的widget
|
||||
uiReg.scroll = new QScrollArea(groupStation.get());
|
||||
uiReg.scroll->setFixedHeight(600); // 设置滚动区域固定高度600px
|
||||
uiReg.scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); // 垂直滚动条在需要时出现
|
||||
//scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded); // 水平滚动条在需要时出现
|
||||
uiReg.scroll->setGeometry(10, 90, 460, 700);
|
||||
uiReg.scroll->setObjectName("MyScroll");
|
||||
uiReg.scroll->setStyleSheet("#MyScroll {background-color: transparent; border: 1px solid gray;}");
|
||||
uiReg.scroll->setWidgetResizable(true);
|
||||
|
||||
std::string QSS_LISTVIEW =
|
||||
"QListView { background-color: transparent; color: white; }"
|
||||
"QListView::item { background-color: transparent; border-bottom: 0px solid gray; padding: 0px; height: 20px; }";
|
||||
|
||||
uiReg.listReg = new QListWidget(groupStation.get());
|
||||
uiReg.listReg->setStyleSheet(QSS_LISTVIEW.c_str());
|
||||
uiReg.scroll->setWidget(uiReg.listReg);
|
||||
};
|
||||
|
||||
QWMonitor::~QWMonitor()
|
||||
{
|
||||
curDevice = nullptr;
|
||||
curStation = nullptr;
|
||||
curActiveBtn = nullptr;
|
||||
mapBtnStation.clear();
|
||||
table->clear();
|
||||
}
|
||||
|
||||
void QWMonitor::initStation(shared_ptr<Station> station)
|
||||
{
|
||||
table->clearSelection();
|
||||
this->curDevice = NULL;
|
||||
if (uiReg.listReg)
|
||||
{
|
||||
uiReg.listReg->clearSelection();
|
||||
uiReg.listReg->clear();
|
||||
}
|
||||
this->updateStation(station);
|
||||
}
|
||||
|
||||
void QWMonitor::updateStation(shared_ptr<Station> station)
|
||||
{
|
||||
auto& appdata = Application::data();
|
||||
//table->clearContents();
|
||||
int row = 0;
|
||||
for (auto& iter : station->mapDevice)
|
||||
{
|
||||
auto& device = iter.second;
|
||||
MyQUI::setTableCell(table, row, 0, Utils::toStr(device->deviceId));
|
||||
MyQUI::setTableCell(table, row, 1, Utils::toStr(device->type));
|
||||
MyQUI::setTableCell(table, row, 2, appdata.getDeviceNameById(device->type));
|
||||
MyQUI::setTableCell(table, row, 3, device->name);
|
||||
MyQUI::setTableCell(table, row, 4, device->code);
|
||||
MyQUI::setTableCell(table, row, 5, device->isOpen ? "启用" : "未启用", device->isOpen ? "OK" : "ERR");
|
||||
MyQUI::setTableCell(table, row, 6, device->online ? "在线" : "离线", device->online ? "OK" : "ERR");
|
||||
MyQUI::setTableCell(table, row, 7, device->running ? "工作" : "空闲", device->running ? "OK" : "WARN");
|
||||
MyQUI::setTableCell(table, row, 8, device->err ? "故障" : "正常", device->err ? "ERR" : "OK");
|
||||
++row;
|
||||
}
|
||||
|
||||
int rowCount = table->rowCount();
|
||||
for (int i = station->mapDevice.size(); i<rowCount; ++i)
|
||||
{
|
||||
table->removeRow(i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
shared_ptr<Station> QWMonitor::getCurrentStation()
|
||||
{
|
||||
return curActiveBtn ? mapBtnStation[curActiveBtn] : nullptr;
|
||||
}
|
||||
|
||||
void QWMonitor::onCurrentCellChanged(int row, int col, int oldRow, int oldCol)
|
||||
{
|
||||
auto station = getCurrentStation();
|
||||
if (!station)
|
||||
{
|
||||
labDeviceInfo->setText("--");
|
||||
return;
|
||||
}
|
||||
if (row != oldRow)
|
||||
{
|
||||
auto item = table->item(row, 0);
|
||||
if (item)
|
||||
{
|
||||
auto deviceId = item->text().toInt();
|
||||
curDevice = station->getDevice(deviceId);
|
||||
if (curDevice)
|
||||
{
|
||||
string info = curDevice->name;
|
||||
labDeviceInfo->setText(info.c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void QWMonitor::onTimer()
|
||||
{
|
||||
auto station = getCurrentStation();
|
||||
if (!station) return;
|
||||
|
||||
this->updateStation(station);
|
||||
|
||||
if (curDevice)
|
||||
{
|
||||
auto mapRegPtr = REGAddr::getRegMapByDeviceType(curDevice->type);
|
||||
auto& mapDeviceParams = curDevice->mapParams;
|
||||
|
||||
stringstream ss;
|
||||
int ind = 0;
|
||||
for (auto& iter : mapDeviceParams)
|
||||
{
|
||||
ss.str("");
|
||||
|
||||
auto& addr = iter.first;
|
||||
ss << std::setw(3) << std::setfill('0') << ind << ": " << addr << ": " << iter.second;
|
||||
if (mapRegPtr) {
|
||||
auto iter = mapRegPtr->find(addr);
|
||||
if (iter != mapRegPtr->end())
|
||||
{
|
||||
ss << " (" << iter->second.name << ")";
|
||||
}
|
||||
}
|
||||
ss << "\n";
|
||||
|
||||
if (ind < uiReg.listReg->count())
|
||||
{
|
||||
uiReg.listReg->item(ind)->setText(ss.str().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
uiReg.listReg->addItem(ss.str().c_str());
|
||||
}
|
||||
++ind;
|
||||
}
|
||||
for (int i = uiReg.listReg->count()-1; i>=ind; --i)
|
||||
{
|
||||
uiReg.listReg->takeItem(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
|
||||
#include "qt/MyQUI.h"
|
||||
|
||||
#include <QScrollArea>
|
||||
#include <QListWidget>
|
||||
|
||||
class Station;
|
||||
class Device;
|
||||
|
||||
class QWMonitor : public MyWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
QWMonitor(QWidget* parent);
|
||||
~QWMonitor();
|
||||
|
||||
void initStation(shared_ptr<Station> station);
|
||||
shared_ptr<Station> getCurrentStation();
|
||||
void updateStation(shared_ptr<Station> station);
|
||||
|
||||
void onTimer() override;
|
||||
|
||||
public slots:
|
||||
void onCurrentCellChanged(int row, int col, int oldRow, int oldCol);
|
||||
|
||||
|
||||
public:
|
||||
std::shared_ptr<QPushButton> curActiveBtn;
|
||||
std::map<std::shared_ptr<QPushButton>, std::shared_ptr<Station>> mapBtnStation;
|
||||
std::shared_ptr<Station> curStation;
|
||||
std::shared_ptr<Device> curDevice;
|
||||
|
||||
shared_ptr<QTableWidget> table;
|
||||
|
||||
std::shared_ptr<QGroupBox> groupStation;
|
||||
|
||||
std::shared_ptr<QLabel> labDeviceInfo;
|
||||
|
||||
std::shared_ptr<QTextEdit> texteditDevice;
|
||||
|
||||
//std::vector<std::shared_ptr<QLabel>> vecLabelRegData;
|
||||
|
||||
struct {
|
||||
//QWidget* widget;
|
||||
//QVBoxLayout* layout;
|
||||
QScrollArea* scroll {};
|
||||
QListWidget* listReg {};
|
||||
} uiReg;
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user