From 9962a6718edb92713c9a9837121b8a62ed99c7fe Mon Sep 17 00:00:00 2001 From: duanshengchao <519970194@qq.com> Date: Mon, 14 Jul 2025 15:02:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=B7=BB=E5=8A=A0=E5=9D=90=E6=A0=87?= =?UTF-8?q?=E8=BD=B4=E9=85=8D=E7=BD=AE=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dataPanel/dpBaseChart.h | 10 +- dataPanel/dpBaseWidget.h | 2 + dataPanel/dpConfigurationDialog.cpp | 16 +++ dataPanel/dpGlobals.h | 9 ++ dataPanel/dpLineChart.cpp | 15 +++ dataPanel/dpLineChart.h | 3 + include/dataPanel.h | 2 +- resource/PowerMaster.qrc | 1 + resource/images/down-arrow.png | Bin 0 -> 246 bytes source/dataPanel.cpp | 11 +- ui/dpConfigurationDialog.ui | 151 +++++++++++++++++++++++++++- 11 files changed, 209 insertions(+), 11 deletions(-) create mode 100644 resource/images/down-arrow.png diff --git a/dataPanel/dpBaseChart.h b/dataPanel/dpBaseChart.h index 22936b6..ac4d790 100644 --- a/dataPanel/dpBaseChart.h +++ b/dataPanel/dpBaseChart.h @@ -14,6 +14,7 @@ public: void setTimeRange(TimeUnit) {} void setDateTime(const QDateTime&) {} void viewHistoricalData(const QDateTime&) {} + void synchronizeConfigData(const configurationResults&) {} protected: struct ChartStyle @@ -23,7 +24,14 @@ protected: QColor tickColor; //刻度颜色 QColor tickLabelColor; //刻度label颜色 QFont tickLabelFont; //刻度label字体 - QPen gridPen; //网格线颜色 + QPen gridPen; //网格线画笔 + }; + + struct Axis //坐标轴配置信息 + { + QString name; //坐标轴名称,例如:电压 + QString unit; //坐标轴单位,例如:V + RealTimeDataType dataType; }; }; diff --git a/dataPanel/dpBaseWidget.h b/dataPanel/dpBaseWidget.h index 30e706d..344116d 100644 --- a/dataPanel/dpBaseWidget.h +++ b/dataPanel/dpBaseWidget.h @@ -14,6 +14,7 @@ #include #include #include "global.h" +#include "dpGlobals.h" class dpBaseWidget : public QWidget { @@ -26,6 +27,7 @@ public: virtual void setTimeRange(TimeUnit) {} virtual void setDateTime(const QDateTime&) {} virtual void viewHistoricalData(const QDateTime&) {} + virtual void synchronizeConfigData(const configurationResults&) {} }; #endif diff --git a/dataPanel/dpConfigurationDialog.cpp b/dataPanel/dpConfigurationDialog.cpp index a7fc068..a383581 100644 --- a/dataPanel/dpConfigurationDialog.cpp +++ b/dataPanel/dpConfigurationDialog.cpp @@ -220,6 +220,22 @@ void dpConfigurationDialog::setPanel(DataPanel* pPanel) // ui->typeSelectedList->setModel(m_pModel_typeSelected); ui->serviceIP->setText(pPanel->m_cofigurationResults.dataServiceIP); ui->servicePort->setText(QString::number(pPanel->m_cofigurationResults.dataServicePort)); + + DataPanelType panelType = pPanel->getType(); + switch (panelType) + { + case lineChart: + case curveChart: + case barChart: + { + ui->specialSettings->setCurrentIndex(0); + ui->specialSettings->setVisible(true); + break; + } + default: + ui->specialSettings->setVisible(false); + break; + } } void dpConfigurationDialog::onBtnClicked_tabBtn() diff --git a/dataPanel/dpGlobals.h b/dataPanel/dpGlobals.h index 0aa50c9..e6add4f 100644 --- a/dataPanel/dpGlobals.h +++ b/dataPanel/dpGlobals.h @@ -29,6 +29,12 @@ struct configurationResults QString dataServiceIP; int dataServicePort; + struct Axis + { + QString name; + QString unit; + } axisInfo; + configurationResults() { m_pModel_dataType = nullptr; @@ -36,6 +42,9 @@ struct configurationResults dataServiceIP = "127.0.0.1"; dataServicePort = 1987; + + axisInfo.name = ""; + axisInfo.unit = ""; } void setParent(QObject* parent) diff --git a/dataPanel/dpLineChart.cpp b/dataPanel/dpLineChart.cpp index f3beb92..97c92c4 100644 --- a/dataPanel/dpLineChart.cpp +++ b/dataPanel/dpLineChart.cpp @@ -154,6 +154,21 @@ void dpLineChart::viewHistoricalData(const QDateTime& dateTime) } +void dpLineChart::synchronizeConfigData(const configurationResults& cfg) +{ + //Y坐标轴的数量由数据类型决定 + QHash cfgAxisMap; //将最新配置信息中的坐标轴相关数据存储在QHash中,有助于更好的判断当前坐标轴是否需要发生同步更新 + for(int i = 0; i< cfg.m_pModel_dataType->rowCount(); i++) + { + Axis axis; + axis.name = cfg.axisInfo.name; + axis.unit = cfg.axisInfo.unit; + RealTimeDataType dataType = (RealTimeDataType)cfg.m_pModel_dataType->item(i, 0)->data(Qt::UserRole + itemRole_dataType).toInt(); + axis.dataType = dataType; + cfgAxisMap.insert(dataType, axis); + } +} + void dpLineChart::onSignal_rangeChanged_xAxis(const QCPRange& range) { // qDebug() << "m_timeRange: " << m_timeRange; diff --git a/dataPanel/dpLineChart.h b/dataPanel/dpLineChart.h index 7fa6e81..4f7fffc 100644 --- a/dataPanel/dpLineChart.h +++ b/dataPanel/dpLineChart.h @@ -27,6 +27,8 @@ public: void setDateTime(const QDateTime&) override; void viewHistoricalData(const QDateTime&) override; + void synchronizeConfigData(const configurationResults&) override; + public slots: void onSignal_rangeChanged_xAxis(const QCPRange&); @@ -37,6 +39,7 @@ private: ChartStyle m_chartStyle; qint64 m_timeRange; QDateTime m_curDateTime; + QVector m_axes; }; #endif diff --git a/include/dataPanel.h b/include/dataPanel.h index f7f21ab..567124d 100644 --- a/include/dataPanel.h +++ b/include/dataPanel.h @@ -101,7 +101,7 @@ signals: private: void setupScrollArea(); void autoSetGeometry(); //在缩放和移动时以其它panel和parent的border为依据自动调整 - void createDataWidget(DataPanelType); + void createDataWidget(); bool m_bMouseEnter; bool m_bConfigurationComplete; diff --git a/resource/PowerMaster.qrc b/resource/PowerMaster.qrc index c7a08b0..f2257b3 100644 --- a/resource/PowerMaster.qrc +++ b/resource/PowerMaster.qrc @@ -1,5 +1,6 @@ + images/down-arrow.png images/branch_closed.png images/branch_open.png images/appIcon.png diff --git a/resource/images/down-arrow.png b/resource/images/down-arrow.png new file mode 100644 index 0000000000000000000000000000000000000000..b0d1c9490b32b73348b6c163a3857c9c66388499 GIT binary patch literal 246 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz&H|6fVg?3oVGw3ym^DWND7eDY z#WAE}&f6)5Tug=nuEh-5qW;-08B?z+w}|{dyySlBfuz92H}87pJahICobmmcIOoB~ zA1iG1I}P6*+MmX3!CbLqir=*YLCXnyChZY<%W%h|uj=`n{;-0%rt@QSoLs*7pT4-N z^X4-NqFhBMSHDji}uKA%b#e_yndoVyZ*!sw)GP;`2MS1addAction(QString::fromWCharArray(L"放置最前"), this, SLOT(onAction_moveToFront())); m_pToolMenu->addAction(QString::fromWCharArray(L"放置最后"), this, SLOT(onAction_moveToBack())); - createDataWidget(type); + createDataWidget(); m_cofigurationResults.setParent(this); connect(DataManager::instance(), &DataManager::dataUpdated, this, &DataPanel::onSignal_dataUpdated); @@ -238,9 +238,9 @@ void DataPanel::autoSetGeometry() } -void DataPanel::createDataWidget(DataPanelType type) +void DataPanel::createDataWidget() { - switch(type) + switch(m_type) { case lineChart: { @@ -402,8 +402,9 @@ void DataPanel::configurationComplete() if(m_pConfigurationWidget->isVisible()) m_pConfigurationWidget->hide(); - //读取配置数据,根据所选的数据类型数量同步创建不同的Y坐标轴 - + dpBaseWidget* baseWidget = qobject_cast(m_pContentWidget); + if(baseWidget) + baseWidget->synchronizeConfigData(m_cofigurationResults); } void DataPanel::onToolBtnClicked_setting() diff --git a/ui/dpConfigurationDialog.ui b/ui/dpConfigurationDialog.ui index 7947b45..169e17f 100644 --- a/ui/dpConfigurationDialog.ui +++ b/ui/dpConfigurationDialog.ui @@ -56,6 +56,44 @@ QLineEdit:focus border:1px solid rgb(67,160,249); } +QComboBox +{ +font: 11pt "黑体"; +color: rgb(250, 250, 250); +background-color: rgb(54, 62, 74); +border: 0px; +border-radius: 0px; +} +QComboBox:hover +{ +background-color: rgb(72, 83, 99); +} +QComboBox::drop-down +{ +border:0px; +} +QComboBox::down-arrow +{ +margin-right:10px; +width:14px; +border-image: url(:/images/down-arrow.png); +} +QComboBox QAbstractItemView +{ +outline: 0px; /*去除选中虚线框 */ +border:0px; +background-color:rgba(25,25,25,240); +} +QComboBox QAbstractItemView::item:hover +{ +background-color: rgb(43, 102, 158); +} +QComboBox QAbstractItemView::item:selected +{ +color: rgb(250, 250, 250); +background-color: rgb(43, 102, 158); +} + QTreeView { padding:6px; @@ -141,8 +179,7 @@ border:0px; QListView::item:hover { background-color: rgba(67,160,249, 30); border:0px; -} - +} @@ -240,7 +277,7 @@ QPushButton:pressed } - 数据配置 + 其它配置 @@ -286,7 +323,7 @@ QPushButton:pressed - 0 + 2 @@ -557,6 +594,112 @@ background-color: rgb(24, 32, 38); + + + + 0 + 110 + 521 + 221 + + + + 0 + + + + QWidget #coordinate +{ +background-color:transparent; +} + + + + + 0 + 0 + 41 + 21 + + + + Y轴: + + + + + + 40 + 0 + 91 + 22 + + + + + 电压 + + + + + 电流 + + + + + 功率 + + + + + + + 30 + 35 + 41 + 21 + + + + 名称: + + + + + + 80 + 35 + 71 + 21 + + + + + + + 190 + 35 + 41 + 21 + + + + 单位: + + + + + + 240 + 35 + 71 + 21 + + + + + +