Commit 8a9b9db2 authored by Volker Krause's avatar Volker Krause
Browse files

Add properties to show the available/supported vehicle types at a dock

parent 42d06659
......@@ -73,6 +73,30 @@ bool RentalVehicleStation::isValid() const
return d->network.isValid() || d->capacity >= 0 || d->availableVehicles >= 0;
}
RentalVehicle::VehicleTypes RentalVehicleStation::supportedVehicleTypes() const
{
RentalVehicle::VehicleTypes types = {};
const auto me = QMetaEnum::fromType<RentalVehicle::VehicleType>();
for (auto i = 0; i < me.keyCount() && i < (int)d->capacities.size(); ++i) {
if (d->capacities[i] >= 0) {
types |= (RentalVehicle::VehicleType)me.value(i);
}
}
return types | availableVehicleTypes();
}
RentalVehicle::VehicleTypes KPublicTransport::RentalVehicleStation::availableVehicleTypes() const
{
RentalVehicle::VehicleTypes types = {};
const auto me = QMetaEnum::fromType<RentalVehicle::VehicleType>();
for (auto i = 0; i < me.keyCount() && i < (int)d->availabilities.size(); ++i) {
if (d->availabilities[i] >= 0) {
types |= (RentalVehicle::VehicleType)me.value(i);
}
}
return types;
}
int RentalVehicleStation::capacity(RentalVehicle::VehicleType type) const
{
const auto me = QMetaEnum::fromType<RentalVehicle::VehicleType>();
......
......@@ -81,8 +81,15 @@ class KPUBLICTRANSPORT_EXPORT RentalVehicleStation
/** Not an empty/default constructed object. */
Q_PROPERTY(bool isValid READ isValid)
/** Supported vehicle types at this station. */
Q_PROPERTY(KPublicTransport::RentalVehicle::VehicleTypes supportedVehicleTypes READ supportedVehicleTypes STORED false)
/** Available vehicle types at this station. */
Q_PROPERTY(KPublicTransport::RentalVehicle::VehicleTypes availableVehicleTypes READ availableVehicleTypes STORED false)
public:
bool isValid() const;
RentalVehicle::VehicleTypes supportedVehicleTypes() const;
RentalVehicle::VehicleTypes availableVehicleTypes() const;
/** Capacity for a given vehicle type. */
Q_INVOKABLE int capacity(KPublicTransport::RentalVehicle::VehicleType type) const;
......
......@@ -74,13 +74,18 @@ Kirigami.ApplicationWindow {
function vehicleTypeIcon(type)
{
switch (type) {
case RentalVehicle.ElectricKickScooter: return "🛴";
case RentalVehicle.ElectricMoped: return "🛵";
case RentalVehicle.Car: return "🚗";
case RentalVehicle.Pedelec: return "⚡🚲";
}
return "🚲";
var s = "";
if (type & RentalVehicle.Bicycle)
s += "🚲";
if (type & RentalVehicle.ElectricKickScooter)
s += "🛴";
if (type & RentalVehicle.ElectricMoped)
s += "🛵";
if (type & RentalVehicle.Car)
s += "🚗";
if (type & RentalVehicle.Pedelec)
s += "⚡🚲";
return s ? s : "🚲";
}
Component {
......@@ -106,7 +111,7 @@ Kirigami.ApplicationWindow {
switch (location.type) {
case Location.Stop: return "🚏 " + location.name;
case Location.RentedVehicleStation:
return '🚏' + vehicleTypeIcon(location.rentalVehicleStation.network.vehicleTypes) + ' ' + location.name;
return '🚏' + vehicleTypeIcon(location.rentalVehicleStation.supportedVehicleTypes) + ' ' + location.name;
case Location.RentedVehicle:
return vehicleTypeIcon(location.rentalVehicle.type) + ' ' + location.name;
case Location.Equipment:
......
Supports Markdown
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