Commit 514138ac authored by Volker Krause's avatar Volker Krause

Add de/serialization methods for Departure

parent 4e45b010
......@@ -17,6 +17,7 @@
#include "departure.h"
#include "datatypes_p.h"
#include "json.h"
#include <QDateTime>
......@@ -193,4 +194,20 @@ Departure Departure::merge(const Departure &lhs, const Departure &rhs)
return dep;
}
QJsonObject Departure::toJson(const Departure &dep)
{
auto obj = Json::toJson(dep);
// obj.insert(QLatin1String("route"), Route::toJson(dep.route());
obj.insert(QLatin1String("stopPoint"), Location::toJson(dep.stopPoint()));
return obj;
}
Departure Departure::fromJson(const QJsonObject &obj)
{
auto dep = Json::fromJson<Departure>(obj);
// dep.setRoute(Route::fromJson(obj.value(QLatin1String("route")).toObject()));
dep.setStopPoint(Location::fromJson(obj.value(QLatin1String("stopPoint")).toObject()));
return dep;
}
#include "moc_departure.cpp"
......@@ -42,7 +42,7 @@ class Departure
/** @c true if this has real-time data. */
Q_PROPERTY(bool hasExpectedArrivalTime READ hasExpectedArrivalTime STORED false)
/** Difference to schedule in minutes. */
Q_PROPERTY(int arrivalDelay READ arrivalDelay)
Q_PROPERTY(int arrivalDelay READ arrivalDelay STORED false)
/** Planned departure time. */
Q_PROPERTY(QDateTime scheduledDepartureTime READ scheduledDepartureTime WRITE setScheduledDepartureTime)
......@@ -53,7 +53,7 @@ class Departure
/** @c true if this has real-time data. */
Q_PROPERTY(bool hasExpectedDepartureTime READ hasExpectedDepartureTime STORED false)
/** Difference to schedule in minutes. */
Q_PROPERTY(int departureDelay READ departureDelay)
Q_PROPERTY(int departureDelay READ departureDelay STORED false)
/** Planned departure platform. */
Q_PROPERTY(QString scheduledPlatform READ scheduledPlatform WRITE setScheduledPlatform)
......@@ -101,6 +101,11 @@ public:
* This assumes isSame(lhs, rhs) and tries to preserve the most detailed information.
*/
static Departure merge(const Departure &lhs, const Departure &rhs);
/** Serializes one object to JSON. */
static QJsonObject toJson(const Departure &dep);
/** Deserialize an object from JSON. */
static Departure fromJson(const QJsonObject &obj);
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment