KPublicTransport

vehiclelayoutrequest.cpp
1/*
2 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
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
16using namespace KPublicTransport;
17
18enum { StopoverCacheTimeResolution = 60 }; // in seconds
19
20namespace KPublicTransport {
21
22class VehicleLayoutRequestPrivate : public QSharedData
23{
24public:
25 Stopover stopover;
26 QStringList backendIds;
27};
28
29}
30
31KPUBLICTRANSPORT_MAKE_GADGET(VehicleLayoutRequest)
32KPUBLICTRANSPORT_MAKE_PROPERTY(VehicleLayoutRequest, Stopover, stopover, setStopover)
33
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
51QJsonObject 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"
Information about an arrival and/or departure of a vehicle at a stop area.
Definition stopover.h:26
static QJsonObject toJson(const Stopover &stopover)
Serializes one object to JSON.
Definition stopover.cpp:216
Describes a query for vehicle layout information.
QString cacheKey() const
Unique string representation used for caching results.
bool isValid() const
Returns true if this is a valid request, that is it has enough parameters set to perform a query.
void setBackendIds(const QStringList &backendIds)
Set identifiers of backends that should be queried.
QStringList backendIds() const
Identifiers of the backends that should be queried.
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...
QString number(double n, char format, int precision)
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.