MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / applySavedGeometries

Method applySavedGeometries

app/src/UI/WindowManager.cpp:707–742  ·  view source on GitHub ↗

* @brief Applies saved manual-mode geometries to live windows and stashes the * anchored rects for any window that hasn't registered yet. */

Source from the content-addressed store, hash-verified

705 * anchored rects for any window that hasn't registered yet.
706 */
707void UI::WindowManager::applySavedGeometries(const QJsonObject& layout,
708 const QHash<StableKey, int>& stableLookup,
709 int marginCanvasW,
710 int marginCanvasH)
711{
712 const int canvasW = static_cast<int>(width());
713 const int canvasH = static_cast<int>(height());
714 const QJsonArray geometries = layout["geometries"].toArray();
715
716 for (const auto& val : std::as_const(geometries)) {
717 const QJsonObject winGeom = val.toObject();
718 const int id = resolveSavedWindowId(winGeom, stableLookup, m_windows);
719 if (id < 0)
720 continue;
721
722 const int x = static_cast<int>(SerialStudio::toDouble(winGeom["x"], 0.0));
723 const int y = static_cast<int>(SerialStudio::toDouble(winGeom["y"], 0.0));
724 const int w = static_cast<int>(SerialStudio::toDouble(winGeom["width"], 200.0));
725 const int h = static_cast<int>(SerialStudio::toDouble(winGeom["height"], 150.0));
726 const QRect geom(x, y, w, h);
727 const QMargins margins = manualMarginsForGeometry(geom, marginCanvasW, marginCanvasH);
728 const QRect anchored = anchoredGeometry(geom, margins, canvasW, canvasH);
729
730 auto* win = m_windows.value(id);
731 if (win) {
732 win->setX(anchored.x());
733 win->setY(anchored.y());
734 win->setWidth(anchored.width());
735 win->setHeight(anchored.height());
736 }
737
738 m_manualGeometries.insert(id, geom);
739 m_manualMargins.insert(id, margins);
740 m_pendingGeometries.insert(id, anchored);
741 }
742}
743
744/**
745 * @brief Restores a previously serialized window layout.

Callers

nothing calls this directly

Calls 7

resolveSavedWindowIdFunction · 0.85
manualMarginsForGeometryFunction · 0.85
anchoredGeometryFunction · 0.85
xMethod · 0.80
widthMethod · 0.80
heightMethod · 0.80
valueMethod · 0.45

Tested by

no test coverage detected