PowerMaster/dataPanel/dpBaseChart.h

100 lines
2.7 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;
}
void setQCPAxis( QCPAxis* axis, bool isDefualtAxis)
{
qAxis = axis;
bIsDefaultAxis = isDefualtAxis;
if(qAxis)
{
qAxis->setLabel(_cfg.name);
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;
}
void setStyle(const ChartStyle chartStyle)
{
style = chartStyle;
}
~Axis()
{
//执行plot->axisRect()->removeAxis(axis)时axis会delete掉
/*if(qAxis && !bIsDefaultAxis) //默认坐标轴由所属plot管理
{
delete qAxis;
qAxis = nullptr;
}*/
}
};
};
#endif