2025-07-09 14:29:29 +08:00
|
|
|
|
#ifndef DPBASECHART_H
|
|
|
|
|
|
#define DPBASECHART_H
|
|
|
|
|
|
|
|
|
|
|
|
#include "dpBaseWidget.h"
|
2025-07-15 19:35:37 +08:00
|
|
|
|
#include "util/Chart/qcustomplot.h"
|
2025-07-09 14:29:29 +08:00
|
|
|
|
|
|
|
|
|
|
class dpBaseChart : public dpBaseWidget
|
|
|
|
|
|
{
|
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
dpBaseChart(QWidget *parent = nullptr);
|
|
|
|
|
|
~dpBaseChart();
|
|
|
|
|
|
|
|
|
|
|
|
void setTimeRange(TimeUnit) {}
|
|
|
|
|
|
void setDateTime(const QDateTime&) {}
|
|
|
|
|
|
void viewHistoricalData(const QDateTime&) {}
|
2025-07-14 15:02:29 +08:00
|
|
|
|
void synchronizeConfigData(const configurationResults&) {}
|
2025-07-09 14:29:29 +08:00
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
struct ChartStyle
|
|
|
|
|
|
{
|
|
|
|
|
|
QColor bgColor; //背景颜色
|
|
|
|
|
|
QColor axisColor; //坐标轴颜色
|
2025-07-25 17:42:15 +08:00
|
|
|
|
QColor labelColor; //坐标轴标签颜色
|
|
|
|
|
|
QFont labelFont; //坐标轴标签字体
|
2025-07-09 14:29:29 +08:00
|
|
|
|
QColor tickColor; //刻度颜色
|
|
|
|
|
|
QColor tickLabelColor; //刻度label颜色
|
|
|
|
|
|
QFont tickLabelFont; //刻度label字体
|
2025-07-14 15:02:29 +08:00
|
|
|
|
QPen gridPen; //网格线画笔
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2025-07-15 19:35:37 +08:00
|
|
|
|
struct AxisConfig //坐标轴配置信息
|
2025-07-14 15:02:29 +08:00
|
|
|
|
{
|
|
|
|
|
|
QString name; //坐标轴名称,例如:电压
|
|
|
|
|
|
QString unit; //坐标轴单位,例如:V
|
|
|
|
|
|
RealTimeDataType dataType;
|
2025-07-09 14:29:29 +08:00
|
|
|
|
};
|
2025-07-15 19:35:37 +08:00
|
|
|
|
struct Axis //坐标轴配置信息
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
AxisConfig _cfg;
|
2025-07-25 17:42:15 +08:00
|
|
|
|
QCPAxis* qAxis;
|
|
|
|
|
|
bool bIsDefaultAxis; //一个plot包含两个默认坐标轴axis和axis2
|
|
|
|
|
|
ChartStyle style;
|
2025-07-15 19:35:37 +08:00
|
|
|
|
|
2025-07-25 17:42:15 +08:00
|
|
|
|
Axis()
|
2025-07-15 19:35:37 +08:00
|
|
|
|
{
|
2025-07-25 17:42:15 +08:00
|
|
|
|
qAxis = nullptr;
|
|
|
|
|
|
bIsDefaultAxis = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-08-13 10:44:23 +08:00
|
|
|
|
void setQCPAxis(QCPAxis* axis, bool isDefualtAxis)
|
2025-07-25 17:42:15 +08:00
|
|
|
|
{
|
|
|
|
|
|
qAxis = axis;
|
|
|
|
|
|
bIsDefaultAxis = isDefualtAxis;
|
|
|
|
|
|
if(qAxis)
|
|
|
|
|
|
{
|
2025-08-13 10:44:23 +08:00
|
|
|
|
if(_cfg.unit.isEmpty())
|
|
|
|
|
|
qAxis->setLabel(_cfg.name);
|
|
|
|
|
|
else
|
|
|
|
|
|
qAxis->setLabel(QString("%1(%2)").arg(_cfg.name,_cfg.unit));
|
2025-07-25 17:42:15 +08:00
|
|
|
|
qAxis->setSubTicks(false);
|
|
|
|
|
|
//颜色
|
|
|
|
|
|
qAxis->setBasePen(style.axisColor);
|
|
|
|
|
|
//label
|
|
|
|
|
|
qAxis->setLabelColor(style.labelColor);
|
|
|
|
|
|
qAxis->setLabelFont(style.labelFont);
|
|
|
|
|
|
//刻度颜色
|
|
|
|
|
|
qAxis->setTickPen(QPen(style.tickColor));
|
|
|
|
|
|
//刻度Label颜色
|
|
|
|
|
|
qAxis->setTickLabelColor(style.tickLabelColor);
|
|
|
|
|
|
qAxis->setTickLabelFont(style.tickLabelFont);
|
|
|
|
|
|
qAxis->setTickLabelColor(style.tickLabelColor);
|
|
|
|
|
|
}
|
2025-07-15 19:35:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void applyConfig(const AxisConfig& cfg)
|
|
|
|
|
|
{
|
|
|
|
|
|
_cfg.name = cfg.name;
|
|
|
|
|
|
_cfg.unit = cfg.unit;
|
|
|
|
|
|
_cfg.dataType = cfg.dataType;
|
2025-08-13 10:44:23 +08:00
|
|
|
|
|
|
|
|
|
|
if(qAxis) //更新轴的名称
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_cfg.unit.isEmpty())
|
|
|
|
|
|
qAxis->setLabel(_cfg.name);
|
|
|
|
|
|
else
|
|
|
|
|
|
qAxis->setLabel(QString("%1(%2)").arg(_cfg.name,_cfg.unit));
|
|
|
|
|
|
}
|
2025-07-15 19:35:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-25 17:42:15 +08:00
|
|
|
|
void setStyle(const ChartStyle chartStyle)
|
|
|
|
|
|
{
|
|
|
|
|
|
style = chartStyle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-15 19:35:37 +08:00
|
|
|
|
~Axis()
|
|
|
|
|
|
{
|
2025-07-25 17:42:15 +08:00
|
|
|
|
//执行plot->axisRect()->removeAxis(axis)时,axis会delete掉
|
|
|
|
|
|
/*if(qAxis && !bIsDefaultAxis) //默认坐标轴由所属plot管理
|
2025-07-15 19:35:37 +08:00
|
|
|
|
{
|
|
|
|
|
|
delete qAxis;
|
|
|
|
|
|
qAxis = nullptr;
|
2025-07-25 17:42:15 +08:00
|
|
|
|
}*/
|
2025-07-15 19:35:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2025-07-31 15:47:32 +08:00
|
|
|
|
|
|
|
|
|
|
struct Graph
|
|
|
|
|
|
{
|
|
|
|
|
|
QColor color;
|
|
|
|
|
|
RealTimeDataType dataType;
|
2025-08-04 10:57:53 +08:00
|
|
|
|
//QCPGraph* qGraph;
|
2025-08-01 10:42:49 +08:00
|
|
|
|
QPointer<QCPGraph> qGraph;
|
2025-08-01 15:25:28 +08:00
|
|
|
|
|
|
|
|
|
|
QString dataID;
|
|
|
|
|
|
QString synchronizeTagging; //同步配置数据时的标记,new、update两种,没有的就是要被删除
|
2025-08-07 11:48:08 +08:00
|
|
|
|
QString name; //用户legend图例展示用
|
2025-08-04 10:57:53 +08:00
|
|
|
|
|
|
|
|
|
|
Graph()
|
|
|
|
|
|
{
|
|
|
|
|
|
dataID = "";
|
|
|
|
|
|
//qGraph = nullptr;
|
|
|
|
|
|
synchronizeTagging = "noTagging";
|
2025-08-07 11:48:08 +08:00
|
|
|
|
name = "";
|
2025-08-04 10:57:53 +08:00
|
|
|
|
}
|
2025-07-31 15:47:32 +08:00
|
|
|
|
};
|
2025-07-09 14:29:29 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|