/******************************************************************************** ** Form generated from reading UI file 'GyroscopeAnalyticUI NxkAxt.ui' ** ** Created by: Qt User Interface Compiler version 5.14.2 ** ** WARNING! All changes made in this file will be lost when recompiling UI file! ********************************************************************************/ #ifndef GYROSCOPEANALYTICUI_20_NXKAXT_H #define GYROSCOPEANALYTICUI_20_NXKAXT_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../HTTPClient/client.h" #include "../MonitorUI/MonitorUI.h" #include "tools.h" QT_BEGIN_NAMESPACE class GyroscopeAnalyticWidget:public QWidget { public: QHBoxLayout *horizontalLayout; QListView *deviceList; QWidget *displayWidget; QGridLayout *gridLayout; QWidget *infoWidget; QVBoxLayout *verticalLayout; QLabel *infoLabel; QLabel *trendLabel; QStandardItemModel *deviceModel; QTimer* timer; int curId; MonitorWidget* monitor; void setupUi(QWidget *GyroscopeAnalyticWidget) { if (GyroscopeAnalyticWidget->objectName().isEmpty()) GyroscopeAnalyticWidget->setObjectName(QString::fromUtf8("GyroscopeAnalyticWidget")); horizontalLayout = new QHBoxLayout(GyroscopeAnalyticWidget); horizontalLayout->setSpacing(0); horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout")); horizontalLayout->setContentsMargins(20, 20, 20, 20); deviceList = new QListView(GyroscopeAnalyticWidget); deviceList->setObjectName(QString::fromUtf8("deviceList")); deviceModel = new QStandardItemModel(); deviceList->setModel(deviceModel); deviceList->setEditTriggers(QAbstractItemView::NoEditTriggers); horizontalLayout->addWidget(deviceList); displayWidget = new QWidget(GyroscopeAnalyticWidget); displayWidget->setObjectName(QString::fromUtf8("displayWidget")); gridLayout = new QGridLayout(displayWidget); gridLayout->setSpacing(0); gridLayout->setObjectName(QString::fromUtf8("gridLayout")); gridLayout->setContentsMargins(0, 0, 0, 0); horizontalLayout->addWidget(displayWidget); infoWidget = new QWidget(GyroscopeAnalyticWidget); infoWidget->setObjectName(QString::fromUtf8("infoWidget")); verticalLayout = new QVBoxLayout(infoWidget); verticalLayout->setSpacing(0); verticalLayout->setObjectName(QString::fromUtf8("verticalLayout")); verticalLayout->setContentsMargins(0, 0, 0, 0); infoLabel = new QLabel(infoWidget); infoLabel->setObjectName(QString::fromUtf8("infoLabel")); verticalLayout->addWidget(infoLabel); trendLabel = new QLabel(infoWidget); trendLabel->setObjectName(QString::fromUtf8("trendLabel")); verticalLayout->addWidget(trendLabel); horizontalLayout->addWidget(infoWidget); horizontalLayout->setStretch(0, 5); horizontalLayout->setStretch(1, 10); horizontalLayout->setStretch(2, 5); retranslateUi(GyroscopeAnalyticWidget); QMetaObject::connectSlotsByName(GyroscopeAnalyticWidget); // addDevice(); // QModelIndex index = deviceList->model()->index(0, 0); // 获取第2行的索引 // deviceList->setCurrentIndex(index); timer = new QTimer(); QObject::connect(timer, &QTimer::timeout, [&]() { // 计时器超时时更新标签 addDevice(); httpClient.getGyroList(curId); addGyroFeature(curId); }); // timer->start(3000); connect(deviceList, &QListView::doubleClicked, [&](const QModelIndex& index) { if (index.isValid()) { QString fanCode = index.data().toString(); curId = fans.allFans[fanCode].fanId; httpClient.getGyroList(curId); addGyroFeature(curId); } }); } // setupUi void retranslateUi(QWidget *GyroscopeAnalyticWidget) { trendLabel->setText(QCoreApplication::translate("GyroscopeAnalyticWidget", "\345\233\276\350\241\250\344\277\241\346\201\257", nullptr)); } // retranslateUi void addDevice(){ // httpClient.getFanList(); map allFans = fans.states; if (!monitor->isInitState()){ if (monitor->displayList.size() > deviceModel->rowCount()){ for (int i = 0; i <= allFans.size() - deviceModel->rowCount() + 1; i++) { QStandardItem* emptyItem = new QStandardItem(""); deviceModel->appendRow(emptyItem); } }else if (monitor->displayList.size() < deviceModel->rowCount()){ for (int i = 0; i <= deviceModel->rowCount() - allFans.size() + 2; i++) { deviceModel->removeRow(0); } } }else{ if (allFans.size() > deviceModel->rowCount()){ for (int i = 0; i <= allFans.size() - deviceModel->rowCount() + 1; i++) { QStandardItem* emptyItem = new QStandardItem(""); deviceModel->appendRow(emptyItem); } }else if (allFans.size() < deviceModel->rowCount()){ for (int i = 0; i <= deviceModel->rowCount() - allFans.size() + 2; i++) { deviceModel->removeRow(0); } } } int count = 0; for (auto it = allFans.begin(); it != allFans.end(); ++it) { if (monitor->shouldDisplay(it->first)){ if (it->first == QString("")){continue;} QStandardItem* item = deviceModel->item(count); // 修改QStandardItem对象的文本和图标 item->setText(it->first); item->setIcon(getDevIcon(it->second)); count++; } } } void addGyroFeature(int fanId){ vector gyros = fans.idMaps[fanId].gyros; QString text; for (auto it = gyros.begin(); it != gyros.end(); ++it) { text += it->featureName + " : " + QString::number(it->featureValue) + "\n"; // qDebug() << it->featureName; } infoLabel->setText(text); } GyroscopeAnalyticWidget(MonitorWidget* monitor) : monitor(monitor) { setupUi(this); } }; QT_END_NAMESPACE #endif // GYROSCOPEANALYTICUI_20_NXKAXT_H