KPublicTransport

journeyrequest.h
1/*
2 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#ifndef KPUBLICTRANSPORT_JOURNEYREQUEST_H
8#define KPUBLICTRANSPORT_JOURNEYREQUEST_H
9
10#include "kpublictransport_export.h"
11
12#include <KPublicTransport/Datatypes>
13#include <KPublicTransport/IndividualTransport>
14#include <KPublicTransport/Journey>
15
16#include <QMetaType>
17#include <QSharedDataPointer>
18#include <QVariant>
19
20#include <vector>
21
22class QDateTime;
23
24namespace KPublicTransport {
25
26class AbstractBackend;
27class JourneyReply;
28class JourneyRequestPrivate;
29class Location;
30class Manager;
31class RequestContext;
32
33/** Describes a journey search.
34 * By default journeys departing now are searched.
35 */
36class KPUBLICTRANSPORT_EXPORT JourneyRequest
37{
38 KPUBLICTRANSPORT_GADGET(JourneyRequest)
39
40 /** The starting point of the journey search. */
41 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Location, from, setFrom)
42 /** The journey destination. */
43 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::Location, to, setTo)
44 /** Date/time at which the journey should start/end. */
45 KPUBLICTRANSPORT_PROPERTY(QDateTime, dateTime, setDateTime)
46
47 /** Modes of transportation that should be considered for this query.
48 * Only transit modes matter (public transport, rented vehicles, etc),
49 * values for tranfers/waits/etc are ignored.
50 */
51 KPUBLICTRANSPORT_PROPERTY(KPublicTransport::JourneySection::Modes, modes, setModes)
52 /** The maximum amount of expected results.
53 * @note This is only an optimization hint for backends, not a guarantee
54 * that all results comply with this constraint.
55 */
56 KPUBLICTRANSPORT_PROPERTY(int, maximumResults, setMaximumResults)
57 /** Retrieve intermediate stops for the queried journeys as well.
58 * @note This is only an optimization hint for backends, not a guarantee
59 * that all results will contain this information.
60 */
61 KPUBLICTRANSPORT_PROPERTY(bool, includeIntermediateStops, setIncludeIntermediateStops)
62 /** Retrieve path details for the journeys.
63 * @note This is only an optimization hint for backends, not a guarantee
64 * that all results will contain this information.
65 */
66 KPUBLICTRANSPORT_PROPERTY(bool, includePaths, setIncludePaths)
67
68 /** Access modes. */
69 Q_PROPERTY(QVariantList accessModes READ accessModesVariant WRITE setAccessModesVariant)
70 /** Egress modes. */
71 Q_PROPERTY(QVariantList egressModes READ egressModesVariant WRITE setEgressModesVariant)
72
73 /** Line modes. */
74 Q_PROPERTY(QVariantList lineModes READ lineModesVariant WRITE setLineModesVariant)
75
76public:
78 Arrival, ///< dateTime() represents the desired arriva time.
79 Departure ///< dateTime() represents the desired departure time.
80 };
81 Q_ENUM(DateTimeMode)
82 /** Controls whether to search for journeys starting or ending at the given time. */
83 KPUBLICTRANSPORT_PROPERTY(DateTimeMode, dateTimeMode, setDateTimeMode)
84
85 Q_PROPERTY(QStringList backends READ backendIds WRITE setBackendIds)
86
87 /** Download graphic assets such as line logos for the data requested here.
88 * Default: @c false
89 */
90 KPUBLICTRANSPORT_PROPERTY(bool, downloadAssets, setDownloadAssets)
91
92public:
93 /** Search a journey from @p from to @p to. */
94 JourneyRequest(const Location &from, const Location &to);
95
96 /** Returns @c true if this is a valid request, that is, it has enough parameters set to perform a query. */
97 bool isValid() const;
98
99 /** Set the desired departure time.
100 * This is mutually exclusive to setting a desired arrival time.
101 */
102 void setDepartureTime(const QDateTime &dt);
103 /** Sets the desired arrival time.
104 * This is mutually exclusive to setting a desired departure time.
105 */
106 void setArrivalTime(const QDateTime &dt);
107
108 /** Identifiers of the backends that should be queried.
109 * @see setBackendIds()
110 */
111 QStringList backendIds() const;
112 /** Set identifiers of backends that should be queried.
113 * Settings this is only needed when you want explicit control over this, leaving
114 * this empty picks suitable backends automatically.
115 */
116 void setBackendIds(const QStringList &backendIds);
117
118 /** Requested access modes.
119 * That is individual transport modes on the first (access) leg of the journey.
120 * Default: walking
121 */
122 const std::vector<IndividualTransport>& accessModes() const;
123 /** Sets the requested access modes. */
124 void setAccessModes(std::vector<IndividualTransport> &&accessModes);
125
126 /** Requested egress modes.
127 * That is, individual transport modes for the last (egress) leg of the journey.
128 * Default: walking
129 */
130 const std::vector<IndividualTransport>& egressModes() const;
131 /** Sets the requested egress modes. */
132 void setEgressModes(std::vector<IndividualTransport> &&egressModes);
133
134 /** Requested line modes.
135 * That is, the possible types of public transport lines to consider for public
136 * transports sections of the journey.
137 * Default: all
138 */
139 const std::vector<Line::Mode>& lineModes() const;
140 /** Sets the requested line modes.
141 * An empty list is considered as all modes being allowed.
142 * @note This relies on backends actually supporting this and is thus does not
143 * provide any guarantee that the results wont contain other modes as well.
144 */
145 void setLineModes(std::vector <Line::Mode> &&modes);
146
147 /** Unique string representation used for caching results. */
148 QString cacheKey() const;
149
150 ///@cond internal
151 static QJsonObject toJson(const JourneyRequest &req);
152 ///@endcond
153private:
154 friend class AbstractBackend;
155 friend class JourneyReply;
156 friend class JourneyReplyPrivate;
157 friend class Manager;
158 friend class JourneyRequestTest;
159
160 Q_DECL_HIDDEN QVariantList accessModesVariant() const;
161 Q_DECL_HIDDEN void setAccessModesVariant(const QVariantList &accessModesVariant);
162 Q_DECL_HIDDEN QVariantList egressModesVariant() const;
163 Q_DECL_HIDDEN void setEgressModesVariant(const QVariantList &egressModesVariant);
164 Q_DECL_HIDDEN QVariantList lineModesVariant() const;
165 Q_DECL_HIDDEN void setLineModesVariant(const QVariantList &modes);
166
167 Q_DECL_HIDDEN RequestContext context(const AbstractBackend *backend) const;
168 Q_DECL_HIDDEN const std::vector<RequestContext>& contexts() const;
169 Q_DECL_HIDDEN void setContext(const AbstractBackend *backend, RequestContext &&context);
170 Q_DECL_HIDDEN void purgeLoops(const JourneyRequest &baseRequest);
171
172 /** Check that the given request parameters are semantically sane, and fix that if needed. */
173 void validate() const;
174};
175
176}
177
178Q_DECLARE_METATYPE(KPublicTransport::JourneyRequest)
179
180#endif // KPUBLICTRANSPORT_JOURNEYREQUEST_H
Individual transport mode details for a journey section, and for specifying journey requests.
Journey query response.
Describes a journey search.
@ Arrival
dateTime() represents the desired arriva time.
A segment of a journey plan.
Definition journey.h:32
A public transport line.
Definition line.h:20
Entry point for starting public transport queries.
Definition manager.h:42
Query operations and data types for accessing realtime public transport information from online servi...
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:06 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.