新增U盘获取图语License功能

This commit is contained in:
2024-08-06 20:32:02 +08:00
parent f0b1152cad
commit 1f7bc017ca
27 changed files with 1325 additions and 481 deletions

View File

@@ -2,6 +2,7 @@
#include "MainWidget.h"
#include "../RecvDataHandler/RecvDataHandler.h"
#include "../Json/readJsonFile.h"
#include "../LicenseGenerate/LicenseGenerate.h"
void onThreadFinished(QThread* thread, ClientHandler* handler)
{
@@ -10,7 +11,7 @@ void onThreadFinished(QThread* thread, ClientHandler* handler)
thread->deleteLater();
}
// 构造函数,初始化 UI 组件和服务器
// 初始化 UI 组件和服务器
MainWidget::MainWidget(QWidget* parent) :
QWidget(parent),
nextClientId(1),
@@ -61,12 +62,9 @@ MainWidget::MainWidget(QWidget* parent) :
}
});
// 每连接一个新客户端创建一个新的线程
QThread* thread = new QThread(this);
/*ClientHandler* handler = new ClientHandler(socket, testJsonConfig, funcJsonConfig, getDevInfoJson,
getPicJson, getVideoJson, clientId, nullptr);*/
ClientHandler* handler = new ClientHandler(socket, frontBoardOneClickTest, frontBoardTest, frontBoardFuncConfig, getDevInfoJson,
ClientHandler* handler = new ClientHandler(socket, frontBoardOneClickTest, frontBoardTest, frontBoardFuncConfig,
frontBoardDevInfoJson, frontBoardLicenseJson, backBoardDevInfoJson,
getPicJson, getVideoJson, clientId, nullptr);
// 将 ClientHandler 移动到线程池中的线程
@@ -101,7 +99,6 @@ MainWidget::MainWidget(QWidget* parent) :
connect(handler, &ClientHandler::selectClientDisconnected, this, &MainWidget::onDisconnectClient);
// 创建 DataHandler 对象并连接信号
//QLabel* imageDisplayLabel = new QLabel;
DataHandler* dataHandler = new DataHandler(leftLens_imageLabel, rightLens_imageLabel, videoLabel, this);
connect(handler, &ClientHandler::dataReceived, dataHandler, &DataHandler::handleData);
connect(dataHandler, &DataHandler::statusUpdated, this, &MainWidget::onStatusUpdated);
@@ -137,6 +134,28 @@ MainWidget::~MainWidget() {
handler->deleteLater();
}
server->close();
for (auto thread : clientThreads) {
thread->quit();
thread->wait();
delete thread;
}
clientThreads.clear();
for (auto handler : clients_1) {
handler->deleteLater();
}
clients_1.clear();
for (auto timer : clientTimers) {
timer->stop();
delete timer;
}
clientTimers.clear();
if (server->isListening()) {
server->close();
}
qDebug() << "MainWidget destroyed";
}
@@ -228,7 +247,8 @@ void MainWidget::setupUI()
sendAllButton->setEnabled(false);
statusListWidget = new QListWidget(this);
statusListWidget->setMinimumSize(350, 880);
//statusListWidget->setMinimumSize(350, 880);
statusListWidget->setMinimumSize(350, 680);
statusListWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // 设置大小策略为扩展
QHBoxLayout* buttonLayout = new QHBoxLayout;
@@ -240,7 +260,7 @@ void MainWidget::setupUI()
leftLayout->addLayout(buttonLayout);
leftLayout->setStretch(0, 1);
leftLayout->addWidget(statusListWidget);
leftLayout->setStretch(1, 20);
leftLayout->setStretch(1, 200);
saveCheckBox = new QCheckBox("", this);
selectFileButton = new QPushButton("Save", this);
@@ -260,31 +280,78 @@ void MainWidget::setupUI()
leftLayout->addLayout(fileLayout);
leftLayout->setStretch(2, 1);
// 读取 JSON 配置文件
readJsonConfig();
QGroupBox* groupBox = new QGroupBox("算法 license", this);
QHBoxLayout* buttonRowLayout = new QHBoxLayout;
for (int i = 0; i < frontBoardLicenseJson.size(); ++i) {
QJsonObject item = frontBoardLicenseJson[i].toObject();
QString buttonText = item["lable"].toString();
QPushButton* button = new QPushButton(buttonText, this);
button->setProperty("licenseIndex", i);
buttonRowLayout->addWidget(button);
connect(button, &QPushButton::clicked, this, &MainWidget::onLicenseButtonClicked);
}
QLineEdit* readOnlyLineEdit = new QLineEdit(this);
readOnlyLineEdit->setReadOnly(true);
readOnlyLineEdit->setText("This is a read-only text");
readOnlyLineEdit->setFixedHeight(80);
QVBoxLayout* groupBoxLayout_license = new QVBoxLayout;
groupBoxLayout_license->addLayout(buttonRowLayout);
groupBoxLayout_license->addWidget(readOnlyLineEdit);
groupBox->setLayout(groupBoxLayout_license);
leftLayout->addWidget(groupBox);
leftLayout->setStretch(3, 1);
QWidget* leftContainer = new QWidget(this);
leftContainer->setLayout(leftLayout);
leftContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// 读取 JSON 配置文件
readJsonConfig();
QTabWidget* tabWidget = new QTabWidget(this);
tabWidget->setFixedSize(900, 315); // 设置 QTabWidget 的固定大小
QGroupBox* frontDeviceInfoGroupBox = new QGroupBox("前板设备信息", this);
QVBoxLayout* frontDeviceInfoLayout = new QVBoxLayout(frontDeviceInfoGroupBox);
QHBoxLayout* frontDeviceButtonsLayout = new QHBoxLayout;
for (int i = 0; i < 2; ++i) {
QPushButton* button = new QPushButton(QString("Device %1").arg(i + 1), this);
button->setProperty("deviceInfoIndex", i);
frontDeviceButtonsLayout->addWidget(button);
connect(button, &QPushButton::clicked, this, &MainWidget::onSendGetDevInfoClicked);
QVBoxLayout* frontDeviceLabelsLayout = new QVBoxLayout;
for (const QJsonValue& value : frontBoardDevInfoJson) {
QJsonObject item = value.toObject();
QString label = item["lable"].toString();
QLabel* itemLabel = new QLabel(label, this);
QLineEdit* itemLineEdit = new QLineEdit(this);
itemLineEdit->setReadOnly(true);
QHBoxLayout* itemLayout = new QHBoxLayout;
itemLayout->addWidget(itemLabel);
itemLayout->addWidget(itemLineEdit);
frontDeviceLabelsLayout->addLayout(itemLayout);
}
frontDeviceInfoLayout->addLayout(frontDeviceButtonsLayout);
frontDeviceInfoLayout->addLayout(frontDeviceLabelsLayout);
frontDeviceInfoLayout->addStretch();
QGroupBox* backDeviceInfoGroupBox = new QGroupBox("后板设备信息", this);
QVBoxLayout* backDeviceInfoLayout = new QVBoxLayout(backDeviceInfoGroupBox);
QGroupBox* backDeviceInfoGroupBox = new QGroupBox("后板设备信息", this);
QVBoxLayout* backDeviceInfoLayout = new QVBoxLayout(backDeviceInfoGroupBox);
QVBoxLayout* backDeviceLabelsLayout = new QVBoxLayout;
for (const QJsonValue& value : backBoardDevInfoJson) {
QJsonObject item = value.toObject();
QString label = item["lable"].toString();
QLabel* itemLabel = new QLabel(label, this);
QLineEdit* itemLineEdit = new QLineEdit(this);
itemLineEdit->setReadOnly(true);
QHBoxLayout* itemLayout = new QHBoxLayout;
itemLayout->addWidget(itemLabel);
itemLayout->addWidget(itemLineEdit);
backDeviceLabelsLayout->addLayout(itemLayout);
}
backDeviceInfoLayout->addLayout(backDeviceLabelsLayout);
backDeviceInfoLayout->addStretch();
QHBoxLayout* groupBoxLayout = new QHBoxLayout;
groupBoxLayout->addWidget(frontDeviceInfoGroupBox, 1);
@@ -568,6 +635,7 @@ void MainWidget::readJsonConfig()
frontBoardTest = readJson_frontBoardTest();
frontBoardFuncConfig = readJson_frontBoardFuncConfig();
frontBoardDevInfoJson = readJson_frontDevInfo();
frontBoardLicenseJson = readJson_frontLicense();
backBoardDevInfoJson = readJson_backDevInfo();
testJsonConfig = readJson_testConfig();
funcJsonConfig = readJson_funcConfig();
@@ -640,6 +708,29 @@ void MainWidget::updateServerButtonText()
}
}
// 处理 License 按键点击事件
void MainWidget::onLicenseButtonClicked()
{
if (connectedClientsCount) {
QPushButton* button = qobject_cast<QPushButton*>(sender());
if (button) {
int index = button->property("licenseIndex").toInt();
if (index >= 0 && index < frontBoardLicenseJson.size()) {
QJsonObject jsonObject = frontBoardLicenseJson[index].toObject();
QString jsonString = QJsonDocument(jsonObject).toJson(QJsonDocument::Compact);
//qDebug() << "license Button clicked, sending JSON:" << jsonString;
for (ClientHandler* handler : clients) {
handler->sendLicenseItem(index);
}
}
}
}
else {
QListWidgetItem* listItem = new QListWidgetItem(QString("No device is connected !!!"), statusListWidget);
listItem->setBackground(Qt::red);
}
}
// 处理开始服务器按键点击事件
void MainWidget::onStartServerClicked()
{
@@ -792,6 +883,11 @@ void MainWidget::onOpenFocusWindowClicked()
}
}
//void MainWidget::onPowerOnSend()
//{
//
//}
// 处理一键发送按键点击事件
void MainWidget::onSendAllClicked()
{
@@ -805,8 +901,9 @@ void MainWidget::onSendAllClicked()
for (ClientHandler* handler : clients) {
// 重置索引
handler->resetCurrentItemIndex();
qDebug() << "------> handler->sendNextItem()";
handler->sendNextItem();
//handler->sendNextItem();
handler->sendDevInfoItem();
//licenseGenerate();
}
}
else {

View File

@@ -48,6 +48,7 @@ private slots:
void onSendGetPicClicked();
// 处理发送拉视频流按键点击事件
void onSendGetVideoClicked();
void onLicenseButtonClicked();
// 处理一键发送按钮点击事件
void onSendAllClicked();
// 处理单独发送项按钮点击事件
@@ -81,6 +82,7 @@ private slots:
void startClientReadTimer(int clientId);
void stopClientReadTimer(int clientId);
private:
// 读取 test JSON 配置文件
void readJsonConfig();
@@ -99,6 +101,7 @@ private:
QJsonArray frontBoardTest; // 前板单项测试 JSON
QJsonArray frontBoardFuncConfig; // 前板功能配置参数 JSON
QJsonArray frontBoardDevInfoJson; // 前板设备信息参数 JSON
QJsonArray frontBoardLicenseJson; // 前板License JSON
QJsonArray backBoardDevInfoJson; // 后板设备信息参数 JSON
QJsonArray testJsonConfig; // 功能测试区 JSON 配置
QJsonArray funcJsonConfig; // 功能配置区 JSON 配置