From 6386d002295e942ca97e3ee4ef67f75e18c0caa9 Mon Sep 17 00:00:00 2001 From: duanshengchao <519970194@qq.com> Date: Fri, 1 Aug 2025 15:25:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=AE=8C=E6=88=90=E6=9B=B2=E7=BA=BF?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dataPanel/dpBaseChart.h | 4 +++- dataPanel/dpLineChart.cpp | 21 ++++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/dataPanel/dpBaseChart.h b/dataPanel/dpBaseChart.h index e7e8d21..72923e6 100644 --- a/dataPanel/dpBaseChart.h +++ b/dataPanel/dpBaseChart.h @@ -97,11 +97,13 @@ protected: struct Graph { - QString dataID; QColor color; RealTimeDataType dataType; //QCPGraph* qGraph = nullptr; QPointer qGraph; + + QString dataID; + QString synchronizeTagging; //同步配置数据时的标记,new、update两种,没有的就是要被删除 }; }; diff --git a/dataPanel/dpLineChart.cpp b/dataPanel/dpLineChart.cpp index a1c0ed8..1ecdd9d 100644 --- a/dataPanel/dpLineChart.cpp +++ b/dataPanel/dpLineChart.cpp @@ -365,7 +365,6 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg) arrangeAxes(); //2.曲线-数据源决定 - QList deleteGraphs; for(int i = 0; i < cfg.m_pModel_dataSource->rowCount(); i++) { QString stationID = cfg.m_pModel_dataSource->item(i, 0)->data(Qt::UserRole + itemRole_stationID).toString(); @@ -382,6 +381,7 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg) Graph graph; graph.dataID = graphID; graph.dataType = dataType; + graph.synchronizeTagging = "new"; QCPGraph* newGraph = m_pCustomPlot->addGraph(m_pCustomPlot->xAxis, valueAxis); if(newGraph) { @@ -395,11 +395,26 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg) m_graphs.insert(graphID, graph); } } - else + else //更新数据 { - + m_graphs.value(graphID).synchronizeTagging = "update"; } } + //没有标记的就是需要删除的 + QStringList keysToRemove; + for(auto it = m_graphs.begin(); it != m_graphs.end(); ++it) + { + if(it.value().synchronizeTagging =="noTagging") //删除 + keysToRemove.append(it.key()); + else + it.value().synchronizeTagging = "noTagging"; + } + foreach (const QString& key, keysToRemove) + { + Graph g = m_graphs.take(key); + if( !m_pCustomPlot->removeGraph(g.qGraph) ) + qWarning() << "Failed to remove graph:" << key; + } m_updateData = true; }