mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user