mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 07:43:57 +02:00
Fix JSON integration for JobConfig
This commit is contained in:
parent
5f395654f0
commit
991d6328ef
2 changed files with 6 additions and 5 deletions
|
@ -71,10 +71,12 @@ public:
|
|||
bool alwaysEnabled{ true };
|
||||
bool enabled{ true };
|
||||
|
||||
// This must be named toJSON to integrate with the global scripting JSON object
|
||||
Q_INVOKABLE QString toJSON() { return QJsonDocument(toJsonValue(*this).toObject()).toJson(QJsonDocument::Compact); }
|
||||
Q_INVOKABLE void load(const QVariantMap& map) { qObjectFromJsonValue(QJsonObject::fromVariantMap(map), *this); }
|
||||
|
||||
public slots:
|
||||
Q_INVOKABLE void fromJSON(const QJsonValue& json) { qObjectFromJsonValue(json, *this); }
|
||||
void load(const QJsonObject& val) { qObjectFromJsonValue(val, *this); }
|
||||
};
|
||||
|
||||
class TaskConfig : public JobConfig {
|
||||
|
|
|
@ -111,10 +111,9 @@ void qObjectFromJsonValue(const QJsonValue& j, QObject& o) {
|
|||
for (auto it = object.begin(); it != object.end(); it++) {
|
||||
std::string key = it.key().toStdString();
|
||||
if (it.value().isObject()) {
|
||||
QVariant child = o.property(key.c_str());
|
||||
if (child.isValid()) {
|
||||
QObject* object = child.value<QObject*>();
|
||||
qObjectFromJsonValue(it.value(), *object);
|
||||
QObject* child = o.findChild<QObject*>(key.c_str(), Qt::FindChildOption::FindDirectChildrenOnly);
|
||||
if (child) {
|
||||
qObjectFromJsonValue(it.value(), *child);
|
||||
}
|
||||
} else {
|
||||
o.setProperty(key.c_str(), it.value());
|
||||
|
|
Loading…
Reference in a new issue