153 lines
4.0 KiB
C++

#ifndef CTRENDGRAPH_H
#define CTRENDGRAPH_H
#include <QString>
#include <QColor>
#include <QMap>
#include <QList>
#include <QtMath>
#include <float.h>
/******************************趋势图形**************************
* 此类包含趋势静态配置属性
**************************************************************/
extern const double _EPSILON_;
struct Range
{
Range()
: min(DBL_MAX),
max(-DBL_MAX)
{}
Range(double _min, double _max)
: min(_min),
max(_max)
{}
double min;
double max;
};
struct Curve
{
Curve(const QString &strTagName = QString())
: visible(true),
rtMax(-DBL_MAX),
rtMin(DBL_MAX),
rtAverage(-DBL_MAX),
rtAccuml(0),
hisMax(-DBL_MAX),
hisMin(DBL_MAX),
hisAverage(-DBL_MAX),
hisAccuml(0),
graphFactor(1.),
graphOffset(0.),
factor(1.),
offset(0.),
rtMaxTime(-DBL_MAX),
rtMinTime(DBL_MAX),
hisMaxTime(-DBL_MAX),
hisMinTime(DBL_MAX),
sHisMax(-DBL_MAX),
sHisMin(DBL_MAX),
sHisMaxTime(-DBL_MAX),
sHisMinTime(DBL_MAX),
tag(strTagName),
desc(QString()),
type(QString()),
unit(QString()),
color(QColor()){}
inline bool operator==(const Curve &curve) const
{
return tag == curve.tag;
}
inline bool operator==(const QString &strTagName) const
{
return tag == strTagName;
}
bool visible;
double rtMax;
double rtMin;
double rtAverage;
double rtAccuml;
double hisMax;
double hisMin;
double hisAverage;
double hisAccuml;
double graphFactor;
double graphOffset;
double factor;
double offset;
double rtMaxTime;
double rtMinTime;
double hisMaxTime;
double hisMinTime;
double sHisMax; //< 实际的最大值(influx统计),仅用于显示
double sHisMin; //< 实际的最小值(influx统计),仅用于显示
double sHisMaxTime; //< 实际的最大值时间(influx统计),仅用于显示
double sHisMinTime; //< 实际的最小值时间(influx统计),仅用于显示
Range hisPlotRange; //< hisPlotRange > Range(hisMin, hisMax) [趋势对比计算刻度]
QString tag;
QString desc;
QString type;
QString unit;
QColor color;
QVector< QPair <double, QPair< double, int > > > values;
};
class CTrendGraph
{
public:
CTrendGraph();
~CTrendGraph();
const QList<Curve> curves() const;
void setCurves(QList<Curve> listCurve);
const QList<QColor> curveColors() const;
const Curve &curve(const QString &tag) const;
int index(const QString &tag) const;
void clear();
void addCurve(const Curve &curve);
int removeCurve(const QString &tag);
void setCurveVisible(const int &nIndex, const bool &visible);
void setCurveColor(const int &nIndex, const QColor &color);
void setCurveFactor(const int &nIndex, const double &factor);
void setCurveOffset(const int &nIndex, const double &offset);
void setCurveHisDataValue(const QString &tag, const double &max, const double &min, const double &maxTime, const double &minTime, const double &average, const double &accuml, const Range &range);
void pushCurveRTDataValue(const QString &tag, const double &key, const double &value, const int &status);
void setCurveStatisMax(const QString &tag, const double &max, const double &maxTime);
void setCurveStatisMin(const QString &tag, const double &min, const double &minTime);
void resetCurveStatisMax(const QString &tag);
void resetCurveStatisMin(const QString &tag);
void setCurveGraphFactor(const int &nIndex, const double &factor);
void setCurveGraphOffset(const int &nIndex, const double &offset);
//< 更新实时曲线统计信息
void updateRTCurveStatisticsInfo(const QString &strTagName);
void updateRTCurveStatisticsInfo(Curve &curve);
private:
QList<Curve> m_listCurve;
};
#endif // CTRENDGRAPH_H