* @brief Serializes the current window layout to a JSON object. */
| 613 | * @brief Serializes the current window layout to a JSON object. |
| 614 | */ |
| 615 | QJsonObject UI::WindowManager::serializeLayout() const |
| 616 | { |
| 617 | QJsonObject layout; |
| 618 | QJsonArray geometries; |
| 619 | for (int id : m_windowOrder) { |
| 620 | auto* win = m_windows.value(id); |
| 621 | if (!win) |
| 622 | continue; |
| 623 | |
| 624 | const StableKey key = stableKeyForWindowId(id); |
| 625 | |
| 626 | QJsonObject winGeom; |
| 627 | winGeom["id"] = id; |
| 628 | winGeom["x"] = win->x(); |
| 629 | winGeom["y"] = win->y(); |
| 630 | winGeom["width"] = win->width(); |
| 631 | winGeom["height"] = win->height(); |
| 632 | winGeom["state"] = win->state(); |
| 633 | if (key.isValid()) { |
| 634 | winGeom["widgetType"] = key.widgetType; |
| 635 | winGeom["relativeIndex"] = key.relativeIndex; |
| 636 | } |
| 637 | geometries.append(winGeom); |
| 638 | } |
| 639 | |
| 640 | layout["geometries"] = geometries; |
| 641 | |
| 642 | layout["canvasWidth"] = static_cast<int>(width()); |
| 643 | layout["canvasHeight"] = static_cast<int>(height()); |
| 644 | |
| 645 | QJsonArray orderArray; |
| 646 | QJsonArray orderTypedArray; |
| 647 | for (int id : m_windowOrder) { |
| 648 | orderArray.append(id); |
| 649 | |
| 650 | const StableKey key = stableKeyForWindowId(id); |
| 651 | if (!key.isValid()) |
| 652 | continue; |
| 653 | |
| 654 | QJsonObject entry; |
| 655 | entry["widgetType"] = key.widgetType; |
| 656 | entry["relativeIndex"] = key.relativeIndex; |
| 657 | orderTypedArray.append(entry); |
| 658 | } |
| 659 | |
| 660 | layout["windowOrder"] = orderArray; |
| 661 | layout["windowOrderTyped"] = orderTypedArray; |
| 662 | layout["autoLayout"] = m_autoLayoutEnabled; |
| 663 | layout["userReordered"] = m_userReordered; |
| 664 | |
| 665 | return layout; |
| 666 | } |
| 667 | |
| 668 | /** |
| 669 | * @brief Resolves a saved window-order array into live windowIds. |