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