8#include "datatypes_p.h"
10#include "../geo/geojson_p.h"
25 int startFloorLevel = std::numeric_limits<int>::lowest();
26 int floorLevelChange = 0;
34KPUBLICTRANSPORT_MAKE_PROPERTY(
PathSection,
int, startFloorLevel, setStartFloorLevel)
35KPUBLICTRANSPORT_MAKE_PROPERTY(
PathSection,
int, floorLevelChange, setFloorLevelChange)
40 if (d->path.size() < 2) {
45 for (
auto it = d->path.begin(); it != std::prev(d->path.end()); ++it) {
46 const auto nextIt = std::next(it);
47 dist += Location::distance((*it).y(), (*it).x(), (*nextIt).y(), (*nextIt).x());
49 return (
int)std::round(dist);
56 if (d->path.size() < 2 || p1 == p2) {
59 return static_cast<int>(450 -
QLineF(p1.x(), -p1.y(), p2.x(), -p2.y()).
angle()) % 360;
64 return d->startFloorLevel > std::numeric_limits<int>::lowest() && d->startFloorLevel < std::numeric_limits<int>::max();
69 return d->path.empty() ?
QPointF() : d->path.constFirst();
74 return d->path.empty() ?
QPointF() : d->path.constLast();
81 return u
"qrc:///org.kde.kpublictransport/assets/images/transport-mode-walk.svg"_s;
83 return u
"qrc:///org.kde.kpublictransport/assets/images/path-elevator.svg"_s;
85 return u
"qrc:///org.kde.kpublictransport/assets/images/path-escalator.svg"_s;
87 return u
"qrc:///org.kde.kpublictransport/assets/images/path-stairs.svg"_s;
100 auto obj = Json::toJson(section);
102 obj.insert(
"path"_L1, GeoJson::writeLineString(section.
path()));
105 obj.remove(
"maneuver"_L1);
108 obj.remove(
"startFloorLevel"_L1);
111 obj.remove(
"floorLevelChange"_L1);
118 return Json::toJson(sections);
123 auto section = Json::fromJson<PathSection>(obj);
124 section.setPath(GeoJson::readLineString(obj.
value(
"path"_L1).
toObject()));
130 return Json::fromJson<PathSection>(array);
137 std::vector<PathSection> sections;
141KPUBLICTRANSPORT_MAKE_GADGET(
Path)
156 return std::move(d->sections);
167 return std::accumulate(d->sections.begin(), d->sections.end(), 0, [](
int d,
const auto &sec) { return d + sec.distance(); });
182 auto obj = Json::toJson(path);
189 auto path = Json::fromJson<Path>(obj);
196 return (
int)d->sections.size();
199#include "moc_path.cpp"
static Q_INVOKABLE QString maneuverIconName(KPublicTransport::PathSection::Maneuver maneuver)
An icon representing maneuver.
Maneuver
Maneuver associated with a path section.
@ Elevator
Take an elevator.
@ Escalator
Take an escalator.
@ Move
Move/drive with the default mode of transport for this path.
@ Stairs
Walk up or down stairs.
QString iconName
An icon representing the maneuver.
bool hasStartFloorLevel
Indicates an absolute start floor level is known.
QPolygonF path
The geo coordinate poly-line followed by this path section.
static QJsonObject toJson(const PathSection §ion)
Serializes one path section section to JSON.
QPointF startPoint
First point on the path of this section.
QPointF endPoint
Last point on the path of this section.
int floorLevelChange
Floor level change during this path section.
static PathSection fromJson(const QJsonObject &obj)
Deserialize an object from JSON.
int direction
The overall direction of this section in degree.
Maneuver maneuver
Movement maneuver for this path section.
A path followed by any kind of location change.
std::vector< PathSection > && takeSections()
Moves the path sections out of this object.
QPointF endPoint
Last point on this path.
int sectionCount
Number of path sections for QML.
int distance
The length of this path in meters.
bool isEmpty() const
Returns true if this is an empty/not-set path.
QPointF startPoint
First point on this path.
static Path fromJson(const QJsonObject &obj)
Deserialize an object from JSON.
void setSections(std::vector< PathSection > &§ions)
Sets the path sections.
static QJsonObject toJson(const Path &path)
Serializes one path object to JSON.
std::vector< KPublicTransport::PathSection > sections
Access to path sections for QML.
Query operations and data types for accessing realtime public transport information from online servi...
QJsonValue value(QLatin1StringView key) const const
QJsonArray toArray() const const
QJsonObject toObject() const const
qreal angle() const const