1.增加整机测试工厂信息输入; 2. 增加前后板连接后自动发送获取设备版本信息指令; 3. 优化UI布局代码

This commit is contained in:
2024-09-10 11:29:44 +08:00
parent 9a49eab4af
commit 843b2058c3
377 changed files with 197841 additions and 231069 deletions

View File

@@ -27,13 +27,19 @@ MainWidget::MainWidget(QWidget* parent) :
multicastTimer(new QTimer(this))
#endif
{
leftLens_imageLabel = new QLabel(this);
rightLens_imageLabel = new QLabel(this);
videoLabel = new QLabel(this);
frontFuncConfigLineEdit = new QLineEdit(this);
backFuncConfigLineEdit = new QLineEdit(this);
licenseHwInfoEdit = new QTextEdit(this);
UuidHwInfoEdit = new QTextEdit(this);
leftLens_imageLabel = new QLabel(this);
rightLens_imageLabel = new QLabel(this);
leftLens_imageLabel_back = new QLabel(this);
rightLens_imageLabel_back = new QLabel(this);
leftLens_imageLabel_all = new QLabel(this);
rightLens_imageLabel_all = new QLabel(this);
videoLabel = new QLabel(this);
video_Label_back = new QLabel(this);
video_Label_all = new QLabel(this);
frontFuncConfigLineEdit = new QLineEdit(this);
backFuncConfigLineEdit = new QLineEdit(this);
licenseHwInfoEdit = new QTextEdit(this);
UuidHwInfoEdit = new QTextEdit(this);
setupUI();
// 打印线程池状态信息
@@ -84,14 +90,7 @@ MainWidget::MainWidget(QWidget* parent) :
}
}
});
QThread* thread = new QThread(this);
#if TEST_TCP_MOVE_TO_MAIN
ClientHandler* handler = new ClientHandler(socket, frontBoardOneClickTest, frontBoardTest, frontBoardFuncConfig,
frontBoardDevInfoJson, frontBoardLicenseJson,
backBoardOneClickTest, backBoardTest, backBoardFuncConfig, backBoardDevInfoJson,
backBoardUuidJson, getPicJson, getVideoJson, clientId, isBackBoardOrAllBoard, nullptr);
#else
ClientHandler* handler = new ClientHandler(frontBoardOneClickTest, frontBoardTest, frontBoardFuncConfig,
frontBoardDevInfoJson, frontBoardLicenseJson,
backBoardOneClickTest, backBoardTest, backBoardFuncConfig, backBoardDevInfoJson,
@@ -101,9 +100,9 @@ MainWidget::MainWidget(QWidget* parent) :
// 将 socket 移动到新的线程中
socket->moveToThread(thread);
// 将 socket 传递到 handler
handler->initialize(socket);
#endif
DataHandler* dataHandler = new DataHandler(videoLabel, VideoResolutionEdit, leftLens_imageLabel->size(), &devInfoLineEdits,
handler->initialize(socket);
DataHandler* dataHandler = new DataHandler(videoLabel, video_Label_back, VideoResolutionEdit, VideoResolutionEdit_back,
leftLens_imageLabel->size(), &devInfoLineEdits, isBackBoardOrAllBoard,
frontBoardOneClickTest, frontBoardTest, frontBoardFuncConfig,
frontBoardDevInfoJson, frontBoardLicenseJson,
backBoardOneClickTest, backBoardTest, backBoardFuncConfig, backBoardDevInfoJson,
@@ -111,34 +110,8 @@ MainWidget::MainWidget(QWidget* parent) :
// 将 ClientHandler 和 DataHandler 移到线程池中的线程
handler->moveToThread(thread);
dataHandler->moveToThread(thread);
#if TEST_TCP_MOVE_TO_MAIN
// 将sendData信号连接到主线程中的槽上
connect(handler, &ClientHandler::sendData, this, [socket](const QByteArray& data, int isBoardType) {
/*socket->write(data);
socket->flush();*/
//qDebug() << "---------------------data.size():" << data.size();
QByteArray prefix;
QDataStream stream(&prefix, QIODevice::WriteOnly);
stream.setByteOrder(QDataStream::LittleEndian);
stream << quint32(0x55AA55AA);
if (isBoardType != 0) {
stream << quint16(0x0421);
}
else {
stream << quint16(0x0420);
}
stream << quint32(data.size());
prefix.append(data);
qDebug() << "Sending data:" << prefix.toHex();
socket->write(prefix);
socket->flush();
});
#else
connect(handler, &ClientHandler::sendData, handler, &ClientHandler::onSendData, Qt::QueuedConnection);
#endif
connect(handler, &ClientHandler::startTimeout, this, [this, clientId](int timeout) {
connect(handler, &ClientHandler::sendData, handler, &ClientHandler::onSendData, Qt::QueuedConnection);
connect(handler, &ClientHandler::startTimeout, this, [this, clientId](int timeout) {
this->onStartTimeout(clientId, timeout);
});
@@ -146,13 +119,15 @@ MainWidget::MainWidget(QWidget* parent) :
clients_1[clientId] = handler;
clientThreads[clientId] = thread;
connect(handler, &ClientHandler::statusUpdated, this, &MainWidget::onStatusUpdated);
connect(handler, &ClientHandler::HandleInvalidOperate, this, &MainWidget::onHandleInvalidOperate);
connect(handler, &ClientHandler::clientDisconnected, this, &MainWidget::onClientDisconnected);
connect(handler, &ClientHandler::allItemsProcessed, this, &MainWidget::onAllItemsProcessed);
connect(handler, &ClientHandler::selectClientDisconnected, this, &MainWidget::onDisconnectClient);
dataHandlers[clientId] = dataHandler;
connect(handler, &ClientHandler::dataReceived, dataHandler, &DataHandler::handleData);
connect(dataHandler, &DataHandler::statusUpdated, this, &MainWidget::onStatusUpdated);
connect(handler, &ClientHandler::dataReceived, dataHandler, &DataHandler::handleData);
connect(dataHandler, &DataHandler::picRecvFinished, handler, &ClientHandler::onPicRecvFinished);
connect(dataHandler, &DataHandler::statusUpdated, this, &MainWidget::onStatusUpdated);
// 当线程结束时删除 handler
connect(thread, &QThread::finished, this, [=]() {
onThreadFinished(thread, handler, dataHandler);
@@ -160,6 +135,9 @@ MainWidget::MainWidget(QWidget* parent) :
connect(dataHandler, &DataHandler::updateLicenseHwInfoEdit, this, [this](const QString& text) {
licenseHwInfoEdit->setPlainText(text);
});
connect(dataHandler, &DataHandler::updateUuidHwInfoEdit, this, [this](const QString& text) {
UuidHwInfoEdit->setPlainText(text);
});
connect(dataHandler, &DataHandler::updateLeftLensImage, leftLens_imageLabel, &QLabel::setPixmap);
connect(dataHandler, &DataHandler::updateRightLensImage, rightLens_imageLabel, &QLabel::setPixmap);
@@ -181,6 +159,9 @@ MainWidget::MainWidget(QWidget* parent) :
clientReadTimers[clientId] = readTimer;
connect(handler, &ClientHandler::sendDataToSomeClient, this, &MainWidget::sendDataToClient);
if (connectedClientsCount == 1) {
handler->sendDevInfoItem();
}
}
});
@@ -276,7 +257,7 @@ void MainWidget::onClientDisconnected(ClientHandler* handler)
int clientId = handler->getClientId();
qDebug() << " preVideoClientId :" << handler->preVideoClientId;
qDebug() << " clientId :" << clientId;
if (handler->preVideoClientId == clientId) {
if ((isBackBoardOrAllBoard != 0) || (handler->preVideoClientId == clientId)) {
qDebug() << "Current path: " << QDir::currentPath();
QString filePath = QDir::currentPath() + "/add1.h264";
if (QFile::exists(filePath)) {
@@ -344,13 +325,13 @@ void MainWidget::updateServerButtonText()
}
}
// 设置 UI
void MainWidget::setupUI()
{
startServerButton = new QPushButton("开始监听\n(Start Listening...)", this);
// 左侧部分 UI 元素
startServerButton = new QPushButton(QString(START_LISTENING), this);
startServerButton->setFixedSize(190, 70);
sendAllButton = new QPushButton("一键功能测试", this);
sendAllButton = new QPushButton(QString(ONE_CLICKED_TEST), this);
sendAllButton->setFixedSize(190, 70);
sendAllButton->setEnabled(false);
@@ -395,72 +376,41 @@ void MainWidget::setupUI()
leftContainer->setLayout(leftLayout);
leftContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
// 前板
QGroupBox* frontDeviceInfoGroupBox = createFrontDeviceInfoGroupBox();
QGroupBox* frontLicenseGroupBox = createLicenseGroupBox();
QTabWidget* mainTabWidget = new QTabWidget(this);
QHBoxLayout* frontGroupBoxLayout = new QHBoxLayout;
frontGroupBoxLayout->addWidget(frontDeviceInfoGroupBox, 1);
frontGroupBoxLayout->addWidget(frontLicenseGroupBox, 1);
VideoResolutionEdit = new QLineEdit(this);
VideoResolutionEdit_back = new QLineEdit(this);
VideoResolutionEdit_all = new QLineEdit(this);
QTabWidget* frontTabWidget = new QTabWidget(this);
frontTabWidget->setFixedSize(900, 315);
QWidget* frontFunctionTestTab = createFunctionTestTab(frontBoardTest, "frontBoardTest");
QWidget* frontFunctionConfigTab = createFunctionConfigTab(frontBoardFuncConfig, "frontBoardFuncConfig");
frontTabWidget->addTab(frontFunctionTestTab, "前板测试项");
frontTabWidget->addTab(frontFunctionConfigTab, "前板配置项");
// 添加前板、后板、整机的布局
addDeviceAreaTab(mainTabWidget, QString(FRONT_BOARD_NAME),
createFrontDeviceInfoGroupBox(), createLicenseGroupBox(),
frontBoardTest, frontBoardFuncConfig, "frontBoardTest", "frontBoardFuncConfig",
QString(FRONT_TEST_ITEM), QString(FRONT_CONFID_ITEM), leftLens_imageLabel, rightLens_imageLabel,
videoLabel, VideoResolutionEdit);
QTabWidget* mainTabWidget = new QTabWidget(this);
QWidget* frontDevAreaTab = new QWidget(this);
QVBoxLayout* frontDevLayout = new QVBoxLayout(frontDevAreaTab);
frontDevLayout->addLayout(frontGroupBoxLayout);
frontDevLayout->addWidget(frontTabWidget, 2, Qt::AlignTop | Qt::AlignLeft);
mainTabWidget->addTab(frontDevAreaTab, "前 板");
addDeviceAreaTab(mainTabWidget, QString(BACK_BOARD_NAME),
createBackDeviceInfoGroupBox(), createBackConnectServerGroupBox(),
backBoardTest, backBoardFuncConfig, "backBoardTest", "backBoardFuncConfig",
QString(BACK_TEST_ITEM), QString(BACK_CONFID_ITEM), leftLens_imageLabel_back, rightLens_imageLabel_back,
video_Label_back, VideoResolutionEdit_back);
// 后板
QGroupBox* backDeviceInfoGroupBox1 = createBackDeviceInfoGroupBox();
QGroupBox* BackConnectServerGroupBox = createBackConnectServerGroupBox();
QHBoxLayout* backGroupBoxLayout = new QHBoxLayout;
backGroupBoxLayout->addWidget(backDeviceInfoGroupBox1, 1);
backGroupBoxLayout->addWidget(BackConnectServerGroupBox, 1);
QTabWidget* backTabWidget = new QTabWidget(this);
backTabWidget->setFixedSize(900, 315);
QWidget* backFunctionTestTab = createFunctionTestTab(backBoardTest, "backBoardTest");
QWidget* backFunctionConfigTab = createFunctionConfigTab(backBoardFuncConfig, "backBoardFuncConfig");
backTabWidget->addTab(backFunctionTestTab, "后板测试项");
backTabWidget->addTab(backFunctionConfigTab, "后板配置项");
QWidget* backDevAreaTab = new QWidget(this);
QVBoxLayout* backDevLayout = new QVBoxLayout(backDevAreaTab);
backDevLayout->addLayout(backGroupBoxLayout);
backDevLayout->addWidget(backTabWidget, 2, Qt::AlignTop | Qt::AlignLeft);
mainTabWidget->addTab(backDevAreaTab, "后 板");
// 整机
QWidget* allDevAreaTab = new QWidget(this);
QVBoxLayout* allDevLayout = new QVBoxLayout(allDevAreaTab);
mainTabWidget->addTab(allDevAreaTab, "整 机");
QTabWidget* tabWidget_media = new QTabWidget(this);
QWidget* imageDisplayTab = createImageDisplayTab();
QWidget* videoDisplayTab = createVideoDisplayTab();
tabWidget_media->addTab(imageDisplayTab, "图像显示区");
tabWidget_media->addTab(videoDisplayTab, "视频显示区");
addAllDeviceAreaTab(mainTabWidget, QString(ALL_BOARD_NAME), leftLens_imageLabel_all, rightLens_imageLabel_all, video_Label_all, VideoResolutionEdit_all);
// 右侧主布局
QVBoxLayout* rightVerticalLayout = new QVBoxLayout;
rightVerticalLayout->addWidget(mainTabWidget, 5);
rightVerticalLayout->addWidget(tabWidget_media, 4);
// 主布局
QHBoxLayout* mainLayout = new QHBoxLayout;
mainLayout->addWidget(leftContainer, 1, Qt::AlignTop | Qt::AlignLeft);
mainLayout->addLayout(rightVerticalLayout, 3);
setLayout(mainLayout);
setWindowTitle("SL100 工厂产测工具 - V0.0.5");
resize(1340, 900);
setWindowTitle(QString(TOOL_VERSION));
resize(SL100_FACTORY_TOOL_W, SL100_FACTORY_TOOL_H);
// 信号槽连接
connect(startServerButton, &QPushButton::clicked, this, &MainWidget::onStartServerClicked);
connect(sendAllButton, &QPushButton::clicked, this, &MainWidget::onSendAllClicked);
connect(statusListWidget, &QListWidget::itemChanged, this, &MainWidget::scrollToBottom);
@@ -542,7 +492,7 @@ QString calculateSignature(const QMap<QString, QString>& params, const QString&
// 3. 构造 BaseString
//QString baseString = params["batch"] + params["label"] + params["model"] + params["request_id"] + params["timestamp"] + params["factory_id"];
QString baseString = "240830SL100LabelSL100" + request_id + timestamp + "TEST";
QString baseString = "1TEST_SL100_20240826SL100" + request_id + timestamp + "TEST";
qDebug() << "baseString:" << baseString;
// 4. 构造 stringToSign
@@ -555,8 +505,8 @@ QString calculateSignature(const QMap<QString, QString>& params, const QString&
// 请求头
void prepareRequestHeaders(QNetworkRequest& request, const QString& sign, const QString& request_id) {
request.setRawHeader("factory_id", "TEST");
request.setRawHeader("label", "SL100Label");
request.setRawHeader("batch", QString::number(240830).toUtf8());
request.setRawHeader("label", "TEST_SL100_20240826");
request.setRawHeader("batch", QString::number(1).toUtf8());
request.setRawHeader("model", "SL100");
request.setRawHeader("timestamp", QString::number(QDateTime::currentSecsSinceEpoch()).toUtf8());
request.setRawHeader("request_id", request_id.toUtf8());
@@ -598,7 +548,7 @@ void sendPostRequest(HttpClient* httpClient, const QUrl& url, const QMap<QString
// GET 获取 UUID
void MainWidget::FactoryToolSendGetUuidToHttpServer(const QString& mac_addr) {
QUrl url("http://admin.hassecurity.cn/v1/getUuid");
QMap<QString, QString> params = {
QMap<QString, QString> params = {
{"label", "TEST_SL100_20240826"},
{"model", "SL100"},
{"batch", "1"},
@@ -780,6 +730,8 @@ void MainWidget::readJsonConfig()
backBoardDevInfoJson = readJson_backDevInfo();
backBoardUuidJson = readJson_backUuid();
factoryProductInfo = readJson_factoryProductInfo();
testJsonConfig = readJson_testConfig();
funcJsonConfig = readJson_funcConfig();
@@ -989,26 +941,6 @@ void MainWidget::onLicenseButtonClicked()
}
}
else {
#if 0
if (jsonObject["lable"].toString() == "write_license") {
QString hwInfoText = licenseHwInfoEdit->toPlainText();
dataStr = hwInfoText.remove(","); // 去掉所有的逗号
QByteArray dataByteArray = QByteArray::fromHex(dataStr.toUtf8());
memcpy(hardware_info, dataByteArray.data(), qMin(dataByteArray.size(), PIX_HARDWARE_INFO_BYTES));
qDebug() << "hardware_info:" << QByteArray(reinterpret_cast<char*>(hardware_info), PIX_HARDWARE_INFO_BYTES).toHex();
licenseGenerate(hardware_info, license_info);
QString licenseInfoStr;
printf("License is\n");
for (int j = 0; j < PIX_LICENCE_BYTES; ++j) {
printf("0x%02x, ", license_info[j]);
licenseInfoStr.append(QString::asprintf("0x%02x, ", license_info[j]));
}
printf("\n");
licenseHwInfoEdit->setPlainText(licenseInfoStr);
dataStr = QByteArray(reinterpret_cast<char*>(license_info), PIX_LICENCE_BYTES).toHex();
qDebug() << "license_info:" << dataStr;
}
#else
if (jsonObject["lable"].toString() == "write_license") {
QString licenseInfoText = licenseHwInfoEdit->toPlainText();
qDebug() << "licenseInfoText:" << licenseInfoText;
@@ -1025,7 +957,6 @@ void MainWidget::onLicenseButtonClicked()
dataStr = dataByteArray.toBase64();
qDebug() << "Base64 Encoded:" << dataStr;
}
#endif
for (ClientHandler* handler : clients) {
handler->sendLicenseItem(index, dataStr);
}
@@ -1052,25 +983,75 @@ void MainWidget::onUuidButtonClicked()
QString sendToHttpServerDataStr = UuidHwInfoEdit->toPlainText();
qDebug() << "sendToHttpServerDataStr:" << sendToHttpServerDataStr;
// 测试随机生成8-12位字符串
sendToHttpServerDataStr = generateRandomRequestID(8, 13);
// sendToHttpServerDataStr = generateRandomRequestID(8, 13);
FactoryToolSendGetUuidToHttpServer(sendToHttpServerDataStr);
while (isRequestSuccessful == 0) {
QCoreApplication::processEvents(); // 防止阻塞UI线程
}
qDebug() << "isRequestSuccessful:" << isRequestSuccessful;
if (isRequestSuccessful == 2) {
UuidHwInfoEdit->setPlainText("服务器没有回复UUID和SN !!!");
isRequestSuccessful = 0;
return;
}
else if (isRequestSuccessful == 1) {
if (licenseDataArray.contains("uuid") && licenseDataArray.contains("sn")) {
QString backBoardUuid = licenseDataArray["uuid"].toString();
QString backBoardSn = licenseDataArray["sn"].toString();
QString displayText = QString("UUID:\n%1\nSN:\n%2").arg(backBoardUuid).arg(backBoardSn);
UuidHwInfoEdit->setPlainText(displayText);
qDebug() << "HTTP Server backBoardUuid is:" << backBoardUuid;
qDebug() << "HTTP Server backBoardSn is:" << backBoardSn;
isRequestSuccessful = 0;
return;
}
else {
qDebug() << "The UUID and SN are not found from the HTTP server!!!";
UuidHwInfoEdit->setPlainText("服务器没有回复UUID和SN !!!");
isRequestSuccessful = 0;
return;
}
}
}
else {
QString backBoardUuid = "";
QString backBoardSn = "";
if (jsonObject["lable"].toString() == "write_UUID_SN") {
QString UUIDAndSNInfoText = UuidHwInfoEdit->toPlainText();
QStringList lines = UUIDAndSNInfoText.split("\n");
bool isUuidSection = false;
bool isSnSection = false;
for (const QString& line : lines) {
QString trimmedLine = line.trimmed();
if (trimmedLine == "UUID:") {
isUuidSection = true;
isSnSection = false;
continue;
}
if (trimmedLine == "SN:") {
isUuidSection = false;
isSnSection = true;
continue;
}
if (isUuidSection) {
if (!backBoardUuid.isEmpty()) {
backBoardUuid += "\n";
}
backBoardUuid += trimmedLine;
}
if (isSnSection) {
if (!backBoardSn.isEmpty()) {
backBoardSn += "\n";
}
backBoardSn += trimmedLine;
}
}
qDebug() << "UuidHwInfoEdit backBoardUuid is:" << backBoardUuid;
qDebug() << "UuidHwInfoEdit backBoardSn is:" << backBoardSn;
}
qDebug() << "onUuidButtonClicked index:" << index;
for (ClientHandler* handler : clients) {
handler->sendUuidItem(index, "");
handler->sendUuidItem(index, backBoardUuid, backBoardSn);
}
}
}
@@ -1191,7 +1172,7 @@ void MainWidget::onSendGetPicClicked()
}
else {
if (lastClickedGetPicCamIndex == -1) {
QListWidgetItem* listItem = new QListWidgetItem(QString("Please select IR or RGB lens to get image!!!"), statusListWidget);
QListWidgetItem* listItem = new QListWidgetItem(QString("Please select \"左边镜头\" or \"右边镜头\" to get image!!!"), statusListWidget);
listItem->setBackground(Qt::red);
}
else {
@@ -1227,47 +1208,135 @@ void MainWidget::onSendGetVideoClicked()
{
if (connectedClientsCount) {
QPushButton* button = qobject_cast<QPushButton*>(sender());
int itemIndex = button->property("getVideoIndex").toInt();
if (itemIndex < 4) {
button->setStyleSheet("background-color: green;");
if (lastClickedGetVideoCamIndex != -1 && lastClickedGetVideoCamIndex != itemIndex) {
getVideoButtons[lastClickedGetVideoCamIndex]->setStyleSheet("");
if (lastClickedGetVideoDevIndex != -1) {
getVideoButtons[lastClickedGetVideoDevIndex - 2]->setStyleSheet("");
}
}
lastClickedGetVideoCamIndex = itemIndex;
}
else {
if (lastClickedGetVideoCamIndex == -1) {
QListWidgetItem* listItem = new QListWidgetItem(QString("Please select lens to get video!!!"), statusListWidget);
listItem->setBackground(Qt::red);
}
else {
if (itemIndex - 8 >= connectedClientsCount) {
QListWidgetItem* listItem = new QListWidgetItem(QString("This device is not connected !!!").arg(itemIndex - 6), statusListWidget);
listItem->setBackground(Qt::red);
}
else {
int itemIndex = -1;
if (button) {
if (button->property(FRONT_BOARD_VIDEO_BUTTON_INDEX_PROPERTY).isValid()) {
itemIndex = button->property(FRONT_BOARD_VIDEO_BUTTON_INDEX_PROPERTY).toInt();
if (itemIndex < 4) {
button->setStyleSheet("background-color: green;");
if (lastClickedGetVideoDevIndex != -1 && lastClickedGetVideoDevIndex != itemIndex) {
//qDebug() << "itemIndex:" << itemIndex;
getVideoButtons[lastClickedGetVideoDevIndex - 2]->setStyleSheet("");
}
lastClickedGetVideoDevIndex = itemIndex;
//QMutexLocker locker(&mutex);
for (ClientHandler* handler : clients) {
if (handler->getClientId() == handler->controlClientId) {
qDebug() << "lens number:" << lastClickedGetVideoCamIndex;
handler->sendGetVideoItem(itemIndex - 7, lastClickedGetVideoCamIndex);
break;
if (lastClickedGetVideoCamIndex != -1 && lastClickedGetVideoCamIndex != itemIndex) {
getVideoButtons[lastClickedGetVideoCamIndex]->setStyleSheet("");
if (lastClickedGetVideoDevIndex != -1) {
getVideoButtons[lastClickedGetVideoDevIndex - 2]->setStyleSheet("");
}
}
lastClickedGetVideoCamIndex = itemIndex;
}
else {
if (lastClickedGetVideoCamIndex == -1) {
QListWidgetItem* listItem = new QListWidgetItem(QString("Please select lens to get video!!!"), statusListWidget);
listItem->setBackground(Qt::red);
}
else {
if (itemIndex - 8 >= connectedClientsCount) {
QListWidgetItem* listItem = new QListWidgetItem(QString("This device is not connected !!!").arg(itemIndex - 6), statusListWidget);
listItem->setBackground(Qt::red);
}
else {
button->setStyleSheet("background-color: green;");
if (lastClickedGetVideoDevIndex != -1 && lastClickedGetVideoDevIndex != itemIndex) {
//qDebug() << "itemIndex:" << itemIndex;
getVideoButtons[lastClickedGetVideoDevIndex - 2]->setStyleSheet("");
}
lastClickedGetVideoDevIndex = itemIndex;
//QMutexLocker locker(&mutex);
for (ClientHandler* handler : clients) {
if ((isBackBoardOrAllBoard) || (handler->getClientId() == handler->controlClientId)) {
qDebug() << "lens number:" << lastClickedGetVideoCamIndex;
handler->sendGetVideoItem(itemIndex - 7, lastClickedGetVideoCamIndex);
break;
}
}
getVideoButtons[FOCUS_WINDOWS_BUTTON]->setEnabled(true);
}
}
getVideoButtons[FOCUS_WINDOWS_BUTTON]->setEnabled(true);
}
}
}
else if (button->property(BACK_BOARD_VIDEO_BUTTON_INDEX_PROPERTY).isValid()) {
itemIndex = button->property(BACK_BOARD_VIDEO_BUTTON_INDEX_PROPERTY).toInt();
if (itemIndex < 4) {
button->setStyleSheet("background-color: green;");
if (lastClickedGetVideoCamIndex != -1 && lastClickedGetVideoCamIndex != itemIndex) {
getBackVideoButtons[lastClickedGetVideoCamIndex]->setStyleSheet("");
if (lastClickedGetVideoDevIndex != -1) {
getBackVideoButtons[lastClickedGetVideoDevIndex - 2]->setStyleSheet("");
}
}
lastClickedGetVideoCamIndex = itemIndex;
}
else {
if (lastClickedGetVideoCamIndex == -1) {
QListWidgetItem* listItem = new QListWidgetItem(QString("Please select lens to get video!!!"), statusListWidget);
listItem->setBackground(Qt::red);
}
else {
if (itemIndex - 8 >= connectedClientsCount) {
QListWidgetItem* listItem = new QListWidgetItem(QString("This device is not connected !!!").arg(itemIndex - 6), statusListWidget);
listItem->setBackground(Qt::red);
}
else {
button->setStyleSheet("background-color: green;");
if (lastClickedGetVideoDevIndex != -1 && lastClickedGetVideoDevIndex != itemIndex) {
//qDebug() << "itemIndex:" << itemIndex;
getBackVideoButtons[lastClickedGetVideoDevIndex - 2]->setStyleSheet("");
}
lastClickedGetVideoDevIndex = itemIndex;
//QMutexLocker locker(&mutex);
for (ClientHandler* handler : clients) {
if ((isBackBoardOrAllBoard) || (handler->getClientId() == handler->controlClientId)) {
qDebug() << "lens number:" << lastClickedGetVideoCamIndex;
handler->sendGetVideoItem(itemIndex - 7, lastClickedGetVideoCamIndex);
break;
}
}
getBackVideoButtons[FOCUS_WINDOWS_BUTTON]->setEnabled(true);
}
}
}
}
else if (button->property(ALL_BOARD_VIDEO_BUTTON_INDEX_PROPERTY).isValid()) {
itemIndex = button->property(ALL_BOARD_VIDEO_BUTTON_INDEX_PROPERTY).toInt();
if (itemIndex < 4) {
button->setStyleSheet("background-color: green;");
if (lastClickedGetVideoCamIndex != -1 && lastClickedGetVideoCamIndex != itemIndex) {
getAllVideoButtons[lastClickedGetVideoCamIndex]->setStyleSheet("");
if (lastClickedGetVideoDevIndex != -1) {
getAllVideoButtons[lastClickedGetVideoDevIndex - 2]->setStyleSheet("");
}
}
lastClickedGetVideoCamIndex = itemIndex;
}
else {
if (lastClickedGetVideoCamIndex == -1) {
QListWidgetItem* listItem = new QListWidgetItem(QString("Please select lens to get video!!!"), statusListWidget);
listItem->setBackground(Qt::red);
}
else {
if (itemIndex - 8 >= connectedClientsCount) {
QListWidgetItem* listItem = new QListWidgetItem(QString("This device is not connected !!!").arg(itemIndex - 6), statusListWidget);
listItem->setBackground(Qt::red);
}
else {
button->setStyleSheet("background-color: green;");
if (lastClickedGetVideoDevIndex != -1 && lastClickedGetVideoDevIndex != itemIndex) {
//qDebug() << "itemIndex:" << itemIndex;
getAllVideoButtons[lastClickedGetVideoDevIndex - 2]->setStyleSheet("");
}
lastClickedGetVideoDevIndex = itemIndex;
//QMutexLocker locker(&mutex);
for (ClientHandler* handler : clients) {
if ((isBackBoardOrAllBoard) || (handler->getClientId() == handler->controlClientId)) {
qDebug() << "lens number:" << lastClickedGetVideoCamIndex;
handler->sendGetVideoItem(itemIndex - 7, lastClickedGetVideoCamIndex);
break;
}
}
getAllVideoButtons[FOCUS_WINDOWS_BUTTON]->setEnabled(true);
}
}
}
}
}
}
else {
QListWidgetItem* listItem = new QListWidgetItem(QString("No device is connected !!!"), statusListWidget);
@@ -1311,8 +1380,11 @@ void MainWidget::onSendAllClicked()
// 重置索引
handler->resetCurrentItemIndex();
if (handler->getClientId() == handler->controlClientId) {
handler->sendNextItem();
//handler->sendDevInfoItem();
handler->sendNextItem(frontBoardOneClickTest);
break;
}
else if (isBackBoardOrAllBoard) {
handler->sendNextItem(backBoardOneClickTest);
break;
}
}
@@ -1339,7 +1411,7 @@ void MainWidget::onSendFrontFuncItemClicked()
QPushButton* button = qobject_cast<QPushButton*>(sender());
int itemIndex = button->property("frontBoardFuncConfig").toInt();
for (ClientHandler* handler : clients) {
if (handler->getClientId() == handler->controlClientId) {
if ((isBackBoardOrAllBoard) || (handler->getClientId() == handler->controlClientId)) {
QString text = frontFuncConfigLineEdit->text();
qDebug() << "Text in frontFuncConfigLineEdit:" << text;
handler->sendFrontFuncItem(itemIndex, text);
@@ -1381,7 +1453,7 @@ void MainWidget::onSendFrontItemClicked()
QPushButton* button = qobject_cast<QPushButton*>(sender());
int itemIndex = button->property("frontBoardTest").toInt();
for (ClientHandler* handler : clients) {
if (handler->getClientId() == handler->controlClientId) {
if ((isBackBoardOrAllBoard) || (handler->getClientId() == handler->controlClientId)) {
handler->sendFrontItem(itemIndex);
break;
}
@@ -1412,50 +1484,18 @@ void MainWidget::onSendBackItemClicked()
}
}
// 处理状态更新信号
void MainWidget::onStatusUpdated(const QString& client, int itemIndex, int FuncItemIndex,
bool success, const QString& itemData, const QString& funcItemData,
const QJsonArray& jsonArray, int itemJsonIndex)
void MainWidget::onStatusUpdated(const QString& client, bool success, const QJsonArray& jsonArray, int itemJsonIndex)
{
int clientId = -1;
QString label;
// 遍历所有的 ClientHandler找到匹配的 client
for (ClientHandler* handler : clients) {
if (handler->getClientAddress() == client) {
clientId = handler->getClientId();
QString lable = handler->getCurrentItemLable();
lable = handler->getCurrentFuncItemLable();
break;
}
else
{
//qDebug() << "" << __FUNCTION__ << "handler->getClientAddress() != client" ;
}
}
//qDebug() << "itemIndex :" << itemIndex;
//qDebug() << "FuncItemIndex:" << FuncItemIndex;
//if (itemIndex > 0) {
// QListWidgetItem* listItem = new QListWidgetItem(QString("device ID: %1 - Item %2: %3 ---> %4")
// .arg(clientId)
// .arg(itemIndex)
// .arg(itemData) // data 字段
// .arg(success ? "OK" : "NG"), statusListWidget);
// listItem->setBackground(success ? Qt::green : Qt::red);
// statusListWidget->addItem(listItem);
//}
//else if (FuncItemIndex > 0) {
// QListWidgetItem* listItem = new QListWidgetItem(QString("device ID: %1 - funcItem %2: %3 ---> %4")
// .arg(clientId)
// .arg(FuncItemIndex)
// .arg(funcItemData) // data 字段
// .arg(success ? "OK" : "NG"), statusListWidget);
// listItem->setBackground(success ? Qt::green : Qt::red);
// statusListWidget->addItem(listItem);
//}
}
}
qDebug() << "itemJsonIndex :" << itemJsonIndex;
if (itemJsonIndex >= 0 && itemJsonIndex < jsonArray.size()) {
QJsonObject jsonObject = jsonArray.at(itemJsonIndex).toObject();
@@ -1467,7 +1507,7 @@ void MainWidget::onStatusUpdated(const QString& client, int itemIndex, int FuncI
QListWidgetItem* listItem = new QListWidgetItem(QString("device ID: %1 - Item %2: %3 ---> %4")
.arg(clientId)
.arg(itemJsonIndex + 1)
.arg(label) // data 字段
.arg(label)
.arg(success ? "OK" : "NG"), statusListWidget);
listItem->setBackground(success ? Qt::green : Qt::red);
statusListWidget->addItem(listItem);
@@ -1504,3 +1544,12 @@ void MainWidget::onAllItemsProcessed(const QString& client, int itemsProcessedCo
statusListWidget->scrollToBottom();
}
void MainWidget::onHandleInvalidOperate(const QString& text)
{
QListWidgetItem* listItem = new QListWidgetItem(QString("%1")
.arg(text), statusListWidget);
listItem->setBackground(Qt::red);
statusListWidget->addItem(listItem);
statusListWidget->scrollToBottom();
}

View File

@@ -44,6 +44,7 @@
#include <QMessageAuthenticationCode>
#include <QCoreApplication>
#include "./UI_Widget/UI_Name.h"
#include "../Json/readJsonFile.h"
#include "../RecvDataHandler/RecvDataHandler.h"
#include "../LicenseGenerate/LicenseGenerate.h"
@@ -64,6 +65,9 @@
#define START_MDNS 1
#define FOCUS_WINDOWS_BUTTON 4 // 大窗口播放视频的按键编号
#define TCP_CONNECT_PORT 12412 // TCP监听的端口
#define GET_PIC_DATA_SIZE (480 * 640 * 1.5)
#define NEW_MAP 1
class MainWidget : public QWidget
{
@@ -105,9 +109,7 @@ private slots:
// 处理数据接收信号
//void onDataReceived(const QString& client, const QByteArray& data);
// 处理状态更新信号
void onStatusUpdated(const QString& client, int itemIndex, int funcItemIndex,
bool success, const QString& itemData, const QString& funcItemData,
const QJsonArray& jsonArray, int itemJsonIndex);
void onStatusUpdated(const QString& client, bool success, const QJsonArray& jsonArray, int itemJsonIndex);
// 处理所有项目处理完毕信号
void onAllItemsProcessed(const QString& client, int itemsProcessedCount);
// 处理客户端断开连接
@@ -138,18 +140,34 @@ private:
void readJsonConfig();
// 设置 UI
void setupUI();
#if NEW_MAP
void addDeviceAreaTab(QTabWidget* mainTabWidget, const QString& tabName,
QGroupBox* deviceInfoGroupBox, QGroupBox* licenseGroupBox,
const QJsonArray& boardTest, const QJsonArray& boardFuncConfig,
const QString& boardTestName, const QString& boardFuncConfigName,
const QString& boardTestTitle, const QString& boardConfigTitle,
QLabel* leftLensLabel, QLabel* rightLensLabel, QLabel* videoLabel,
QLineEdit* VideoResolutionEdit_type);
void addAllDeviceAreaTab(QTabWidget* mainTabWidget, const QString& tabName,
QLabel* leftLensLabel, QLabel* rightLensLabel, QLabel* videoLabel,
QLineEdit* VideoResolutionEdit_type);
QTabWidget* createMediaTabWidget(QLabel* leftLensLabel, QLabel* rightLensLabel, QLabel* videoLabel,
QLineEdit* VideoResolutionEdit_type, const QString& tabName);
#endif
QGroupBox* createLicenseGroupBox();
QGroupBox* createFrontDeviceInfoGroupBox();
QGroupBox* createBackDeviceInfoGroupBox();
QWidget* createFunctionTestTab(const QJsonArray& BoardFuncTest, const QString& propertyName);
QWidget* createFunctionConfigTab(const QJsonArray& BoardFuncConfig, const QString& propertyName);
QWidget* createImageDisplayTab();
QWidget* createVideoDisplayTab();
QWidget* createImageDisplayTab(QLabel* leftLensLabel, QLabel* rightLensLabel);
QWidget* createVideoDisplayTab(QLabel* videoLabel, QLineEdit* VideoResolutionEdit_type, const QString& tabName);
QGroupBox* createBackConnectServerGroupBox();
// 保存日志到文件
void saveStatusListToFile(const QString& filePath);
// 用于更新按键文本的函数
void updateServerButtonText();
void onHandleInvalidOperate(const QString& text);
void onDisconnectClient(int clientId);
void setupTimerForThreadPoolInfo();
void sendDataToClient(int clientId, const QByteArray& data);
@@ -172,6 +190,7 @@ private:
QJsonArray backBoardFuncConfig; // 后板功能配置参数 JSON
QJsonArray backBoardDevInfoJson; // 后板设备信息参数 JSON
QJsonArray backBoardUuidJson; // 后板UUID JSON
QJsonArray factoryProductInfo; // 整机:工厂生产信息
QJsonArray testJsonConfig; // 功能测试区 JSON 配置
QJsonArray funcJsonConfig; // 功能配置区 JSON 配置
QJsonArray getDevInfoJson; // 获取设备信息 JSON 配置
@@ -199,19 +218,30 @@ private:
QVector<QPushButton*> funcItemButtons; // 功能配置项目按键集合
QVector<QPushButton*> getPicButtons; // 保存两个取图的摄像头的按键的指针
QVector<QPushButton*> getVideoButtons; // 保存拉视频设备的按键的指针
QVector<QPushButton*> getBackVideoButtons;
QVector<QPushButton*> getAllVideoButtons;
QList<ClientHandler*> clients; // 客户端处理器集合
QMap<int, QTimer*> clientTimers; // 每个客户端的定时器
QMap<QString, QLineEdit*> devInfoLineEdits;// msg_id 和对应的 QLineEdit 的映射关系
QMap<QString, QLineEdit*> productInfoLineEdits;
QCheckBox* saveCheckBox; // 保存文件复选框
QPushButton* selectFileButton; // Save Log 按键
QPushButton* clearLogButton; // clear Log 按键
QLineEdit* filePathLineEdit; // 文件路径显示
QLineEdit* VideoResolutionEdit; // 视频分辨率显示
QLineEdit* VideoResolutionEdit_back; // 视频分辨率显示
QLineEdit* VideoResolutionEdit_all; // 视频分辨率显示
//QLineEdit* frameRateEdit; // 视频帧率显示
QLabel* leftLens_imageLabel; // 左边镜头图像显示
QLabel* rightLens_imageLabel; // 右边镜头图像显示
QLabel* videoLabel; // 视频显示
QLabel* leftLens_imageLabel; // 前板左边镜头图像显示
QLabel* rightLens_imageLabel; // 前板右边镜头图像显示
QLabel* leftLens_imageLabel_back; // 后板左边镜头图像显示
QLabel* rightLens_imageLabel_back; // 后板右边镜头图像显示
QLabel* leftLens_imageLabel_all; // 整机左边镜头图像显示
QLabel* rightLens_imageLabel_all; // 整机右边镜头图像显示
QLabel* videoLabel; // 前板视频显示
QLabel* video_Label_back; // 后板视频显示
QLabel* video_Label_all; // 整机视频显示
QLineEdit* frontFuncConfigLineEdit; // 前板功能配置编辑框
QLineEdit* backFuncConfigLineEdit; // 后板功能配置编辑框
QTextEdit* licenseHwInfoEdit; // 获取license的硬件信息

View File

@@ -0,0 +1,42 @@
// UI_Name.h
#ifndef UI_NAME_H
#define UI_NAME_H
#define SL100_FACTORY_TOOL_W 1340
#define SL100_FACTORY_TOOL_H 900
#define START_LISTENING "开始监听\n(Start Listening...)"
#define ONE_CLICKED_TEST "一键功能测试"
#define TOOL_VERSION "SL100 工厂产测工具 - V0.0.7"
#define FRONT_BOARD_NAME "前 板"
#define BACK_BOARD_NAME "后 板"
#define ALL_BOARD_NAME "整 机"
#define FRONT_BOARD_TEST "前板测试项"
#define IMAGE_DISPLAYAREA "图像显示区"
#define VIDEO_DISPLAYAREA "视频显示区"
#define RESOLUTION_EDIT "分辨率:"
#define LEFT_LENS "左边镜头"
#define RIGHT_LENS "右边镜头"
#define CAT_EYE_LENS_RGB "猫眼镜头(RGB)"
#define CAT_EYE_LENS_IR "猫眼镜头(IR)"
#define BIG_WINDOW_PRE_VIDEO "大窗口播放视频"
#define IMAGE_DISPLAY_TAB "图像显示区"
#define VIDEO_DISPLAY_TAB "视频显示区"
#define INPUT_CONFIG_PARA "请输入配置参数..."
#define FRONT_TEST_ITEM "前板测试项"
#define FRONT_CONFID_ITEM "前板配置项"
#define FRONT_DEVICE_INFO "前板设备信息"
#define FRONT_TUYU_LICENSE "算法 license"
#define BACK_TEST_ITEM "后板测试项"
#define BACK_CONFID_ITEM "后板配置项"
#define BACK_GET_UUID_SN "后板获取 UUID/SN"
#define BACK_DEVICE_INFO "后板设备信息"
#define ALL_BOARD "整机设备信息"
#define ALL_PRODUCT_INFO "工厂生产信息"
#define FRONT_BOARD_VIDEO_BUTTON_INDEX_PROPERTY "getVideoIndex"
#define BACK_BOARD_VIDEO_BUTTON_INDEX_PROPERTY "BackGetVideoIndex"
#define ALL_BOARD_VIDEO_BUTTON_INDEX_PROPERTY "AllGetVideoIndex"
#endif

View File

@@ -2,7 +2,7 @@
QGroupBox* MainWidget::createLicenseGroupBox()
{
QGroupBox* groupBox = new QGroupBox("算法 license", this);
QGroupBox* groupBox = new QGroupBox(QString(FRONT_TUYU_LICENSE), this);
QHBoxLayout* buttonRowLayout = new QHBoxLayout;
for (int i = 0; i < frontBoardLicenseJson.size(); ++i) {
@@ -29,9 +29,8 @@ QGroupBox* MainWidget::createLicenseGroupBox()
QGroupBox* MainWidget::createFrontDeviceInfoGroupBox()
{
QGroupBox* frontDeviceInfoGroupBox = new QGroupBox("前板设备信息", this);
QGroupBox* frontDeviceInfoGroupBox = new QGroupBox(QString(FRONT_DEVICE_INFO), this);
QFormLayout* formLayout = new QFormLayout(frontDeviceInfoGroupBox);
for (const QJsonValue& value : frontBoardDevInfoJson) {
QJsonObject item = value.toObject();
QString label = item["lable"].toString();
@@ -43,19 +42,17 @@ QGroupBox* MainWidget::createFrontDeviceInfoGroupBox()
formLayout->addRow(itemLabel, itemLineEdit);
devInfoLineEdits[cmd] = itemLineEdit;
}
return frontDeviceInfoGroupBox;
}
QGroupBox* MainWidget::createBackDeviceInfoGroupBox()
{
QGroupBox* backDeviceInfoGroupBox = new QGroupBox("后板设备信息", this);
QGroupBox* backDeviceInfoGroupBox = new QGroupBox(QString(BACK_DEVICE_INFO), this);
QFormLayout* formLayout = new QFormLayout(backDeviceInfoGroupBox);
for (const QJsonValue& value : backBoardDevInfoJson) {
QJsonObject item = value.toObject();
QString label = item["lable"].toString();
QString cmd = item["cmd"].toString();
QJsonObject item = value.toObject();
QString label = item["lable"].toString();
QString cmd = item["cmd"].toString();
QLabel* itemLabel = new QLabel(label, this);
QLineEdit* itemLineEdit = new QLineEdit(this);
itemLineEdit->setReadOnly(true);
@@ -63,13 +60,12 @@ QGroupBox* MainWidget::createBackDeviceInfoGroupBox()
formLayout->addRow(itemLabel, itemLineEdit);
devInfoLineEdits[cmd] = itemLineEdit;
}
return backDeviceInfoGroupBox;
}
QGroupBox* MainWidget::createBackConnectServerGroupBox()
{
QGroupBox* BackConnectServerGroupBox = new QGroupBox("后板获取UUID", this);
QGroupBox* BackConnectServerGroupBox = new QGroupBox(QString(BACK_GET_UUID_SN), this);
QHBoxLayout* frontDeviceInfoLayout = new QHBoxLayout;
for (int i = 0; i < backBoardUuidJson.size(); ++i) {
@@ -141,11 +137,11 @@ QWidget* MainWidget::createFunctionConfigTab(const QJsonArray& BoardFuncConfig,
QWidget* functionConfigTab = new QWidget(this);
QVBoxLayout* functionConfigLayout = new QVBoxLayout(functionConfigTab);
if (propertyName == "frontBoardFuncConfig") {
frontFuncConfigLineEdit->setPlaceholderText("请输入配置参数...");
frontFuncConfigLineEdit->setPlaceholderText(QString(INPUT_CONFIG_PARA));
functionConfigLayout->addWidget(frontFuncConfigLineEdit);
}
else if (propertyName == "backBoardFuncConfig") {
backFuncConfigLineEdit->setPlaceholderText("请输入配置参数...");
backFuncConfigLineEdit->setPlaceholderText(QString(INPUT_CONFIG_PARA));
functionConfigLayout->addWidget(backFuncConfigLineEdit);
}
@@ -186,7 +182,7 @@ QWidget* MainWidget::createFunctionConfigTab(const QJsonArray& BoardFuncConfig,
return functionConfigTab;
}
QWidget* MainWidget::createImageDisplayTab()
QWidget* MainWidget::createImageDisplayTab(QLabel* leftLensLabel, QLabel* rightLensLabel)
{
QWidget* imageDisplayTab = new QWidget(this);
QVBoxLayout* imageDisplayLayout = new QVBoxLayout(imageDisplayTab);
@@ -197,7 +193,7 @@ QWidget* MainWidget::createImageDisplayTab()
for (int j = 0; j < 2; ++j) {
QPushButton* button;
if (i == 0 && j == 0) {
button = new QPushButton(QString("IR"), this);
button = new QPushButton(QString(LEFT_LENS), this);
button->setFixedSize(73, 50);
imageButtonsRowLayout->addWidget(button);
button->setProperty("getPicIndex", i * 2 + j);
@@ -206,7 +202,7 @@ QWidget* MainWidget::createImageDisplayTab()
continue;
}
else if (i == 0 && j == 1) {
button = new QPushButton(QString("RGB"), this);
button = new QPushButton(QString(RIGHT_LENS), this);
button->setFixedSize(73, 50);
imageButtonsRowLayout->addWidget(button);
button->setProperty("getPicIndex", i * 2 + j);
@@ -215,7 +211,7 @@ QWidget* MainWidget::createImageDisplayTab()
continue;
}
button = new QPushButton(QString("Device %1").arg(i * 2 + j - 1), this);
button = new QPushButton(QString("Device %1\n取图").arg(i * 2 + j - 1), this);
button->setFixedSize(73, 50);
imageButtonsRowLayout->addWidget(button);
button->setProperty("getPicIndex", i * 2 + j);
@@ -226,10 +222,12 @@ QWidget* MainWidget::createImageDisplayTab()
}
QHBoxLayout* lensesLayout = new QHBoxLayout;
leftLens_imageLabel = new QLabel(this);
rightLens_imageLabel = new QLabel(this);
lensesLayout->addWidget(leftLens_imageLabel);
lensesLayout->addWidget(rightLens_imageLabel);
//leftLens_imageLabel = new QLabel(this);
//rightLens_imageLabel = new QLabel(this);
//lensesLayout->addWidget(leftLens_imageLabel);
//lensesLayout->addWidget(rightLens_imageLabel);
lensesLayout->addWidget(leftLensLabel);
lensesLayout->addWidget(rightLensLabel);
QHBoxLayout* imageAndButtonsLayout = new QHBoxLayout;
imageAndButtonsLayout->addLayout(imageButtonsColumnLayout, 1);
@@ -239,12 +237,23 @@ QWidget* MainWidget::createImageDisplayTab()
return imageDisplayTab;
}
QWidget* MainWidget::createVideoDisplayTab()
QWidget* MainWidget::createVideoDisplayTab(QLabel* video_Label, QLineEdit* VideoResolutionEdit_type, const QString& tabName)
{
QWidget* videoDisplayTab = new QWidget(this);
QWidget* videoDisplayTab = new QWidget(this);
QVBoxLayout* videoDisplayLayout = new QVBoxLayout(videoDisplayTab);
QVBoxLayout* videoButtonsColumnLayout = new QVBoxLayout;
const char* videoIndexProperty;
if (tabName == QString(FRONT_BOARD_NAME)) {
videoIndexProperty = FRONT_BOARD_VIDEO_BUTTON_INDEX_PROPERTY;
}
else if (tabName == QString(BACK_BOARD_NAME)) {
videoIndexProperty = BACK_BOARD_VIDEO_BUTTON_INDEX_PROPERTY;
}
else if(tabName == QString(ALL_BOARD_NAME)) {
videoIndexProperty = ALL_BOARD_VIDEO_BUTTON_INDEX_PROPERTY;
}
for (int i = 0; i < 6; ++i) {
QHBoxLayout* videoButtonsRowLayout = new QHBoxLayout;
@@ -252,52 +261,92 @@ QWidget* MainWidget::createVideoDisplayTab()
QPushButton* button;
if (i == 0 && j == 0) {
button = new QPushButton(QString("猫眼镜头(IR)"), this);
button = new QPushButton(QString(CAT_EYE_LENS_IR), this);
button->setFixedSize(110, 50);
videoButtonsRowLayout->addWidget(button);
button->setProperty("getVideoIndex", i * 2 + j);
button->setProperty(videoIndexProperty, i * 2 + j);
connect(button, &QPushButton::clicked, this, &MainWidget::onSendGetVideoClicked);
getVideoButtons.append(button);
if (tabName == QString(FRONT_BOARD_NAME)) {
getVideoButtons.append(button);
}
else if (tabName == QString(BACK_BOARD_NAME)) {
getBackVideoButtons.append(button);
}
else if (tabName == QString(ALL_BOARD_NAME)) {
getAllVideoButtons.append(button);
}
continue;
}
else if (i == 0 && j == 1) {
button = new QPushButton(QString("猫眼镜头(RGB)"), this);
button = new QPushButton(QString(CAT_EYE_LENS_RGB), this);
button->setFixedSize(110, 50);
videoButtonsRowLayout->addWidget(button);
button->setProperty("getVideoIndex", i * 2 + j);
button->setProperty(videoIndexProperty, i * 2 + j);
connect(button, &QPushButton::clicked, this, &MainWidget::onSendGetVideoClicked);
getVideoButtons.append(button);
if (tabName == QString(FRONT_BOARD_NAME)) {
getVideoButtons.append(button);
}
else if (tabName == QString(BACK_BOARD_NAME)) {
getBackVideoButtons.append(button);
}
else if (tabName == QString(ALL_BOARD_NAME)) {
getAllVideoButtons.append(button);
}
continue;
}
if (i == 1 && j == 0) {
button = new QPushButton(QString("左边镜头"), this);
button->setFixedSize(110, 50);
videoButtonsRowLayout->addWidget(button);
button->setProperty("getVideoIndex", i * 2 + j);
connect(button, &QPushButton::clicked, this, &MainWidget::onSendGetVideoClicked);
getVideoButtons.append(button);
continue;
if (tabName != QString(BACK_BOARD_NAME)) {
if (i == 1 && j == 0) {
button = new QPushButton(QString(LEFT_LENS), this);
button->setFixedSize(110, 50);
videoButtonsRowLayout->addWidget(button);
button->setProperty(videoIndexProperty, i * 2 + j);
connect(button, &QPushButton::clicked, this, &MainWidget::onSendGetVideoClicked);
if (tabName == QString(FRONT_BOARD_NAME)) {
getVideoButtons.append(button);
}
else if (tabName == QString(BACK_BOARD_NAME)) {
getBackVideoButtons.append(button);
}
else if (tabName == QString(ALL_BOARD_NAME)) {
getAllVideoButtons.append(button);
}
continue;
}
else if (i == 1 && j == 1) {
button = new QPushButton(QString(RIGHT_LENS), this);
button->setFixedSize(110, 50);
videoButtonsRowLayout->addWidget(button);
button->setProperty(videoIndexProperty, i * 2 + j);
connect(button, &QPushButton::clicked, this, &MainWidget::onSendGetVideoClicked);
if (tabName == QString(FRONT_BOARD_NAME)) {
getVideoButtons.append(button);
}
else if (tabName == QString(BACK_BOARD_NAME)) {
getBackVideoButtons.append(button);
}
else if (tabName == QString(ALL_BOARD_NAME)) {
getAllVideoButtons.append(button);
}
continue;
}
}
else if (i == 1 && j == 1) {
button = new QPushButton(QString("右边镜头"), this);
button->setFixedSize(110, 50);
videoButtonsRowLayout->addWidget(button);
button->setProperty("getVideoIndex", i * 2 + j);
connect(button, &QPushButton::clicked, this, &MainWidget::onSendGetVideoClicked);
getVideoButtons.append(button);
continue;
}
if (i == 2 && j == 0) {
button = new QPushButton(QString("大窗口播放视频"), this);
button = new QPushButton(QString(BIG_WINDOW_PRE_VIDEO), this);
button->setFixedSize(224, 50);
button->setEnabled(false);
videoButtonsRowLayout->addWidget(button);
button->setProperty("getVideoIndex", i * 2 + j);
button->setProperty(videoIndexProperty, i * 2 + j);
connect(button, &QPushButton::clicked, this, &MainWidget::onOpenFocusWindowClicked);
getVideoButtons.append(button);
break; // 跳出内层循环,只添加一个按键
if (tabName == QString(FRONT_BOARD_NAME)) {
getVideoButtons.append(button);
}
else if (tabName == QString(BACK_BOARD_NAME)) {
getBackVideoButtons.append(button);
}
else if (tabName == QString(ALL_BOARD_NAME)) {
getAllVideoButtons.append(button);
}
break;
}
if (i >= 3 && i <= 5) {
@@ -312,28 +361,30 @@ QWidget* MainWidget::createVideoDisplayTab()
button->setFixedSize(110, 50);
videoButtonsRowLayout->addWidget(button);
button->setProperty("getVideoIndex", i * 2 + j + 1);
button->setProperty(videoIndexProperty, i * 2 + j + 1);
connect(button, &QPushButton::clicked, this, &MainWidget::onSendGetVideoClicked);
getVideoButtons.append(button);
if (tabName == QString(FRONT_BOARD_NAME)) {
getVideoButtons.append(button);
}
else if (tabName == QString(BACK_BOARD_NAME)) {
getBackVideoButtons.append(button);
}
else if (tabName == QString(ALL_BOARD_NAME)) {
getAllVideoButtons.append(button);
}
}
videoButtonsColumnLayout->addLayout(videoButtonsRowLayout);
}
QHBoxLayout* videoAndButtonsLayout = new QHBoxLayout;
QFormLayout* formLayout = new QFormLayout;
QLabel* VideoResolution = new QLabel("分辨率:");
VideoResolutionEdit = new QLineEdit;
VideoResolutionEdit->setFixedWidth(120);
formLayout->addRow(VideoResolution, VideoResolutionEdit);
/*QLabel* frameRate = new QLabel("帧率:");
frameRateEdit = new QLineEdit;
frameRateEdit->setFixedWidth(120);
formLayout->addRow(frameRate, frameRateEdit);*/
videoLabel = new QLabel(this);
videoLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
QLabel* VideoResolution = new QLabel(QString(RESOLUTION_EDIT));
VideoResolutionEdit_type->setFixedWidth(120);
formLayout->addRow(VideoResolution, VideoResolutionEdit_type);
video_Label->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
videoAndButtonsLayout->addLayout(videoButtonsColumnLayout);
videoAndButtonsLayout->addLayout(formLayout);
videoAndButtonsLayout->addWidget(videoLabel);
videoAndButtonsLayout->addWidget(video_Label);
videoAndButtonsLayout->setStretch(0, 1);
videoAndButtonsLayout->setStretch(1, 1);
videoAndButtonsLayout->setStretch(2, 1);
@@ -342,4 +393,79 @@ QWidget* MainWidget::createVideoDisplayTab()
return videoDisplayTab;
}
// 创建设备区域布局(前板或后板)
void MainWidget::addDeviceAreaTab(QTabWidget* mainTabWidget, const QString& tabName,
QGroupBox* deviceInfoGroupBox, QGroupBox* licenseGroupBox,
const QJsonArray& boardTest, const QJsonArray& boardFuncConfig,
const QString& boardTestName, const QString& boardFuncConfigName,
const QString& boardTestTitle, const QString& boardConfigTitle,
QLabel* leftLensLabel, QLabel* rightLensLabel, QLabel* video_Label,
QLineEdit* VideoResolutionEdit_type)
{
QHBoxLayout* groupBoxLayout = new QHBoxLayout;
groupBoxLayout->addWidget(deviceInfoGroupBox, 1);
groupBoxLayout->addWidget(licenseGroupBox, 1);
QTabWidget* boardTabWidget = new QTabWidget(this);
boardTabWidget->setFixedSize(900, 315);
QWidget* functionTestTab = createFunctionTestTab(boardTest, boardTestName);
QWidget* functionConfigTab = createFunctionConfigTab(boardFuncConfig, boardFuncConfigName);
boardTabWidget->addTab(functionTestTab, boardTestTitle);
boardTabWidget->addTab(functionConfigTab, boardConfigTitle);
QTabWidget* mediaTabWidget = createMediaTabWidget(leftLensLabel, rightLensLabel, video_Label, VideoResolutionEdit_type, tabName);
QWidget* devAreaTab = new QWidget(this);
QVBoxLayout* devLayout = new QVBoxLayout(devAreaTab);
devLayout->addLayout(groupBoxLayout);
devLayout->addWidget(boardTabWidget, 2, Qt::AlignTop | Qt::AlignLeft);
devLayout->addWidget(mediaTabWidget, 3);
mainTabWidget->addTab(devAreaTab, tabName);
}
// 创建整机区域布局
void MainWidget::addAllDeviceAreaTab(QTabWidget* mainTabWidget, const QString& tabName,
QLabel* leftLensLabel, QLabel* rightLensLabel, QLabel* video_Label,
QLineEdit* VideoResolutionEdit_type)
{
QHBoxLayout* groupBoxLayout = new QHBoxLayout;
QGroupBox* allDeviceInfoGroupBox = new QGroupBox(QString(ALL_BOARD), this);
QGroupBox* allProductInfoGroupBox = new QGroupBox(QString(ALL_PRODUCT_INFO), this);
QFormLayout* formLayout = new QFormLayout(allProductInfoGroupBox);
for (const QJsonValue& value : factoryProductInfo) {
QJsonObject item = value.toObject();
QString label = item["lable"].toString();
QString cmd = item["cmd"].toString();
QLabel* itemLabel = new QLabel(label, this);
QLineEdit* itemLineEdit = new QLineEdit(this);
itemLineEdit->setReadOnly(false);
formLayout->addRow(itemLabel, itemLineEdit);
productInfoLineEdits[cmd] = itemLineEdit;
}
groupBoxLayout->addWidget(allProductInfoGroupBox, 1);
groupBoxLayout->addWidget(allDeviceInfoGroupBox, 1);
QTabWidget* mediaTabWidget = createMediaTabWidget(leftLensLabel, rightLensLabel, video_Label, VideoResolutionEdit_type, tabName);
QWidget* allDevAreaTab = new QWidget(this);
QVBoxLayout* allDevLayout = new QVBoxLayout(allDevAreaTab);
allDevLayout->addLayout(groupBoxLayout, 5);
allDevLayout->addWidget(mediaTabWidget, 3);
mainTabWidget->addTab(allDevAreaTab, tabName);
}
// 创建媒体显示区的 tabWidget
QTabWidget* MainWidget::createMediaTabWidget(QLabel* leftLensLabel, QLabel* rightLensLabel, QLabel* video_Label,
QLineEdit* VideoResolutionEdit_type, const QString& tabName)
{
QTabWidget* tabWidget_media = new QTabWidget(this);
if (tabName != QString(BACK_BOARD_NAME)){
QWidget* imageDisplayTab = createImageDisplayTab(leftLensLabel, rightLensLabel);
tabWidget_media->addTab(imageDisplayTab, IMAGE_DISPLAY_TAB);
}
QWidget* videoDisplayTab = createVideoDisplayTab(video_Label, VideoResolutionEdit_type, tabName);
tabWidget_media->addTab(videoDisplayTab, VIDEO_DISPLAY_TAB);
return tabWidget_media;
}