| 686 | } |
| 687 | |
| 688 | PlotWidget::CurveInfo* PlotWidget::applyCurveElement(const QDomElement& curve_element) { |
| 689 | const QColor color(curve_element.attribute(QStringLiteral("color"))); |
| 690 | CurveInfo* loaded_curve = nullptr; |
| 691 | if (isXYPlot() && curve_element.hasAttribute(QStringLiteral("curve_x")) && |
| 692 | curve_element.hasAttribute(QStringLiteral("curve_y"))) { |
| 693 | const QString x_name = curve_element.attribute(QStringLiteral("curve_x")); |
| 694 | const QString y_name = curve_element.attribute(QStringLiteral("curve_y")); |
| 695 | const QString source_name = curve_element.attribute(QStringLiteral("name")); |
| 696 | for (CurveInfo& info : curveList()) { |
| 697 | if (auto* xy_series = info.curve != nullptr ? dynamic_cast<PointSeriesXY*>(info.curve->data()) : nullptr) { |
| 698 | if (curveKey(info.source_name, xy_series->xSource().name, xy_series->ySource().name) == |
| 699 | curveKey(source_name, x_name, y_name)) { |
| 700 | loaded_curve = &info; |
| 701 | break; |
| 702 | } |
| 703 | } |
| 704 | } |
| 705 | if (loaded_curve == nullptr) { |
| 706 | // Restore the saved alias as the title; no dialog on load. |
| 707 | loaded_curve = addCurveXY(x_name, y_name, source_name, color.isValid() ? color : Qt::transparent); |
| 708 | } |
| 709 | } else { |
| 710 | const QString curve_name = curve_element.attribute(QStringLiteral("name")); |
| 711 | loaded_curve = curveFromTitle(curve_name); |
| 712 | if (loaded_curve == nullptr) { |
| 713 | loaded_curve = addCurve(curve_name, color.isValid() ? color : Qt::transparent); |
| 714 | } |
| 715 | } |
| 716 | if (loaded_curve != nullptr && loaded_curve->curve != nullptr && color.isValid()) { |
| 717 | loaded_curve->curve->setPen(color, loaded_curve->curve->pen().widthF()); |
| 718 | // Seed the session color memory so this curve keeps its saved color when |
| 719 | // later dragged into another plot (issue #68). Time-series only — see the |
| 720 | // matching note in onChangeCurveColor; XY curves are out of scope here. |
| 721 | if (CurveColorRegistry* registry = colorRegistryOf(session_); registry != nullptr && !isXYPlot()) { |
| 722 | registry->setColor(loaded_curve->source_name, color.name()); |
| 723 | } |
| 724 | } |
| 725 | // Style and width are plot-level (restored once in xmlLoadState); only colour |
| 726 | // and visibility are per-curve. |
| 727 | if (loaded_curve != nullptr) { |
| 728 | const QString visible_attr = curve_element.attribute(QStringLiteral("visible"), QStringLiteral("true")); |
| 729 | loaded_curve->curve->setVisible(visible_attr == QStringLiteral("true")); |
| 730 | } |
| 731 | return loaded_curve; |
| 732 | } |
| 733 | |
| 734 | void PlotWidget::zoomOut(bool emit_signal) { |
| 735 | if (curveList().empty()) { |