PowerMaster/dataPanel/dpBaseChart.h

140 lines
3.9 KiB
C
Raw Normal View History

#ifndef DPBASECHART_H
#define DPBASECHART_H
#include "dpBaseWidget.h"
#include "util/Chart/qcustomplot.h"
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&) {}
protected:
struct ChartStyle
{
QColor bgColor; //背景颜色
QColor axisColor; //坐标轴颜色
QColor labelColor; //坐标轴标签颜色
QFont labelFont; //坐标轴标签字体
QColor tickColor; //刻度颜色
QColor tickLabelColor; //刻度label颜色
QFont tickLabelFont; //刻度label字体
2025-07-14 15:02:29 +08:00
QPen gridPen; //网格线画笔
};
struct AxisConfig //坐标轴配置信息
2025-07-14 15:02:29 +08:00
{
QString name; //坐标轴名称,例如:电压
QString unit; //坐标轴单位例如V
RealTimeDataType dataType;
};
struct Axis //坐标轴配置信息
{
AxisConfig _cfg;
QCPAxis* qAxis;
bool bIsDefaultAxis; //一个plot包含两个默认坐标轴axis和axis2
ChartStyle style;
Axis()
{
qAxis = nullptr;
bIsDefaultAxis = false;
}
~Axis()
{
//执行plot->axisRect()->removeAxis(axis)时axis会delete掉
/*if(qAxis && !bIsDefaultAxis) //默认坐标轴由所属plot管理
{
delete qAxis;
qAxis = nullptr;
}*/
}
void setQCPAxis(QCPAxis* axis, bool isDefualtAxis)
{
qAxis = axis;
bIsDefaultAxis = isDefualtAxis;
if(qAxis)
{
setAxisLabel();
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);
}
}
void applyConfig(const AxisConfig& cfg)
{
_cfg.name = cfg.name;
_cfg.unit = cfg.unit;
_cfg.dataType = cfg.dataType;
setAxisLabel(); //更新轴的名称
}
void setStyle(const ChartStyle chartStyle)
{
style = chartStyle;
}
private:
void setAxisLabel()
{
if(qAxis)
{
QString labelText = "";
if(_cfg.unit.isEmpty())
labelText = _cfg.name;
else
labelText = QString("%1(%2)").arg(_cfg.name,_cfg.unit);
//因为QCPAxis左右不同位置时lable的方向不一致且没有提供设置方法在这里通过字符串反转的方式来矫正
// if(qAxis->axisType() == QCPAxis::atLeft)
// std::reverse(labelText.begin(), labelText.end());
qAxis->setLabel(labelText);
}
}
};
struct Graph
{
QColor color;
RealTimeDataType dataType;
//QCPGraph* qGraph;
QPointer<QCPGraph> qGraph;
2025-08-01 15:25:28 +08:00
QString dataID;
QString synchronizeTagging; //同步配置数据时的标记new、update两种没有的就是要被删除
QString name; //用户legend图例展示用
Graph()
{
dataID = "";
//qGraph = nullptr;
synchronizeTagging = "noTagging";
name = "";
}
};
};
#endif