Commit 4eb10601 authored by Volker Krause's avatar Volker Krause
Browse files

Extend JourneySection to be able to hold individual transport data

parent b8a388e6
......@@ -38,6 +38,11 @@ bool IndividualTransport::operator==(const IndividualTransport &other) const
return d->mode == other.mode() && d->qualifier == other.qualifier();
}
bool IndividualTransport::operator!=(const IndividualTransport &other) const
{
return d->mode != other.mode() || d->qualifier != other.qualifier();
}
QJsonObject IndividualTransport::toJson(const IndividualTransport &it)
{
return Json::toJson(it);
......
......@@ -44,6 +44,7 @@ public:
IndividualTransport(Mode mode, Qualifier qualifier = None);
bool operator==(const IndividualTransport &other) const;
bool operator!=(const IndividualTransport &other) const;
/** Serializes one object to JSON. */
static QJsonObject toJson(const IndividualTransport &it);
......
......@@ -50,6 +50,7 @@ public:
Platform departurePlatformLayout;
Vehicle arrivalVehicleLayout;
Platform arrivalPlatformLayout;
IndividualTransport individualTransport;
};
class JourneyPrivate : public QSharedData
......@@ -77,6 +78,7 @@ KPUBLICTRANSPORT_MAKE_PROPERTY(JourneySection, Vehicle, departureVehicleLayout,
KPUBLICTRANSPORT_MAKE_PROPERTY(JourneySection, Platform, departurePlatformLayout, setDeparturePlatformLayout)
KPUBLICTRANSPORT_MAKE_PROPERTY(JourneySection, Vehicle, arrivalVehicleLayout, setArrivalVehicleLayout)
KPUBLICTRANSPORT_MAKE_PROPERTY(JourneySection, Platform, arrivalPlatformLayout, setArrivalPlatformLayout)
KPUBLICTRANSPORT_MAKE_PROPERTY(JourneySection, KPublicTransport::IndividualTransport, individualTransport, setIndividualTransport)
bool JourneySection::hasExpectedDepartureTime() const
{
......@@ -350,6 +352,10 @@ bool JourneySection::isSame(const JourneySection &lhs, const JourneySection &rhs
return false;
}
if (lhs.d->mode == JourneySection::IndividualTransport && lhs.d->individualTransport != rhs.d->individualTransport) {
return false;
}
// we have N criteria to compare here, with 3 possible results:
// - equal
// - similar-ish, unknwon, or at least not conflicting
......@@ -482,6 +488,10 @@ QJsonObject JourneySection::toJson(const JourneySection &section)
obj.insert(QLatin1String("arrivalPlatformLayout"), Platform::toJson(section.arrivalPlatformLayout()));
}
if (section.mode() == JourneySection::IndividualTransport) {
obj.insert(QLatin1String("individualTransport"), IndividualTransport::toJson(section.individualTransport()));
}
if (obj.size() <= 3) { // only the disruption and mode enums and distance, ie. this is an empty object
return {};
}
......@@ -507,6 +517,7 @@ JourneySection JourneySection::fromJson(const QJsonObject &obj)
section.setDeparturePlatformLayout(Platform::fromJson(obj.value(QLatin1String("departurePlatformLayout")).toObject()));
section.setArrivalVehicleLayout(Vehicle::fromJson(obj.value(QLatin1String("arrivalVehicleLayout")).toObject()));
section.setArrivalPlatformLayout(Platform::fromJson(obj.value(QLatin1String("arrivalPlatformLayout")).toObject()));
section.setIndividualTransport(IndividualTransport::fromJson(obj.value(QLatin1String("individualTransport")).toObject()));
return section;
}
......
......@@ -9,6 +9,7 @@
#include "datatypes.h"
#include "disruption.h"
#include "individualtransport.h"
#include "line.h"
#include "load.h"
#include "location.h"
......@@ -42,6 +43,7 @@ public:
Walking = 4,
Waiting = 8,
RentedVehicle = 16, ///< free floating or dock-based rental bike service, electric scooters, car sharing services, ie. any vehicle you drive yourself but that isn't your own
IndividualTransport = 32, ///< using your own vehicle (bike, car, etc).
};
Q_ENUM(Mode)
Q_DECLARE_FLAGS(Modes, Mode)
......@@ -150,6 +152,9 @@ public:
/** Platform layout information at arrival. */
KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Platform, arrivalPlatformLayout, setArrivalPlatformLayout)
/** Individual transport details for sections using your own vehicle. */
KPUBLICTRANSPORT_PROPERTY(KPublicTransport::IndividualTransport, individualTransport, setIndividualTransport)
public:
bool hasExpectedDepartureTime() const;
int departureDelay() const;
......
......@@ -107,7 +107,8 @@ Kirigami.ApplicationWindow {
{
switch(loc.type) {
case Location.Stop: return "🚏 " + loc.name;
case Location.RentedVehicleStation: return "🚲 " + loc.name;
case Location.RentedVehicleStation: return "🚏🚲 " + loc.name;
case Location.RentedVehicle: return "🚲 " + loc.name;
case Location.Place: return loc.name;
}
}
......@@ -181,14 +182,22 @@ Kirigami.ApplicationWindow {
case JourneySection.RentedVehicle:
{
switch (modelData.rentalVehicle.type) {
case RentalVehicle.Bicycle: return "🚲";
case RentalVehicle.Pedelec: return "🚲";
case RentalVehicle.ElectricKickScooter: return "🛴";
case RentalVehicle.ElectricMoped: return "🛵";
case RentalVehicle.Car: return "🚗";
case RentalVehicle.Bicycle: return "🔑🚲";
case RentalVehicle.Pedelec: return "🔑🔌🚲";
case RentalVehicle.ElectricKickScooter: return "🔑🛴";
case RentalVehicle.ElectricMoped: return "🔑🛵";
case RentalVehicle.Car: return "🔑🚗";
default: return "?";
}
}
case JourneySection.IndividualTransport:
{
switch (modelData.individualTransport.mode) {
case IndividualTransport.Walk: return "🚶";
case IndividualTransport.Bike: return "🚲";
case IndividualTransport.Car: return "🚗";
}
}
default: return "?";
}
}
......@@ -243,6 +252,8 @@ Kirigami.ApplicationWindow {
return "Wait " + displayDuration(modelData.duration)
case JourneySection.RentedVehicle:
return "Drive (" + modelData.rentalVehicle.network.name + ") " + displayDuration(modelData.duration) + " / " + displayDistance(modelData.distance);
case JourneySection.IndividualTransport:
return "Drive " + displayDuration(modelData.duration) + " / " + displayDistance(modelData.distance)
return "???";
}}
}
......
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