Continues migration with DDS, Common
This commit is contained in:
1 parent
9b15cee841
commit
fa48db111e
668 files changed
+111841
-2
No files matched your search
+95
@@ -0,0 +1,95 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Template for 'real' structures including insert/update/delete functions for db
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
{% autoescape off %}
|
||||
// filename: {{ namespace_abbr }}_db_structs.cpp
|
||||
#include "{{ namespace_abbr }}_db_structs.h"
|
||||
#include "{{ namespace_abbr }}_export.h"
|
||||
|
||||
namespace {{ namespace }}
|
||||
{
|
||||
namespace Database
|
||||
{
|
||||
QString jsonValueToJsonString(const QJsonValue &value)
|
||||
{
|
||||
return value.isNull() ? QStringLiteral("{}") : value.toString();
|
||||
}
|
||||
|
||||
QString qVariantToJsonString(const QVariant &value)
|
||||
{
|
||||
return value.isNull() ? QStringLiteral("{}") : value.toString();
|
||||
}
|
||||
|
||||
QString fixupEmptyJsonString(const QString &str)
|
||||
{
|
||||
return str.isEmpty() ? QStringLiteral("{}") : str;
|
||||
}
|
||||
|
||||
|
||||
// QPointF
|
||||
QJsonValue toJson(const QPointF &element)
|
||||
{
|
||||
QJsonObject obj;
|
||||
obj.insert(QStringLiteral("x"), QJsonValue(element.x()));
|
||||
obj.insert(QStringLiteral("y"), QJsonValue(element.y()));
|
||||
return QJsonValue(obj);
|
||||
}
|
||||
template<>
|
||||
QPointF fromJson(const QJsonValue &val)
|
||||
{
|
||||
QJsonObject obj = val.toObject();
|
||||
return QPointF(obj.value(QStringLiteral("x")).toDouble(), obj.value(QStringLiteral("y")).toDouble());
|
||||
}
|
||||
{% if need_point3d %}
|
||||
// QPoint3D
|
||||
QJsonValue toJson(const LtsUtils::QPoint3D &element)
|
||||
{
|
||||
QJsonObject obj;
|
||||
obj.insert(QStringLiteral("x"), QJsonValue(element.x()));
|
||||
obj.insert(QStringLiteral("y"), QJsonValue(element.y()));
|
||||
obj.insert(QStringLiteral("z"), QJsonValue(element.z()));
|
||||
return QJsonValue(obj);
|
||||
}
|
||||
template<>
|
||||
LtsUtils::QPoint3D fromJson(const QJsonValue &val)
|
||||
{
|
||||
QJsonObject obj = val.toObject();
|
||||
return LtsUtils::QPoint3D(obj.value(QStringLiteral("x")).toDouble(), obj.value(QStringLiteral("y")).toDouble(), obj.value(QStringLiteral("z")).toDouble());
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
{% for cpp_struct in cpp_structs %}
|
||||
//
|
||||
// Struct: {{ cpp_struct.name }}
|
||||
//
|
||||
QJsonObject toJson(const {{ cpp_struct.name }} &element)
|
||||
{
|
||||
QJsonObject obj;
|
||||
{% for row in cpp_struct.jsonMember %}
|
||||
{{ row.dbToJsonElement }};
|
||||
{% endfor %}
|
||||
return obj;
|
||||
}
|
||||
|
||||
template<>
|
||||
{{ cpp_struct.name }} fromJson(const QJsonValue &value)
|
||||
{
|
||||
const QJsonObject objElement(value.toObject());
|
||||
{{ cpp_struct.name }} element;
|
||||
|
||||
{% for row in cpp_struct.jsonMember %}
|
||||
{ {{ row.jsonElementToDb }}; } {% endfor %}
|
||||
|
||||
return element;
|
||||
}
|
||||
// {{ cpp_struct.name }} end
|
||||
{% endfor %}
|
||||
|
||||
} // namespace Database
|
||||
} // namespace {{ namespace }}
|
||||
{% endautoescape %}
|
||||
Reference in new issue
Block a user