feat:添加直方图模块相关文件

This commit is contained in:
duanshengchao 2025-08-25 15:10:02 +08:00
parent bc0133e128
commit d4c24d364f
9 changed files with 174 additions and 23 deletions

View File

@ -120,6 +120,8 @@ set(DATAPANEL_FILES
dataPanel/dpBaseChart.cpp dataPanel/dpBaseChart.cpp
dataPanel/dpLineChart.h dataPanel/dpLineChart.h
dataPanel/dpLineChart.cpp dataPanel/dpLineChart.cpp
dataPanel/dpBarsChart.h
dataPanel/dpBarsChart.cpp
) )
# #

98
dataPanel/dpBarsChart.cpp Normal file
View File

@ -0,0 +1,98 @@
#include "dpBarsChart.h"
#include "dataManager.h"
dpBarsChart::dpBarsChart(QWidget* parent)
:dpBaseChart(parent)
{
setAttribute(Qt::WA_TranslucentBackground,true);
m_pCustomPlot = new QCustomPlot(this);
initQCP();
m_barsGroup = new QCPBarsGroup(m_pCustomPlot);
QBoxLayout* mainLayout = new QBoxLayout(QBoxLayout::LeftToRight);
mainLayout->setContentsMargins(0, 1, 0, 0);
mainLayout->addWidget(m_pCustomPlot);
setLayout(mainLayout);
connect(DataManager::instance(), &DataManager::dataUpdated, this, &dpBarsChart::onSignal_dataUpdated);
}
dpBarsChart::~dpBarsChart()
{
}
void dpBarsChart::initQCP()
{
m_chartStyle.bgColor = Qt::transparent;
m_chartStyle.axisColor = QColor(87, 100, 120);
m_chartStyle.labelColor = QColor(250, 250, 250);
m_chartStyle.labelFont = QFont("黑体", 12);
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->setInteractions(QCP::iNone);
/*m_pCustomPlot->axisRect()->setRangeDrag(Qt::Horizontal); //只允许x轴方向的拖拽
double zoomFactor = m_pCustomPlot->axisRect()->rangeZoomFactor(Qt::Horizontal);
m_pCustomPlot->axisRect()->setRangeZoomFactor(zoomFactor, 1); //只做x轴的缩放*/
m_pCustomPlot->xAxis->setTicks(false);
m_pCustomPlot->xAxis->setSubTicks(false);
m_pCustomPlot->yAxis->setTicks(false);
m_pCustomPlot->yAxis->setSubTicks(false);
//m_pCustomPlot->yAxis->setVisible(false);
//m_pCustomPlot->yAxis2->setTicks(false);
m_pCustomPlot->yAxis2->setSubTicks(false);
m_pCustomPlot->yAxis2->setVisible(false);
//背景颜色
m_pCustomPlot->setBackground(QBrush(m_chartStyle.bgColor));
//坐标轴颜色
m_pCustomPlot->xAxis->setBasePen(m_chartStyle.axisColor);
m_pCustomPlot->xAxis2->setBasePen(m_chartStyle.axisColor);
m_pCustomPlot->yAxis->setBasePen(m_chartStyle.axisColor);
m_pCustomPlot->yAxis2->setBasePen(m_chartStyle.axisColor);
//坐标刻度颜色
m_pCustomPlot->xAxis->setTickPen(QPen(m_chartStyle.tickColor));
m_pCustomPlot->yAxis->setTickPen(QPen(m_chartStyle.tickColor));
m_pCustomPlot->yAxis2->setTickPen(QPen(m_chartStyle.tickColor));
//坐标刻度Label颜色
m_pCustomPlot->xAxis->setTickLabels(false);
m_pCustomPlot->xAxis->setTickLabelColor(m_chartStyle.tickLabelColor);
m_pCustomPlot->xAxis->setTickLabelFont(m_chartStyle.tickLabelFont);
m_pCustomPlot->yAxis->setTickLabels(false);
m_pCustomPlot->yAxis->setTickLabelColor(m_chartStyle.tickLabelColor);
m_pCustomPlot->yAxis->setTickLabelFont(m_chartStyle.tickLabelFont);
m_pCustomPlot->yAxis2->setTickLabelColor(m_chartStyle.tickLabelColor);
m_pCustomPlot->yAxis2->setTickLabelFont(m_chartStyle.tickLabelFont);
//网格线颜色
m_pCustomPlot->xAxis->grid()->setVisible(false);
m_pCustomPlot->xAxis->grid()->setPen(m_chartStyle.gridPen);
m_pCustomPlot->xAxis->grid()->setZeroLinePen(m_chartStyle.gridPen);
//m_pCustomPlot->xAxis2->grid()->setPen(m_chartStyle.gridPen);
m_pCustomPlot->yAxis->grid()->setVisible(false);
m_pCustomPlot->yAxis->grid()->setPen(m_chartStyle.gridPen);
m_pCustomPlot->yAxis->grid()->setZeroLinePen(m_chartStyle.gridPen);
m_pCustomPlot->yAxis2->grid()->setPen(m_chartStyle.gridPen);
//Legend
m_pCustomPlot->legend->setBrush(QBrush(QColor(255,255,255,12))); //背景透明
m_pCustomPlot->legend->setBorderPen(QPen(QColor(255,255,255,0))); //边框透明
m_pCustomPlot->legend->setFont(m_chartStyle.labelFont);
m_pCustomPlot->legend->setTextColor( m_chartStyle.labelColor);
}
void dpBarsChart::setTimeRange(TimeUnit unit)
{}
void dpBarsChart::setDateTime(const QDateTime& dateTime)
{}
void dpBarsChart::viewHistoricalData(const QDateTime& dateTime)
{}
void dpBarsChart::synchronizeConfigData(const configurationResults& cfg)
{}
void dpBarsChart::onSignal_dataUpdated(const QString& dataKey, const QVariant& data, const QDateTime& timestamp)
{}

