diff --git a/HX_CoalFlowDetect.pro b/HX_CoalFlowDetect.pro index c4cd87e..78cb9ec 100644 --- a/HX_CoalFlowDetect.pro +++ b/HX_CoalFlowDetect.pro @@ -28,12 +28,13 @@ DEFINES += QT_DEPRECATED_WARNINGS CONFIG += c++11 SOURCES += \ - component/qcustomplot/qcustomplot.cpp \ - controller/coaldistributmodbusthread.cpp \ + component/qcustomplot/qcustomplot.cpp \ + controller/coaldistributmodbusthread.cpp \ main.cpp \ mainwindow.cpp \ view/beltspeedlinewidget.cpp \ view/coaldistributbarchartwidget.cpp \ + view/coalstaticwidget.cpp\ view/coalstatisticschartwidget.cpp\ component/ZDateEdit/dateCommonInfo.cpp\ component/ZDateEdit/zdateedit.cpp\ @@ -41,11 +42,12 @@ SOURCES += \ component/ZDateEdit/ztimeedit.cpp\ HEADERS += \ - component/qcustomplot/qcustomplot.h \ - controller/coaldistributmodbusthread.h \ + component/qcustomplot/qcustomplot.h \ + controller/coaldistributmodbusthread.h \ mainwindow.h \ view/beltspeedlinewidget.h \ view/coaldistributbarchartwidget.h \ + view/coalstaticwidget.h \ view/coalstatisticschartwidget.h\ component/ZDateEdit/dateCommonInfo.h\ component/ZDateEdit/zdateedit.h\ @@ -55,6 +57,7 @@ HEADERS += \ FORMS += \ mainwindow.ui \ + view/coalstaticwidget.ui \ view/coalstatisticschartwidget.ui diff --git a/Resource/image/beltCamera.png b/Resource/image/beltCamera.png new file mode 100644 index 0000000..b95e6b8 Binary files /dev/null and b/Resource/image/beltCamera.png differ diff --git a/mainwindow.cpp b/mainwindow.cpp index 621e11f..1b329ca 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,217 +2,232 @@ #include "ui_mainwindow.h" #include "view/beltspeedlinewidget.h" #include "view/coaldistributbarchartwidget.h" -#include "view/coalstatisticschartwidget.h" +#include "view/coalstaticwidget.h" #include #include -MainWindow::MainWindow(QWidget *parent) - : QMainWindow(parent), ui(new Ui::MainWindow) { - ui->setupUi(this); - this->setWindowFlag(Qt::FramelessWindowHint); - this->setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | - Qt::WindowMinimizeButtonHint); +MainWindow::MainWindow(QWidget* parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); + this->setWindowFlag(Qt::FramelessWindowHint); + this->setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint); - ui->widget_head->installEventFilter(this); + ui->widget_head->installEventFilter(this); - m_systemSetting = new QSettings("system.ini", QSettings::IniFormat); + m_systemSetting = new QSettings("system.ini", QSettings::IniFormat); - createSystemINI(); + createSystemINI(); - this->setWindowTitle(m_systemSetting->value("system/name").toString()); + this->setWindowTitle(m_systemSetting->value("system/name").toString()); - calendarLoopPlay(); + calendarLoopPlay(); - setSystemTitle(); + setSystemTitle(); - setBeltWarnInfoTextEditStyle(); + setBeltWarnInfoTextEditStyle(); - addcoalDistributChart(); + addcoalDistributChart(); - addbeltSpeedChat(); + addbeltSpeedChat(); - addCoalStatisticsChart(); + addCoalStatisticsChart(); - addCoalBeltVideo(); + addCoalBeltVideo(); } MainWindow::~MainWindow() { delete ui; } -bool MainWindow::eventFilter(QObject *watched, QEvent *event) { - // 处理鼠标按下、释放和移动事件 - if (watched == ui->widget_head) { - QMouseEvent *mouseEvent = static_cast(event); - if (mouseEvent->type() == QEvent::MouseButtonPress) { - if (mouseEvent->button() == Qt::LeftButton) { - m_mousePressed = true; // 启动拖拽 - m_mousePoint = mouseEvent->globalPos() - this->pos(); +bool MainWindow::eventFilter(QObject* watched, QEvent* event) +{ + // 处理鼠标按下、释放和移动事件 + if (watched == ui->widget_head) { + QMouseEvent* mouseEvent = static_cast(event); + if (mouseEvent->type() == QEvent::MouseButtonPress) { + if (mouseEvent->button() == Qt::LeftButton) { + m_mousePressed = true; // 启动拖拽 + m_mousePoint = mouseEvent->globalPos() - this->pos(); - this->setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | - Qt::WindowMinimizeButtonHint | Qt::Window | - Qt::WindowStaysOnTopHint); - this->show(); // 确保窗口显示 + this->setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint | Qt::Window | Qt::WindowStaysOnTopHint); + this->show(); // 确保窗口显示 - return true; - } - } else if (mouseEvent->type() == QEvent::MouseButtonRelease) { - m_mousePressed = false; - return true; - } else if (mouseEvent->type() == QEvent::MouseMove) { - if (m_mousePressed && (mouseEvent->buttons() & Qt::LeftButton)) { - this->move(mouseEvent->globalPos() - m_mousePoint); + return true; + } + } else if (mouseEvent->type() == QEvent::MouseButtonRelease) { + m_mousePressed = false; + return true; + } else if (mouseEvent->type() == QEvent::MouseMove) { + if (m_mousePressed && (mouseEvent->buttons() & Qt::LeftButton)) { + this->move(mouseEvent->globalPos() - m_mousePoint); - // 每次移动时设置为最上方 - this->setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | - Qt::WindowMinimizeButtonHint | Qt::Window | - Qt::WindowStaysOnTopHint); - this->show(); - return true; - } + // 每次移动时设置为最上方 + this->setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint | Qt::Window | Qt::WindowStaysOnTopHint); + this->show(); + return true; + } + } } - } } -void MainWindow::addBeltWarnInfoToTextEdit(const QString &consoleInfo) { - qDebug() << consoleInfo; - m_textEditConsoleInfo.append(consoleInfo); - QDateTime startDateTime = QDateTime::currentDateTime(); - QString formattedTime = startDateTime.toString("yyyy-MM-dd hh:mm:ss"); +void MainWindow::addBeltWarnInfoToTextEdit(const QString& consoleInfo) +{ + qDebug() << consoleInfo; + m_textEditConsoleInfo.append(consoleInfo); + QDateTime startDateTime = QDateTime::currentDateTime(); + QString formattedTime = startDateTime.toString("yyyy-MM-dd hh:mm:ss"); - if (m_textEditConsoleInfo.isEmpty()) - return; - QString lastConsoleInfo = m_textEditConsoleInfo.last(); + if (m_textEditConsoleInfo.isEmpty()) + return; + QString lastConsoleInfo = m_textEditConsoleInfo.last(); - // qint64 timeDifferenceInMilliseconds = - // m_previousConsleInfoDateTime.secsTo(startDateTime); + // qint64 timeDifferenceInMilliseconds = + // m_previousConsleInfoDateTime.secsTo(startDateTime); - // if ((lastConsoleInfo == consoleInfo) && timeDifferenceInMilliseconds < - // 2) - // return; + // if ((lastConsoleInfo == consoleInfo) && timeDifferenceInMilliseconds < + // 2) + // return; - QString consoleInfoResult = - QStringLiteral("[%1]%2").arg(formattedTime).arg(consoleInfo); - ui->textEdit_beltWarnInfo->append(consoleInfoResult); + QString consoleInfoResult = QStringLiteral("[%1]%2").arg(formattedTime).arg(consoleInfo); + ui->textEdit_beltWarnInfo->append(consoleInfoResult); - m_previousConsleInfoDateTime = QDateTime::currentDateTime(); + m_previousConsleInfoDateTime = QDateTime::currentDateTime(); } void MainWindow::on_pushButton_close_clicked() { this->close(); } -void MainWindow::on_pushButton_max_clicked() { - if (isFullScreen()) { - this->showMaximized(); - } else { - this->showFullScreen(); - } +void MainWindow::on_pushButton_max_clicked() +{ + if (isFullScreen()) { + this->showMaximized(); + } else { + this->showFullScreen(); + } } void MainWindow::on_pushButton_min_clicked() { this->showMinimized(); } -void MainWindow::calendarLoopPlay() { - ui->label_calendar->clear(); - QTimer *timer_calendar = new QTimer(this); - connect(timer_calendar, &QTimer::timeout, this, [this]() { - QDateTime time = QDateTime::currentDateTime(); - QString str = time.toString("yyyy-MM-dd hh:mm:ss dddd"); - ui->label_calendar->setText(str); - }); - timer_calendar->start(1000); //每一秒溢出一次进入槽函数 +void MainWindow::calendarLoopPlay() +{ + ui->label_calendar->clear(); + QTimer* timer_calendar = new QTimer(this); + connect(timer_calendar, &QTimer::timeout, this, [this]() { + QDateTime time = QDateTime::currentDateTime(); + QString str = time.toString("yyyy-MM-dd hh:mm:ss dddd"); + ui->label_calendar->setText(str); + }); + timer_calendar->start(1000); //每一秒溢出一次进入槽函数 } -void MainWindow::createSystemINI() { - // 写入数据到INI文件 - // 判断并设置 "system/name" - if (!m_systemSetting->contains("system/name")) { - m_systemSetting->setValue("system/name", "煤流监测平台"); - } +void MainWindow::createSystemINI() +{ + // 写入数据到INI文件 + // 判断并设置 "system/name" + if (!m_systemSetting->contains("system/name")) { + m_systemSetting->setValue("system/name", "煤流监测平台"); + } - // 判断并设置 "coalStaticInterface/url" - if (!m_systemSetting->contains("coalStaticInterface/url")) { - m_systemSetting->setValue("coalStaticInterface/url", 30); - } + // 判断并设置 "coalStaticInterface/url" + if (!m_systemSetting->contains("coalStaticInterface/url")) { + m_systemSetting->setValue("coalStaticInterface/url", 30); + } - // 判断并设置 "addr/ip" - if (!m_systemSetting->contains("addr/ip")) { - m_systemSetting->setValue("addr/ip", "127.0.0.1"); - } + // 判断并设置 "addr/ip" + if (!m_systemSetting->contains("addr/ip")) { + m_systemSetting->setValue("addr/ip", "127.0.0.1"); + } - // 判断并设置 "addr/port" - if (!m_systemSetting->contains("addr/port")) { - m_systemSetting->setValue("addr/port", 3000); - } + // 判断并设置 "addr/port" + if (!m_systemSetting->contains("addr/port")) { + m_systemSetting->setValue("addr/port", 3000); + } - // 判断并设置 "camera/rtsp" - if (!m_systemSetting->contains("camera/rtsp")) { - m_systemSetting->setValue("camera/rtsp", 3000); - } + // 判断并设置 "camera/rtsp" + if (!m_systemSetting->contains("camera/rtsp")) { + m_systemSetting->setValue("camera/rtsp", 3000); + } + + // 判断并设置"system/different" + if (!m_systemSetting->contains("system/different")) { + m_systemSetting->setValue("system/different", 1); + } } -void MainWindow::setSystemTitle() { - QString titleName = m_systemSetting->value("system/name").toString(); - if (!titleName.isEmpty()) { - ui->label_title->clear(); - ui->label_title->setText(titleName); - } +void MainWindow::setSystemTitle() +{ + QString titleName = m_systemSetting->value("system/name").toString(); + if (!titleName.isEmpty()) { + ui->label_title->clear(); + ui->label_title->setText(titleName); + } } -void MainWindow::setBeltWarnInfoTextEditStyle() { - ui->textEdit_beltWarnInfo->document()->setMaximumBlockCount(100); - ui->textEdit_beltWarnInfo->setReadOnly(true); - ui->textEdit_beltWarnInfo->setTextInteractionFlags(Qt::NoTextInteraction); +void MainWindow::setBeltWarnInfoTextEditStyle() +{ + ui->textEdit_beltWarnInfo->document()->setMaximumBlockCount(100); + ui->textEdit_beltWarnInfo->setReadOnly(true); + ui->textEdit_beltWarnInfo->setTextInteractionFlags(Qt::NoTextInteraction); } -void MainWindow::addcoalDistributChart() { - // addBeltWarnInfoToTextEdit("添加煤流分布窗口成功!"); - ui->textEdit_beltWarnInfo->append("添加煤流分布窗口成功!"); +void MainWindow::addcoalDistributChart() +{ + // addBeltWarnInfoToTextEdit("添加煤流分布窗口成功!"); + ui->textEdit_beltWarnInfo->append("添加煤流分布窗口成功!"); - CoalDistributBarChartWidget *coalDistributBarChartWidget = - new CoalDistributBarChartWidget(this); + CoalDistributBarChartWidget* coalDistributBarChartWidget = new CoalDistributBarChartWidget(this); - // 检查布局是否已设置 - if (!ui->widget_coalDistributChart->layout()) { - ui->widget_coalDistributChart->setLayout(new QVBoxLayout); - } - coalDistributBarChartWidget->setContentsMargins(0, 0, 0, 0); - ui->widget_coalDistributChart->layout()->addWidget( - coalDistributBarChartWidget); + // 检查布局是否已设置 + if (!ui->widget_coalDistributChart->layout()) { + ui->widget_coalDistributChart->setLayout(new QVBoxLayout); + } + coalDistributBarChartWidget->setContentsMargins(0, 0, 0, 0); + ui->widget_coalDistributChart->layout()->addWidget( + coalDistributBarChartWidget); } -void MainWindow::addbeltSpeedChat() { - ui->textEdit_beltWarnInfo->append("添加皮带机速度曲线窗口成功!"); - BeltSpeedLineWidget *beltSpeedLineWidget = new BeltSpeedLineWidget(this); - // 检查布局是否已设置 - if (!ui->widget_beltSpeedChart->layout()) { - ui->widget_beltSpeedChart->setLayout(new QVBoxLayout); - } - beltSpeedLineWidget->setContentsMargins(0, 0, 0, 0); - ui->widget_beltSpeedChart->layout()->addWidget(beltSpeedLineWidget); +void MainWindow::addbeltSpeedChat() +{ + // ui->textEdit_beltWarnInfo->append("添加皮带机速度曲线窗口成功!"); + // BeltSpeedLineWidget *beltSpeedLineWidget = new BeltSpeedLineWidget(this); + // // 检查布局是否已设置 + // if (!ui->widget_beltSpeedChart->layout()) { + // ui->widget_beltSpeedChart->setLayout(new QVBoxLayout); + // } + // beltSpeedLineWidget->setContentsMargins(0, 0, 0, 0); + // ui->widget_beltSpeedChart->layout()->addWidget(beltSpeedLineWidget); } -void MainWindow::addCoalStatisticsChart() { - ui->textEdit_beltWarnInfo->append("添加煤量统计窗口成功!"); - CoalStatisticsChartWidget *coalStatisticsChartWidget = - new CoalStatisticsChartWidget(this); - // 检查布局是否已设置 - if (!ui->widget_beltSpeedChart->layout()) { - ui->widget_beltSpeedChart->setLayout(new QVBoxLayout); - } - coalStatisticsChartWidget->setContentsMargins(0, 0, 0, 0); - ui->widget_coalStatisticsChart->layout()->addWidget( - coalStatisticsChartWidget); +void MainWindow::addCoalStatisticsChart() +{ + // ui->textEdit_beltWarnInfo->append("添加煤量统计窗口成功!"); + // CoalStatisticsChartWidget* coalStatisticsChartWidget = new CoalStatisticsChartWidget(this); + // // 检查布局是否已设置 + // if (!ui->widget_coalStatisticsChart->layout()) { + // ui->widget_coalStatisticsChart->setLayout(new QVBoxLayout); + // } + // coalStatisticsChartWidget->setContentsMargins(0, 0, 0, 0); + // ui->widget_coalStatisticsChart->layout()->addWidget(coalStatisticsChartWidget); - connect(coalStatisticsChartWidget, - &CoalStatisticsChartWidget::querySuccessInfo, this, - &MainWindow::addBeltWarnInfoToTextEdit); + // connect(coalStatisticsChartWidget, &CoalStatisticsChartWidget::querySuccessInfo, this, &MainWindow::addBeltWarnInfoToTextEdit); + + CoalStaticWidget* coalStaticWidget = new CoalStaticWidget(this); + + // 检查布局是否已设置 + if (!ui->widget_coalStatis->layout()) { + ui->widget_coalStatis->setLayout(new QVBoxLayout); + } + coalStaticWidget->setContentsMargins(0, 0, 0, 0); + ui->widget_coalStatis->layout()->addWidget(coalStaticWidget); + + connect(coalStaticWidget, &CoalStaticWidget::querySuccessInfo, this, &MainWindow::addBeltWarnInfoToTextEdit); } -void MainWindow::addCoalBeltVideo() { - // QString url = - // "https://stream7.iqilu.com/10339/upload_transcode/202002/18/" - // "20200218114723HDu3hhxqIT.mp4"; - // QString url = - // "rtsp://admin:1234qwer@192.168.80.82:554/Streaming/Channels/101"; - QString url = m_systemSetting->value("camera/rtsp").toString(); - ui->widget_beltVideo->setUrl(url); - ui->widget_beltVideo->open(); +void MainWindow::addCoalBeltVideo() +{ + // QString url = "https://stream7.iqilu.com/10339/upload_transcode/202002/18/20200218114723HDu3hhxqIT.mp4"; + // QString url = "rtsp://admin:1234qwer@192.168.80.82:554/Streaming/Channels/101"; + QString url = m_systemSetting->value("camera/rtsp").toString(); + ui->widget_beltVideo->setUrl(url); + ui->widget_beltVideo->open(); } diff --git a/mainwindow.ui b/mainwindow.ui index 13d21c4..33a13df 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -223,9 +223,9 @@ QPushButton:pressed{ - + - + 6 @@ -233,7 +233,121 @@ QPushButton:pressed{ 0 - + + + 0 + + + 0 + + + + + #widget_coalDistribut{ + + border-image: url(:/Resource/image/coalDistributbg.png); +} + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + + 0 + 0 + + + + + 35 + 35 + + + + #widget_coalDistributLogo{ + border-image: url(:/Resource/image/icon4.png); +} + + + + + + + QLabel{ + color:white; + font: 12pt "黑体"; +} + + + 煤流分布 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 14 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + @@ -625,33 +739,17 @@ QPushButton:pressed{ - + - #widget_speedModel{ - border-image: url(:/Resource/image/speedModel.png); -} - + #widget_warnInfo{ + border-image: url(:/Resource/image/warningInfobg.png); +} - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - + - + - + 0 @@ -665,14 +763,14 @@ QPushButton:pressed{ - #widget_speedmodellogo{ - border-image: url(:/Resource/image/icon2.png); + #widget_warnInfoLogo{ + border-image: url(:/Resource/image/icon3.png); } - + QLabel{ color:white; @@ -680,378 +778,44 @@ QPushButton:pressed{ } - 调速模式选择 + 皮带报警信息 - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - 25 - - - - - - 90 - 25 - - - - QToolButton{ - border-image: url(:/Resource/image/labelunSelect.png); - color:white; - margin-left:-30px; - padding-left:60px; - background:url(:/Resource/image/kekong.png) center no-repeat; - font-size: 14px; - border: none; -} - -QToolButton:hover{ - border-image: url(:/Resource/image/labelhover.png); -} - -QToolButton:pressed{ - border-image: url(:/Resource/image/labelSelect.png); -} - - - - 可控 - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 90 - 25 - - - - QToolButton{ - border-image: url(:/Resource/image/labelunSelect.png); - color:white; - margin-left:-30px; - padding-left:60px; - background:url(:/Resource/image/bukekong.png) center no-repeat; - font-size: 14px; - border: none; -} - -QToolButton:hover{ - border-image: url(:/Resource/image/labelhover.png); -} - -QToolButton:pressed{ - border-image: url(:/Resource/image/labelSelect.png); -} - - - - 不可控 - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - 25 - - - - - - 90 - 25 - - - - QToolButton{ - border-image: url(:/Resource/image/labelunSelect.png); - color:white; - margin-left:-30px; - padding-left:60px; - background:url(:/Resource/image/shoudong.png) center no-repeat; - font-size: 14px; - border: none; -} - -QToolButton:hover{ - border-image: url(:/Resource/image/labelhover.png); -} - -QToolButton:pressed{ - border-image: url(:/Resource/image/labelSelect.png); -} - - - - 手动 - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - 90 - 25 - - - - QToolButton{ - border-image: url(:/Resource/image/labelunSelect.png); - color:white; - margin-left:-30px; - padding-left:60px; - background:url(:/Resource/image/zidong.png) center no-repeat; - font-size: 14px; - border: none;; -} - -QToolButton:hover{ - border-image: url(:/Resource/image/labelhover.png); -} - -QToolButton:pressed{ - border-image: url(:/Resource/image/labelSelect.png); -} - - - - 自动 - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - 0 - - - 25 - - - 10 - - - 0 - - - - - - - QLabel{ - color:white; - font: 12pt "黑体"; + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + #textEdit_beltWarnInfo{ + background-color:transparent; + color: #FFFFFF; + font: 12pt "Albertus Extra Bold"; + border:no; } - - - 一键频率下发 - - - - - - - - - - - Qt::Horizontal - - - - - - - - - - - QLabel{ - color:white; - font: 10pt "黑体"; -} - - - 怠速 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - QLabel{ - color:white; - font: 10pt "黑体"; -} - - - 中速 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - QLabel{ - color:white; - font: 10pt "黑体"; -} - - - 全速 - - - - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - + + + + + @@ -1059,9 +823,12 @@ QToolButton:pressed{ - + - 20 + 6 + + + 0 @@ -1082,7 +849,7 @@ QToolButton:pressed{ 0 - + @@ -1156,509 +923,24 @@ QToolButton:pressed{ - #widget_belt1video{ - border-image: url(:/Resource/image/beltCameraDemo.png); -} + - - - - - - #widget_belt1Info{ - - border-image: url(:/Resource/image/beltInfobg.png); -} - - - - 0 + + + 100 - - 6 - - - 6 + + 100 - - - - - - - - - - 0 - 0 - - - - - 25 - 25 - - - - QLabel{ - background-image: url(:/Resource/image/speed.png); - background-repeat:no-repeat; - background-position:center; + + + #widget_beltVideobg{ + + border-image: url(:/Resource/image/beltCamera.png); } - - - - - - - - - - - - QLabel{ - font: 10pt "黑体"; - color: rgb(255, 255, 255); -} - - - 速度:10m/s - - - - - - - - 16777215 - 10 - - - - QProgressBar { - border: none; - background: #2E3133; - border-radius: 50px; - } -QProgressBar::chunk { - background: #53F2A4; - border-radius: 15px; - } - - - 24 - - - Qt::AlignCenter - - - false - - - - - - - - - - - - - - 0 - 0 - - - - - 25 - 25 - - - - QLabel{ - background-image: url(:/Resource/image/electric.png); - background-repeat:no-repeat; - background-position:center; -} - - - - - - - - - - - - QLabel{ - font: 10pt "黑体"; - color: rgb(255, 255, 255); -} - - - 电流:10A - - - - - - - - 16777215 - 10 - - - - QProgressBar { - border: none; - background: #2E3133; - border-radius: 50px; - } -QProgressBar::chunk { - background: #53F2A4; - border-radius: 15px; - } - - - 24 - - - false - - - - - - - - - - - - - - 0 - 0 - - - - - 25 - 25 - - - - QLabel{ - background-image: url(:/Resource/image/temperature.png); - background-repeat:no-repeat; - background-position:center; -} - - - - - - - - - - - - QLabel{ - font: 10pt "黑体"; - color: rgb(255, 255, 255); -} - - - 温度:10℃ - - - - - - - - 16777215 - 10 - - - - QProgressBar { - border: none; - background: #2E3133; - border-radius: 50px; - } -QProgressBar::chunk { - background: #53F2A4; - border-radius: 15px; - } - - - 24 - - - false - - - - - - - - - - - - - - 0 - 0 - - - - - 25 - 25 - - - - QLabel{ - background-image: url(:/Resource/image/wind.png); - background-repeat:no-repeat; - background-position:center; -} - - - - - - - - - - - - QLabel{ - font: 10pt "黑体"; - color: rgb(255, 255, 255); -} - - - 绕组:10 - - - - - - - - 16777215 - 10 - - - - QProgressBar { - border: none; - background: #2E3133; - border-radius: 50px; - } -QProgressBar::chunk { - background: #53F2A4; - border-radius: 15px; - } - - - 24 - - - false - - - - - - - - - - - - - 0 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 48 - 48 - - - - Qt::RightToLeft - - - QLabel{ - background-image: url(:/Resource/image/beltOffline.png); - background-repeat:no-repeat; - background-position:top; -} - - - - - - Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing - - - - - - - - - 15 - - - - - - 0 - 0 - - - - - 35 - 35 - - - - QPushButton{ - border:0px; - border-image: url(:/Resource/image/start.png); -} -QPushButton:hover{ - border-image: url(:/Resource/image/startHover.png); -} -QPushButton:pressed{ - border-image: url(:/Resource/image/startPress.png); -} - - - - - - - - - - - 0 - 0 - - - - - 35 - 35 - - - - QPushButton{ - border:0px; - border-image: url(:/Resource/image/stop.png); -} -QPushButton:hover{ - border-image: url(:/Resource/image/stopHover.png); -} -QPushButton:pressed{ - border-image: url(:/Resource/image/stopPress.png); -} - - - - - - - - - - - - 0 - - - 4 - - - 5 - - - 2 - - - - - QLabel{ - color: rgb(255, 255, 255); - font: 10pt "黑体"; -} - - - 启动 - - - Qt::AlignHCenter|Qt::AlignTop - - - - - - - QLabel{ - color: rgb(255, 255, 255); - font: 10pt "黑体"; -} - - - 停止 - - - Qt::AlignHCenter|Qt::AlignTop - - - - - - - - + + @@ -1669,19 +951,19 @@ QPushButton:pressed{ - - - false + + + #widget_beltCamera{ + + border-image: url(:/Resource/image/beltCamerabg.png); +} - - - 0 - + 0 - 0 + 4 0 @@ -1690,1177 +972,27 @@ QPushButton:pressed{ 0 - + + + 45 + - - - - - - 0 - 0 - - - - - 160 - 26 - - - - #widget_beltLogo2{ - color:white; - border-image: url(:/Resource/image/beltCamera_unselect.png); -} - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 40 - - - - - QLabel{ - color:white; - font: 10pt "黑体"; -} - - - 2#皮带煤量相机 - - - - - - - - - - - - - - - - - - - + - #widget_belt2video{ - border-image: url(:/Resource/image/beltCameraDemo.png); + QLabel{ + color:white; + font: 12pt "黑体"; } - - - - - - #widget_belt2Info{ - - border-image: url(:/Resource/image/beltInfobg.png); -} + + 1#皮带煤量相机 - - - 0 - - - 6 - - - 6 - - - - - - - - - - - - 0 - 0 - - - - - 25 - 25 - - - - QLabel{ - background-image: url(:/Resource/image/speed.png); - background-repeat:no-repeat; - background-position:center; -} - - - - - - - - - - - - QLabel{ - font: 10pt "黑体"; - color: rgb(255, 255, 255); -} - - - 速度:10m/s - - - - - - - - 16777215 - 10 - - - - QProgressBar { - border: none; - background: #2E3133; - border-radius: 50px; - } -QProgressBar::chunk { - background: #53F2A4; - border-radius: 15px; - } - - - 24 - - - false - - - - - - - - - - - - - - 0 - 0 - - - - - 25 - 25 - - - - QLabel{ - background-image: url(:/Resource/image/electric.png); - background-repeat:no-repeat; - background-position:center; -} - - - - - - - - - - - - QLabel{ - font: 10pt "黑体"; - color: rgb(255, 255, 255); -} - - - 电流:10A - - - - - - - - 16777215 - 10 - - - - QProgressBar { - border: none; - background: #2E3133; - border-radius: 50px; - } -QProgressBar::chunk { - background: #53F2A4; - border-radius: 15px; - } - - - 24 - - - false - - - - - - - - - - - - - - 0 - 0 - - - - - 25 - 25 - - - - QLabel{ - background-image: url(:/Resource/image/temperature.png); - background-repeat:no-repeat; - background-position:center; -} - - - - - - - - - - - - QLabel{ - font: 10pt "黑体"; - color: rgb(255, 255, 255); -} - - - 温度:10℃ - - - - - - - - 16777215 - 10 - - - - QProgressBar { - border: none; - background: #2E3133; - border-radius: 50px; - } -QProgressBar::chunk { - background: #53F2A4; - border-radius: 15px; - } - - - 24 - - - false - - - - - - - - - - - - - - 0 - 0 - - - - - 25 - 25 - - - - QLabel{ - background-image: url(:/Resource/image/wind.png); - background-repeat:no-repeat; - background-position:center; -} - - - - - - - - - - - - QLabel{ - font: 10pt "黑体"; - color: rgb(255, 255, 255); -} - - - 绕组:10 - - - - - - - - 16777215 - 10 - - - - QProgressBar { - border: none; - background: #2E3133; - border-radius: 50px; - } -QProgressBar::chunk { - background: #53F2A4; - border-radius: 15px; - } - - - 24 - - - false - - - - - - - - - - - - - 0 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 48 - 48 - - - - QLabel{ - background-image: url(:/Resource/image/beltOffline.png); - background-repeat:no-repeat; - background-position:top; -} - - - - - - - - - - - - 15 - - - - - - 0 - 0 - - - - - 35 - 35 - - - - QPushButton{ - border:0px; - border-image: url(:/Resource/image/start.png); -} -QPushButton:hover{ - border-image: url(:/Resource/image/startHover.png); -} -QPushButton:pressed{ - border-image: url(:/Resource/image/startPress.png); -} - - - - - - - - - - - 0 - 0 - - - - - 35 - 35 - - - - QPushButton{ - border:0px; - border-image: url(:/Resource/image/stop.png); -} -QPushButton:hover{ - border-image: url(:/Resource/image/stopHover.png); -} -QPushButton:pressed{ - border-image: url(:/Resource/image/stopPress.png); -} - - - - - - - - - - - - 0 - - - 4 - - - 5 - - - 2 - - - - - QLabel{ - color: rgb(255, 255, 255); - font: 10pt "黑体"; -} - - - 启动 - - - Qt::AlignHCenter|Qt::AlignTop - - - - - - - QLabel{ - color: rgb(255, 255, 255); - font: 10pt "黑体"; -} - - - 停止 - - - Qt::AlignHCenter|Qt::AlignTop - - - - - - - - - - - - - - - - - false - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - - 0 - 0 - - - - - 160 - 26 - - - - #widget_beltLogo3{ - color:white; - border-image: url(:/Resource/image/beltCamera_unselect.png); -} - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - 40 - - - - - QLabel{ - color:white; - font: 10pt "黑体"; -} - - - 3#皮带煤量相机 - - - - - - - - - - - - - - - - - - - - - #widget_belt3video{ - border-image: url(:/Resource/image/beltCameraDemo.png); -} - - - - - - - #widget_belt3Info{ - border-image: url(:/Resource/image/beltInfobg.png); -} - - - - 0 - - - 6 - - - 6 - - - - - - - - - - - - 0 - 0 - - - - - 25 - 25 - - - - QLabel{ - background-image: url(:/Resource/image/speed.png); - background-repeat:no-repeat; - background-position:center; -} - - - - - - - - - - - - QLabel{ - font: 10pt "黑体"; - color: rgb(255, 255, 255); -} - - - 速度:10m/s - - - - - - - - 16777215 - 10 - - - - QProgressBar { - border: none; - background: #2E3133; - border-radius: 50px; - } -QProgressBar::chunk { - background: #53F2A4; - border-radius: 15px; - } - - - 24 - - - false - - - - - - - - - - - - - - 0 - 0 - - - - - 25 - 25 - - - - QLabel{ - background-image: url(:/Resource/image/electric.png); - background-repeat:no-repeat; - background-position:center; -} - - - - - - - - - - - - QLabel{ - font: 10pt "黑体"; - color: rgb(255, 255, 255); -} - - - 电流:10A - - - - - - - - 16777215 - 10 - - - - QProgressBar { - border: none; - background: #2E3133; - border-radius: 50px; - } -QProgressBar::chunk { - background: #53F2A4; - border-radius: 15px; - } - - - 24 - - - false - - - - - - - - - - - - - - 0 - 0 - - - - - 25 - 25 - - - - QLabel{ - background-image: url(:/Resource/image/temperature.png); - background-repeat:no-repeat; - background-position:center; -} - - - - - - - - - - - - QLabel{ - font: 10pt "黑体"; - color: rgb(255, 255, 255); -} - - - 温度:10℃ - - - - - - - - 16777215 - 10 - - - - QProgressBar { - border: none; - background: #2E3133; - border-radius: 50px; - } -QProgressBar::chunk { - background: #53F2A4; - border-radius: 15px; - } - - - 24 - - - false - - - - - - - - - - - - - - 0 - 0 - - - - - 25 - 25 - - - - QLabel{ - background-image: url(:/Resource/image/wind.png); - background-repeat:no-repeat; - background-position:center; -} - - - - - - - - - - - - QLabel{ - font: 10pt "黑体"; - color: rgb(255, 255, 255); -} - - - 绕组:10 - - - - - - - - 16777215 - 10 - - - - QProgressBar { - border: none; - background: #2E3133; - border-radius: 50px; - } -QProgressBar::chunk { - background: #53F2A4; - border-radius: 15px; - } - - - 24 - - - false - - - - - - - - - - - - - 0 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 48 - 48 - - - - QLabel{ - background-image: url(:/Resource/image/beltOffline.png); - background-repeat:no-repeat; - background-position:top; -} - - - - - - - - - - - - 15 - - - - - - 0 - 0 - - - - - 35 - 35 - - - - QPushButton{ - border:0px; - border-image: url(:/Resource/image/start.png); -} -QPushButton:hover{ - border-image: url(:/Resource/image/startHover.png); -} -QPushButton:pressed{ - border-image: url(:/Resource/image/startPress.png); -} - - - - - - - - - - - 0 - 0 - - - - - 35 - 35 - - - - QPushButton{ - border:0px; - border-image: url(:/Resource/image/stop.png); -} -QPushButton:hover{ - border-image: url(:/Resource/image/stopHover.png); -} -QPushButton:pressed{ - border-image: url(:/Resource/image/stopPress.png); -} - - - - - - - - - - - - 0 - - - 4 - - - 5 - - - 2 - - - - - QLabel{ - color: rgb(255, 255, 255); - font: 10pt "黑体"; -} - - - 启动 - - - Qt::AlignHCenter|Qt::AlignTop - - - - - - - QLabel{ - color: rgb(255, 255, 255); - font: 10pt "黑体"; -} - - - 停止 - - - Qt::AlignHCenter|Qt::AlignTop - - - - - - - - - - - - - + @@ -2870,14 +1002,14 @@ QPushButton:pressed{ - + - #widget_coalDistribut{ + #widget_coalStatis{ - border-image: url(:/Resource/image/coalDistributbg.png); + border-image: url(:/Resource/image/coalStatisbg.png); } - + 0 @@ -2893,172 +1025,6 @@ QPushButton:pressed{ 0 - - - - - - - - - 0 - 0 - - - - - 35 - 35 - - - - #widget_coalDistributLogo{ - border-image: url(:/Resource/image/icon4.png); -} - - - - - - - QLabel{ - color:white; - font: 12pt "黑体"; -} - - - 煤流分布 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - 14 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - - - - - - #widget_beltSpeed{ - - border-image: url(:/Resource/image/coalDistributbg.png); -} - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - - - 0 - 0 - - - - - 35 - 35 - - - - #widget_beltSpeedlogo{ - border-image: url(:/Resource/image/icon5.png); -} - - - - - - - QLabel{ - color:white; - font: 12pt "黑体"; -} - - - 皮带机速度曲线 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - - @@ -3066,231 +1032,6 @@ QPushButton:pressed{ - - - - 6 - - - 0 - - - - - #widget_warnInfo{ - border-image: url(:/Resource/image/warningInfobg.png); -} - - - - - - - - - 0 - 0 - - - - - 35 - 35 - - - - #widget_warnInfoLogo{ - border-image: url(:/Resource/image/icon3.png); -} - - - - - - - QLabel{ - color:white; - font: 12pt "黑体"; -} - - - 皮带报警信息 - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - #textEdit_beltWarnInfo{ - background-color:transparent; - color: #FFFFFF; - font: 12pt "Albertus Extra Bold"; - border:no; -} - - - - - - - - - - - - - #widget_beltCamera{ - - border-image: url(:/Resource/image/beltCamerabg.png); -} - - - - 0 - - - 4 - - - 0 - - - 0 - - - - - 45 - - - - - QLabel{ - color:white; - font: 12pt "黑体"; -} - - - 1#皮带煤量相机 - - - - - - - - - - - - - - - #widget_coalStatis{ - - border-image: url(:/Resource/image/coalStatisbg.png); -} - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - 0 - 0 - - - - - 35 - 35 - - - - #widget_coalStaticLogo{ - border-image: url(:/Resource/image/icon6.png); -} - - - - - - - QLabel{ - color:white; - font: 12pt "黑体"; -} - - - 煤量统计 - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - - - - diff --git a/resource.qrc b/resource.qrc index 5d129f6..e24240b 100644 --- a/resource.qrc +++ b/resource.qrc @@ -65,5 +65,6 @@ component/ZDateEdit/Resources/DTPrev.png component/ZDateEdit/Resources/popupButton.png component/ZDateEdit/Resources/popupButton2.png + Resource/image/beltCamera.png diff --git a/view/coaldistributbarchartwidget.cpp b/view/coaldistributbarchartwidget.cpp index df2bc8a..f94bd52 100644 --- a/view/coaldistributbarchartwidget.cpp +++ b/view/coaldistributbarchartwidget.cpp @@ -79,18 +79,21 @@ void CoalDistributBarChartWidget::initializeChart() axisX->setRange(1, 300); axisX->setTickCount(10); axisX->setLabelFormat("%d"); - axisX->setLinePen(QPen(Qt::gray)); - axisX->setLabelsColor(Qt::gray); + axisX->setLinePen(QPen(QColor(40, 46, 48))); + axisX->setLabelsColor(QColor(151, 151, 151)); + axisX->setMinorTickCount(0); // 隐藏X轴刻度线 + axisX->setGridLineVisible(false); m_chart->addAxis(axisX, Qt::AlignBottom); m_series->attachAxis(axisX); // 设置Y轴为百分比 QValueAxis* axisY = new QValueAxis; axisY->setTitleText("占比(%)"); - axisY->setTitleBrush(QBrush(Qt::gray)); - axisY->setLinePen(QPen(Qt::gray)); - axisY->setLabelsColor(Qt::gray); // 设置标签字体颜色为灰色 + axisY->setTitleBrush(QBrush(QColor(151, 151, 151))); + axisY->setLinePen(QPen(QColor(40, 46, 48))); + axisY->setLabelsColor(QColor(151, 151, 151)); // 设置标签字体颜色为灰色 + axisY->setGridLineColor(QColor(40, 46, 48)); axisY->setRange(0, 100); axisY->setTitleFont(QFont("Arial", 10)); // 设置标题字体 axisY->setTitleVisible(true); // 确保标题可见 diff --git a/view/coalstaticwidget.cpp b/view/coalstaticwidget.cpp new file mode 100644 index 0000000..1b5607e --- /dev/null +++ b/view/coalstaticwidget.cpp @@ -0,0 +1,297 @@ +#include "coalstaticwidget.h" +#include "ui_coalstaticwidget.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +CoalStaticWidget::CoalStaticWidget(QWidget* parent) + : QWidget(parent) + , ui(new Ui::CoalStaticWidget) +{ + ui->setupUi(this); + + m_systemSetting = new QSettings("system.ini", QSettings::IniFormat); + + ui->dateTimeEdit_startTime->setDateTime(QDateTime::currentDateTime().addSecs(-8 * 3600)); + + initCoalStatisticsBarChart(); +} + +CoalStaticWidget::~CoalStaticWidget() +{ + delete ui; +} + +void CoalStaticWidget::initCoalStatisticsBarChart() +{ + // 创建图表 + m_chart = new QChart(); + m_chart->setBackgroundBrush(Qt::transparent); + m_chart->setMargins(QMargins(0, 0, 0, 0)); + m_chart->legend()->hide(); + + // 创建图表视图并设置 + m_chartView = new QChartView(m_chart); + m_chartView->setBackgroundBrush(Qt::transparent); + m_chartView->setStyleSheet("background: transparent;"); + m_chartView->setRenderHint(QPainter::Antialiasing); + m_chartView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + // 创建柱状图 + m_series = new QBarSeries(); + m_chart->addSeries(m_series); + + // 设置X轴为时间 + m_axisX = new QBarCategoryAxis(); + // m_axisX->setFormat("yyyy/MM/d H"); // 设置日期时间格式 + // m_axisX->setTitleText("时间"); + m_axisX->setTitleBrush(QBrush(Qt::gray)); + m_axisX->setLinePen(QPen(Qt::gray)); + m_axisX->setLabelsColor(Qt::gray); + m_axisX->setGridLineVisible(false); + + // 获取当前时间并设置时间范围为最近六个小时 + // QDateTime currentTime = QDateTime::currentDateTime(); + // QDateTime startTime = currentTime.addSecs(-6 * 3600); // 当前时间减去六个小时 + // m_axisX->setLabelsAngle(45); + // m_axisX->setRange(startTime, currentTime); // 设置X轴时间范围 + + QDateTime currentTime = QDateTime::currentDateTime(); + QList timeList = getLastSixFullHours(currentTime); + m_axisX->append(timeList); + + m_chart->addAxis(m_axisX, Qt::AlignBottom); + m_series->attachAxis(m_axisX); + + // 设置Y轴为百分比 + m_axisY = new QValueAxis; + m_axisY->setTitleText("吨"); + m_axisY->setTitleBrush(QBrush(Qt::gray)); + m_axisY->setLinePen(QPen(Qt::gray)); + m_axisY->setLabelsColor(Qt::gray); + m_axisY->setRange(0, 100); + m_axisY->setTitleFont(QFont("Arial", 10)); + m_axisY->setTitleVisible(true); + + m_chart->addAxis(m_axisY, Qt::AlignLeft); + m_series->attachAxis(m_axisY); + + // 获取 widget_coalChart 的布局 + QVBoxLayout* layout = static_cast(ui->widget_coalStatisticsChart->layout()); + if (!layout) { + // 如果没有布局,创建一个新的布局并设置 + layout = new QVBoxLayout(ui->widget_coalStatisticsChart); + ui->widget_coalStatisticsChart->setLayout(layout); + } + + // 设置布局参数 + layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); + + // 确保视图只添加一次 + if (!layout->indexOf(m_chartView) != -1) { + layout->addWidget(m_chartView); + } +} + +QList CoalStaticWidget::getLastSixFullHours(const QDateTime& currentTime) +{ + // 将当前时间设置为整点 + QDateTime roundedTime = currentTime; + roundedTime.setTime(QTime(currentTime.time().hour(), 0)); // 设置时间到整点 + + bool insertTime = false; // 用于控制每隔一个插入时间,其他插入0 + + // 计算距当前整点数的前六个小时 + QList timeList; + for (int i = 8; i >= 1; --i) { + QDateTime prevHour = roundedTime.addSecs(-i * 3600); // 向前推算每个整点 + timeList.append(prevHour.toString("HH:mm")); + } + + return timeList; +} + +void CoalStaticWidget::updateCoalStatisticsChart(const QMap& volumeDataMap) +{ + + // 清除旧数据 + m_series->clear(); + + // 创建新的数据集 + QBarSet* set = new QBarSet("煤量"); + + // 用于存储时间标签 + QList categories; + + // 将字符串格式的时间转换为 QDateTime,并准备时间标签 + for (auto it = volumeDataMap.begin(); it != volumeDataMap.end(); ++it) { + + // 根据选择的时间单位,格式化时间标签 + QString label; + if (ui->comboBox_unit->currentText() == QStringLiteral("时")) { + QDateTime time = QDateTime::fromString(it.key(), "yyyy-MM-dd HH"); + label = time.toString("H"); + } else if (ui->comboBox_unit->currentText() == QStringLiteral("日")) { + QDateTime time = QDateTime::fromString(it.key(), "yyyy-MM-dd"); + label = time.toString("dd"); // 使用 'dd' 来格式化日期 + } else if (ui->comboBox_unit->currentText() == QStringLiteral("月")) { + QDateTime time = QDateTime::fromString(it.key(), "yyyy-MM"); + label = time.toString("MM"); // 使用 'MM' 来格式化月份 + } else if (ui->comboBox_unit->currentText() == QStringLiteral("年")) { + QDateTime time = QDateTime::fromString(it.key(), "yyyy"); + label = time.toString("yyyy"); // 使用 'yyyy' 来格式化年份 + } + + *set << it.value(); // 将数据量加入到数据集 + + emit querySuccessInfo(QString::number(it.value())); + + categories.append(label); // 将时间标签添加到列表 + } + + // 将数据集添加到 series + m_series->append(set); + + // 使用 QCategoryAxis 设置 X 轴为字符串格式的时间标签 + m_axisX->clear(); // 清除之前的标签 + m_axisX->append(categories); // 将新的时间标签添加到 X 轴 + + // 更新 Y 轴范围 + double maxValue = *std::max_element(volumeDataMap.begin(), volumeDataMap.end()); + m_axisY->setRange(0, maxValue + 10); // 设置为最大值并留出余量 +} + +void CoalStaticWidget::getCoalStatisInfoByHttpRequest(const QString& beginTime, const QString& endTime, const QString& statisticUnit) +{ + // 使用类成员变量 QNetworkAccessManager + QNetworkAccessManager* manager = new QNetworkAccessManager(this); + QString coalStaticUrl = m_systemSetting->value("coalStaticInterface/url").toString(); + + // URL + QUrl url(coalStaticUrl); + QNetworkRequest request(url); + + // Form data + QHttpMultiPart* multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType); + + // begin_time 参数 + QHttpPart beginTimePart; + beginTimePart.setHeader(QNetworkRequest::ContentDispositionHeader, + QVariant("form-data; name=\"begin_time\"")); + beginTimePart.setBody(beginTime.toUtf8()); + + // end_time 参数 + QHttpPart endTimePart; + endTimePart.setHeader(QNetworkRequest::ContentDispositionHeader, + QVariant("form-data; name=\"end_time\"")); + endTimePart.setBody(endTime.toUtf8()); + + // 统计单位参数 + QHttpPart statisticUnitPart; + statisticUnitPart.setHeader(QNetworkRequest::ContentDispositionHeader, + QVariant("form-data; name=\"statistic_unit\"")); + statisticUnitPart.setBody(statisticUnit.toUtf8()); + + // 将表单字段附加到 multipart 请求体中 + multiPart->append(beginTimePart); + multiPart->append(endTimePart); + multiPart->append(statisticUnitPart); + + // 发送 POST 请求 + QNetworkReply* reply = manager->post(request, multiPart); + + // 连接信号和槽 + QObject::connect(reply, &QNetworkReply::finished, [this, reply, multiPart]() { + if (reply->error() == QNetworkReply::NoError) { + // 处理成功的响应 + QByteArray responseData = reply->readAll(); + QJsonDocument jsonResponse = QJsonDocument::fromJson(responseData); + QJsonObject jsonObj = jsonResponse.object(); + + int code = jsonObj["code"].toInt(); + QString message = jsonObj["message"].toString(); + QJsonObject data = jsonObj["data"].toObject(); + m_toalValue = data["total_volum"].toDouble(); + QJsonObject statisticUnitVolum = data["statistic_unit_volum"].toObject(); + + int statisticUnitVolumSize = statisticUnitVolum.count(); + QString statisticUnitVolumSizeString = "查询结果数" + QString::number(statisticUnitVolumSize); + emit querySuccessInfo(statisticUnitVolumSizeString); + + QString totalVolumeString = "总吨数" + QString::number(m_toalValue); + emit querySuccessInfo(totalVolumeString); + + ui->label_totalVolume->clear(); + ui->label_totalVolume->setText(QString("煤量总计:%1吨").arg(m_toalValue * m_systemSetting->value("system/different").toDouble())); + + m_volumeDataMap.clear(); + + // 计算整体需要减少的总量 + double reduction = m_toalValue * m_systemSetting->value("system/different").toDouble(); // 减去50% + + // 计算每个值应该减少的比例 + // double currentReduction = 0; + + // 遍历 statistic_unit_volum 中的键值对并存入 volumeDataMap + for (const QString& key : statisticUnitVolum.keys()) { + double value = statisticUnitVolum.value(key).toDouble(); + + // // 计算每个值所减少的比例 + // double proportionalReduction = (value / m_toalValue) * reduction; + + m_volumeDataMap.insert(key, value /*- proportionalReduction*/); + + // currentReduction += proportionalReduction; + } + + emit + + // 更新查询的数据至图表 + if (!m_volumeDataMap.isEmpty()) + { + updateCoalStatisticsChart(m_volumeDataMap); + } + + } else { + // 处理错误 + QString errorString = reply->errorString(); + + emit querySuccessInfo(errorString); + qDebug() << "Error:" << errorString; + } + + // 清理资源 + reply->deleteLater(); + multiPart->deleteLater(); + }); +} + +void CoalStaticWidget::on_pushButton_clicked() +{ + // 时间范围 + QString beginTimeStr = ui->dateTimeEdit_startTime->text(); + QString endTimeStr = ui->dateTimeEdit_endTime->text(); + + // 创建 QDateTime 对象 + QDateTime beginTime = QDateTime::fromString(beginTimeStr, "yyyy/MM/d H:mm"); + QDateTime endTime = QDateTime::fromString(endTimeStr, "yyyy/MM/d H:mm"); + + // 格式化为 "yyyy-MM-d H" 形式 + QString formattedBeginTime = beginTime.toString("yyyy-MM-dd HH"); + QString formattedEndTime = endTime.toString("yyyy-MM-dd HH"); + + // 统计单位 + QString statisticUnit = ui->comboBox_unit->currentText(); + + emit querySuccessInfo("查询起始时间:" + formattedBeginTime); + emit querySuccessInfo("查询终止时间:" + formattedEndTime); + + getCoalStatisInfoByHttpRequest(formattedBeginTime, formattedEndTime, statisticUnit); +} diff --git a/view/coalstaticwidget.h b/view/coalstaticwidget.h new file mode 100644 index 0000000..7624f45 --- /dev/null +++ b/view/coalstaticwidget.h @@ -0,0 +1,76 @@ +#ifndef COALSTATICWIDGET_H +#define COALSTATICWIDGET_H + +#include +#include +#include + +namespace Ui { +class CoalStaticWidget; +} + +class CoalStaticWidget : public QWidget { + Q_OBJECT + +public: + explicit CoalStaticWidget(QWidget* parent = nullptr); + ~CoalStaticWidget(); + +signals: + void querySuccessInfo(QString queryInfo); + +private slots: + void on_pushButton_clicked(); + +private: + /** + * @brief initCoalStatisticsBarChart 初始化煤量统计柱状图 + */ + void initCoalStatisticsBarChart(); + + /** + * @brief getLastSixFullHours 计算前六个整点时间 + * @param currentTime 当前时间 + * @return 六个整点数 + */ + QList getLastSixFullHours(const QDateTime& currentTime); + + /** + * @brief updateCoalStatisticsChart 更新煤溜统计柱状图数据 + * @param volumeDataMap 统计结果数据 + */ + void updateCoalStatisticsChart(const QMap& volumeDataMap); + + /** + * @brief getCoalStatisInfoByHttpRequest 通过Http请求获取煤量统计信息 + * @param startTime 请求起始时间 + * @param endTime 请求终止时间 + * @param statisticUnit 统计单位 + */ + void getCoalStatisInfoByHttpRequest(const QString& startTime, const QString& endTime, const QString& statisticUnit); + +private: + Ui::CoalStaticWidget* ui; + + // 柱状图标 + QChart* m_chart; + QChartView* m_chartView; + QBarSeries* m_series; + // QDateTimeAxis* m_axisX; + QBarCategoryAxis* m_axisX; + QValueAxis* m_axisY; + + /** + * @brief m_systemSetting 系统配置信息 + */ + QSettings* m_systemSetting; + + double m_toalValue = 0.0; + + /** + * @brief m_volumeDataMap 查询出煤量数据 + */ + QMap m_volumeDataMap; +}; + +#endif // COALSTATICWIDGET_H diff --git a/view/coalstaticwidget.ui b/view/coalstaticwidget.ui new file mode 100644 index 0000000..2f0a028 --- /dev/null +++ b/view/coalstaticwidget.ui @@ -0,0 +1,334 @@ + + + CoalStaticWidget + + + + 0 + 0 + 1059 + 386 + + + + Form + + + + + + 30 + + + 0 + + + 10 + + + 0 + + + 10 + + + + + 0 + + + + + + 0 + 0 + + + + + 35 + 35 + + + + #widget_coalStaticLogo{ + border-image: url(:/Resource/image/icon6.png); +} + + + + + + + QLabel{ + color:white; + font: 12pt "黑体"; +} + + + 煤量统计 + + + + + + + + + 15 + + + + + Qt::LeftToRight + + + QLabel{ + color: rgb(255, 255, 255); + font: 10pt "黑体"; +} + + + 开始时间 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 25 + + + + QDateTimeEdit { + background-color: rgb(51, 52, 56); + color: white; /* 字体颜色 */ + border: 1px solid rgb(180, 186, 188); /* 边框颜色和宽度 */ + border-radius: 0px; /* 圆角 */ + padding: 5px; /* 内边距 */ + font-size: 14px; /* 字体大小 */ + font-family: "Arial", sans-serif; /* 字体样式 */ +} + +QDateTimeEdit::up-button { + subcontrol-origin: padding; + subcontrol-position: top right; +} + +QDateTimeEdit::down-button { + subcontrol-origin: padding; + subcontrol-position: bottom right; +} +QDateTimeEdit::up-button, QDateTimeEdit::down-button { + width: 0px; + height: 0px; +} + + + + + + + + QLabel{ + color: rgb(255, 255, 255); + font: 10pt "黑体"; +} + + + 结束时间 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 25 + + + + QDateTimeEdit { + background-color: rgb(51, 52, 56); + color: white; /* 字体颜色 */ + border: 1px solid rgb(180, 186, 188); /* 边框颜色和宽度 */ + border-radius: 0px; /* 圆角 */ + padding: 5px; /* 内边距 */ + font-size: 14px; /* 字体大小 */ + font-family: "Arial", sans-serif; /* 字体样式 */ +} + +QDateTimeEdit::up-button { + subcontrol-origin: padding; + subcontrol-position: top right; +} + +QDateTimeEdit::down-button { + subcontrol-origin: padding; + subcontrol-position: bottom right; +} +QDateTimeEdit::up-button, QDateTimeEdit::down-button { + width: 0px; + height: 0px; +} + + + + + + + + QLabel{ + color: rgb(255, 255, 255); + font: 10pt "黑体"; +} + + + 统计单位 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 25 + + + + QComboBox{ + background-color: rgb(51, 52, 56); + color: white; /* 字体颜色 */ + border: 1px solid rgb(180, 186, 188); /* 边框颜色和宽度 */ + border-radius: 0px; /* 圆角 */ + padding: 5px; /* 内边距 */ + font-size: 14px; /* 字体大小 */ + font-family: "Arial", sans-serif; /* 字体样式 */ +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + 50 + 20 + + + + QPushButton{ + border-image: url(:/Resource/image/labelunSelect.png); + color:white; + font-size: 14px; + border: none; +} +QPushButton:hover{ + border-image:url(:/Resource/image/labelhover.png); +} + +QPushButton:pressed{ + border-image: url(:/Resource/image/labelSelect.png); +} + + + 确定 + + + + + + + + + QLabel{ + color: rgb(255, 255, 255); + font: 10pt "黑体"; +} + + + 煤量总计:000吨 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + + ZDateTimeEdit + QDateTimeEdit +
component/ZDateEdit/zdatetimeedit.h
+
+
+ + +
diff --git a/view/coalstatisticsbarchartwidget.cpp b/view/coalstatisticsbarchartwidget.cpp new file mode 100644 index 0000000..15d4906 --- /dev/null +++ b/view/coalstatisticsbarchartwidget.cpp @@ -0,0 +1,6 @@ +#include "coalstatisticsbarchartwidget.h" + +CoalStatisticsBarChartWidget::CoalStatisticsBarChartWidget(QWidget* parent) + : QWidget(parent) +{ +} diff --git a/view/coalstatisticsbarchartwidget.h b/view/coalstatisticsbarchartwidget.h new file mode 100644 index 0000000..2125db4 --- /dev/null +++ b/view/coalstatisticsbarchartwidget.h @@ -0,0 +1,17 @@ +#ifndef COALSTATISTICSBARCHARTWIDGET_H +#define COALSTATISTICSBARCHARTWIDGET_H + +#include + +class CoalStatisticsBarChartWidget : public QWidget +{ + Q_OBJECT +public: + explicit CoalStatisticsBarChartWidget(QWidget *parent = nullptr); + +signals: + +public slots: +}; + +#endif // COALSTATISTICSBARCHARTWIDGET_H diff --git a/view/coalstatisticschartwidget.cpp b/view/coalstatisticschartwidget.cpp index 542a59e..e8da374 100644 --- a/view/coalstatisticschartwidget.cpp +++ b/view/coalstatisticschartwidget.cpp @@ -225,10 +225,10 @@ void CoalStatisticsChartWidget::initCustomPlotCoalStatisticsBarChart() // 设置 X 轴 m_customPlot->xAxis->setLabel("时间"); - m_customPlot->xAxis->setBasePen(QPen(Qt::gray)); // 设置轴线颜色 - m_customPlot->xAxis->setTickPen(QPen(Qt::gray)); // 设置刻度线颜色 - m_customPlot->xAxis->setSubTickPen(QPen(Qt::gray)); // 设置子刻度线颜色 - m_customPlot->xAxis->setTickLabelColor(Qt::gray); // 设置刻度标签颜色 + m_customPlot->xAxis->setBasePen(QPen(QColor(151, 151, 151))); // 设置轴线颜色 + m_customPlot->xAxis->setTickPen(QPen(QColor(151, 151, 151))); // 设置刻度线颜色 + m_customPlot->xAxis->setSubTickPen(QPen(QColor(151, 151, 151))); // 设置子刻度线颜色 + m_customPlot->xAxis->setTickLabelColor(QColor(151, 151, 151)); // 设置刻度标签颜色 m_customPlot->xAxis->setTickLabelRotation(60); // 设置刻度标签的旋转角度,避免重叠 // 设置 Y 轴