High-level declarative configuration facade. More...
#include <phosphor-config/include/PhosphorConfig/Store.h>
Signals | |
| void | changed (const QString &group, const QString &key) |
Emitted after any successful write() or reset() operation. | |
Public Member Functions | |
| Store (IBackend *backend, Schema schema, QObject *parent=nullptr) | |
Construct a store that borrows backend and applies schema. | |
| ~Store () override | |
| template<typename T > | |
| T | read (const QString &group, const QString &key) const |
| Read a declared key. | |
| QVariant | readVariant (const QString &group, const QString &key) const |
Read as QVariant. | |
| void | write (const QString &group, const QString &key, const QVariant &value) |
| Write a value. | |
| void | reset (const QString &group, const QString &key) |
| Reset one key to its schema default. | |
| void | resetGroup (const QString &group) |
Reset every key declared in group. Undeclared extras are left alone. | |
| void | resetAll () |
| Reset every declared key in every declared group. Extras are untouched. | |
| QJsonObject | exportToJson () const |
| Produce a JSON snapshot of every declared key's current value. | |
| bool | importFromJson (const QJsonObject &snapshot) |
Overwrite declared keys from snapshot. | |
| bool | sync () |
| Flush the underlying backend. | |
| IBackend * | backend () const |
| Direct access for callers that still need the backend (e.g. | |
| const Schema & | schema () const |
| The schema the store was constructed with. | |
| template<> | |
| PHOSPHORCONFIG_EXPORT QString | read (const QString &, const QString &) const |
| template<> | |
| PHOSPHORCONFIG_EXPORT int | read (const QString &, const QString &) const |
| template<> | |
| PHOSPHORCONFIG_EXPORT bool | read (const QString &, const QString &) const |
| template<> | |
| PHOSPHORCONFIG_EXPORT double | read (const QString &, const QString &) const |
| template<> | |
| PHOSPHORCONFIG_EXPORT QColor | read (const QString &, const QString &) const |
| template<> | |
| PHOSPHORCONFIG_EXPORT QVariantMap | read (const QString &, const QString &) const |
| template<> | |
| PHOSPHORCONFIG_EXPORT QVariantList | read (const QString &, const QString &) const |
High-level declarative configuration facade.
Wraps an IBackend with a Schema so consumers get:
reset() / resetGroup() / resetAll() operations, no hand-written switch statementsexportToJson() / importFromJson() for backup, dotfile sync, and settings-panel "export"changed() signal that consumers can wire directly to UI updatesConstruct a store that borrows backend and applies schema.
The backend must outlive the store — typically owned by the caller via std::unique_ptr in a containing class. On entry the schema's migration chain runs against the backend's in-memory state; after migration the version key is stamped (JsonBackend only).
|
override |
| IBackend * PhosphorConfig::Store::backend | ( | ) | const |
Direct access for callers that still need the backend (e.g.
to read an undeclared key or to call groupList()).
|
signal |
| QJsonObject PhosphorConfig::Store::exportToJson | ( | ) | const |
Produce a JSON snapshot of every declared key's current value.
Useful for "export settings" UIs and dotfile sync. Keys absent from the backing store are emitted with their schema default.
| bool PhosphorConfig::Store::importFromJson | ( | const QJsonObject & | snapshot | ) |
Overwrite declared keys from snapshot.
Unknown groups/keys in snapshot are ignored (silently — no adaptive migration). Use MigrationRunner first if snapshot came from an older schema.
Keys declared in the schema but ABSENT from snapshot are also skipped — importFromJson is strictly additive / overwriting, never subtractive. For a full "restore defaults from snapshot" workflow, call resetAll() before importFromJson so absent keys land at their schema defaults.
true on a successful import; false when the snapshot is rejected (version mismatch, malformed version key). On a false return no keys are written. Callers should propagate the result so settings-panel UIs can distinguish "import succeeded" from "import
refused" instead of relying on log scraping. | PHOSPHORCONFIG_EXPORT QString PhosphorConfig::Store::read | ( | const QString & | , |
| const QString & | |||
| ) | const |
| PHOSPHORCONFIG_EXPORT int PhosphorConfig::Store::read | ( | const QString & | , |
| const QString & | |||
| ) | const |
| PHOSPHORCONFIG_EXPORT bool PhosphorConfig::Store::read | ( | const QString & | , |
| const QString & | |||
| ) | const |
| PHOSPHORCONFIG_EXPORT double PhosphorConfig::Store::read | ( | const QString & | , |
| const QString & | |||
| ) | const |
| PHOSPHORCONFIG_EXPORT QColor PhosphorConfig::Store::read | ( | const QString & | , |
| const QString & | |||
| ) | const |
| PHOSPHORCONFIG_EXPORT QVariantMap PhosphorConfig::Store::read | ( | const QString & | , |
| const QString & | |||
| ) | const |
| PHOSPHORCONFIG_EXPORT QVariantList PhosphorConfig::Store::read | ( | const QString & | , |
| const QString & | |||
| ) | const |
|
inline |
Read a declared key.
T: QString, int, bool, double, QColor) returns the schema default.QVariantMap and QVariantList, returns an EMPTY collection (not the schema default). This intentional asymmetry lets the Settings layer distinguish "user has
never written this blob" (returns the schema default — populated value) from "blob is corrupt" (returns empty — caller substitutes library/project defaults instead of stamping the schema default back over corrupt user data).QVariant() — effectively T{}.The primary template is intentionally a static_assert trap: Store::read<T> is only fully specialized for the types listed below, and instantiating it with anything else should fail at compile time with a clear message rather than at link time with an opaque "undefined reference" error.
| QVariant PhosphorConfig::Store::readVariant | ( | const QString & | group, |
| const QString & | key | ||
| ) | const |
Read as QVariant.
Uses QString coercion on the wire and reconstructs the type via QMetaType when possible. Undeclared keys return QVariant().
| void PhosphorConfig::Store::reset | ( | const QString & | group, |
| const QString & | key | ||
| ) |
Reset one key to its schema default.
No-op when the key is undeclared.
Only emits changed when the key was actually present in the backing store — a reset on a never-written key is a no-op that skips the changed() emission, since the read path already returned the schema default and no observer would see a change. Callers relying on reset() to force a QML rebinding on a pristine key should re-read via read and emit their own signal instead.
| void PhosphorConfig::Store::resetAll | ( | ) |
Reset every declared key in every declared group. Extras are untouched.
| void PhosphorConfig::Store::resetGroup | ( | const QString & | group | ) |
Reset every key declared in group. Undeclared extras are left alone.
| const Schema & PhosphorConfig::Store::schema | ( | ) | const |
The schema the store was constructed with.
| bool PhosphorConfig::Store::sync | ( | ) |
Flush the underlying backend.
Returns the backend's sync() result — true on success (or nothing to flush), false on an I/O error.
| void PhosphorConfig::Store::write | ( | const QString & | group, |
| const QString & | key, | ||
| const QVariant & | value | ||
| ) |
Write a value.
If the schema declares an expectedType for this key and value has a different typeId, a warning is logged but the write proceeds (Qt will coerce on read back). Emits changed.