feat:添加折线图信息
|
@ -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
|
||||
|
|
After Width: | Height: | Size: 4.2 KiB |
After Width: | Height: | Size: 146 B |
After Width: | Height: | Size: 223 B |
After Width: | Height: | Size: 211 B |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 429 B |
|
@ -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;}
|
8
main.cpp
|
@ -1,5 +1,6 @@
|
|||
#include "mainwindow.h"
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
|
||||
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();
|
||||
}
|
||||
|
|
143
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 <QDateTime>
|
||||
#include <QTimer>
|
||||
|
||||
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<QVBoxLayout *>(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);
|
||||
}
|
||||
|
|
55
mainwindow.h
|
@ -1,6 +1,7 @@
|
|||
#ifndef MAINWINDOW_H
|
||||
#define MAINWINDOW_H
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QMainWindow>
|
||||
|
||||
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<QString> m_textEditConsoleInfo;
|
||||
|
||||
/**
|
||||
* @brief m_previousConsleInfoDateTime 上一条控制台命令发送时间
|
||||
*/
|
||||
QDateTime m_previousConsleInfoDateTime;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -205,7 +205,7 @@ QPushButton:pressed{
|
|||
<widget class="QWidget" name="widget_body" native="true">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="4,2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="2,4,3">
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="2,4,4">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
|
@ -1040,6 +1040,9 @@ QToolButton:pressed{
|
|||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<property name="spacing">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_belt1" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_22">
|
||||
|
@ -3026,7 +3029,7 @@ QPushButton:pressed{
|
|||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_2" native="true"/>
|
||||
<widget class="QWidget" name="widget_beltSpeedChart" native="true"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
|
@ -3038,7 +3041,7 @@ QPushButton:pressed{
|
|||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="3,3,4">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
|
@ -3092,7 +3095,37 @@ QPushButton:pressed{
|
|||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_3" native="true"/>
|
||||
<widget class="QWidget" name="widget_beltWarnInfoEdit" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_43">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QTextEdit" name="textEdit_beltWarnInfo">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">#textEdit_beltWarnInfo{
|
||||
background-color:transparent;
|
||||
color: #FFFFFF;
|
||||
font: 12pt "Albertus Extra Bold";
|
||||
border:no;
|
||||
}</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
@ -3153,6 +3186,21 @@ QPushButton:pressed{
|
|||
}</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_9" stretch="1,9">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_19">
|
||||
<item>
|
||||
|
@ -3192,7 +3240,25 @@ QPushButton:pressed{
|
|||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_5" native="true"/>
|
||||
<widget class="QWidget" name="widget_coalStatisticsChart" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_44">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
|
|
@ -58,5 +58,12 @@
|
|||
<file>Resource/image/startPress.png</file>
|
||||
<file>Resource/image/stopHover.png</file>
|
||||
<file>Resource/image/stopPress.png</file>
|
||||
<file>component/ZDateEdit/qss/zDateTimeEdit.qss</file>
|
||||
<file>component/ZDateEdit/Resources/bk.png</file>
|
||||
<file>component/ZDateEdit/Resources/ComboBoxArrow.png</file>
|
||||
<file>component/ZDateEdit/Resources/DTNext.png</file>
|
||||
<file>component/ZDateEdit/Resources/DTPrev.png</file>
|
||||
<file>component/ZDateEdit/Resources/popupButton.png</file>
|
||||
<file>component/ZDateEdit/Resources/popupButton2.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
#include "beltspeedlinewidget.h"
|
||||
|
||||
#include <QDateTimeAxis>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
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);
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#ifndef BELTSPEEDLINEWIDGET_H
|
||||
#define BELTSPEEDLINEWIDGET_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QWidget>
|
||||
#include <QtCharts>
|
||||
|
||||
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
|
|
@ -0,0 +1,104 @@
|
|||
#include "coaldistributbarchartwidget.h"
|
||||
|
||||
#include <QDateTimeAxis>
|
||||
#include <QList>
|
||||
#include <QRandomGenerator>
|
||||
#include <QScopedPointer>
|
||||
#include <QVBoxLayout>
|
||||
#include <QtCharts/QChart>
|
||||
|
||||
#include <QBarSeries>
|
||||
#include <QBarSet>
|
||||
#include <QChart>
|
||||
#include <QChartView>
|
||||
#include <QDateTimeAxis>
|
||||
#include <QTimer>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include <memory>
|
||||
|
||||
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<QBarSet*>(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); // 每秒更新一次
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
#ifndef COALDISTRIBUTBARCHARTWIDGET_H
|
||||
#define COALDISTRIBUTBARCHARTWIDGET_H
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
#include <QWidget>
|
||||
|
||||
#include <QDateTimeAxis>
|
||||
#include <QtCharts/QBarSeries>
|
||||
#include <QtCharts/QBarSet>
|
||||
#include <QtCharts/QCategoryAxis>
|
||||
#include <QtCharts/QChartView>
|
||||
#include <QtCharts/QValueAxis>
|
||||
|
||||
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<QString> m_timeLabels;
|
||||
QList<QDateTime> m_timeLabels; // 存储时间标签
|
||||
QList<double> m_values; // 存储比例值
|
||||
|
||||
// QList<QDateTime> timestamps; // 存储时间戳
|
||||
};
|
||||
|
||||
#endif // COALDISTRIBUTBARCHARTWIDGET_H
|
|
@ -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<QVBoxLayout*>(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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef COALSTATISTICSCHARTWIDGET_H
|
||||
#define COALSTATISTICSCHARTWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QtCharts>
|
||||
|
||||
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
|
|
@ -0,0 +1,316 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CoalStatisticsChartWidget</class>
|
||||
<widget class="QWidget" name="CoalStatisticsChartWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>630</width>
|
||||
<height>350</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,1,8">
|
||||
<property name="spacing">
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<property name="spacing">
|
||||
<number>15</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="layoutDirection">
|
||||
<enum>Qt::LeftToRight</enum>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QLabel{
|
||||
color: rgb(255, 255, 255);
|
||||
font: 10pt "黑体";
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>开始时间</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ZDateTimeEdit" name="dateTimeEdit_startTime">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">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;
|
||||
}
|
||||
</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QLabel{
|
||||
color: rgb(255, 255, 255);
|
||||
font: 10pt "黑体";
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>结束时间</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="ZDateTimeEdit" name="dateTimeEdit_endTime">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">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;
|
||||
}
|
||||
</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QLabel{
|
||||
color: rgb(255, 255, 255);
|
||||
font: 10pt "黑体";
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>统计单位</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox_unit">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>25</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">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; /* 字体样式 */
|
||||
}</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>时</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>日</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>月</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>年</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<property name="leftMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QLabel{
|
||||
color: rgb(255, 255, 255);
|
||||
font: 10pt "黑体";
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>煤量总计:000吨</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_hour">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QRadioButton{
|
||||
|
||||
color: rgb(255, 255, 255);
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>时</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_day">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QRadioButton{
|
||||
|
||||
color: rgb(255, 255, 255);
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>日</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_month">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QRadioButton{
|
||||
|
||||
color: rgb(255, 255, 255);
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>月</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="radioButton_year">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">QRadioButton{
|
||||
|
||||
color: rgb(255, 255, 255);
|
||||
}</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>年</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_coalChart" native="true">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3"/>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>ZDateTimeEdit</class>
|
||||
<extends>QDateTimeEdit</extends>
|
||||
<header>component/ZDateEdit/zdatetimeedit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|