43
dataPanel/dpBarsChart.h Normal file
View File

@ -0,0 +1,43 @@
#ifndef DPBARSCHART_H
#define DPBARSCHART_H
/*******************************************************************************
** DataPanel-BarsChart
** author dsc
**
** ()
** QCustomPlot实现
**
******************************************************************************/
#include "dpBaseChart.h"
class QCustomPlot;
class QCPBarsGroup;
class dpBarsChart : public dpBaseChart
{
Q_OBJECT
public:
dpBarsChart(QWidget *parent = nullptr);
~dpBarsChart();
void setTimeRange(TimeUnit) override;
void setDateTime(const QDateTime&) override;
void viewHistoricalData(const QDateTime&) override;
void synchronizeConfigData(const configurationResults&) override;
public slots:
void onSignal_dataUpdated(const QString& dataKey, const QVariant& data, const QDateTime& timestamp);
private:
void initQCP();
QCustomPlot* m_pCustomPlot;
ChartStyle m_chartStyle;
QCPBarsGroup* m_barsGroup;
};
#endif

View File

@ -256,8 +256,6 @@ void dpConfigurationDialog::setPanel(DataPanel* pPanel)
switch (panelType) switch (panelType)
{ {
case lineChart: case lineChart:
case curveChart:
case barChart:
{ {
ui->specialSettings->setCurrentIndex(0); ui->specialSettings->setCurrentIndex(0);
ui->specialSettings->setVisible(true); ui->specialSettings->setVisible(true);
@ -290,6 +288,7 @@ void dpConfigurationDialog::setPanel(DataPanel* pPanel)
connect(ui->axisObject, &QComboBox::currentIndexChanged, this, &dpConfigurationDialog::onComboBoxIndexChanged_axis); connect(ui->axisObject, &QComboBox::currentIndexChanged, this, &dpConfigurationDialog::onComboBoxIndexChanged_axis);
break; break;
} }
case barChart:
default: default:
ui->specialSettings->setVisible(false); ui->specialSettings->setVisible(false);
break; break;

View File

@ -71,6 +71,7 @@ void dpLineChart::initQCP()
m_pCustomPlot->yAxis->setTickLabelFont(m_chartStyle.tickLabelFont); m_pCustomPlot->yAxis->setTickLabelFont(m_chartStyle.tickLabelFont);
m_pCustomPlot->yAxis2->setTickLabelColor(m_chartStyle.tickLabelColor); m_pCustomPlot->yAxis2->setTickLabelColor(m_chartStyle.tickLabelColor);
m_pCustomPlot->yAxis2->setTickLabelFont(m_chartStyle.tickLabelFont); m_pCustomPlot->yAxis2->setTickLabelFont(m_chartStyle.tickLabelFont);
m_pCustomPlot->yAxis->setTickLabels(false);
//网格线颜色 //网格线颜色
m_pCustomPlot->xAxis->grid()->setPen(m_chartStyle.gridPen); m_pCustomPlot->xAxis->grid()->setPen(m_chartStyle.gridPen);
m_pCustomPlot->xAxis->grid()->setZeroLinePen(m_chartStyle.gridPen); m_pCustomPlot->xAxis->grid()->setZeroLinePen(m_chartStyle.gridPen);
@ -267,6 +268,7 @@ void dpLineChart::viewHistoricalData(const QDateTime& dateTime)
void dpLineChart::synchronizeConfigData(const configurationResults& cfg) void dpLineChart::synchronizeConfigData(const configurationResults& cfg)
{ {
m_updateData = false; //停止更新数据 m_updateData = false; //停止更新数据
//m_pCustomPlot->yAxis->setTickLabels(true);
//1.Y坐标轴-数量由数据类型决定 //1.Y坐标轴-数量由数据类型决定
@ -511,7 +513,7 @@ void dpLineChart::onSignal_rangeChanged_xAxis(const QCPRange& range)
m_timeRange = range.size() * 1000; m_timeRange = range.size() * 1000;
} }
void dpLineChart::onSignal_dataUpdated(const QString& dataID, const QVariant& data, const QDateTime& timestamp) void dpLineChart::onSignal_dataUpdated(const QString& dataID, const QVariant& data, const QDateTime& timestamp)
{ {
auto it = m_graphs.find(dataID); auto it = m_graphs.find(dataID);
if(it != m_graphs.end()) if(it != m_graphs.end())

View File

@ -31,7 +31,7 @@ public:
public slots: public slots:
void onSignal_rangeChanged_xAxis(const QCPRange&); void onSignal_rangeChanged_xAxis(const QCPRange&);
void onSignal_dataUpdated(const QString& dataKey, const QVariant& data, const QDateTime& timestamp); void onSignal_dataUpdated(const QString& dataKey, const QVariant& data, const QDateTime& timestamp);
private: private:
//处理关联图形的策略 //处理关联图形的策略

View File

@ -53,7 +53,7 @@ public:
ForceNoScrollArea ForceNoScrollArea
}; };
void setWiget(QWidget*, eInsertMode InsertMode = ForceNoScrollArea); void setWidget(QWidget*, eInsertMode InsertMode = ForceNoScrollArea);
QWidget* takeWidget(); QWidget* takeWidget();
void setName(const QString&); void setName(const QString&);

View File

@ -6,6 +6,7 @@
#include "customMenu.h" #include "customMenu.h"
#include "dataManager.h" #include "dataManager.h"
#include "dataPanel/dpLineChart.h" #include "dataPanel/dpLineChart.h"
#include "dataPanel/dpBarsChart.h"
#include <QKeyEvent> #include <QKeyEvent>
#include <QBoxLayout> #include <QBoxLayout>
@ -245,7 +246,13 @@ void DataPanel::createDataWidget()
case lineChart: case lineChart:
{ {
dpLineChart* lineChart = new dpLineChart(this); dpLineChart* lineChart = new dpLineChart(this);
setWiget(lineChart); setWidget(lineChart);
break;
}
case barChart:
{
dpBarsChart* barsChart = new dpBarsChart(this);
setWidget(barsChart);
break; break;
} }
default: default:
@ -253,7 +260,7 @@ void DataPanel::createDataWidget()
} }
} }
void DataPanel::setWiget(QWidget* pWidget, eInsertMode InsertMode) void DataPanel::setWidget(QWidget* pWidget, eInsertMode InsertMode)
{ {
if(m_pContentWidget) if(m_pContentWidget)
{ {

View File

@ -618,15 +618,15 @@ background-color: rgb(24, 32, 38);
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
<y>110</y> <y>150</y>
<width>521</width> <width>521</width>
<height>221</height> <height>181</height>
</rect> </rect>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="coordinate"> <widget class="QWidget" name="lineChart">
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">QWidget #coordinate <string notr="true">QWidget #coordinate
{ {
@ -750,22 +750,22 @@ background-color:transparent;
<string>Y轴排列</string> <string>Y轴排列</string>
</property> </property>
</widget> </widget>
<widget class="QRadioButton" name="radioBtn_showLegend">
<property name="geometry">
<rect>
<x>0</x>
<y>100</y>
<width>121</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>显示图例</string>
</property>
</widget>
</widget> </widget>
<widget class="QWidget" name="page_2"/> <widget class="QWidget" name="page_2"/>
</widget> </widget>
<widget class="QRadioButton" name="radioBtn_showLegend">
<property name="geometry">
<rect>
<x>0</x>
<y>105</y>
<width>121</width>
<height>31</height>
</rect>
</property>
<property name="text">
<string>显示图例</string>
</property>
</widget>
</widget> </widget>
</widget> </widget>
<widget class="QPushButton" name="btnCancle"> <widget class="QPushButton" name="btnCancle">