Files
EJM_Display/PublicFunctions/CurvePlotWidget - 副本.h
2025-09-15 22:28:43 +08:00

67 lines
1.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#ifndef CURVEPLOTWIDGET_H
#define CURVEPLOTWIDGET_H
#include <QWidget>
#include <QVector>
#include <QColor>
#include <QMap>
#include <QElapsedTimer>
struct CurveCfg
{
QString name; // 图例
double yMax; // y 满量程
QColor normal; // 绿色(正常)
QColor warning; // 橙色(警告)
QColor fault; // 红色(故障)
double thWarning; // 警告阈值
double thFault; // 故障阈值
};
class CurvePlotWidget : public QWidget
{
Q_OBJECT
public:
explicit CurvePlotWidget(QWidget *parent = nullptr);
/* x 轴总时长(秒) */
void setTimeRange(double secs);
/* 添加一条曲线 */
void initCurve(int id, const CurveCfg &cfg);
/* 清空所有曲线 */
void clearAllCurves();
/* 追加数据yValue 为物理量timeStamp 为 QDateTime::toMSecsSinceEpoch()/1000.0 */
void appendPoint(int curveId, double timeStamp, double yValue);
protected:
void paintEvent(QPaintEvent *event) override;
void resizeEvent(QResizeEvent *event) override;
private:
struct Curve
{
CurveCfg cfg;
QVector<double> tBuf;
QVector<double> yBuf;
int head = 0;
};
double m_tRange = 10.0; // 总时长(秒)
int m_xMax = 72000; // 内部缓冲区点数
int m_topMargin = 40; // 顶部留图例
int m_bottomMargin = 25; // X 轴
int m_leftMargin = 35; // Y 轴
int m_rightMargin = 10;
QMap<int, Curve> m_curves;
double m_t0 = 0; // 第一条数据的时间基准
bool m_t0set = false;
QPointF mapToWidget(double t, double y, const Curve &c) const;
};
#endif // CURVEPLOTWIDGET_H