#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&) {} void synchronizeConfigData(const configurationResults&) {} protected: struct ChartStyle { QColor bgColor; //背景颜色 QColor axisColor; //坐标轴颜色 QColor labelColor; //坐标轴标签颜色 QFont labelFont; //坐标轴标签字体 QColor tickColor; //刻度颜色 QColor tickLabelColor; //刻度label颜色 QFont tickLabelFont; //刻度label字体 QPen gridPen; //网格线画笔 }; struct AxisConfig //坐标轴配置信息 { 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) { if(_cfg.unit.isEmpty()) qAxis->setLabel(_cfg.name); else qAxis->setLabel(QString("%1(%2)").arg(_cfg.name,_cfg.unit)); 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; if(qAxis) //更新轴的名称 { if(_cfg.unit.isEmpty()) qAxis->setLabel(_cfg.name); else qAxis->setLabel(QString("%1(%2)").arg(_cfg.name,_cfg.unit)); } } void setStyle(const ChartStyle chartStyle) { style = chartStyle; } ~Axis() { //执行plot->axisRect()->removeAxis(axis)时,axis会delete掉 /*if(qAxis && !bIsDefaultAxis) //默认坐标轴由所属plot管理 { delete qAxis; qAxis = nullptr; }*/ } }; struct Graph { QColor color; RealTimeDataType dataType; //QCPGraph* qGraph; QPointer qGraph; QString dataID; QString synchronizeTagging; //同步配置数据时的标记,new、update两种,没有的就是要被删除 QString name; //用户legend图例展示用 Graph() { dataID = ""; //qGraph = nullptr; synchronizeTagging = "noTagging"; name = ""; } }; }; #endif