diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user index 05a81d7..f8ff50e 100644 --- a/CMakeLists.txt.user +++ b/CMakeLists.txt.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -401,305 +401,9 @@ 1 - - ProjectExplorer.Project.Target.1 - - WebAssemblyDeviceType - Qt 5.14.2 WebAssembly - Qt 5.14.2 WebAssembly - qt.qt5.5142.wasm_32_kit - 0 - -1 - 0 - - Debug - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=Debug --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} - 0 - C:\Users\zcw\Desktop\DAM\build-DAM-Qt_5_14_2_WebAssembly-Debug - - - - - all - - false - - true - CMakeProjectManager.MakeStep - - 1 - 构建 - 构建 - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - CMakeProjectManager.MakeStep - - 1 - 清除 - 清除 - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Debug - CMakeProjectManager.CMakeBuildConfiguration - - - Release - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=Release --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} - C:\Users\zcw\Desktop\DAM\build-DAM-Qt_5_14_2_WebAssembly-Release - - - - - all - - false - - true - CMakeProjectManager.MakeStep - - 1 - 构建 - 构建 - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - CMakeProjectManager.MakeStep - - 1 - 清除 - 清除 - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release - CMakeProjectManager.CMakeBuildConfiguration - - - RelWithDebInfo - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} - C:\Users\zcw\Desktop\DAM\build-DAM-Qt_5_14_2_WebAssembly-RelWithDebInfo - - - - - all - - false - - true - CMakeProjectManager.MakeStep - - 1 - 构建 - 构建 - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - CMakeProjectManager.MakeStep - - 1 - 清除 - 清除 - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Release with Debug Information - CMakeProjectManager.CMakeBuildConfiguration - - - RelWithDebInfo - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} - 0 - C:\Users\zcw\Desktop\DAM\build-DAM-Qt_5_14_2_WebAssembly-Profile - - - - - all - - false - - true - CMakeProjectManager.MakeStep - - 1 - 构建 - 构建 - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - CMakeProjectManager.MakeStep - - 1 - 清除 - 清除 - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Profile - CMakeProjectManager.CMakeBuildConfiguration - - - MinSizeRel - 2 - false - - -DCMAKE_GENERATOR:STRING=Ninja --DCMAKE_BUILD_TYPE:STRING=MinSizeRel --DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{buildDir}/.qtc/package-manager/auto-setup.cmake --DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} --DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} --DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} --DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} - C:\Users\zcw\Desktop\DAM\build-DAM-Qt_5_14_2_WebAssembly-MinSizeRel - - - - - all - - false - - true - CMakeProjectManager.MakeStep - - 1 - 构建 - 构建 - ProjectExplorer.BuildSteps.Build - - - - - - clean - - false - - true - CMakeProjectManager.MakeStep - - 1 - 清除 - 清除 - ProjectExplorer.BuildSteps.Clean - - 2 - false - - false - - Minimum Size Release - CMakeProjectManager.CMakeBuildConfiguration - - 5 - 0 - - true - true - true - - 2 - - ProjectExplorer.CustomExecutableRunConfiguration - - false - true - false - true - - 1 - - ProjectExplorer.Project.TargetCount - 2 + 1 ProjectExplorer.Project.Updater.FileVersion diff --git a/DAM.qrc b/DAM.qrc index 5c5844b..83efab7 100644 --- a/DAM.qrc +++ b/DAM.qrc @@ -3,5 +3,17 @@ Static/close.png Static/min.png Static/DamQSS.Qss + Static/fanNormal.png + Static/fanError.png + Static/fanHutdown.png + Static/fanRun.png + Static/fanStandby.png + Static/flangeError.png + Static/flangeNormal.png + Static/gyroError.png + Static/gyroNormal.png + Static/headError.png + Static/headNormal.png + Static/fanInterrupted.png diff --git a/HTTPClient/client.cpp b/HTTPClient/client.cpp index fb4dbd7..53d2c60 100644 --- a/HTTPClient/client.cpp +++ b/HTTPClient/client.cpp @@ -13,6 +13,27 @@ using json = nlohmann::json; using namespace std; HTTPClient httpClient; +FanManage fans; + +void delNameFromList(QString element){ + fans.interruptedFans.erase(std::remove(fans.interruptedFans.begin(), fans.interruptedFans.end(), element), fans.interruptedFans.end()); + fans.standbyFans.erase(std::remove(fans.standbyFans.begin(), fans.standbyFans.end(), element), fans.standbyFans.end()); + fans.normalFans.erase(std::remove(fans.normalFans.begin(), fans.normalFans.end(), element), fans.normalFans.end()); + fans.failureFans.erase(std::remove(fans.failureFans.begin(), fans.failureFans.end(), element), fans.failureFans.end()); + fans.hutdownFans.erase(std::remove(fans.hutdownFans.begin(), fans.hutdownFans.end(), element), fans.hutdownFans.end()); + fans.runFans.erase(std::remove(fans.runFans.begin(), fans.runFans.end(), element), fans.runFans.end()); +} + + +bool isInLists(QString element) { + // 使用 std::find_first_of 函数查找元素是否在列表中 + auto it1 = std::find_first_of(fans.standbyFans.begin(), fans.standbyFans.end(), &element, &element + 1); + auto it2 = std::find_first_of(fans.hutdownFans.begin(), fans.hutdownFans.end(), &element, &element + 1); + auto it3 = std::find_first_of(fans.runFans.begin(), fans.runFans.end(), &element, &element + 1); + + // 如果元素在任意一个列表中,则返回 true,否则返回 false + return it1 != fans.standbyFans.end() || it2 != fans.hutdownFans.end() || it3 != fans.runFans.end(); +} HTTPClient::HTTPClient() : client("https://121.36.33.250:9000") { header = {{"GroupId", "dam"}}; @@ -24,26 +45,42 @@ HTTPClient httpClient; client.enable_server_certificate_verification(false); // 取消SSL验证 } - FanManage HTTPClient::getFanList(){ - FanManage Fans; - if (auto res = client.Post(fanListIndex, header)) { - json resJson = json::parse(res->body); - for (const auto& data : resJson["data"]) { - FanClass fan; - fan.fanCode = QString::fromStdString(data["fanCode"]); - if (data["functions"]["gyro"]["features"][0]["featureValue"].is_number() && data["functions"]["headRoom"]["features"][0]["featureValue"].is_number()) { + void HTTPClient::getFanList(){ + if (auto res = client.Post(fanListIndex, header)) { + json resJson = json::parse(res->body); + for (const auto& data : resJson["data"]) { + FanClass fan; + fan.fanCode = QString::fromStdString(data["fanCode"]); + if (data["functions"]["gyro"]["features"][0]["featureValue"].is_number()) { fan.angle = data["functions"]["gyro"]["features"][0]["featureValue"].get(); - fan.distance = data["functions"]["headRoom"]["features"][0]["featureValue"].get(); - } - fan.gyroState = QString::fromStdString(data["functions"]["flange"]["state"]); - fan.flangeState = QString::fromStdString(data["functions"]["gyro"]["state"]); - fan.headroomState = QString::fromStdString(data["functions"]["headRoom"]["state"]); - Fans.allFans[fan.fanCode] = fan; - //std::cout << fan.angle << std::endl; - - } - } - return Fans; + } + if (data["functions"]["headRoom"]["features"][0]["featureValue"].is_number()){ + fan.distance = data["functions"]["headRoom"]["features"][0]["featureValue"].get(); + } + fan.gyroState = QString::fromStdString(data["functions"]["flange"]["state"]); + fan.flangeState = QString::fromStdString(data["functions"]["gyro"]["state"]); + fan.headroomState = QString::fromStdString(data["functions"]["headRoom"]["state"]); + fans.allFans[fan.fanCode] = fan; + if (isInLists(fan.fanCode)){ + return; + } + delNameFromList(fan.fanCode); + if (fan.gyroState == QString("正常") && fan.flangeState == QString("正常") && fan.headroomState == QString("正常")){ + fans.normalFans.push_back(fan.fanCode); + fans.states[fan.fanCode] = QString("正常运行"); + } + if (fan.gyroState == QString("故障") || fan.flangeState == QString("故障") || fan.headroomState == QString("故障")){ + fans.failureFans.push_back(fan.fanCode); + fans.states[fan.fanCode] = QString("故障停机"); + } + if (fan.gyroState == QString("通讯中断") || fan.flangeState == QString("通讯中断") || fan.headroomState == QString("通讯中断")){ + fans.interruptedFans.push_back(fan.fanCode); + fans.states[fan.fanCode] = QString("通讯中断"); + } +// std::cout << fan.distance << std::endl; + + } + } } QString HTTPClient::getFlangeList(int fanId) { diff --git a/HTTPClient/client.h b/HTTPClient/client.h index f23e8d6..f9b5910 100644 --- a/HTTPClient/client.h +++ b/HTTPClient/client.h @@ -10,15 +10,18 @@ #include #include #include +#include using namespace std; +void delNameFromList(QString element); + class FanClass // 风机类 { public: int errorCode; int fanId; - double angle; // 角度 - double distance; // 相对距离 + double angle = 0; // 角度 + double distance = 0; // 相对距离 QString errorInfo; QString fanCode; QString flangeState; @@ -31,6 +34,7 @@ class FanManage // 所有风机管理类 { public: std::map allFans; // 所有风机 + std::map states; // 风机状态 std::vector interruptedFans; // 通讯中断 std::vector standbyFans; // 待机等风 std::vector normalFans; // 正常运行 @@ -54,7 +58,7 @@ private: public: httplib::Client client; HTTPClient(); - FanManage getFanList(); + void getFanList(); QString getFlangeList(int fanId); QString getHeadroomList(int fanId); QString getGyroList(int fanId); @@ -62,7 +66,7 @@ public: }; extern HTTPClient httpClient; - +extern FanManage fans; diff --git a/MainWindow.h b/MainWindow.h index b4051f6..79ec69d 100644 --- a/MainWindow.h +++ b/MainWindow.h @@ -32,7 +32,7 @@ public: QPushButton *clearanceButton; QPushButton *gyroscopeButton; QStackedWidget *stackedWidget; - Ui::MonitorWidget *monitorPage; + MonitorWidget *monitorPage; Ui::ClearanceAnalyticWidget *clearancePage; Ui::FlangeAnalyticWidget *flangePage; Ui::GyroscopeAnalyticWidget *gyroscopePage; @@ -113,7 +113,7 @@ public: stackedWidget = new QStackedWidget(centralwidget); stackedWidget->setObjectName(QString::fromUtf8("stackedWidget")); - monitorPage = new Ui::MonitorWidget(); + monitorPage = new MonitorWidget(); monitorPage->setObjectName(QString::fromUtf8("monitorPage")); stackedWidget->addWidget(monitorPage); diff --git a/MonitorUI/MonitorTagUI.h b/MonitorUI/MonitorTagUI.h index 1ff90fb..a5c2579 100644 --- a/MonitorUI/MonitorTagUI.h +++ b/MonitorUI/MonitorTagUI.h @@ -11,6 +11,11 @@ #include #include #include +#include +#include +#include +#include + #include "../HTTPClient/client.h" @@ -30,13 +35,18 @@ public: QPushButton *clearanceButton; QPushButton *flangeButton; QPushButton *gyroscopeButton; - QLabel *speedLabel; - QLabel *powerLabel; + QLabel *distanceLabel; + QLabel *angelLabel; QWidget *simplifyPage; QWidget *horizontalLayoutWidget; QHBoxLayout *horizontalLayout_2; QLabel *pictureLabel_2; QLabel *statusLabel; + QComboBox *stateBox; + + FanClass fan; + QTimer timer; + int state; void setupUi(QWidget *MonitorTag) { @@ -46,7 +56,7 @@ public: horizontalLayout = new QHBoxLayout(MonitorTag); horizontalLayout->setSpacing(0); horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); - horizontalLayout->setContentsMargins(0, 0, 0, 0); + horizontalLayout->setContentsMargins(10, 10, 10, 10); stackedWidget = new QStackedWidget(MonitorTag); stackedWidget->setObjectName(QString::fromUtf8("stackedWidget")); @@ -59,6 +69,31 @@ public: verticalLayout = new QVBoxLayout(); verticalLayout->setSpacing(0); verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); + + stateBox = new QComboBox(MonitorTag); + QStringList options = {"远程模式", "待机等风", "停机维护", "启动"}; + stateBox->addItems(options); + + auto it1 = std::find(fans.standbyFans.begin(), fans.standbyFans.end(), fan.fanCode); + auto it2 = std::find(fans.hutdownFans.begin(), fans.hutdownFans.end(), fan.fanCode); + auto it3 = std::find(fans.runFans.begin(), fans.runFans.end(), fan.fanCode); + if (it1 != fans.standbyFans.end()){ + stateBox->setCurrentIndex(1); + } + else if (it2 != fans.hutdownFans.end()){ + stateBox->setCurrentIndex(2); + } + else if (it3 != fans.runFans.end()){ + stateBox->setCurrentIndex(3); + } + else{ + stateBox->setCurrentIndex(0); + } + + connect(stateBox, QOverload::of(&QComboBox::currentIndexChanged), [this](int index) {this->stateChanged(index);}); + verticalLayout->addWidget(stateBox); + + pictureLabel = new QLabel(detailPage); pictureLabel->setObjectName(QString::fromUtf8("pictureLabel")); pictureLabel->setAlignment(Qt::AlignCenter); @@ -71,7 +106,8 @@ public: verticalLayout->addWidget(nameLabel); - verticalLayout->setStretch(0, 8); + verticalLayout->setStretch(0, 1); + verticalLayout->setStretch(1, 9); verticalLayout->setStretch(1, 2); horizontalLayout_3->addLayout(verticalLayout); @@ -94,15 +130,15 @@ public: gridLayout->addWidget(gyroscopeButton, 0, 2, 1, 1); - speedLabel = new QLabel(detailPage); - speedLabel->setObjectName(QString::fromUtf8("speedLabel")); + distanceLabel = new QLabel(detailPage); + distanceLabel->setObjectName(QString::fromUtf8("distanceLabel")); - gridLayout->addWidget(speedLabel, 2, 0, 1, 3); + gridLayout->addWidget(distanceLabel, 2, 0, 1, 3); - powerLabel = new QLabel(detailPage); - powerLabel->setObjectName(QString::fromUtf8("powerLabel")); + angelLabel = new QLabel(detailPage); + angelLabel->setObjectName(QString::fromUtf8("angelLabel")); - gridLayout->addWidget(powerLabel, 1, 0, 1, 3); + gridLayout->addWidget(angelLabel, 1, 0, 1, 3); horizontalLayout_3->addLayout(gridLayout); @@ -110,9 +146,9 @@ public: stackedWidget->addWidget(detailPage); simplifyPage = new QWidget(); simplifyPage->setObjectName(QString::fromUtf8("simplifyPage")); + horizontalLayoutWidget = new QWidget(simplifyPage); horizontalLayoutWidget->setObjectName(QString::fromUtf8("horizontalLayoutWidget")); - horizontalLayoutWidget->setGeometry(QRect(110, 50, 471, 241)); horizontalLayout_2 = new QHBoxLayout(horizontalLayoutWidget); horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2")); horizontalLayout_2->setContentsMargins(0, 0, 0, 0); @@ -126,6 +162,8 @@ public: statusLabel->setObjectName(QString::fromUtf8("statusLabel")); statusLabel->setAlignment(Qt::AlignCenter); + statusLabel->setText(fan.fanCode + fans.states[fan.fanCode]); + simplifyPage->setLayout(horizontalLayout_2); horizontalLayout_2->addWidget(statusLabel); @@ -134,35 +172,123 @@ public: horizontalLayout->addWidget(stackedWidget); + if (state == 1){ + stackedWidget->setCurrentIndex(1); + }else{ + stackedWidget->setCurrentIndex(0); + } + + nameLabel->setText(fan.fanCode); + if (fan.angle != 0){ + angelLabel->setText("角度: " + QString::number(fan.angle)); + }else{ + angelLabel->setText("角度: 数据为空"); + } + + if (fan.distance != 0){ + distanceLabel->setText("距离: " + QString::number(fan.distance)); + }else{ + distanceLabel->setText("距离: 数据为空"); + } + + QMetaObject::connectSlotsByName(MonitorTag); + if (fans.states[fan.fanCode] == QString("正常运行")){ + QPixmap pixmap(":/Static/fanNormal.png"); + pixmap = pixmap.scaled(100, 100, Qt::KeepAspectRatio); + pictureLabel->setPixmap(pixmap); + pictureLabel_2->setPixmap(pixmap); + this->setStyleSheet("QWidget#MonitorTag{background-color: #374065;border-radius: 5px;border: 3px solid;border-color: #1AFA29;}"); + }else if (fans.states[fan.fanCode] == QString("通讯中断")){ + QPixmap pixmap(":/Static/fanfanInterrupted.png"); + pixmap = pixmap.scaled(100, 100, Qt::KeepAspectRatio); + pictureLabel->setPixmap(pixmap); + pictureLabel_2->setPixmap(pixmap); + this->setStyleSheet("QWidget#MonitorTag{background-color: #374065;border-radius: 5px;border: 3px solid;border-color: white;}"); + }else if (fans.states[fan.fanCode] == QString("待机等风")){ + QPixmap pixmap(":/Static/fanStandby.png"); + pixmap = pixmap.scaled(100, 100, Qt::KeepAspectRatio); + pictureLabel->setPixmap(pixmap); + pictureLabel_2->setPixmap(pixmap); + this->setStyleSheet("QWidget#MonitorTag{background-color: #374065;border-radius: 5px;border: 3px solid;border-color: #F4EA2A;}"); + }else if (fans.states[fan.fanCode] == QString("停机维护")){ + QPixmap pixmap(":/Static/fanHutdown.png"); + pixmap = pixmap.scaled(100, 100, Qt::KeepAspectRatio); + pictureLabel->setPixmap(pixmap); + pictureLabel_2->setPixmap(pixmap); + this->setStyleSheet("QWidget#MonitorTag{background-color: #374065;border-radius: 5px;border: 3px solid;border-color: #C0397C;}"); + }else if (fans.states[fan.fanCode] == QString("故障停机")){ + QPixmap pixmap(":/Static/fanError.png"); + pixmap = pixmap.scaled(100, 100, Qt::KeepAspectRatio); + pictureLabel->setPixmap(pixmap); + pictureLabel_2->setPixmap(pixmap); + this->setStyleSheet("QWidget#MonitorTag{background-color: #374065;border-radius: 5px;border: 3px solid;border-color: #d81e06;}"); + }else if (fans.states[fan.fanCode] == QString("启动")){ + QPixmap pixmap(":/Static/fanRun.png"); + pixmap = pixmap.scaled(100, 100, Qt::KeepAspectRatio); + pictureLabel->setPixmap(pixmap); + pictureLabel_2->setPixmap(pixmap); + this->setStyleSheet("QWidget#MonitorTag{background-color: #374065;border-radius: 5px;border: 3px solid;border-color: #0caba2;}"); + } + + + + if (fan.headroomState == QString("正常")){ + clearanceButton->setIcon(QIcon(":/Static/headNormal.png")); + } + if (fan.headroomState == QString("故障")){ + clearanceButton->setIcon(QIcon(":/Static/headError.png")); + } + if (fan.flangeState == QString("正常")){ + flangeButton->setIcon(QIcon(":/Static/flangeNormal.png")); + } + if (fan.flangeState == QString("故障")){ + flangeButton->setIcon(QIcon(":/Static/flangeError.png")); + } + if (fan.gyroState == QString("正常")){ + gyroscopeButton->setIcon(QIcon(":/Static/gyroNormal.png")); + } + if (fan.gyroState == QString("故障")){ + gyroscopeButton->setIcon(QIcon(":/Static/gyroError.png")); + } + } // setupUi - retranslateUi(MonitorTag); + void stateChanged(int index){ +// "远程模式", "待机等风", "停机维护", "启动" + + switch (index){ + case 0: + delNameFromList(fan.fanCode); + break; + case 1: + delNameFromList(fan.fanCode); + fans.standbyFans.push_back(fan.fanCode); + fans.states[fan.fanCode] = QString("待机等风"); + break; + case 2: + delNameFromList(fan.fanCode); + fans.hutdownFans.push_back(fan.fanCode); + for (auto it = fans.runFans.begin(); it != fans.runFans.end(); ++it) {qDebug() << *it;} + fans.states[fan.fanCode] = QString("停机维护"); + break; + case 3: + delNameFromList(fan.fanCode); + fans.runFans.push_back(fan.fanCode); + fans.states[fan.fanCode] = QString("启动"); + break; + } + } - stackedWidget->setCurrentIndex(0); - QMetaObject::connectSlotsByName(MonitorTag); - } // setupUi - void retranslateUi(QWidget *MonitorTag) - { - MonitorTag->setWindowTitle(QCoreApplication::translate("MonitorTag", "Form", nullptr)); - pictureLabel->setText(QCoreApplication::translate("MonitorTag", "\350\256\276\345\244\207\345\233\276", nullptr)); - nameLabel->setText(QCoreApplication::translate("MonitorTag", "\350\256\276\345\244\207\345\220\215\347\247\260", nullptr)); - clearanceButton->setText(QCoreApplication::translate("MonitorTag", "\345\212\237\350\203\2752", nullptr)); - flangeButton->setText(QCoreApplication::translate("MonitorTag", "\345\212\237\350\203\2751", nullptr)); - gyroscopeButton->setText(QCoreApplication::translate("MonitorTag", "\345\212\237\350\203\2753", nullptr)); - speedLabel->setText(QCoreApplication::translate("MonitorTag", "\346\225\260\345\200\274B\357\274\232", nullptr)); - powerLabel->setText(QCoreApplication::translate("MonitorTag", "\346\225\260\345\200\274A\357\274\232", nullptr)); - pictureLabel_2->setText(QCoreApplication::translate("MonitorTag", "\350\256\276\345\244\207\345\233\276\347\211\207", nullptr)); - statusLabel->setText(QCoreApplication::translate("MonitorTag", "\350\256\276\345\244\207\347\212\266\346\200\201", nullptr)); - } // retranslateUi - - MonitorTag(FanClass fan) + + MonitorTag(FanClass fan, int state) : fan(fan), state(state) { setupUi(this); } + }; diff --git a/MonitorUI/MonitorUI.h b/MonitorUI/MonitorUI.h index aeb5b59..c121219 100644 --- a/MonitorUI/MonitorUI.h +++ b/MonitorUI/MonitorUI.h @@ -12,13 +12,17 @@ #include #include #include +#include +#include +#include +#include #include "MonitorTagUI.h" #include "../HTTPClient/client.h" QT_BEGIN_NAMESPACE -class Ui_MonitorWidget:public QWidget +class MonitorWidget:public QWidget { public: QVBoxLayout *verticalLayout; @@ -37,6 +41,7 @@ public: int state; QList> tagList; + QTimer *timer; void setupUi(QWidget *MonitorWidget) { @@ -90,31 +95,38 @@ public: filterlLayout->setObjectName(QString::fromUtf8("filterlLayout")); interruptedButton = new QPushButton(MonitorWidget); interruptedButton->setObjectName(QString::fromUtf8("interruptedButton")); + interruptedButton->setIcon(QIcon(":/Static/fanInterrupted.png")); filterlLayout->addWidget(interruptedButton); normalButton = new QPushButton(MonitorWidget); normalButton->setObjectName(QString::fromUtf8("normalButton")); + normalButton->setIcon(QIcon(":/Static/fanNormal.png")); filterlLayout->addWidget(normalButton); standbyButton = new QPushButton(MonitorWidget); standbyButton->setObjectName(QString::fromUtf8("standbyButton")); + standbyButton->setIcon(QIcon(":/Static/fanStandby.png")); + filterlLayout->addWidget(standbyButton); hutdownButton = new QPushButton(MonitorWidget); hutdownButton->setObjectName(QString::fromUtf8("hutdownButton")); + hutdownButton->setIcon(QIcon(":/Static/fanHutdown.png")); filterlLayout->addWidget(hutdownButton); failureButton = new QPushButton(MonitorWidget); failureButton->setObjectName(QString::fromUtf8("failureButton")); + failureButton->setIcon(QIcon(":/Static/fanError.png")); filterlLayout->addWidget(failureButton); runButton = new QPushButton(MonitorWidget); runButton->setObjectName(QString::fromUtf8("runButton")); + runButton->setIcon(QIcon(":/Static/fanRun.png")); filterlLayout->addWidget(runButton); filterlLayout->setContentsMargins(10, 10, 10, 10); @@ -128,33 +140,46 @@ public: MonitorWidget->setLayout(verticalLayout); - - retranslateUi(MonitorWidget); - QMetaObject::connectSlotsByName(MonitorWidget); + retranslateUi(MonitorWidget); addTag(); + timer = new QTimer(MonitorWidget); + QObject::connect(timer, &QTimer::timeout, [&]() { + // 计时器超时时更新标签 + addTag(); + }); + timer->start(5000); + + connect(exchangeButton, &QPushButton::clicked, this, [=](){this->exchangeClicked();}); + } // setupUi void retranslateUi(QWidget *MonitorWidget) { MonitorWidget->setWindowTitle(QCoreApplication::translate("MonitorWidget", "Form", nullptr)); exchangeButton->setText(QCoreApplication::translate("MonitorWidget", "\345\244\247\345\260\217\345\233\276\346\240\207\345\210\207\346\215\242", nullptr)); - interruptedButton->setText(QCoreApplication::translate("MonitorWidget", "\351\200\232\350\256\257\344\270\255\346\226\255 x\345\217\260", nullptr)); - normalButton->setText(QCoreApplication::translate("MonitorWidget", "\346\255\243\345\270\270\350\277\220\350\241\214 x\345\217\260", nullptr)); - standbyButton->setText(QCoreApplication::translate("MonitorWidget", "\345\276\205\346\234\272\347\255\211\351\243\216 x\345\217\260", nullptr)); - hutdownButton->setText(QCoreApplication::translate("MonitorWidget", "\345\201\234\346\234\272\347\273\264\346\212\244 x\345\217\260", nullptr)); - failureButton->setText(QCoreApplication::translate("MonitorWidget", "\346\225\205\351\232\234\345\276\205\346\234\272 x\345\217\260", nullptr)); - runButton->setText(QCoreApplication::translate("MonitorWidget", "\345\220\257\345\212\250 x\345\217\260", nullptr)); } // retranslateUi - void exchangeClicked(MonitorTag *newTag) + void exchangeClicked() { - if (this->state == 1) { - newTag->stackedWidget->setCurrentIndex(1); - } else if (this->state == 0) { - newTag->stackedWidget->setCurrentIndex(0); + int count = monitorLayout->count(); + + // 遍历布局中的所有子对象 + for (int i = 0; i < count; ++i) { + // 获取第 i 个子对象的指针 + QLayoutItem *item = monitorLayout->itemAt(i); + MonitorTag *tag = dynamic_cast(item->widget()); + // 判断子对象的类型 + if (tag) { + if (this->state == 1) { + tag->stackedWidget->setCurrentIndex(1); + } else if (this->state == 0) { + tag->stackedWidget->setCurrentIndex(0); + } + } } + } void changeState() @@ -168,27 +193,35 @@ public: void addTag() { - map fans = httpClient.getFanList().allFans; + httpClient.getFanList(); + map allFans = fans.allFans; + // 获取与 clicked() 信号相关的接收器数量 + + while (QLayoutItem *item = monitorLayout->takeAt(0)) { + if (QWidget *widget = item->widget()) { + widget->deleteLater(); // 或使用 delete 关键字删除控件的内存 + } + delete item; + } tagList.clear(); int count = 0; int index = 0; QList tags; - for (auto it = fans.begin(); it != fans.end(); ++it) { + for (auto it = allFans.begin(); it != allFans.end(); ++it) { if (index == 6){ tagList.append(tags); tags.clear(); index = 0; count++; } - MonitorTag *newTag = new MonitorTag(it->second); - connect(exchangeButton, &QPushButton::clicked, this, [=](){this->exchangeClicked(newTag);}); + MonitorTag *newTag = new MonitorTag(it->second, state); monitorLayout->addWidget(newTag, count, index); tags.append(newTag); index++; } - if (fans.size() < 28){ + if (allFans.size() < 28){ fillWidget->setFixedHeight(228 * 4); - for (int i = 0; i < 28 - fans.size(); i++) { + for (int i = 0; i < 28 - allFans.size(); i++) { if (index == 6){ index = 0; count++; @@ -203,12 +236,22 @@ public: monitorLayout->setRowStretch(3, 1); } fillWidget->setFixedWidth(1900); - int c = monitorLayout->count(); - qDebug() << c; + setButtonMes(); +// int c = monitorLayout->count(); +// qDebug() << c; + + } + void setButtonMes(){ + interruptedButton->setText(QString("通讯中断") + QString::number(fans.interruptedFans.size())); + normalButton->setText(QString("正常运行") + QString::number(fans.normalFans.size())); + standbyButton->setText(QString("待机等风") + QString::number(fans.standbyFans.size())); + hutdownButton->setText(QString("停机维护") + QString::number(fans.hutdownFans.size())); + failureButton->setText(QString("故障停机") + QString::number(fans.interruptedFans.size())); + runButton->setText(QString("启动") + QString::number(fans.runFans.size())); } - Ui_MonitorWidget() + MonitorWidget() { setupUi(this); } @@ -219,9 +262,7 @@ public: -namespace Ui { -class MonitorWidget: public Ui_MonitorWidget {}; -} // namespace Ui + QT_END_NAMESPACE diff --git a/Static/DamQSS.Qss b/Static/DamQSS.Qss index 643a052..0428ba8 100644 --- a/Static/DamQSS.Qss +++ b/Static/DamQSS.Qss @@ -21,6 +21,12 @@ QLabel{ } +QPushButton#ClearanceButton, QPushButton#FlangeButton, QPushButton#GyroscopeButton{ + +border: none; + +} + QPushButton#monitorButton, QPushButton#flangeButton, QPushButton#clearanceButton, QPushButton#gyroscopeButton{ color: white; diff --git a/Static/fan.png b/Static/fan.png deleted file mode 100644 index aa5474d..0000000 Binary files a/Static/fan.png and /dev/null differ diff --git a/Static/fanError.png b/Static/fanError.png new file mode 100644 index 0000000..bd129fd Binary files /dev/null and b/Static/fanError.png differ diff --git a/Static/fanHutdown.png b/Static/fanHutdown.png new file mode 100644 index 0000000..3970578 Binary files /dev/null and b/Static/fanHutdown.png differ diff --git a/Static/fanInterrupted.png b/Static/fanInterrupted.png new file mode 100644 index 0000000..42c0c5c Binary files /dev/null and b/Static/fanInterrupted.png differ diff --git a/Static/fanNormal.png b/Static/fanNormal.png new file mode 100644 index 0000000..afb1a21 Binary files /dev/null and b/Static/fanNormal.png differ diff --git a/Static/fanRun.png b/Static/fanRun.png new file mode 100644 index 0000000..2d4ea19 Binary files /dev/null and b/Static/fanRun.png differ diff --git a/Static/fanRunning.png b/Static/fanRunning.png deleted file mode 100644 index 74c98bd..0000000 Binary files a/Static/fanRunning.png and /dev/null differ diff --git a/Static/fanStandby.png b/Static/fanStandby.png new file mode 100644 index 0000000..3592b24 Binary files /dev/null and b/Static/fanStandby.png differ diff --git a/Static/flangeError.png b/Static/flangeError.png new file mode 100644 index 0000000..0618282 Binary files /dev/null and b/Static/flangeError.png differ diff --git a/Static/flangeNormal.png b/Static/flangeNormal.png new file mode 100644 index 0000000..ecf5ecb Binary files /dev/null and b/Static/flangeNormal.png differ diff --git a/Static/gyroError.png b/Static/gyroError.png new file mode 100644 index 0000000..0139a70 Binary files /dev/null and b/Static/gyroError.png differ diff --git a/Static/gyroNormal.png b/Static/gyroNormal.png new file mode 100644 index 0000000..ffa4f1b Binary files /dev/null and b/Static/gyroNormal.png differ diff --git a/Static/headError.png b/Static/headError.png new file mode 100644 index 0000000..ced10ea Binary files /dev/null and b/Static/headError.png differ diff --git a/Static/headNormal.png b/Static/headNormal.png new file mode 100644 index 0000000..8b806e4 Binary files /dev/null and b/Static/headNormal.png differ