You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
395 lines
14 KiB
C++
395 lines
14 KiB
C++
|
|
#ifndef MONITOROVOZEZ_H
|
|
#define MONITOROVOZEZ_H
|
|
|
|
#include <QtCore/QVariant>
|
|
#include <QtWidgets/QApplication>
|
|
#include <QtWidgets/QGridLayout>
|
|
#include <QtWidgets/QHBoxLayout>
|
|
#include <QtWidgets/QPushButton>
|
|
#include <QtWidgets/QSpacerItem>
|
|
#include <QtWidgets/QVBoxLayout>
|
|
#include <QtWidgets/QWidget>
|
|
#include <QtWidgets/QScrollArea>
|
|
#include <QDebug>
|
|
#include <QTimer>
|
|
#include <QMouseEvent>
|
|
#include <QApplication>
|
|
#include <QIcon>
|
|
|
|
#include "MonitorTagUI.h"
|
|
#include "../HTTPClient/client.h"
|
|
//#pragma execution_character_set("utf-8")
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
class MonitorWidget:public QWidget
|
|
{
|
|
public:
|
|
QVBoxLayout *verticalLayout;
|
|
QHBoxLayout *operationLayout;
|
|
// QPushButton *exchangeButton;
|
|
QSpacerItem *horizontalSpacer;
|
|
QGridLayout *monitorLayout;
|
|
QHBoxLayout *filterlLayout;
|
|
QPushButton *interruptedButton;
|
|
QPushButton *normalButton;
|
|
QPushButton *standbyButton;
|
|
QPushButton *hutdownButton;
|
|
QPushButton *failureButton;
|
|
QPushButton *runButton;
|
|
QWidget *fillWidget;
|
|
|
|
int state = 0;
|
|
int curDisplayCount = 0;
|
|
QTimer *viewTimer;
|
|
QTimer *dataTimer;
|
|
QList<MonitorTag*> tagList;
|
|
vector<QString> displayList;
|
|
|
|
void setupUi(QWidget *MonitorWidget)
|
|
{
|
|
state = 0;
|
|
if (MonitorWidget->objectName().isEmpty())
|
|
MonitorWidget->setObjectName(QString::fromUtf8("MonitorWidget"));
|
|
verticalLayout = new QVBoxLayout(MonitorWidget);
|
|
verticalLayout->setSpacing(0);
|
|
verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
|
|
verticalLayout->setContentsMargins(0, 0, 0, 0);
|
|
operationLayout = new QHBoxLayout();
|
|
operationLayout->setObjectName(QString::fromUtf8("operationLayout"));
|
|
// exchangeButton = new QPushButton(MonitorWidget);
|
|
// exchangeButton->setObjectName(QString::fromUtf8("exchangeButton"));
|
|
|
|
// operationLayout->addWidget(exchangeButton);
|
|
|
|
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
|
|
|
operationLayout->addItem(horizontalSpacer);
|
|
|
|
|
|
// verticalLayout->addLayout(operationLayout);
|
|
|
|
monitorLayout = new QGridLayout();
|
|
monitorLayout->setObjectName(QString::fromUtf8("monitorLayout"));
|
|
monitorLayout->setSpacing(30);
|
|
monitorLayout->setContentsMargins(20, 20, 20, 20);
|
|
monitorLayout->setColumnStretch(0, 1);
|
|
monitorLayout->setColumnStretch(1, 1);
|
|
monitorLayout->setColumnStretch(2, 1);
|
|
monitorLayout->setColumnStretch(3, 1);
|
|
monitorLayout->setColumnStretch(4, 1);
|
|
monitorLayout->setColumnStretch(5, 1);
|
|
monitorLayout->setColumnStretch(6, 1);
|
|
fillWidget = new QWidget();
|
|
fillWidget->setLayout(monitorLayout);
|
|
fillWidget->setObjectName(QString::fromUtf8("fillWidget"));
|
|
// connect(exchangeButton, &QPushButton::clicked, this, [=](){this->changeState();});
|
|
|
|
|
|
QScrollArea *scrollArea = new QScrollArea();
|
|
|
|
scrollArea->setWidget(fillWidget);
|
|
scrollArea->setWidgetResizable(true);
|
|
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
|
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
|
scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
|
|
|
|
|
|
|
|
filterlLayout = new QHBoxLayout();
|
|
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(30, 10, 30, 30);
|
|
filterlLayout->setSpacing(150);
|
|
|
|
verticalLayout->addLayout(filterlLayout);
|
|
verticalLayout->addWidget(scrollArea);
|
|
|
|
verticalLayout->setStretch(0, 2);
|
|
verticalLayout->setStretch(1, 30);
|
|
verticalLayout->setStretch(2, 3);
|
|
|
|
MonitorWidget->setLayout(verticalLayout);
|
|
|
|
QMetaObject::connectSlotsByName(MonitorWidget);
|
|
retranslateUi(MonitorWidget);
|
|
|
|
updateData();
|
|
updateTag();
|
|
|
|
viewTimer = new QTimer(MonitorWidget);
|
|
QObject::connect(viewTimer, &QTimer::timeout, [&]() {
|
|
// 计时器超时时更新标签
|
|
updateTag();
|
|
});
|
|
viewTimer->start(2500);
|
|
|
|
dataTimer = new QTimer(MonitorWidget);
|
|
QObject::connect(dataTimer, &QTimer::timeout, [&]() {
|
|
// 计时器超时时更新数据
|
|
updateData();
|
|
});
|
|
dataTimer->start(2000);
|
|
|
|
interruptedButton->setCheckable(true);
|
|
normalButton->setCheckable(true);
|
|
standbyButton->setCheckable(true);
|
|
hutdownButton->setCheckable(true);
|
|
failureButton->setCheckable(true);
|
|
runButton->setCheckable(true);
|
|
|
|
connect(interruptedButton, &QPushButton::clicked, this, [=](){this->updateTag();});
|
|
connect(normalButton, &QPushButton::clicked, this, [=](){this->updateTag();});
|
|
connect(standbyButton, &QPushButton::clicked, this, [=](){this->updateTag();});
|
|
connect(hutdownButton, &QPushButton::clicked, this, [=](){this->updateTag();});
|
|
connect(failureButton, &QPushButton::clicked, this, [=](){this->updateTag();});
|
|
connect(runButton, &QPushButton::clicked, this, [=](){this->updateTag();});
|
|
|
|
|
|
// 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));
|
|
} // retranslateUi
|
|
|
|
void exchangeClicked()
|
|
{
|
|
int count = monitorLayout->count();
|
|
|
|
// 遍历布局中的所有子对象
|
|
for (int i = 0; i < count; ++i) {
|
|
// 获取第 i 个子对象的指针
|
|
QLayoutItem *item = monitorLayout->itemAt(i);
|
|
MonitorTag *tag = dynamic_cast<MonitorTag*>(item->widget());
|
|
// 判断子对象的类型
|
|
if (tag) {
|
|
if (this->state == 1) {
|
|
tag->stackedWidget->setCurrentIndex(1);
|
|
} else if (this->state == 0) {
|
|
tag->stackedWidget->setCurrentIndex(0);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
void changeState()
|
|
{
|
|
if (state == 0){
|
|
state = 1;
|
|
} else if (state == 1) {
|
|
state = 0;
|
|
}
|
|
}
|
|
|
|
void updateTag()
|
|
{
|
|
|
|
map allFans = fans.allFans;
|
|
updateDisplay();
|
|
// 获取与 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;
|
|
int curCount = curDisplayCount;
|
|
int displayLSize = displayList.size();
|
|
// qDebug() << curCount;
|
|
// qDebug() << displayLSize;
|
|
if (displayLSize < curCount){
|
|
for (int i = curCount - 1; i >= displayLSize; i--) {
|
|
int row = i / 7;
|
|
int column = i % 7;
|
|
QLayoutItem *item = monitorLayout->itemAtPosition(row, column);
|
|
// QLayoutItem *item = monitorLayout->itemAt(i);
|
|
monitorLayout->removeItem(item);
|
|
delete item->widget();
|
|
delete item;
|
|
// tagList.erase(tagList.begin() + i);
|
|
}
|
|
// qDebug() << tagList;
|
|
// qDebug() << monitorLayout->count();
|
|
|
|
} else if (displayList.size() > curCount) {
|
|
// 添加新的控件
|
|
for (int i = curCount; i < displayList.size(); i++) {
|
|
int row = i / 7;
|
|
int column = i % 7;
|
|
// qDebug() << row;
|
|
// qDebug() << column;
|
|
MonitorTag *newTag = new MonitorTag(state);
|
|
// connect(newTag->stateBox, QOverload<int>::of(&QComboBox::currentIndexChanged), [this](int index) {updateDisplay();});
|
|
monitorLayout->addWidget(newTag, row, column);
|
|
// tagList.append(newTag);
|
|
}
|
|
// qDebug() << tagList;
|
|
}
|
|
curDisplayCount = displayList.size();
|
|
// qDebug() << displayList;
|
|
// qDebug() << displayList;
|
|
for (auto it = displayList.begin(); it != displayList.end(); ++it) {
|
|
// qDebug() << displayList;
|
|
QLayoutItem *item = monitorLayout->itemAtPosition(index / 7, index % 7);
|
|
MonitorTag* tag = dynamic_cast<MonitorTag*>(item->widget());
|
|
tag->fan = allFans[*it];
|
|
tag->changeContent();
|
|
// tagList[index]->fan = allFans[*it];
|
|
// tagList[index]->changeContent();
|
|
index++;
|
|
}
|
|
count = (curDisplayCount - 1) / 7;
|
|
index = curDisplayCount % 7;
|
|
if (monitorLayout->count() < 8){
|
|
fillWidget->setFixedHeight(228 * 4);
|
|
for (int i = 0; i < 28 - curDisplayCount; i++) {
|
|
if (index == 6){
|
|
index = 0;
|
|
count++;
|
|
}
|
|
QWidget *w = new QWidget();
|
|
|
|
monitorLayout->addWidget(w, count, index);
|
|
index++;
|
|
}
|
|
monitorLayout->setRowStretch(0, 1);
|
|
monitorLayout->setRowStretch(1, 1);
|
|
monitorLayout->setRowStretch(2, 1);
|
|
monitorLayout->setRowStretch(3, 1);
|
|
|
|
}else{
|
|
// fillWidget->setFixedHeight(228 * ceil(monitorLayout->count() / 4));
|
|
}
|
|
fillWidget->setFixedWidth(1900);
|
|
setButtonMes();
|
|
// int c = monitorLayout->count();
|
|
// qDebug() << c;
|
|
}
|
|
|
|
void updateData(){
|
|
httpClient.getFanList();
|
|
}
|
|
|
|
void setButtonMes(){
|
|
interruptedButton->setText(QString("通讯中断 %1/%2").arg(fans.interruptedFans.size()).arg(fans.allFans.size()));
|
|
normalButton->setText(QString("正常运行 %1/%2").arg(fans.normalFans.size()).arg(fans.allFans.size()));
|
|
standbyButton->setText(QString("待机等风 %1/%2").arg(fans.standbyFans.size()).arg(fans.allFans.size()));
|
|
hutdownButton->setText(QString("停机维护 %1/%2").arg(fans.hutdownFans.size()).arg(fans.allFans.size()));
|
|
failureButton->setText(QString("故障停机 %1/%2").arg(fans.interruptedFans.size()).arg(fans.allFans.size()));
|
|
runButton->setText(QString("启动 %1/%2").arg(fans.runFans.size()).arg(fans.allFans.size()));
|
|
}
|
|
|
|
bool shouldDisplay(QString FanCode){
|
|
if(isInitState()){
|
|
return true;
|
|
}
|
|
if (std::find(displayList.begin(), displayList.end(), FanCode) != displayList.end()) {
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
bool isInitState(){
|
|
if (!interruptedButton->isChecked()
|
|
&& !normalButton->isChecked()
|
|
&& !standbyButton->isChecked()
|
|
&& !hutdownButton->isChecked()
|
|
&& !failureButton->isChecked()
|
|
&& !runButton->isChecked()){
|
|
return true;
|
|
}else{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
void updateDisplay(){
|
|
displayList.clear();
|
|
if (!interruptedButton->isChecked() && !normalButton->isChecked() && !standbyButton->isChecked() && !hutdownButton->isChecked() && !failureButton->isChecked() && !runButton->isChecked()){
|
|
displayList.insert(displayList.end(), fans.interruptedFans.begin(), fans.interruptedFans.end());
|
|
displayList.insert(displayList.end(), fans.normalFans.begin(), fans.normalFans.end());
|
|
displayList.insert(displayList.end(), fans.standbyFans.begin(), fans.standbyFans.end());
|
|
displayList.insert(displayList.end(), fans.hutdownFans.begin(), fans.hutdownFans.end());
|
|
displayList.insert(displayList.end(), fans.failureFans.begin(), fans.failureFans.end());
|
|
displayList.insert(displayList.end(), fans.runFans.begin(), fans.runFans.end());
|
|
// qDebug() << displayList;
|
|
return;
|
|
}
|
|
if (interruptedButton->isChecked()){displayList.insert(displayList.end(), fans.interruptedFans.begin(), fans.interruptedFans.end());}
|
|
if (normalButton->isChecked()){displayList.insert(displayList.end(), fans.normalFans.begin(), fans.normalFans.end());}
|
|
if (standbyButton->isChecked()){displayList.insert(displayList.end(), fans.standbyFans.begin(), fans.standbyFans.end());}
|
|
if (hutdownButton->isChecked()){displayList.insert(displayList.end(), fans.hutdownFans.begin(), fans.hutdownFans.end());}
|
|
if (failureButton->isChecked()){displayList.insert(displayList.end(), fans.failureFans.begin(), fans.failureFans.end());}
|
|
if (runButton->isChecked()){displayList.insert(displayList.end(), fans.runFans.begin(), fans.runFans.end());}
|
|
// qDebug() << displayList;
|
|
setButtonMes();
|
|
// updateTag();
|
|
// qDebug() << displayList;
|
|
}
|
|
|
|
MonitorWidget()
|
|
{
|
|
setupUi(this);
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
#endif // MONITOROVOZEZ_H
|
|
|
|
|
|
|
|
|