* @brief Restores a previously serialized window layout. */
| 745 | * @brief Restores a previously serialized window layout. |
| 746 | */ |
| 747 | bool UI::WindowManager::restoreLayout(const QJsonObject& layout) |
| 748 | { |
| 749 | if (layout.isEmpty()) |
| 750 | return false; |
| 751 | |
| 752 | bool autoLayout = layout["autoLayout"].toBool(true); |
| 753 | const int savedCanvasW = layout["canvasWidth"].toInt(0); |
| 754 | const int savedCanvasH = layout["canvasHeight"].toInt(0); |
| 755 | m_userReordered = layout["userReordered"].toBool(false); |
| 756 | |
| 757 | const QHash<StableKey, int> stableLookup = buildStableKeyToWindowId(); |
| 758 | |
| 759 | if (layout.contains("windowOrderTyped") || layout.contains("windowOrder")) |
| 760 | m_windowOrder = resolveSavedOrder(layout, stableLookup); |
| 761 | |
| 762 | m_manualGeometries.clear(); |
| 763 | m_manualMargins.clear(); |
| 764 | m_pendingGeometries.clear(); |
| 765 | if (!autoLayout && layout.contains("geometries")) { |
| 766 | const int canvasW = static_cast<int>(width()); |
| 767 | const int canvasH = static_cast<int>(height()); |
| 768 | const int marginCanvasW = savedCanvasW > 0 ? savedCanvasW : canvasW; |
| 769 | const int marginCanvasH = savedCanvasH > 0 ? savedCanvasH : canvasH; |
| 770 | m_manualCanvasWidth = marginCanvasW; |
| 771 | m_manualCanvasHeight = marginCanvasH; |
| 772 | |
| 773 | applySavedGeometries(layout, stableLookup, marginCanvasW, marginCanvasH); |
| 774 | |
| 775 | constrainWindows(); |
| 776 | Q_EMIT geometryChanged(nullptr); |
| 777 | } |
| 778 | |
| 779 | if (m_autoLayoutEnabled != autoLayout) { |
| 780 | m_autoLayoutEnabled = autoLayout; |
| 781 | Q_EMIT autoLayoutEnabledChanged(); |
| 782 | } |
| 783 | |
| 784 | if (autoLayout) |
| 785 | loadLayout(); |
| 786 | else |
| 787 | m_layoutRestored = true; |
| 788 | |
| 789 | return true; |
| 790 | } |
| 791 | |
| 792 | /** |
| 793 | * @brief Pre-stashes saved geometries so registerWindow can apply them per-window before first |
no test coverage detected