KPublicTransport

attribution.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 "attribution.h"
8#include "datatypes_p.h"
9#include "json_p.h"
10
11#include <QString>
12#include <QUrl>
13
14using namespace KPublicTransport;
15
17
18class AttributionPrivate : public QSharedData {
19public:
20 QString name;
21 QUrl url;
22 QString license;
23 QUrl licenseUrl;
24};
25}
26
27KPUBLICTRANSPORT_MAKE_GADGET(Attribution)
28KPUBLICTRANSPORT_MAKE_PROPERTY(Attribution, QString, name, setName)
29KPUBLICTRANSPORT_MAKE_PROPERTY(Attribution, QUrl, url, setUrl)
30KPUBLICTRANSPORT_MAKE_PROPERTY(Attribution, QString, license, setLicense)
31KPUBLICTRANSPORT_MAKE_PROPERTY(Attribution, QUrl, licenseUrl, setLicenseUrl)
32
33bool Attribution::isEmpty() const
34{
35 return d->name.isEmpty() && d->license.isEmpty();
36}
37
38bool Attribution::hasLicense() const
39{
40 return !d->license.isEmpty() || !d->licenseUrl.isEmpty();
41}
42
43std::vector<Attribution> Attribution::fromJson(const QJsonArray &a)
44{
45 return Json::fromJson<Attribution>(a);
46}
47
49{
50 // read compatibility with github.com/public-transport/transport-apis
51 if (obj.value(QLatin1String("isProprietary")).toBool() == true) {
52 return {};
53 }
54
55 auto attr = Json::fromJson<Attribution>(obj);
56 if (attr.url().isEmpty()) {
57 attr.setUrl(QUrl(obj.value(QLatin1String("homepage")).toString()));
58 }
59
60 return attr;
61}
62
63QJsonArray Attribution::toJson(const std::vector<Attribution> &attrs)
64{
65 return Json::toJson(attrs);
66}
67
69{
70 return Json::toJson(attr);
71}
72
73#include "moc_attribution.cpp"
Copyright and license information about the provided data.
Definition attribution.h:29
bool hasLicense
true if there is license information for this attribution object.
Definition attribution.h:41
QString name
Name of the entity providing the data.
Definition attribution.h:32
static Attribution fromJson(const QJsonObject &obj)
Deserialize an Attribution object from JSON.
static QJsonObject toJson(const Attribution &attr)
Serializes one Attribution object to JSON.
Query operations and data types for accessing realtime public transport information from online servi...
QJsonValue value(QLatin1StringView key) const const
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:57 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.