feat:完成曲线的数据配置

This commit is contained in:
duanshengchao 2025-08-01 15:25:28 +08:00
parent 352c0b6b39
commit 6386d00229
2 changed files with 21 additions and 4 deletions

View File

@ -97,11 +97,13 @@ protected:
struct Graph struct Graph
{ {
QString dataID;
QColor color; QColor color;
RealTimeDataType dataType; RealTimeDataType dataType;
//QCPGraph* qGraph = nullptr; //QCPGraph* qGraph = nullptr;
QPointer<QCPGraph> qGraph; QPointer<QCPGraph> qGraph;
QString dataID;
QString synchronizeTagging; //同步配置数据时的标记new、update两种没有的就是要被删除
}; };
}; };

View File

@ -365,7 +365,6 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg)
arrangeAxes(); arrangeAxes();
//2.曲线-数据源决定 //2.曲线-数据源决定
QList<Graph> deleteGraphs;
for(int i = 0; i < cfg.m_pModel_dataSource->rowCount(); i++) 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(); 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 graph;
graph.dataID = graphID; graph.dataID = graphID;
graph.dataType = dataType; graph.dataType = dataType;
graph.synchronizeTagging = "new";
QCPGraph* newGraph = m_pCustomPlot->addGraph(m_pCustomPlot->xAxis, valueAxis); QCPGraph* newGraph = m_pCustomPlot->addGraph(m_pCustomPlot->xAxis, valueAxis);
if(newGraph) if(newGraph)
{ {
@ -395,11 +395,26 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg)
m_graphs.insert(graphID, graph); 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; m_updateData = true;
} }