1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2025-09-01 08:52:45 +00:00

Extract OpenAPI writeflns to template files

With a few exceptions if the code would actually get larger
This commit is contained in:
Chris Josten 2021-03-19 23:01:29 +01:00
parent 96e19548d7
commit 05f79197eb
4 changed files with 166 additions and 133 deletions

View file

@ -0,0 +1,49 @@
{{className}}::{{className}}(QObject *parent) : QObject(parent) {}
{{className}} *{{className}}::fromJSON(QJsonObject source, QObject *parent) {
{{className}} *instance = new {{className}}(parent);
instance->updateFromJSON(source, false);
return instance;
}
void {{className}}::updateFromJSON(QJsonObject source, bool emitSignals) {
{{#each properties as |property|}}
{{property.memberName}} = fromJsonValue<{{property.typeNameWithQualifiers}}>(source["{{property.originalName}}"]);
{{/each}}
if (emitSignals) {
{{#each properties as |property|}}
emit {{property.name}}Changed({{property.memberName}});
{{/each}}
}
}
QJsonObject {{className}}::toJSON() {
QJsonObject result;
{{#each properties as |property|}}
result["{{property.originalName}}"] = toJsonValue<{{property.typeNameWithQualifiers}}>({{property.memberName}});
{{/each}}
return result;
}"
{{#each properties as |property|}}
{{property.typeNameWithQualifiers}} {{className}}::{{property.name}}() const { return {{property.memberName}}; }
void {{className}}::set{{property.writeName}}({{property.typeNameWithQualifiers}} new{{property.writeName}}) {
{{property.memberName}} = new{{property.writeName}};
emit {{property.name}}Changed(new{{property.writeName}});
}
{{/each}}