1
0
Fork 0
mirror of https://github.com/HenkKalkwater/harbour-sailfin.git synced 2024-05-19 04:12:43 +00:00
harbour-sailfin/core/codegen/object_implementation.hbs
Chris Josten 05f79197eb Extract OpenAPI writeflns to template files
With a few exceptions if the code would actually get larger
2021-03-19 23:01:29 +01:00

50 lines
1.2 KiB
Handlebars

{{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}}