KPublicTransport

vehiclelayoutrequest.cpp
1 /*
2  SPDX-FileCopyrightText: 2019 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "vehiclelayoutrequest.h"
8 #include "datatypes/locationutil_p.h"
9 #include "datatypes/datatypes_p.h"
10 #include "datatypes/stopover.h"
11 #include "datatypes/journey.h"
12 #include "datatypes/json_p.h"
13 
14 #include <QStringList>
15 
16 using namespace KPublicTransport;
17 
18 enum { StopoverCacheTimeResolution = 60 }; // in seconds
19 
20 namespace KPublicTransport {
21 
22 class VehicleLayoutRequestPrivate : public QSharedData
23 {
24 public:
25  Stopover stopover;
26  QStringList backendIds;
27 };
28 
29 }
30 
31 KPUBLICTRANSPORT_MAKE_GADGET(VehicleLayoutRequest)
32 KPUBLICTRANSPORT_MAKE_PROPERTY(VehicleLayoutRequest, Stopover, stopover, setStopover)
33 
34 VehicleLayoutRequest::VehicleLayoutRequest(const Stopover &stopover)
35  : d(new VehicleLayoutRequestPrivate)
36 {
37  d->stopover = stopover;
38 }
39 
41 {
42  return (d->stopover.scheduledDepartureTime().isValid() || d->stopover.scheduledArrivalTime().isValid()) && !d->stopover.route().line().name().isEmpty();
43 }
44 
46 {
47  return QString::number(d->stopover.scheduledDepartureTime().toSecsSinceEpoch() / StopoverCacheTimeResolution) + QLatin1Char('_')
48  + LocationUtil::cacheKey(d->stopover.stopPoint());
49 }
50 
51 QJsonObject VehicleLayoutRequest::toJson(const VehicleLayoutRequest &req)
52 {
53  auto obj = Json::toJson(req);
54  obj.insert(QLatin1String("stopover"), Stopover::toJson(req.stopover()));
55  return obj;
56 }
57 
59 {
60  return d->backendIds;
61 }
62 
64 {
65  d.detach();
66  d->backendIds = backendIds;
67 }
68 
69 #include "moc_vehiclelayoutrequest.cpp"
KPublicTransport::Stopover stopover
The stopover vehicle and platform layout information are requested for.
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
static QJsonObject toJson(const Stopover &stopover)
Serializes one object to JSON.
Definition: stopover.cpp:209
QString number(int n, int base)
bool isValid() const
Returns true if this is a valid request, that is it has enough parameters set to perform a query...
QString cacheKey() const
Unique string representation used for caching results.
Describes a query for vehicle layout information.
Information about an arrival and/or departure of a vehicle at a stop area.
Definition: stopover.h:25
void setBackendIds(const QStringList &backendIds)
Set identifiers of backends that should be queried.
QStringList backendIds() const
Identifiers of the backends that should be queried.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:05:21 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.