From 338baafe7455730c6ffec743c369ac9bc1b3f009 Mon Sep 17 00:00:00 2001 From: duanshengchao <519970194@qq.com> Date: Mon, 4 Aug 2025 15:11:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8Dchart=E5=9B=BE=E5=85=83(g?= =?UTF-8?q?raph)=E9=9A=8F=E5=9D=90=E6=A0=87=E8=BD=B4=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E5=88=A0=E5=87=8F=E8=87=AA=E5=AE=9A=E4=B9=89=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=AF=B9=E8=B1=A1=E6=95=B0=E6=8D=AE=E5=92=8CQCustomPlot?= =?UTF-8?q?=E4=B8=ADgraphs=E5=90=8C=E6=AD=A5=E4=B8=8D=E4=B8=80=E8=87=B4?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dataPanel/dpConfigurationDialog.cpp | 1 + dataPanel/dpLineChart.cpp | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dataPanel/dpConfigurationDialog.cpp b/dataPanel/dpConfigurationDialog.cpp index ebefb61..3e4dcec 100644 --- a/dataPanel/dpConfigurationDialog.cpp +++ b/dataPanel/dpConfigurationDialog.cpp @@ -146,6 +146,7 @@ void dpConfigurationDialog::copyModelData(QStandardItemModel* sourceModel, QStan { QStandardItem* newItem = new QStandardItem(item->text()); QString strTag = item->data(Qt::UserRole + itemRole_tag).toString(); + newItem->setData(strTag, Qt::UserRole + itemRole_tag); RealTimeDataType dataType = (RealTimeDataType)item->data(Qt::UserRole + itemRole_dataType).toInt(); newItem->setData(dataType, Qt::UserRole + itemRole_dataType); if(strTag == "point") diff --git a/dataPanel/dpLineChart.cpp b/dataPanel/dpLineChart.cpp index 2aa5d0c..fbe252f 100644 --- a/dataPanel/dpLineChart.cpp +++ b/dataPanel/dpLineChart.cpp @@ -270,13 +270,15 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg) if (it.value().qGraph.isNull() || it.value().qGraph->valueAxis() == axis.qAxis) it.remove(); // 直接删除当前项,无需手动管理迭代器 } - for(int j = 0; j < m_pCustomPlot->graphCount(); j++) + for(int j = 0; j < m_pCustomPlot->graphCount();) { QCPGraph* graph = m_pCustomPlot->graph(j); if(graph->valueAxis() == axis.qAxis) { m_pCustomPlot->removeGraph(graph); } + else + ++j; } //删除轴 m_pCustomPlot->axisRect()->removeAxis(axis.qAxis); @@ -355,10 +357,16 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg) axis.setQCPAxis(pAxis, false); } m_axes.append(axis); - axesMap.insert(axis._cfg.dataType, &m_axes.last()); //临时变量axesMap通过做更新,此处不要直接使用&axis,因为axis是局部变量,地址会被自动释放,造成堆错误 + //axesMap.insert(axis._cfg.dataType, &m_axes.last()); //临时变量axesMap通过做更新,此处不要直接使用&axis,因为axis是局部变量,地址会被自动释放,造成堆错误 #endif } } + //更新axesMap + axesMap.clear(); + for(auto& axis : m_axes) + { + axesMap.insert(axis._cfg.dataType, &axis); + } //重新排列坐标轴 m_axisArrangementMode = cfg.arrangement; @@ -398,7 +406,10 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg) } else //更新数据 { - m_graphs.value(graphID).synchronizeTagging = "update"; + //m_graphs.value(graphID).synchronizeTagging = "update"; + auto it = m_graphs.find(graphID); + if(it != m_graphs.end()) + it.value().synchronizeTagging = "update"; } } //没有标记的就是需要删除的 @@ -414,10 +425,10 @@ void dpLineChart::synchronizeConfigData(const configurationResults& cfg) { Graph g = m_graphs.take(key); if( !m_pCustomPlot->removeGraph(g.qGraph) ) - qWarning() << "Failed to remove graph:" << key; + qWarning() << "Failed to remove gracloxne ph:" << key; } - qDebug() << m_graphs.count(); + qDebug() << "graph count: " << m_graphs.count() << ", " << m_pCustomPlot->graphCount(); m_updateData = true; }