File indexing completed on 2024-12-08 07:19:12
0001 /* 0002 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #include "vehiclelayoutrequest.h" 0008 #include "datatypes/locationutil_p.h" 0009 #include "datatypes/datatypes_p.h" 0010 #include "datatypes/stopover.h" 0011 #include "datatypes/journey.h" 0012 #include "datatypes/json_p.h" 0013 0014 #include <QStringList> 0015 0016 using namespace KPublicTransport; 0017 0018 enum { StopoverCacheTimeResolution = 60 }; // in seconds 0019 0020 namespace KPublicTransport { 0021 0022 class VehicleLayoutRequestPrivate : public QSharedData 0023 { 0024 public: 0025 Stopover stopover; 0026 QStringList backendIds; 0027 }; 0028 0029 } 0030 0031 KPUBLICTRANSPORT_MAKE_GADGET(VehicleLayoutRequest) 0032 KPUBLICTRANSPORT_MAKE_PROPERTY(VehicleLayoutRequest, Stopover, stopover, setStopover) 0033 0034 VehicleLayoutRequest::VehicleLayoutRequest(const Stopover &stopover) 0035 : d(new VehicleLayoutRequestPrivate) 0036 { 0037 d->stopover = stopover; 0038 } 0039 0040 bool VehicleLayoutRequest::isValid() const 0041 { 0042 return (d->stopover.scheduledDepartureTime().isValid() || d->stopover.scheduledArrivalTime().isValid()) && !d->stopover.route().line().name().isEmpty(); 0043 } 0044 0045 QString VehicleLayoutRequest::cacheKey() const 0046 { 0047 return QString::number(d->stopover.scheduledDepartureTime().toSecsSinceEpoch() / StopoverCacheTimeResolution) + QLatin1Char('_') 0048 + LocationUtil::cacheKey(d->stopover.stopPoint()); 0049 } 0050 0051 QJsonObject VehicleLayoutRequest::toJson(const VehicleLayoutRequest &req) 0052 { 0053 auto obj = Json::toJson(req); 0054 obj.insert(QLatin1String("stopover"), Stopover::toJson(req.stopover())); 0055 return obj; 0056 } 0057 0058 QStringList VehicleLayoutRequest::backendIds() const 0059 { 0060 return d->backendIds; 0061 } 0062 0063 void VehicleLayoutRequest::setBackendIds(const QStringList &backendIds) 0064 { 0065 d.detach(); 0066 d->backendIds = backendIds; 0067 } 0068 0069 #include "moc_vehiclelayoutrequest.cpp"