Commit 22b1a284 authored by Volker Krause's avatar Volker Krause
Browse files

Add data type for station equipment, namely elevator and escalators

parent aa90493f
Pipeline #45276 passed with stage
in 23 seconds
......@@ -43,6 +43,8 @@ set(kpublictransport_srcs
datatypes/attributionutil.cpp
datatypes/backend.cpp
datatypes/disruption.cpp
datatypes/equipment.cpp
datatypes/equipmentutil.cpp
datatypes/journey.cpp
datatypes/journeyutil.cpp
datatypes/json.cpp
......@@ -138,6 +140,7 @@ ecm_generate_headers(KPublicTransport_Datatypes_FORWARDING_HEADERS
Datatypes
Departure
Disruption
Equipment
Journey
Line
Load
......
/*
SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "equipment.h"
#include "datatypes_p.h"
#include "json_p.h"
#include "notesutil_p.h"
using namespace KPublicTransport;
namespace KPublicTransport {
class EquipmentPrivate : public QSharedData
{
public:
Equipment::Type type = Equipment::Unknown;
Disruption::Effect disruptionEffect = Disruption::NormalService;
QStringList notes;
};
}
KPUBLICTRANSPORT_MAKE_GADGET(Equipment)
KPUBLICTRANSPORT_MAKE_PROPERTY(Equipment, Equipment::Type, type, setType)
KPUBLICTRANSPORT_MAKE_PROPERTY(Equipment, Disruption::Effect, disruptionEffect, setDisruptionEffect)
KPUBLICTRANSPORT_MAKE_PROPERTY(Equipment, QStringList, notes, setNotes)
void Equipment::addNote(const QString& note)
{
const auto n = NotesUtil::normalizeNote(note);
const auto idx = NotesUtil::needsAdding(d->notes, n);
if (idx >= 0) {
d.detach();
NotesUtil::performAdd(d->notes, n, idx);
}
}
QJsonObject Equipment::toJson(const Equipment &equipment)
{
return Json::toJson(equipment);
}
Equipment Equipment::fromJson(const QJsonObject &obj)
{
return Json::fromJson<Equipment>(obj);
}
#include "moc_equipment.cpp"
/*
SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KPUBLICTRANSPORT_EQUIPMENT_H
#define KPUBLICTRANSPORT_EQUIPMENT_H
#include "kpublictransport_export.h"
#include "datatypes.h"
#include "disruption.h"
#include <QStringList>
class QJsonObject;
namespace KPublicTransport {
class EquipmentPrivate;
/** Status information about equipment such as elevators or escalators. */
class KPUBLICTRANSPORT_EXPORT Equipment
{
KPUBLICTRANSPORT_GADGET(Equipment)
public:
/** Type of equipment. */
enum Type {
Unknown,
Elevator,
Escalator,
};
Q_ENUM(Type)
KPUBLICTRANSPORT_PROPERTY(Type, type, setType)
/** Disruption effect on this section, if any. */
KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Disruption::Effect, disruptionEffect, setDisruptionEffect)
/** General human-readable notes on this service, e.g. details about a disruption. */
KPUBLICTRANSPORT_PROPERTY(QStringList, notes, setNotes)
public:
/** Adds a note. This will check for duplicates and normalize the notes. */
void addNote(const QString &note);
/** Serializes one object to JSON. */
static QJsonObject toJson(const Equipment &equipment);
/** Deserialize an object from JSON. */
static Equipment fromJson(const QJsonObject &obj);
};
}
Q_DECLARE_METATYPE(KPublicTransport::Equipment)
#endif // KPUBLICTRANSPORT_EQUIPMENT_H
/*
SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "equipmentutil.h"
#include "notesutil_p.h"
#include <KPublicTransport/Equipment>
using namespace KPublicTransport;
Equipment EquipmentUtil::merge(const Equipment &lhs, const Equipment &rhs)
{
auto e = lhs;
e.setDisruptionEffect(std::max(lhs.disruptionEffect(), rhs.disruptionEffect()));
e.setNotes(NotesUtil::mergeNotes(lhs.notes(), rhs.notes()));
e.setType(std::max(lhs.type(), rhs.type()));
return e;
}
/*
SPDX-FileCopyrightText: 2020 Volker Krause <vkrause@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef KPUBLICTRANSPORT_EQUIPMENTUTIL_P_H
#define KPUBLICTRANSPORT_EQUIPMENTUTIL_P_H
namespace KPublicTransport {
class Equipment;
/** Utilities for working with Equipment instances. */
namespace EquipmentUtil
{
Equipment merge(const Equipment &lhs, const Equipment &rhs);
}
}
#endif // KPUBLICTRANSPORT_EQUIPMENTUTIL_P_H
......@@ -7,6 +7,8 @@
#include "location.h"
#include "datatypes_p.h"
#include "equipment.h"
#include "equipmentutil.h"
#include "json_p.h"
#include "mergeutil_p.h"
#include "rentalvehicle.h"
......@@ -113,6 +115,11 @@ RentalVehicle Location::rentalVehicle() const
return d->data.value<RentalVehicle>();
}
KPublicTransport::Equipment Location::equipment() const
{
return d->data.value<KPublicTransport::Equipment>();
}
QHash<QString, QString> Location::identifiers() const
{
return d->ids;
......@@ -367,6 +374,9 @@ Location Location::merge(const Location &lhs, const Location &rhs)
case RentedVehicle:
l.setData(RentalVehicleUtil::merge(lhs.rentalVehicle(), rhs.rentalVehicle()));
break;
case Equipment:
l.setData(EquipmentUtil::merge(lhs.equipment(), rhs.equipment()));
break;
}
return l;
......@@ -420,6 +430,9 @@ QJsonObject Location::toJson(const Location &loc)
case RentedVehicle:
obj.insert(QStringLiteral("rentalVehicle"), RentalVehicle::toJson(loc.rentalVehicle()));
break;
case Equipment:
obj.insert(QStringLiteral("equipment"), Equipment::toJson(loc.equipment()));
break;
}
return obj;
......@@ -453,6 +466,9 @@ Location Location::fromJson(const QJsonObject &obj)
case RentedVehicle:
loc.setData(RentalVehicle::fromJson(obj.value(QLatin1String("rentalVehicle")).toObject()));
break;
case Equipment:
loc.setData(Equipment::fromJson(obj.value(QLatin1String("equipment")).toObject()));
break;
}
return loc;
......
......@@ -18,6 +18,7 @@ template <typename K, typename T> class QHash;
namespace KPublicTransport {
class LocationPrivate;
class Equipment;
class RentalVehicle;
class RentalVehicleStation;
......@@ -35,6 +36,7 @@ public:
Stop = 1, ///< a public transport stop (train station, bus stop, etc)
RentedVehicleStation = 2, ///< a pick-up/drop-off point for dock-based rental bike/scooter systems
RentedVehicle = 4, ///< a free-floating rental bike/scooter
Equipment = 8, ///< elevator/escalator
};
Q_ENUM(Type)
Q_DECLARE_FLAGS(Types, Type)
......@@ -72,6 +74,8 @@ public:
Q_PROPERTY(KPublicTransport::RentalVehicleStation rentalVehicleStation READ rentalVehicleStation STORED false)
/** Rental vehicle information, if applicable for this location. */
Q_PROPERTY(KPublicTransport::RentalVehicle rentalVehicle READ rentalVehicle STORED false)
/** Equipment information, if applicable for this location. */
Q_PROPERTY(KPublicTransport::Equipment equipment READ equipment STORED false)
public:
void setCoordinate(float latitude, float longitude);
......@@ -109,6 +113,7 @@ public:
RentalVehicleStation rentalVehicleStation() const;
[[deprecated("use setData instead")]] void setRentalVehicleStation(const RentalVehicleStation &dock);
RentalVehicle rentalVehicle() const;
KPublicTransport::Equipment equipment() const;
/** Serializes one Location object to JSON. */
static QJsonObject toJson(const Location &loc);
......
......@@ -11,6 +11,7 @@
#include <QQmlContext>
#include <KPublicTransport/BackendModel>
#include <KPublicTransport/Equipment>
#include <KPublicTransport/Journey>
#include <KPublicTransport/JourneyQueryModel>
#include <KPublicTransport/JourneyRequest>
......@@ -28,6 +29,7 @@
void KPublicTransportQmlPlugin::registerTypes(const char*)
{
qRegisterMetaType<KPublicTransport::Equipment>();
qRegisterMetaType<KPublicTransport::Line>();
qRegisterMetaType<KPublicTransport::LoadInfo>();
qRegisterMetaType<KPublicTransport::Location>();
......@@ -47,6 +49,7 @@ void KPublicTransportQmlPlugin::registerTypes(const char*)
qmlRegisterUncreatableType<KPublicTransport::VehicleSection>("org.kde.kpublictransport", 1, 0, "VehicleSection", {});
qmlRegisterUncreatableType<KPublicTransport::Platform>("org.kde.kpublictransport", 1, 0, "Platform", {});
qmlRegisterUncreatableType<KPublicTransport::RentalVehicle>("org.kde.kpublictransport", 1, 0, "RentalVehicle", {});
qmlRegisterUncreatableType<KPublicTransport::Equipment>("org.kde.kpublictransport", 1, 0, "Equipment", {});
qmlRegisterUncreatableType<KPublicTransport::JourneyRequest>("org.kde.kpublictransport", 1, 0, "JourneyRequest", {});
qmlRegisterUncreatableType<KPublicTransport::LocationRequest>("org.kde.kpublictransport", 1, 0, "LocationRequest", {});
......
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