Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
LayoutSettingsStore.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <phosphorzones_export.h>
7
8#include <QHash>
9#include <QJsonObject>
10#include <QString>
11
12namespace PhosphorZones {
13
33class PHOSPHORZONES_EXPORT LayoutSettingsStore
34{
35public:
38 static constexpr int SchemaVersion = 1;
39
40 // ── Pure split/merge helpers (no I/O) ──────────────────────────────────
41 // These operate on the FULL layout JSON as produced by Layout::toJson and
42 // consumed by Layout::fromJson. They are the single definition of "which
43 // keys are settings vs structural".
44
48 static QJsonObject extractSettings(const QJsonObject& fullLayout);
49
53 static QJsonObject stripSettings(const QJsonObject& fullLayout);
54
60 static QJsonObject mergeSettings(QJsonObject structural, const QJsonObject& settings);
61
62 // ── Sidecar persistence ────────────────────────────────────────────────
63
67 bool loadFromFile(const QString& path);
68
71 bool saveToFile(const QString& path) const;
72
74 QJsonObject settingsFor(const QString& layoutId) const;
75
77 void setSettingsFor(const QString& layoutId, const QJsonObject& settings);
78
80 void removeLayout(const QString& layoutId);
81
82 bool isEmpty() const
83 {
84 return m_byLayout.isEmpty();
85 }
86
87private:
88 QHash<QString, QJsonObject> m_byLayout;
89};
90
91} // namespace PhosphorZones
Persists per-layout SETTINGS in a sidecar, keyed by layout UUID, separately from the structural layou...
Definition LayoutSettingsStore.h:34
static QJsonObject extractSettings(const QJsonObject &fullLayout)
Pull the settings out of a full layout JSON.
bool saveToFile(const QString &path) const
Atomically write the in-memory map to path (stamped with SchemaVersion).
QJsonObject settingsFor(const QString &layoutId) const
Settings for a layout (empty object if none stored).
bool isEmpty() const
Definition LayoutSettingsStore.h:82
bool loadFromFile(const QString &path)
Replace the in-memory map with the contents of path.
void setSettingsFor(const QString &layoutId, const QJsonObject &settings)
Store (or, when settings is empty, clear) the settings for a layout.
static QJsonObject mergeSettings(QJsonObject structural, const QJsonObject &settings)
Overlay a settings object (as produced by extractSettings) back onto a structural layout JSON,...
void removeLayout(const QString &layoutId)
Drop a layout's settings entry (e.g. when the layout is deleted).
static QJsonObject stripSettings(const QJsonObject &fullLayout)
Return the structural-only layout JSON: the full layout minus every settings key (and minus each zone...
Definition IWindowTrackingService.h:23