HX_CoalFlowDetect/view/coaldistributbarchartwidget.h

71 lines
1.5 KiB
C
Raw Normal View History

2024-11-01 17:40:37 +08:00
#ifndef COALDISTRIBUTBARCHARTWIDGET_H
#define COALDISTRIBUTBARCHARTWIDGET_H
#include <QDateTime>
#include <QObject>
#include <QTimer>
#include <QWidget>
#include <QDateTimeAxis>
2024-11-04 18:11:55 +08:00
#include <QNetworkProxy>
#include <QTcpSocket>
2024-11-01 17:40:37 +08:00
#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);
2024-11-04 18:11:55 +08:00
~CoalDistributBarChartWidget();
2024-11-01 17:40:37 +08:00
private slots:
void updateChart();
private:
void initializeChart();
void setupTimer();
2024-11-04 18:11:55 +08:00
/**
* @brief connectTCPSocket TCP服务
*/
void connectTCPSocket();
/**
* @brief getCoalRatioByTCPSocket通过TCP协议获取煤量占比
* @return
*/
int getCoalRatioByTCPSocket();
/**
* @brief createModbusTcpRequest ModbusTCP报文
* @return
*/
QByteArray createModbusTcpRequest();
2024-11-01 17:40:37 +08:00
private:
QChart* m_chart;
QChartView* m_chartView;
QBarSeries* m_series;
QTimer* m_timer;
QDateTimeAxis* m_axisX;
2024-11-04 18:11:55 +08:00
QBarSet* m_set;
2024-11-01 17:40:37 +08:00
int currentIndex; // 当前更新的柱子的索引
static const int MaxDataPoints = 300; // 最大数据点数5分钟每秒1条
2024-11-04 18:11:55 +08:00
2024-11-01 17:40:37 +08:00
QList<QDateTime> m_timeLabels; // 存储时间标签
2024-11-04 18:11:55 +08:00
QTcpSocket* m_tcpSocket;
2024-11-01 17:40:37 +08:00
};
#endif // COALDISTRIBUTBARCHARTWIDGET_H