refactor:调整chart样式配置的相关代码
This commit is contained in:
parent
d9a74285e9
commit
4c6d184f0f
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QPen>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
class dpBaseWidget : public QWidget
|
class dpBaseWidget : public QWidget
|
||||||
|
|
@ -26,6 +27,17 @@ public:
|
||||||
virtual void setDateTime(const QDateTime&) {}
|
virtual void setDateTime(const QDateTime&) {}
|
||||||
virtual void viewHistoricalData(const QDateTime&) {}
|
virtual void viewHistoricalData(const QDateTime&) {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
struct ChartStyle
|
||||||
|
{
|
||||||
|
QColor bgColor; //背景颜色
|
||||||
|
QColor axisColor; //坐标轴颜色
|
||||||
|
QColor tickColor; //刻度颜色
|
||||||
|
QColor tickLabelColor; //刻度label颜色
|
||||||
|
QFont tickLabelFont; //刻度label字体
|
||||||
|
QPen gridPen; //网格线颜色
|
||||||
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -356,7 +356,6 @@ void dpConfigurationDialog::onBtnClicked_remove_type()
|
||||||
if(itemDataType == dataType)
|
if(itemDataType == dataType)
|
||||||
{
|
{
|
||||||
removeDataSelected(i);
|
removeDataSelected(i);
|
||||||
//i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,13 @@ dpLineChart::~dpLineChart()
|
||||||
|
|
||||||
void dpLineChart::initQCP()
|
void dpLineChart::initQCP()
|
||||||
{
|
{
|
||||||
|
m_chartStyle.bgColor = Qt::transparent;
|
||||||
|
m_chartStyle.axisColor = QColor(87, 100, 120);
|
||||||
|
m_chartStyle.tickColor = QColor(87, 100, 120);
|
||||||
|
m_chartStyle.tickLabelColor = QColor(250, 250, 250);
|
||||||
|
m_chartStyle.tickLabelFont = QFont("黑体", 12);
|
||||||
|
m_chartStyle.gridPen = QPen(QColor(87, 100, 120), 1, Qt::DotLine);
|
||||||
|
|
||||||
//m_pCustomPlot->axisRect()->setupFullAxesBox();
|
//m_pCustomPlot->axisRect()->setupFullAxesBox();
|
||||||
m_pCustomPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
|
m_pCustomPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
|
||||||
m_pCustomPlot->axisRect()->setRangeDrag(Qt::Horizontal); //只允许x轴方向的拖拽
|
m_pCustomPlot->axisRect()->setRangeDrag(Qt::Horizontal); //只允许x轴方向的拖拽
|
||||||
|
|
@ -32,35 +39,36 @@ void dpLineChart::initQCP()
|
||||||
m_pCustomPlot->xAxis2->setTicks(false);
|
m_pCustomPlot->xAxis2->setTicks(false);
|
||||||
m_pCustomPlot->xAxis2->setSubTicks(false);
|
m_pCustomPlot->xAxis2->setSubTicks(false);
|
||||||
m_pCustomPlot->yAxis->setSubTicks(false);
|
m_pCustomPlot->yAxis->setSubTicks(false);
|
||||||
m_pCustomPlot->yAxis2->setTicks(false);
|
//m_pCustomPlot->yAxis2->setTicks(false);
|
||||||
m_pCustomPlot->yAxis2->setSubTicks(false);
|
m_pCustomPlot->yAxis2->setSubTicks(false);
|
||||||
connect(m_pCustomPlot->xAxis, SIGNAL(rangeChanged(const QCPRange&)), this, SLOT(onSignal_rangeChanged_xAxis(const QCPRange&)));
|
m_pCustomPlot->yAxis2->setVisible(true);
|
||||||
|
connect(m_pCustomPlot->xAxis, qOverload<const QCPRange &>(&QCPAxis::rangeChanged), //rangeChanged有两个版本,qOverload可以指定版本
|
||||||
|
this, &dpLineChart::onSignal_rangeChanged_xAxis);
|
||||||
//背景颜色
|
//背景颜色
|
||||||
m_pCustomPlot->setBackground(QBrush(Qt::transparent));
|
m_pCustomPlot->setBackground(QBrush(m_chartStyle.bgColor));
|
||||||
//坐标轴颜色
|
//坐标轴颜色
|
||||||
QColor axisColor(87, 100, 120);
|
m_pCustomPlot->xAxis->setBasePen(m_chartStyle.axisColor);
|
||||||
m_pCustomPlot->xAxis->setBasePen(axisColor);
|
m_pCustomPlot->xAxis2->setBasePen(m_chartStyle.axisColor);
|
||||||
m_pCustomPlot->xAxis2->setBasePen(axisColor);
|
m_pCustomPlot->yAxis->setBasePen(m_chartStyle.axisColor);
|
||||||
m_pCustomPlot->yAxis->setBasePen(axisColor);
|
m_pCustomPlot->yAxis2->setBasePen(m_chartStyle.axisColor);
|
||||||
m_pCustomPlot->yAxis2->setBasePen(axisColor);
|
|
||||||
//坐标刻度颜色
|
//坐标刻度颜色
|
||||||
QColor tickColor(87, 100, 120);
|
m_pCustomPlot->xAxis->setTickPen(QPen(m_chartStyle.tickColor));
|
||||||
m_pCustomPlot->xAxis->setTickPen(QPen(tickColor));
|
m_pCustomPlot->yAxis->setTickPen(QPen(m_chartStyle.tickColor));
|
||||||
m_pCustomPlot->yAxis->setTickPen(QPen(tickColor));
|
m_pCustomPlot->yAxis2->setTickPen(QPen(m_chartStyle.tickColor));
|
||||||
//坐标刻度Label颜色
|
//坐标刻度Label颜色
|
||||||
QColor tickLabelColor(250, 250, 250);
|
m_pCustomPlot->xAxis->setTickLabelColor(m_chartStyle.tickLabelColor);
|
||||||
m_pCustomPlot->xAxis->setTickLabelColor(tickLabelColor);
|
m_pCustomPlot->xAxis->setTickLabelFont(m_chartStyle.tickLabelFont);
|
||||||
m_pCustomPlot->xAxis->setTickLabelFont(QFont(QString::fromWCharArray(L"黑体"), 12));
|
m_pCustomPlot->yAxis->setTickLabelColor(m_chartStyle.tickLabelColor);
|
||||||
m_pCustomPlot->yAxis->setTickLabelColor(tickLabelColor);
|
m_pCustomPlot->yAxis->setTickLabelFont(m_chartStyle.tickLabelFont);
|
||||||
m_pCustomPlot->yAxis->setTickLabelFont(QFont(QString::fromWCharArray(L"黑体"), 12));
|
m_pCustomPlot->yAxis2->setTickLabelColor(m_chartStyle.tickLabelColor);
|
||||||
|
m_pCustomPlot->yAxis2->setTickLabelFont(m_chartStyle.tickLabelFont);
|
||||||
//网格线颜色
|
//网格线颜色
|
||||||
QColor gridColor(87, 100, 120);
|
m_pCustomPlot->xAxis->grid()->setPen(m_chartStyle.gridPen);
|
||||||
m_pCustomPlot->xAxis->grid()->setPen(QPen(gridColor, 1, Qt::DotLine));
|
m_pCustomPlot->xAxis->grid()->setZeroLinePen(m_chartStyle.gridPen);
|
||||||
m_pCustomPlot->xAxis->grid()->setZeroLinePen(QPen(gridColor, 1, Qt::DotLine));
|
//m_pCustomPlot->xAxis2->grid()->setPen(m_chartStyle.gridPen);
|
||||||
//m_pCustomPlot->xAxis2->grid()->setPen(QPen(gridColor, 1, Qt::DotLine));
|
m_pCustomPlot->yAxis->grid()->setPen(m_chartStyle.gridPen);
|
||||||
m_pCustomPlot->yAxis->grid()->setPen(QPen(gridColor, 1, Qt::DotLine));
|
m_pCustomPlot->yAxis->grid()->setZeroLinePen(m_chartStyle.gridPen);
|
||||||
m_pCustomPlot->yAxis->grid()->setZeroLinePen(QPen(gridColor, 1, Qt::DotLine));
|
m_pCustomPlot->yAxis2->grid()->setPen(m_chartStyle.gridPen);
|
||||||
//m_pCustomPlot->yAxis2->grid()->setPen(QPen(gridColor, 1, Qt::DotLine));
|
|
||||||
//x轴用时间格式
|
//x轴用时间格式
|
||||||
QSharedPointer<QCPAxisTickerDateTime> timeTicker(new QCPAxisTickerDateTime);
|
QSharedPointer<QCPAxisTickerDateTime> timeTicker(new QCPAxisTickerDateTime);
|
||||||
timeTicker->setDateTimeFormat("hh:mm:ss:zzz\nyyyy/MM/dd");
|
timeTicker->setDateTimeFormat("hh:mm:ss:zzz\nyyyy/MM/dd");
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@ private:
|
||||||
void initQCP();
|
void initQCP();
|
||||||
|
|
||||||
QCustomPlot* m_pCustomPlot;
|
QCustomPlot* m_pCustomPlot;
|
||||||
|
ChartStyle m_chartStyle;
|
||||||
qint64 m_timeRange;
|
qint64 m_timeRange;
|
||||||
QDateTime m_curDateTime;
|
QDateTime m_curDateTime;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -401,6 +401,9 @@ void DataPanel::configurationComplete()
|
||||||
{
|
{
|
||||||
if(m_pConfigurationWidget->isVisible())
|
if(m_pConfigurationWidget->isVisible())
|
||||||
m_pConfigurationWidget->hide();
|
m_pConfigurationWidget->hide();
|
||||||
|
|
||||||
|
//读取配置数据,根据所选的数据类型数量同步创建不同的Y坐标轴
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataPanel::onToolBtnClicked_setting()
|
void DataPanel::onToolBtnClicked_setting()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue