6#include <phosphorconfig_export.h>
21class IGroupPathResolver;
37 QString
readString(
const QString& key,
const QString& defaultValue = {})
const override;
38 int readInt(
const QString& key,
int defaultValue = 0)
const override;
39 bool readBool(
const QString& key,
bool defaultValue =
false)
const override;
40 double readDouble(
const QString& key,
double defaultValue = 0.0)
const override;
41 QColor
readColor(
const QString& key,
const QColor& defaultValue = {})
const override;
43 void writeString(
const QString& key,
const QString& value)
override;
44 void writeInt(
const QString& key,
int value)
override;
45 void writeBool(
const QString& key,
bool value)
override;
47 void writeColor(
const QString& key,
const QColor& value)
override;
48 void writeJson(
const QString& key,
const QJsonValue& value)
override;
49 QJsonValue
readJson(
const QString& key,
const QJsonValue& defaultValue = {})
const override;
51 bool hasKey(
const QString& key)
const override;
56 QJsonObject groupObject()
const;
57 void setGroupObject(
const QJsonObject& obj);
61 bool refuseWrite(
const char* op)
const;
70 bool m_disabled =
false;
97 std::unique_ptr<IGroup>
group(
const QString& name)
override;
101 QString
readRootString(
const QString& key,
const QString& defaultValue = {})
const override;
213 void incActiveGroupCount();
214 void decActiveGroupCount();
215 int activeGroupCount()
const;
221 bool shouldWarnOnce(
const char* tag,
const QString& key);
224 std::unique_ptr<Data> d;
Pluggable configuration backend.
Definition IBackend.h:150
Scoped view into a single configuration group.
Definition IBackend.h:38
Atomic-write JSON configuration backend.
Definition JsonBackend.h:88
SyncPolicy
Sync timing policy. See setSyncPolicy for the full contract.
Definition JsonBackend.h:164
void setRootGroupName(const QString &name)
Change the JSON object that receives ungrouped writeRootString calls.
QStringList groupList() const override
Enumerate every top-level group name.
QString rootGroupName() const
void writeRootString(const QString &key, const QString &value) override
bool applyMigration(const Schema &schema) override
Run schema's migration chain against the in-memory root, and if any step bumps the version stamp,...
SyncPolicy syncPolicy() const
QString filePath() const
Backing file path (useful for migration-chain callers that need to rewrite via writeJsonAtomically du...
void reparseConfiguration() override
Re-read configuration from disk, discarding any pending in-memory changes.
QString readRootString(const QString &key, const QString &defaultValue={}) const override
Read/write ungrouped (root-level) keys.
std::unique_ptr< IGroup > group(const QString &name) override
Return a scoped view into the named group.
void replaceRoot(QJsonObject root)
Replace the in-memory document with root.
void setPathResolver(std::shared_ptr< IGroupPathResolver > resolver) override
Attach a custom path resolver.
void setSyncPolicy(SyncPolicy policy, int debounceMs=500)
Configure when sync() commits to disk.
bool flushPending()
Flush any pending deferred-sync write to disk now.
std::pair< QString, int > versionStamp() const override
Currently-installed version stamp as {key, version}.
void setVersionStamp(const QString &key, int version) override
Stamp-on-sync: if non-empty, every sync() that writes the file will insert key = version when the key...
std::shared_ptr< IGroupPathResolver > pathResolver() const override
Currently-installed resolver, or nullptr when none is set (also the default for backends that ignore ...
void removeRootKey(const QString &key) override
void deleteGroup(const QString &name) override
Delete an entire group and everything inside it.
static bool writeJsonAtomically(const QString &filePath, const QJsonObject &root)
Atomically write root to filePath (temp file + rename via QSaveFile).
JsonBackend(QString filePath)
Construct a backend backed by filePath.
void clearDirty()
Clear the dirty flag without writing.
QJsonObject jsonRootSnapshot() const
Read-only access to the in-memory document.
bool sync() override
Flush pending writes to disk.
Scoped group view backed by a JsonBackend.
Definition JsonBackend.h:32
QStringList keyList() const override
Enumerate scalar leaf keys directly under this group.
QJsonValue readJson(const QString &key, const QJsonValue &defaultValue={}) const override
Read a structured JSON value.
QColor readColor(const QString &key, const QColor &defaultValue={}) const override
bool hasKey(const QString &key) const override
void writeInt(const QString &key, int value) override
bool readBool(const QString &key, bool defaultValue=false) const override
QString readString(const QString &key, const QString &defaultValue={}) const override
void writeString(const QString &key, const QString &value) override
Write a string.
void writeBool(const QString &key, bool value) override
int readInt(const QString &key, int defaultValue=0) const override
void writeJson(const QString &key, const QJsonValue &value) override
Write a structured JSON value (array/object/scalar) natively where supported, or as a compact-JSON st...
void writeDouble(const QString &key, double value) override
double readDouble(const QString &key, double defaultValue=0.0) const override
JsonGroup(QJsonObject &root, QString groupName, JsonBackend *backend)
void deleteKey(const QString &key) override
void writeColor(const QString &key, const QColor &value) override
Declarative description of a configuration store.
Definition Schema.h:89