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:
parent
96e19548d7
commit
05f79197eb
4 changed files with 166 additions and 133 deletions
49
core/codegen/object_implementation.hbs
Normal file
49
core/codegen/object_implementation.hbs
Normal 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}}
|
Loading…
Add table
Add a link
Reference in a new issue