diff --git a/HX_CoalFlowDetect.pro b/HX_CoalFlowDetect.pro index 1432645..de08f1d 100644 --- a/HX_CoalFlowDetect.pro +++ b/HX_CoalFlowDetect.pro @@ -27,15 +27,29 @@ CONFIG += c++11 SOURCES += \ main.cpp \ mainwindow.cpp \ - view/coaldistributchartwidget.cpp + view/beltspeedlinewidget.cpp \ + view/coaldistributbarchartwidget.cpp \ + view/coalstatisticschartwidget.cpp\ + component/ZDateEdit/dateCommonInfo.cpp\ + component/ZDateEdit/zdateedit.cpp\ + component/ZDateEdit/zdatetimeedit.cpp\ + component/ZDateEdit/ztimeedit.cpp\ HEADERS += \ mainwindow.h \ - view/coaldistributchartwidget.h + view/beltspeedlinewidget.h \ + view/coaldistributbarchartwidget.h \ + view/coalstatisticschartwidget.h\ + component/ZDateEdit/dateCommonInfo.h\ + component/ZDateEdit/zdateedit.h\ + component/ZDateEdit/zdatetimeedit.h\ + component/ZDateEdit/ztimeedit.h\ + FORMS += \ mainwindow.ui \ - view/coaldistributchartwidget.ui + view/coalstatisticschartwidget.ui + # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin diff --git a/Resource/logo.ico b/Resource/logo.ico new file mode 100644 index 0000000..b17e78f Binary files /dev/null and b/Resource/logo.ico differ diff --git a/component/ZDateEdit/Resources/ComboBoxArrow.png b/component/ZDateEdit/Resources/ComboBoxArrow.png new file mode 100644 index 0000000..d427e33 Binary files /dev/null and b/component/ZDateEdit/Resources/ComboBoxArrow.png differ diff --git a/component/ZDateEdit/Resources/DTNext.png b/component/ZDateEdit/Resources/DTNext.png new file mode 100644 index 0000000..68c220c Binary files /dev/null and b/component/ZDateEdit/Resources/DTNext.png differ diff --git a/component/ZDateEdit/Resources/DTPrev.png b/component/ZDateEdit/Resources/DTPrev.png new file mode 100644 index 0000000..7d0f45f Binary files /dev/null and b/component/ZDateEdit/Resources/DTPrev.png differ diff --git a/component/ZDateEdit/Resources/bk.png b/component/ZDateEdit/Resources/bk.png new file mode 100644 index 0000000..3d3b6d7 Binary files /dev/null and b/component/ZDateEdit/Resources/bk.png differ diff --git a/component/ZDateEdit/Resources/popupButton.png b/component/ZDateEdit/Resources/popupButton.png new file mode 100644 index 0000000..dfd60ef Binary files /dev/null and b/component/ZDateEdit/Resources/popupButton.png differ diff --git a/component/ZDateEdit/Resources/popupButton2.png b/component/ZDateEdit/Resources/popupButton2.png new file mode 100644 index 0000000..00a8905 Binary files /dev/null and b/component/ZDateEdit/Resources/popupButton2.png differ diff --git a/component/ZDateEdit/qss/zDateTimeEdit.qss b/component/ZDateEdit/qss/zDateTimeEdit.qss new file mode 100644 index 0000000..d733656 --- /dev/null +++ b/component/ZDateEdit/qss/zDateTimeEdit.qss @@ -0,0 +1,16 @@ +QPushButton#popupButton{ + border-image: url(:/component/ZDateEdit/Resources/popupButton.png);min-height:20px;max-height:20px;min-width:20px;max-width:20px;background-color:#ffffff; +} + +QLabel{color:#cadfff; font-size:12px;} +QLabel#labelWeekend{color:#00caff;} +QLable#label_splite{font: bold 14px;} + +QWidget#widgetTitle{background-color:#061f65;} +QWidget#baseWidget{background-color:#EE013B6B;border-radius: 11px;} + +QComboBox{background-color: transparent; selection-background-color: transparent; color:#ffffff; font-size: 14px; min-height: 20px; selection-text-align: right;border:0px solid} +QComboBox::down-arrow{ image:url(:/component/ZDateEdit/Resources/ComboBoxArrow.png); } +QComboBox::down-arrow:on{ top: 1px; left: 1px; } QComboBox::drop-down{ width: 26px; border:none; } +QComboBox QAbstractItemView {border: none; outline:0px;} QComboBox QAbstractItemView::item{ height: 26px; min-height:26px;} +QComboBox QAbstractItemView::item:selected{ background-color: #0087f1; color: #e6ebf1;} QComboBox QAbstractItemView::item:!selected {background-color: #e6ebf1; color: #000000;} diff --git a/main.cpp b/main.cpp index acfb321..27a9d6d 100644 --- a/main.cpp +++ b/main.cpp @@ -1,5 +1,6 @@ #include "mainwindow.h" #include +#include int main(int argc, char* argv[]) { @@ -7,5 +8,12 @@ int main(int argc, char* argv[]) MainWindow w; w.showMaximized(); + QFile file(":/component/ZDateEdit/qss/zDateTimeEdit.qss"); + if (file.open(QFile::ReadOnly)) { + QString qss = file.readAll(); + a.setStyleSheet(qss); + file.close(); + } + return a.exec(); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 7950030..ca71530 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,64 +1,121 @@ #include "mainwindow.h" #include "ui_mainwindow.h" -#include "view/coaldistributchartwidget.h" +#include "view/beltspeedlinewidget.h" +#include "view/coaldistributbarchartwidget.h" +#include "view/coalstatisticschartwidget.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); - calendarLoopPlay(); + calendarLoopPlay(); - addcoalDistributChart(); + setBeltWarnInfoTextEditStyle(); + + addcoalDistributChart(); + + addbeltSpeedChat(); + + addCoalStatisticsChart(); } MainWindow::~MainWindow() { delete ui; } +void MainWindow::addBeltWarnInfoToTextEdit(const QString& 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(); + + qint64 timeDifferenceInMilliseconds = m_previousConsleInfoDateTime.secsTo(startDateTime); + + if ((lastConsoleInfo == consoleInfo) && timeDifferenceInMilliseconds < 2) + return; + + QString consoleInfoResult = QStringLiteral("[%1]%2").arg(formattedTime).arg(consoleInfo); + ui->textEdit_beltWarnInfo->append(consoleInfoResult); + + 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::addcoalDistributChart() { - - CoalDistributChartWidget *coalDistributChartWidget = - new CoalDistributChartWidget(ui->widget_coalDistributChart); - - // 可选:设置大小 - coalDistributChartWidget->setMinimumSize(400, 300); // 设置最小大小以确保可见 - - // 确保将部件添加到布局中 - QVBoxLayout *layout = - qobject_cast(ui->widget_coalDistributChart->layout()); - if (layout) { - layout->addWidget(coalDistributChartWidget); - } else { - // 如果没有布局,可以手动添加部件 - ui->widget_coalDistributChart->setLayout(new QVBoxLayout()); - ui->widget_coalDistributChart->layout()->addWidget( - coalDistributChartWidget); - } +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("添加煤流分布窗口成功!"); + + 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); +} + +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); } diff --git a/mainwindow.h b/mainwindow.h index 7587b52..dd121b9 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -1,6 +1,7 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H +#include #include namespace Ui { @@ -8,32 +9,64 @@ class MainWindow; } class MainWindow : public QMainWindow { - Q_OBJECT + Q_OBJECT public: - explicit MainWindow(QWidget *parent = nullptr); - ~MainWindow(); + explicit MainWindow(QWidget* parent = nullptr); + ~MainWindow(); + +public slots: + /** + * @brief 皮带报警信息 + * @param consoleInfo + */ + void addBeltWarnInfoToTextEdit(const QString& consoleInfo); private slots: - void on_pushButton_close_clicked(); + void on_pushButton_close_clicked(); - void on_pushButton_max_clicked(); + void on_pushButton_max_clicked(); - void on_pushButton_min_clicked(); + void on_pushButton_min_clicked(); private: - /** + /** * @brief calendarLoopPlay 时间轮播 */ - void calendarLoopPlay(); + void calendarLoopPlay(); - /** + /** + * @brief setBeltWarnInfoTextEditStyle 调整皮带报警信息编辑框样式 + */ + void setBeltWarnInfoTextEditStyle(); + + /** * @brief addcoalDistributChart 添加煤流分布柱状图 */ - void addcoalDistributChart(); + void addcoalDistributChart(); + + /** + * @brief addbeltSpeedChat 添加皮带机速度曲线图 + */ + void addbeltSpeedChat(); + + /** + * @brief addCoalStatisticsChart 添加煤量统计图表 + */ + void addCoalStatisticsChart(); private: - Ui::MainWindow *ui; + Ui::MainWindow* ui; + + /** + * @brief m_textEditConsoleInfo 控制台命令列表信息 + */ + QList m_textEditConsoleInfo; + + /** + * @brief m_previousConsleInfoDateTime 上一条控制台命令发送时间 + */ + QDateTime m_previousConsleInfoDateTime; }; #endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui index 83332f3..a0b2eb7 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -205,7 +205,7 @@ QPushButton:pressed{ - + 6 @@ -1040,6 +1040,9 @@ QToolButton:pressed{ + + 20 + @@ -3026,7 +3029,7 @@ QPushButton:pressed{ - + @@ -3038,7 +3041,7 @@ QPushButton:pressed{ - + 6 @@ -3092,7 +3095,37 @@ QPushButton:pressed{ - + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + #textEdit_beltWarnInfo{ + background-color:transparent; + color: #FFFFFF; + font: 12pt "Albertus Extra Bold"; + border:no; +} + + + + + @@ -3153,6 +3186,21 @@ QPushButton:pressed{ } + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + @@ -3192,7 +3240,25 @@ QPushButton:pressed{ - + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + diff --git a/resource.qrc b/resource.qrc index 42f1898..5d129f6 100644 --- a/resource.qrc +++ b/resource.qrc @@ -58,5 +58,12 @@ Resource/image/startPress.png Resource/image/stopHover.png Resource/image/stopPress.png + component/ZDateEdit/qss/zDateTimeEdit.qss + component/ZDateEdit/Resources/bk.png + component/ZDateEdit/Resources/ComboBoxArrow.png + component/ZDateEdit/Resources/DTNext.png + component/ZDateEdit/Resources/DTPrev.png + component/ZDateEdit/Resources/popupButton.png + component/ZDateEdit/Resources/popupButton2.png diff --git a/view/beltspeedlinewidget.cpp b/view/beltspeedlinewidget.cpp new file mode 100644 index 0000000..d430e4d --- /dev/null +++ b/view/beltspeedlinewidget.cpp @@ -0,0 +1,66 @@ +#include "beltspeedlinewidget.h" + +#include +#include + +BeltSpeedLineWidget::BeltSpeedLineWidget(QWidget* parent) + : QWidget(parent) +{ + initLineChart(); +} + +void BeltSpeedLineWidget::initLineChart() +{ + // 创建图表视图 + m_chartView = new QChartView(this); + + m_chartView->setBackgroundBrush(Qt::transparent); + m_chartView->setStyleSheet("background: transparent;"); // 使用样式表确保透明 + m_chartView->setRenderHint(QPainter::Antialiasing); + m_chartView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + m_chart = new QChart(); + m_chart->setBackgroundBrush(Qt::transparent); + m_chart->setMargins(QMargins(0, 0, 0, 0)); + + // 创建折线系列 + m_series = new QLineSeries(); + m_series->setPointsVisible(false); // 隐藏数据点的标记 + // m_series->setMarkerShape(QLineSeries::MarkerShapeNone); // 隐藏标记形状 + + // 将系列添加到图表 + m_chart->addSeries(m_series); + m_chart->createDefaultAxes(); + + // 假设数据点,替换为你的实时数据 + QDateTime currentTime = QDateTime::currentDateTime(); + for (int i = 0; i < 120; ++i) { // 120个数据点,代表最近两个小时 + double speed = qrand() % 21; // 生成0到20之间的随机速度 + m_series->append(currentTime.addSecs(-i * 60).toMSecsSinceEpoch(), speed); + } + + // 创建并设置X轴为日期时间轴 + QDateTimeAxis* xAxis = new QDateTimeAxis(); + xAxis->setFormat("hh:mm:ss"); + xAxis->setRange(currentTime.addSecs(-7200), currentTime); // 设置范围为最近两个小时 + xAxis->setLinePen(QPen(Qt::gray)); + xAxis->setLabelsColor(Qt::gray); + m_chart->setAxisX(xAxis, m_series); // 将X轴应用到数据系列 + + // 设置Y轴范围 + m_chart->axisY()->setRange(0, 20); + m_chart->axisY()->setTitleText("速度 (m/s)"); + + m_chart->axisY()->setTitleBrush(QBrush(Qt::gray)); + m_chart->axisY()->setLinePen(QPen(Qt::gray)); + m_chart->axisY()->setLabelsColor(Qt::gray); + + // 设置图表到视图并将视图设置为中心部件 + m_chartView->setChart(m_chart); + + QVBoxLayout* layout = new QVBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); // 设置间距为0 + layout->addWidget(m_chartView); + setLayout(layout); +} diff --git a/view/beltspeedlinewidget.h b/view/beltspeedlinewidget.h new file mode 100644 index 0000000..45e67ba --- /dev/null +++ b/view/beltspeedlinewidget.h @@ -0,0 +1,26 @@ +#ifndef BELTSPEEDLINEWIDGET_H +#define BELTSPEEDLINEWIDGET_H + +#include +#include +#include + +QT_CHARTS_USE_NAMESPACE + +class BeltSpeedLineWidget : public QWidget { + Q_OBJECT +public: + explicit BeltSpeedLineWidget(QWidget* parent = nullptr); + +public slots: + +private: + void initLineChart(); + +private: + QChartView* m_chartView; // 图表视图 + QChart* m_chart; // 图表 + QLineSeries* m_series; // 数据系列 +}; + +#endif // BELTSPEEDLINEWIDGET_H diff --git a/view/coaldistributbarchartwidget.cpp b/view/coaldistributbarchartwidget.cpp new file mode 100644 index 0000000..c5e9d63 --- /dev/null +++ b/view/coaldistributbarchartwidget.cpp @@ -0,0 +1,104 @@ +#include "coaldistributbarchartwidget.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +CoalDistributBarChartWidget::CoalDistributBarChartWidget(QWidget* parent) + : QWidget(parent) +{ + initializeChart(); + + // setupTimer(); +} + +void CoalDistributBarChartWidget::updateChart() +{ + double newValue = QRandomGenerator::global()->bounded(0, 99); // 随机生成0-900的Y值 + + // 更新当前柱子的值 + QBarSet* currentBarSet = static_cast(m_series->barSets().at(currentIndex)); + currentBarSet->replace(0, newValue); // 更新当前柱子的值 + + // 循环更新下一个柱子的索引 + currentIndex = (currentIndex + 1) % m_series->count(); // 循环到下一个柱子 +} + +void CoalDistributBarChartWidget::initializeChart() +{ + // 创建图标 + m_chart = new QChart(); + + m_chart->setBackgroundBrush(Qt::transparent); + m_chart->setMargins(QMargins(0, 0, 0, 0)); + + // 创建窗口并设置图表 + 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); + + // 创建300个柱状集 + // for (int i = 0; i < 300; ++i) { + // QBarSet* barSet = new QBarSet(QString::number(i)); // 使用柱子编号作为名称 + // barSet->append(0); // 初始化值为0 + // m_series->append(barSet); + // } + + // 设置X轴为时间 + QValueAxis* axisX = new QValueAxis; + axisX->setRange(1, 300); + axisX->setTickCount(10); + axisX->setLabelFormat("%d"); + axisX->setLinePen(QPen(Qt::gray)); + axisX->setLabelsColor(Qt::gray); + axisX->setMinorTickCount(0); // 隐藏X轴刻度线 + 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->setRange(0, 100); + m_chart->addAxis(axisY, Qt::AlignLeft); + m_series->attachAxis(axisY); + + // 设置Y轴标题位置 + axisY->setTitleFont(QFont("Arial", 10)); // 设置标题字体 + axisY->setTitleVisible(true); // 确保标题可见 + + QVBoxLayout* layout = new QVBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); // 设置间距为0 + layout->addWidget(m_chartView); + setLayout(layout); +} + +void CoalDistributBarChartWidget::setupTimer() +{ + // 定时器设置 + m_timer = new QTimer(this); + connect(m_timer, &QTimer::timeout, this, &CoalDistributBarChartWidget::updateChart); + m_timer->start(1000); // 每秒更新一次 +} diff --git a/view/coaldistributbarchartwidget.h b/view/coaldistributbarchartwidget.h new file mode 100644 index 0000000..72e468a --- /dev/null +++ b/view/coaldistributbarchartwidget.h @@ -0,0 +1,50 @@ +#ifndef COALDISTRIBUTBARCHARTWIDGET_H +#define COALDISTRIBUTBARCHARTWIDGET_H + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +QT_CHARTS_USE_NAMESPACE + +class CoalDistributBarChartWidget : public QWidget { + Q_OBJECT +public: + explicit CoalDistributBarChartWidget(QWidget* parent = nullptr); + +private slots: + void updateChart(); + +private: + void initializeChart(); + + void setupTimer(); + +private: + QChart* m_chart; + QChartView* m_chartView; + QBarSeries* m_series; + QTimer* m_timer; + + QDateTimeAxis* m_axisX; + + int currentIndex; // 当前更新的柱子的索引 + + static const int MaxDataPoints = 300; // 最大数据点数(5分钟,每秒1条) + QBarSet* m_set; + // QList m_timeLabels; + QList m_timeLabels; // 存储时间标签 + QList m_values; // 存储比例值 + + // QList timestamps; // 存储时间戳 +}; + +#endif // COALDISTRIBUTBARCHARTWIDGET_H diff --git a/view/coalstatisticschartwidget.cpp b/view/coalstatisticschartwidget.cpp new file mode 100644 index 0000000..0cb8af4 --- /dev/null +++ b/view/coalstatisticschartwidget.cpp @@ -0,0 +1,77 @@ +#include "coalstatisticschartwidget.h" +#include "ui_coalstatisticschartwidget.h" + +CoalStatisticsChartWidget::CoalStatisticsChartWidget(QWidget* parent) + : QWidget(parent) + , ui(new Ui::CoalStatisticsChartWidget) +{ + ui->setupUi(this); + + initCoalStatisticsBarChart(); +} + +CoalStatisticsChartWidget::~CoalStatisticsChartWidget() +{ + delete ui; +} + +void CoalStatisticsChartWidget::initCoalStatisticsBarChart() +{ + // 创建图表 + m_chart = new QChart(); + m_chart->setBackgroundBrush(Qt::transparent); + m_chart->setMargins(QMargins(0, 0, 0, 0)); + + // 创建图表视图并设置 + 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轴为时间 + QValueAxis* axisX = new QValueAxis; + axisX->setRange(1, 300); + axisX->setTickCount(10); + axisX->setLabelFormat("%d"); + axisX->setLinePen(QPen(Qt::gray)); + axisX->setLabelsColor(Qt::gray); + axisX->setMinorTickCount(0); + 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->setRange(0, 100); + m_chart->addAxis(axisY, Qt::AlignLeft); + m_series->attachAxis(axisY); + + // 设置Y轴标题位置 + axisY->setTitleFont(QFont("Arial", 10)); + axisY->setTitleVisible(true); + + // 获取 widget_coalChart 的布局 + QVBoxLayout* layout = static_cast(ui->widget_coalChart->layout()); + if (!layout) { + // 如果没有布局,创建一个新的布局并设置 + layout = new QVBoxLayout(ui->widget_coalChart); + ui->widget_coalChart->setLayout(layout); + } + + // 设置布局参数 + layout->setContentsMargins(0, 0, 0, 0); + layout->setSpacing(0); + + // 确保视图只添加一次 + if (!layout->indexOf(m_chartView) != -1) { + layout->addWidget(m_chartView); + } +} diff --git a/view/coalstatisticschartwidget.h b/view/coalstatisticschartwidget.h new file mode 100644 index 0000000..e80aa51 --- /dev/null +++ b/view/coalstatisticschartwidget.h @@ -0,0 +1,34 @@ +#ifndef COALSTATISTICSCHARTWIDGET_H +#define COALSTATISTICSCHARTWIDGET_H + +#include +#include + +QT_CHARTS_USE_NAMESPACE +namespace Ui { +class CoalStatisticsChartWidget; +} + +class CoalStatisticsChartWidget : public QWidget { + Q_OBJECT + +public: + explicit CoalStatisticsChartWidget(QWidget* parent = nullptr); + ~CoalStatisticsChartWidget(); + +private: + /** + * @brief initCoalStatisticsBarChart 初始化煤量统计柱状图 + */ + void initCoalStatisticsBarChart(); + +private: + Ui::CoalStatisticsChartWidget* ui; + + QChart* m_chart; + QChartView* m_chartView; + QBarSeries* m_series; + QTimer* m_timer; +}; + +#endif // COALSTATISTICSCHARTWIDGET_H diff --git a/view/coalstatisticschartwidget.ui b/view/coalstatisticschartwidget.ui new file mode 100644 index 0000000..f1a14da --- /dev/null +++ b/view/coalstatisticschartwidget.ui @@ -0,0 +1,316 @@ + + + CoalStatisticsChartWidget + + + + 0 + 0 + 630 + 350 + + + + Form + + + + 6 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 15 + + + 10 + + + 10 + + + + + 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; /* 字体样式 */ +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 10 + + + 10 + + + + + QLabel{ + color: rgb(255, 255, 255); + font: 10pt "黑体"; +} + + + 煤量总计:000吨 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + QRadioButton{ + + color: rgb(255, 255, 255); +} + + + + + + true + + + + + + + QRadioButton{ + + color: rgb(255, 255, 255); +} + + + + + + + + + + QRadioButton{ + + color: rgb(255, 255, 255); +} + + + + + + + + + + QRadioButton{ + + color: rgb(255, 255, 255); +} + + + + + + + + + + + + + + + + + + ZDateTimeEdit + QDateTimeEdit +
component/ZDateEdit/zdatetimeedit.h
+
+
+ + +