| 3554 | } |
| 3555 | |
| 3556 | void MainWindow::applyTimelineStateFromLayout(const QList<layout_xml::DataSourceRef>& sources) { |
| 3557 | if (sources.isEmpty()) { |
| 3558 | return; |
| 3559 | } |
| 3560 | SessionManager& mgr = session_->sessionManager(); |
| 3561 | |
| 3562 | // Re-bind each saved <fileInfo> to whichever loaded dataset came from that |
| 3563 | // file (DatasetIds are re-minted per session; the path is the stable key), |
| 3564 | // apply its display offset, and collect (id, slot) for the order rebuild. |
| 3565 | std::vector<std::pair<int, DatasetId>> ordered; // (timeline_order, id) |
| 3566 | for (const layout_xml::DataSourceRef& ref : sources) { |
| 3567 | DatasetId matched = 0; |
| 3568 | for (const auto& [id, name] : session_->catalogModel().datasets()) { |
| 3569 | (void)name; |
| 3570 | const QString src_path = file_loader_->sourcePathForDataset(id); |
| 3571 | if (!src_path.isEmpty() && layout_xml::isSamePath(src_path, ref.resolved_path)) { |
| 3572 | matched = id; |
| 3573 | break; |
| 3574 | } |
| 3575 | } |
| 3576 | if (matched == 0) { |
| 3577 | continue; // file referenced by the layout isn't loaded — nothing to restore |
| 3578 | } |
| 3579 | if (ref.has_display_offset) { |
| 3580 | mgr.setDisplayOffset(matched, DisplayOffset{Duration{ref.display_offset_ns}}); |
| 3581 | } |
| 3582 | if (ref.timeline_order >= 0) { |
| 3583 | ordered.emplace_back(ref.timeline_order, matched); |
| 3584 | } |
| 3585 | } |
| 3586 | |
| 3587 | // Rebuild the vertical track order from the saved slots. Sorting by the saved |
| 3588 | // index (not document order) keeps the arrangement exact even if <fileInfo> |
| 3589 | // elements were written in load order rather than display order. |
| 3590 | if (source_timeline_controller_ != nullptr && !ordered.empty()) { |
| 3591 | std::sort(ordered.begin(), ordered.end(), [](const auto& a, const auto& b) { return a.first < b.first; }); |
| 3592 | std::vector<DatasetId> order; |
| 3593 | order.reserve(ordered.size()); |
| 3594 | for (const auto& [slot, id] : ordered) { |
| 3595 | (void)slot; |
| 3596 | order.push_back(id); |
| 3597 | } |
| 3598 | source_timeline_controller_->setDisplayOrder(std::move(order)); |
| 3599 | } |
| 3600 | } |
| 3601 | |
| 3602 | QDomElement MainWindow::saveSourceTimelineViewState(QDomDocument& doc) const { |
| 3603 | // Read the view chrome off the widgets; layout_xml owns the XML schema. |
nothing calls this directly
no test coverage detected