Commit 15d5f367 authored by Volker Krause's avatar Volker Krause
Browse files

Export GPX waypoints for arrival/departure locations as well

Also, export stationary elements as waypoints rather than 0-length routes.
parent b7db61f7
......@@ -432,22 +432,10 @@ void ApplicationController::exportTripToGpx(const QString &tripGroupId, const QS
const auto tg = m_tripGroupMgr->tripGroup(tripGroupId);
const auto batches = tg.elements();
for (const auto &batchId : batches) {
exporter.writeStartRoute();
auto transfer = m_transferMgr->transfer(batchId, Transfer::Before);
if (transfer.state() == Transfer::Selected) {
exporter.writeTransfer(transfer);
}
const auto res = m_resMgr->reservation(batchId);
exporter.writeReservation(res, m_liveDataMgr->journey(batchId));
transfer = m_transferMgr->transfer(batchId, Transfer::After);
if (transfer.state() == Transfer::Selected) {
exporter.writeTransfer(transfer);
}
exporter.writeEndRoute();
const auto transferBefore = m_transferMgr->transfer(batchId, Transfer::Before);
const auto transferAfter = m_transferMgr->transfer(batchId, Transfer::After);
exporter.writeReservation(res, m_liveDataMgr->journey(batchId), transferBefore, transferAfter);
}
}
......
......@@ -12,7 +12,9 @@
#include <KItinerary/LocationUtil>
#include <KItinerary/Reservation>
#include <KItinerary/SortUtil>
#include <KItinerary/Visit>
#include <KPublicTransport/Journey>
#include <KPublicTransport/Stopover>
#include <KLocalizedString>
......@@ -30,44 +32,88 @@ GpxExport::GpxExport(QIODevice* out)
GpxExport::~GpxExport() = default;
void GpxExport::writeReservation(const QVariant &res, const KPublicTransport::JourneySection &journey)
void GpxExport::writeReservation(const QVariant &res, const KPublicTransport::JourneySection &journey, const Transfer &before, const Transfer &after)
{
if (LocationUtil::isLocationChange(res)) {
m_writer.writeStartRoute();
writeTransfer(before);
if (!journey.from().isEmpty() && !journey.to().isEmpty()) {
writeJourneySection(journey);
} else {
const auto dep = LocationUtil::departureLocation(res);
auto coord = LocationUtil::geo(dep);
m_writer.writeStartRoutePoint(coord.latitude(), coord.longitude());
m_writer.writeName(LocationUtil::name(dep));
m_writer.writeTime(SortUtil::startDateTime(res));
m_writer.writeEndRoutePoint();
if (coord.isValid()) {
m_writer.writeStartRoutePoint(coord.latitude(), coord.longitude());
m_writer.writeName(LocationUtil::name(dep));
m_writer.writeTime(SortUtil::startDateTime(res));
m_writer.writeEndRoutePoint();
}
const auto arr = LocationUtil::arrivalLocation(res);
coord = LocationUtil::geo(arr);
m_writer.writeStartRoutePoint(coord.latitude(), coord.longitude());
if (coord.isValid()) {
m_writer.writeStartRoutePoint(coord.latitude(), coord.longitude());
m_writer.writeName(LocationUtil::name(arr));
m_writer.writeTime(SortUtil::endDateTime(res));
m_writer.writeEndRoutePoint();
}
}
writeTransfer(after);
m_writer.writeEndRoute();
// waypoints for departure/arrival
const auto dep = LocationUtil::departureLocation(res);
auto coord = LocationUtil::geo(dep);
if (coord.isValid()) {
m_writer.writeStartWaypoint(coord.latitude(), coord.longitude());
m_writer.writeName(LocationUtil::name(dep));
m_writer.writeTime(SortUtil::startDateTime(res));
m_writer.writeEndWaypoint();
}
const auto arr = LocationUtil::arrivalLocation(res);
coord = LocationUtil::geo(arr);
if (coord.isValid()) {
m_writer.writeStartWaypoint(coord.latitude(), coord.longitude());
m_writer.writeName(LocationUtil::name(arr));
m_writer.writeTime(SortUtil::endDateTime(res));
m_writer.writeEndRoutePoint();
}
} else {
if (JsonLd::isA<LodgingReservation>(res)) {
m_writer.writeName(res.value<LodgingReservation>().reservationFor().value<LodgingBusiness>().name());
} else if (JsonLd::isA<EventReservation>(res)) {
m_writer.writeName(res.value<EventReservation>().reservationFor().value<Event>().name());
} else if (JsonLd::isA<FoodEstablishmentReservation>(res)) {
m_writer.writeName(res.value<FoodEstablishmentReservation>().reservationFor().value<FoodEstablishment>().name());
m_writer.writeEndWaypoint();
}
} else {
writeSelfContainedTransfer(before);
const auto loc = LocationUtil::location(res);
const auto coord = LocationUtil::geo(loc);
m_writer.writeStartRoutePoint(coord.latitude(), coord.longitude());
m_writer.writeEndRoutePoint();
m_writer.writeStartRoutePoint(coord.latitude(), coord.longitude());
m_writer.writeEndRoutePoint();
if (coord.isValid()) {
m_writer.writeStartWaypoint(coord.latitude(), coord.longitude());
if (JsonLd::isA<LodgingReservation>(res)) {
m_writer.writeName(res.value<LodgingReservation>().reservationFor().value<LodgingBusiness>().name());
} else if (JsonLd::isA<EventReservation>(res)) {
m_writer.writeName(res.value<EventReservation>().reservationFor().value<Event>().name());
} else if (JsonLd::isA<FoodEstablishmentReservation>(res)) {
m_writer.writeName(res.value<FoodEstablishmentReservation>().reservationFor().value<FoodEstablishment>().name());
} else if (JsonLd::isA<TouristAttractionVisit>(res)) {
m_writer.writeName(res.value<TouristAttractionVisit>().touristAttraction().name());
}
m_writer.writeTime(SortUtil::startDateTime(res));
m_writer.writeEndWaypoint();
}
writeSelfContainedTransfer(after);
}
}
void GpxExport::writeSelfContainedTransfer(const Transfer& transfer)
{
if (transfer.state() != Transfer::Selected) {
return;
}
m_writer.writeStartRoute();
// TODO name
writeTransfer(transfer);
m_writer.writeEndRoute();
}
void GpxExport::writeTransfer(const Transfer &transfer)
{
const auto journey = transfer.journey();
......
......@@ -7,10 +7,12 @@
#ifndef GPXEXPORT_H
#define GPXEXPORT_H
#include <KPublicTransport/Journey>
#include <gpx/gpxwriter.h>
namespace KPublicTransport {
class JourneySection;
}
class FavoriteLocation;
class Transfer;
......@@ -21,14 +23,12 @@ public:
explicit GpxExport(QIODevice *out);
~GpxExport();
void writeReservation(const QVariant &res, const KPublicTransport::JourneySection &journey = {});
void writeTransfer(const Transfer &transfer);
void writeReservation(const QVariant &res, const KPublicTransport::JourneySection &journey, const Transfer &before, const Transfer &after);
void writeFavoriteLocation(const FavoriteLocation &fav);
inline void writeStartRoute() { m_writer.writeStartRoute(); }
inline void writeEndRoute() { m_writer.writeEndRoute(); }
private:
void writeSelfContainedTransfer(const Transfer &transfer);
void writeTransfer(const Transfer &transfer);
void writeJourneySection(const KPublicTransport::JourneySection &section);
Gpx::Writer m_writer;
......
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