KPublicTransport

journeyutil.cpp
1 /*
2  SPDX-FileCopyrightText: 2019 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "journeyutil_p.h"
8 #include "lineutil_p.h"
9 #include "stopoverutil_p.h"
10 #include "timeutil_p.h"
11 
12 #include <KPublicTransport/Journey>
13 #include <KPublicTransport/Stopover>
14 
15 #include <QDateTime>
16 #include <QTimeZone>
17 
18 using namespace KPublicTransport;
19 
20 QDateTime JourneyUtil::firstTransportDeparture(const Journey &jny)
21 {
22  for (const auto &section : jny.sections()) {
23  if (section.mode() == JourneySection::PublicTransport) {
24  return section.scheduledDepartureTime();
25  }
26  }
27 
28  return jny.scheduledDepartureTime();
29 }
30 
31 bool JourneyUtil::firstTransportDepartureLessThan(const Journey &lhs, const Journey &rhs)
32 {
33  return firstTransportDeparture(lhs) < firstTransportDeparture(rhs);
34 }
35 
36 bool JourneyUtil::firstTransportDepartureEqual(const Journey &lhs, const Journey &rhs)
37 {
38  return firstTransportDeparture(lhs) == firstTransportDeparture(rhs);
39 }
40 
41 void JourneyUtil::applyTimeZone(Journey &jny, const QTimeZone &tz)
42 {
43  auto sections = std::move(jny.takeSections());
44  for (auto &sec : sections) {
45  sec.setScheduledDepartureTime(TimeUtil::applyTimeZone(sec.scheduledDepartureTime(), tz));
46  sec.setExpectedDepartureTime(TimeUtil::applyTimeZone(sec.expectedDepartureTime(), tz));
47  sec.setScheduledArrivalTime(TimeUtil::applyTimeZone(sec.scheduledArrivalTime(), tz));
48  sec.setExpectedArrivalTime(TimeUtil::applyTimeZone(sec.expectedArrivalTime(), tz));
49 
50  auto stops = sec.takeIntermediateStops();
51  for (auto &stop : stops) {
52  StopoverUtil::applyTimeZone(stop, tz);
53  }
54  sec.setIntermediateStops(std::move(stops));
55  }
56  jny.setSections(std::move(sections));
57 }
58 
59 void JourneyUtil::applyMetaData(Journey &jny, bool download)
60 {
61  auto sections = std::move(jny.takeSections());
62  for (auto &sec : sections) {
63  if (!sec.from().hasCoordinate() || sec.mode() != JourneySection::PublicTransport) {
64  continue;
65  }
66  auto route = sec.route();
67  auto line = route.line();
68  LineUtil::applyMetaData(line, sec.from(), download);
69  route.setLine(line);
70  sec.setRoute(route);
71 
72  // propagate to intermediate stops
73  auto stops = sec.takeIntermediateStops();
74  for (auto &stop : stops) {
75  stop.setRoute(route);
76  }
77  sec.setIntermediateStops(std::move(stops));
78  }
79  jny.setSections(std::move(sections));
80 }
QDateTime scheduledDepartureTime
Departure time of the journey, according to schedule.
Definition: journey.h:235
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
QVariantList sections
Journey sections for consumption by QML.
Definition: journey.h:233
void setSections(std::vector< JourneySection > &&sections)
Sets the journey sections.
Definition: journey.cpp:543
KGuiItem stop()
std::vector< JourneySection > && takeSections()
Moves the journey sections out of this object.
Definition: journey.cpp:537
A journey plan.
Definition: journey.h:229
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Oct 15 2021 23:07:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.