| 554 | } |
| 555 | |
| 556 | bool TabbedPlotWidget::xmlLoadState(const QDomElement& tabbed_area) { |
| 557 | if (tabbed_area.isNull() || tabbed_area.tagName() != QStringLiteral("tabbed_widget")) { |
| 558 | return false; |
| 559 | } |
| 560 | |
| 561 | setStateId(tabbed_area.attribute(QStringLiteral("id"))); |
| 562 | if (tabbed_area.hasAttribute(QStringLiteral("name"))) { |
| 563 | name_ = tabbed_area.attribute(QStringLiteral("name")); |
| 564 | } |
| 565 | |
| 566 | QVector<QDomElement> target_tabs; |
| 567 | for (QDomElement tab = tabbed_area.firstChildElement(QStringLiteral("Tab")); !tab.isNull(); |
| 568 | tab = tab.nextSiblingElement(QStringLiteral("Tab"))) { |
| 569 | target_tabs.push_back(tab); |
| 570 | } |
| 571 | if (target_tabs.isEmpty()) { |
| 572 | return false; |
| 573 | } |
| 574 | |
| 575 | restoring_state_ = true; |
| 576 | |
| 577 | // Tear down existing tabs (frames + dockers) before rebuilding. |
| 578 | for (TabEntry& entry : tabs_) { |
| 579 | stack_->removeWidget(entry.docker); |
| 580 | entry.docker->deleteLater(); |
| 581 | tabs_bar_layout_->removeWidget(entry.frame); |
| 582 | entry.frame->deleteLater(); |
| 583 | } |
| 584 | tabs_.clear(); |
| 585 | tab_suffix_count_ = 0; |
| 586 | |
| 587 | for (qsizetype target_index = 0; target_index < target_tabs.size(); ++target_index) { |
| 588 | const QDomElement tab_element = target_tabs.at(target_index); |
| 589 | const QString tab_name = |
| 590 | tab_element.attribute(QStringLiteral("tab_name"), QStringLiteral("tab%1").arg(target_index + 1)); |
| 591 | PlotDocker* docker = addTab(tab_name); |
| 592 | docker->setStateId(tab_element.attribute(QStringLiteral("id"))); |
| 593 | docker->setName(tab_name); |
| 594 | if (!docker->xmlLoadState(tab_element)) { |
| 595 | restoring_state_ = false; |
| 596 | return false; |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | const int requested_index = tabbed_area.firstChildElement(QStringLiteral("currentTabIndex")) |
| 601 | .attribute(QStringLiteral("index"), QStringLiteral("0")) |
| 602 | .toInt(); |
| 603 | const int max_index = dockerCount() - 1; |
| 604 | const int current_index = std::clamp(requested_index, 0, std::max(0, max_index)); |
| 605 | if (PlotDocker* docker = dockerAt(current_index)) { |
| 606 | stack_->setCurrentWidget(docker); |
| 607 | updateSelectionStyle(); |
| 608 | emit currentTabChanged(docker); |
| 609 | } |
| 610 | restoring_state_ = false; |
| 611 | return true; |
| 612 | } |
| 613 |
nothing calls this directly
no test coverage detected