mirror of
https://github.com/HenkKalkwater/harbour-sailfin.git
synced 2025-09-05 10:12:46 +00:00
Adjust codegeneration to emit simpler classes
This commit is contained in:
parent
05f79197eb
commit
0358418926
466 changed files with 21405 additions and 13956 deletions
|
@ -14,11 +14,18 @@ private:
|
|||
explicit {{className}}Class();
|
||||
};
|
||||
|
||||
typedef {{className}} Class::Value {{className}};
|
||||
typedef {{className}}Class::Value {{className}};
|
||||
|
||||
} // NS DTO
|
||||
|
||||
namespace Support {
|
||||
|
||||
using {{className}} = Jellyfin::DTO::{{className}};
|
||||
using {{className}}Class = Jellyfin::DTO::{{className}}Class;
|
||||
|
||||
template <>
|
||||
|
||||
{{className}} fromJsonValue<{{className}}>(QJsonValue source) {
|
||||
{{className}} fromJsonValue<{{className}}>(const QJsonValue &source) {
|
||||
if (!source.isString()) return {{className}}Class::EnumNotSet;
|
||||
|
||||
QString str = source.toString();
|
||||
|
|
|
@ -5,13 +5,12 @@ class {{className}};
|
|||
{{/if}}
|
||||
{{/each}}
|
||||
|
||||
class {{className}} : public QObject {
|
||||
Q_OBJECT
|
||||
class {{className}} {
|
||||
public:
|
||||
explicit {{className}}(QObject *parent = nullptr);
|
||||
static {{className}} *fromJSON(QJsonObject source, QObject *parent = nullptr);
|
||||
void updateFromJSON(QJsonObject source, bool emitSignals = true);
|
||||
QJsonObject toJSON();
|
||||
explicit {{className}}();
|
||||
static {{className}} fromJson(QJsonObject source);
|
||||
void setFromJson(QJsonObject source);
|
||||
QJsonObject toJson();
|
||||
|
||||
// Properties
|
||||
|
||||
|
@ -23,26 +22,22 @@ public:
|
|||
*/
|
||||
{{/if}}
|
||||
|
||||
Q_PROPERTY({{p.typeNameWithQualifiers}} {{p.name}} READ {{p.name}} WRITE set{{p.writeName}} NOTIFY {{p.name}}Changed)
|
||||
|
||||
{{/each}}
|
||||
|
||||
// Getters
|
||||
|
||||
{{#each properties as |p|}}
|
||||
{{p.typeNameWithQualifiers}} {{p.name}}() const;
|
||||
|
||||
{{#if p.description.length > 0}}
|
||||
/**
|
||||
* @brief {{p.description}}
|
||||
|
||||
*/
|
||||
{{/if}}
|
||||
|
||||
void set{{p.writeName}}({{p.typeNameWithQualifiers}} new{{p.writeName}});
|
||||
|
||||
|
||||
{{/each}}
|
||||
|
||||
// Signals
|
||||
signals:
|
||||
|
||||
{{#each properties as |p|}}
|
||||
void {{p.name}}Changed({{p.typeNameWithQualifiers}} new{{p.writeName}});
|
||||
|
||||
{{/each}}
|
||||
{{#if p.isNullable}}
|
||||
bool is{{p.writeName}}Null() const;
|
||||
void set{{p.writeName}}Null();
|
||||
{{/if}}
|
||||
{{/each}}
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -55,3 +50,16 @@ protected:
|
|||
|
||||
{{/each}}
|
||||
};
|
||||
|
||||
} // NS DTO
|
||||
|
||||
namespace Support {
|
||||
|
||||
using {{className}} = Jellyfin::DTO::{{className}};
|
||||
|
||||
template <>
|
||||
|
||||
{{className}} fromJsonValue<{{className}}>(const QJsonValue &source) {
|
||||
if (!source.isObject()) throw new ParseException("Expected JSON Object");
|
||||
return {{className}}::fromJson(source.toObject());
|
||||
}
|
||||
|
|
|
@ -1,30 +1,23 @@
|
|||
{{className}}::{{className}}(QObject *parent) : QObject(parent) {}
|
||||
{{className}}::{{className}}(QObject *parent) {}
|
||||
|
||||
|
||||
{{className}} *{{className}}::fromJSON(QJsonObject source, QObject *parent) {
|
||||
{{className}} *instance = new {{className}}(parent);
|
||||
instance->updateFromJSON(source, false);
|
||||
{{className}} {{className}}::fromJson(QJsonObject source) {
|
||||
{{className}} instance;
|
||||
instance->setFromJson(source, false);
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
void {{className}}::updateFromJSON(QJsonObject source, bool emitSignals) {
|
||||
void {{className}}::setFromJson(QJsonObject source) {
|
||||
|
||||
{{#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 {{className}}::toJson() {
|
||||
QJsonObject result;
|
||||
|
||||
{{#each properties as |property|}}
|
||||
|
@ -33,7 +26,7 @@ QJsonObject {{className}}::toJSON() {
|
|||
{{/each}}
|
||||
|
||||
return result;
|
||||
}"
|
||||
}
|
||||
|
||||
|
||||
{{#each properties as |property|}}
|
||||
|
@ -42,8 +35,14 @@ QJsonObject {{className}}::toJSON() {
|
|||
void {{className}}::set{{property.writeName}}({{property.typeNameWithQualifiers}} new{{property.writeName}}) {
|
||||
|
||||
{{property.memberName}} = new{{property.writeName}};
|
||||
emit {{property.name}}Changed(new{{property.writeName}});
|
||||
}
|
||||
|
||||
{{#if property.isNullable}}
|
||||
bool {{className}}::is{{property.writeName}}Null() const {
|
||||
return {{property.nullableCheck}};
|
||||
}
|
||||
|
||||
void {{className}}::setNull() {
|
||||
{{property.nullableSetter}};
|
||||
}
|
||||
{{/each}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue