diff --git a/chart_plugin/src/st_space_display.cpp b/chart_plugin/src/st_space_display.cpp index e3267bfde4d48ce6d9778943881f14c7818e8af6..49082c9e5a3eb88d3878eafea7a64deea5f9d27f 100755 --- a/chart_plugin/src/st_space_display.cpp +++ b/chart_plugin/src/st_space_display.cpp @@ -71,7 +71,6 @@ const qreal CURVE_SYMBOL_PEN_WIDTH = 0x01; const int32_t CURVE_SYMBOL_SIZE_WIDTH = 0x02; const int32_t CURVE_SYMBOL_SIZE_HRIGHT = 0x02; -const int32_t LEGEND_WIDGETS_SIZE = 0x01; const QString LEGEND_STYLE_SHEET = "color: rgb(255, 255, 255);"; const QString QWTPLOT_TITLE_FONT_FAMILY = "楷体"; @@ -313,8 +312,8 @@ void StSpaceDisplay::ShowCurve(QwtPlotItem *item, bool isVisible) item->setVisible(isVisible); QwtLegend *legend = qobject_cast(ui.qwtPlot->legend()); QList legendWidgets = legend->legendWidgets(ui.qwtPlot->itemToInfo(item)); - if (legendWidgets.size() == LEGEND_WIDGETS_SIZE) { - QwtLegendLabel *legendLabel = qobject_cast(legendWidgets[0]); + for (int32_t i = 0; i < legendWidgets.size(); i++) { + QwtLegendLabel *legendLabel = qobject_cast(legendWidgets.at(i)); if (legendLabel != nullptr) { legendLabel->setChecked(isVisible); } @@ -697,9 +696,20 @@ void StSpaceDisplay::ShowObjects(const QMap &stObjectsMap) { auto objectsTypeId = stSpaceData.GetObjectsTypeIdMap(); - if (!stObjectsCurveMap.empty()) { - stObjectsCurveMap.clear(); + for (auto iter = stObjectsCurveMap.begin(); iter != stObjectsCurveMap.end(); iter++) { + QwtLegend *legend = qobject_cast(ui.qwtPlot->legend()); + QList legendWidgets = legend->legendWidgets(ui.qwtPlot->itemToInfo(iter->second.get())); + for (int32_t i = 0; i < legendWidgets.size(); i++) { + QwtLegendLabel *legendLabel = qobject_cast(legendWidgets.at(i)); + if (legendLabel != nullptr) { + delete legendLabel; + legendLabel = nullptr; + } + } + iter->second->detach(); + iter->second->setSamples(QPolygonF()); } + stObjectsCurveMap.clear(); QList listType = objectsTypeId.keys(); @@ -730,10 +740,6 @@ void StSpaceDisplay::ShowObjects(const QMap &stObjectsMap) void StSpaceDisplay::DrawObjects(const QMap &stObjectsMap) { - if (stObjectsMap.isEmpty()) { - return; - } - ShowObjects(stObjectsMap); UpdateObjectsTypeChoice(); }