KPublicTransport

attribution.cpp
1 /*
2  SPDX-FileCopyrightText: 2019 Volker Krause <[email protected]>
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 
14 using namespace KPublicTransport;
15 
16 namespace KPublicTransport {
17 
18 class AttributionPrivate : public QSharedData {
19 public:
20  QString name;
21  QUrl url;
22  QString license;
23  QUrl licenseUrl;
24 };
25 }
26 
27 KPUBLICTRANSPORT_MAKE_GADGET(Attribution)
28 KPUBLICTRANSPORT_MAKE_PROPERTY(Attribution, QString, name, setName)
29 KPUBLICTRANSPORT_MAKE_PROPERTY(Attribution, QUrl, url, setUrl)
30 KPUBLICTRANSPORT_MAKE_PROPERTY(Attribution, QString, license, setLicense)
31 KPUBLICTRANSPORT_MAKE_PROPERTY(Attribution, QUrl, licenseUrl, setLicenseUrl)
32 
33 bool Attribution::isEmpty() const
34 {
35  return d->name.isEmpty() && d->license.isEmpty();
36 }
37 
38 bool Attribution::hasLicense() const
39 {
40  return !d->license.isEmpty() || !d->licenseUrl.isEmpty();
41 }
42 
43 std::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 
63 QJsonArray 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"
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
static Attribution fromJson(const QJsonObject &obj)
Deserialize an Attribution object from JSON.
Definition: attribution.cpp:48
QString toString() const const
bool isEmpty() const const
bool toBool(bool defaultValue) const const
Copyright and license information about the provided data.
Definition: attribution.h:28
QString name
Name of the entity providing the data.
Definition: attribution.h:32
QJsonValue value(const QString &key) const const
static QJsonObject toJson(const Attribution &attr)
Serializes one Attribution object to JSON.
Definition: attribution.cpp:68
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Oct 23 2021 23:05:20 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.