feat: make all configs sparse
This commit is contained in:
parent
31d7a77929
commit
93b5fb5f4f
4 changed files with 2 additions and 60 deletions
|
|
@ -56,7 +56,6 @@ GlobalConfig::GlobalConfig(GlobalConfig* fallback, const QString& filePath, QObj
|
|||
, m_sidebar(new SidebarConfig(this))
|
||||
, m_services(new ServiceConfig(this))
|
||||
, m_paths(new UserPaths(this)) {
|
||||
setSparse(true);
|
||||
if (!filePath.isEmpty())
|
||||
setupFileBackend(filePath);
|
||||
if (fallback)
|
||||
|
|
|
|||
|
|
@ -70,56 +70,6 @@ QJsonObject ConfigObject::toJsonObject() const {
|
|||
QJsonObject obj;
|
||||
const auto* meta = metaObject();
|
||||
|
||||
for (int i = meta->propertyOffset(); i < meta->propertyCount(); ++i) {
|
||||
const auto prop = meta->property(i);
|
||||
|
||||
if (!prop.isReadable())
|
||||
continue;
|
||||
|
||||
const auto key = QString::fromUtf8(prop.name());
|
||||
const auto value = prop.read(this);
|
||||
|
||||
// Recurse into sub-objects
|
||||
if (value.canView<ConfigObject*>()) {
|
||||
auto* const subObj = value.value<ConfigObject*>();
|
||||
if (subObj)
|
||||
obj.insert(key, subObj->toJsonObject());
|
||||
else
|
||||
qCWarning(lcConfig, "Unable to get sub-object when serializing config object");
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip read-only properties (computed values)
|
||||
if (!prop.isWritable())
|
||||
continue;
|
||||
|
||||
// Handle QStringList explicitly
|
||||
if (prop.metaType().id() == QMetaType::QStringList) {
|
||||
QJsonArray arr;
|
||||
const auto strList = value.toStringList();
|
||||
for (const auto& s : strList)
|
||||
arr.append(s);
|
||||
obj.insert(key, arr);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Handle QVariantList explicitly
|
||||
if (prop.metaType().id() == QMetaType::QVariantList) {
|
||||
obj.insert(key, QJsonArray::fromVariantList(value.toList()));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Default case
|
||||
obj.insert(key, QJsonValue::fromVariant(value));
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
QJsonObject ConfigObject::toSparseJsonObject() const {
|
||||
QJsonObject obj;
|
||||
const auto* meta = metaObject();
|
||||
|
||||
for (int i = meta->propertyOffset(); i < meta->propertyCount(); ++i) {
|
||||
const auto prop = meta->property(i);
|
||||
|
||||
|
|
@ -133,7 +83,7 @@ QJsonObject ConfigObject::toSparseJsonObject() const {
|
|||
if (value.canView<ConfigObject*>()) {
|
||||
auto* const subObj = value.value<ConfigObject*>();
|
||||
if (subObj) {
|
||||
auto subJson = subObj->toSparseJsonObject();
|
||||
auto subJson = subObj->toJsonObject();
|
||||
if (!subJson.isEmpty())
|
||||
obj.insert(key, subJson);
|
||||
}
|
||||
|
|
@ -304,7 +254,7 @@ void ConfigObject::setupFileBackend(const QString& path) {
|
|||
return;
|
||||
}
|
||||
|
||||
auto json = m_sparse ? toSparseJsonObject() : toJsonObject();
|
||||
auto json = toJsonObject();
|
||||
file.write(QJsonDocument(json).toJson(QJsonDocument::Indented));
|
||||
if (auto* root = qobject_cast<RootConfig*>(this))
|
||||
emit root->fileSaved();
|
||||
|
|
|
|||
|
|
@ -53,7 +53,6 @@ public:
|
|||
|
||||
void loadFromJson(const QJsonObject& obj);
|
||||
[[nodiscard]] QJsonObject toJsonObject() const;
|
||||
[[nodiscard]] QJsonObject toSparseJsonObject() const;
|
||||
|
||||
// File-backed config support. Call setupFileBackend() to enable
|
||||
// automatic file watching, debounced saving, and reload.
|
||||
|
|
@ -69,10 +68,6 @@ public:
|
|||
|
||||
[[nodiscard]] bool isPropertyLoaded(const QString& name) const { return m_loadedKeys.contains(name); }
|
||||
|
||||
[[nodiscard]] bool isSparse() const { return m_sparse; }
|
||||
|
||||
void setSparse(bool sparse) { m_sparse = sparse; }
|
||||
|
||||
[[nodiscard]] bool recentlySaved() const { return m_recentlySaved; }
|
||||
|
||||
template <typename T> static bool updateMember(T& member, const T& value) {
|
||||
|
|
@ -100,7 +95,6 @@ private:
|
|||
|
||||
QString m_filePath;
|
||||
bool m_recentlySaved = false;
|
||||
bool m_sparse = false;
|
||||
|
||||
// File backend (heap-allocated only when setupFileBackend is called)
|
||||
QFileSystemWatcher* m_watcher = nullptr;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ TokenConfig::TokenConfig(TokenConfig* fallback, const QString& filePath, QObject
|
|||
: RootConfig(parent)
|
||||
, m_appearance(new AppearanceTokens(this))
|
||||
, m_sizes(new SizeTokens(this)) {
|
||||
setSparse(true);
|
||||
if (!filePath.isEmpty())
|
||||
setupFileBackend(filePath);
|
||||
if (fallback)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue