KPublicTransport

lineutil.cpp
1 /*
2  SPDX-FileCopyrightText: 2018 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "lineutil_p.h"
8 #include "linecompare_p.h"
9 #include "assetrepository_p.h"
10 
11 #include <knowledgedb/linemetadata.h>
12 
13 #include <KPublicTransport/Location>
14 
15 #include <QColor>
16 #include <QDebug>
17 #include <QString>
18 #include <QUrl>
19 
20 using namespace KPublicTransport;
21 
22 bool LineUtil::isSameLineNameStrict(const QString &lhs, const QString &rhs)
23 {
24  return Internal::isSameLineName(lhs, rhs, Internal::StrictCompare);
25 }
26 
27 bool LineUtil::isSameLineNameFuzzy(const QString &lhs, const QString &rhs)
28 {
29  return Internal::isSameLineName(lhs, rhs, Internal::FuzzyCompare);
30 }
31 
32 bool LineUtil::isCompatibleMode(Line::Mode lhs, Line::Mode rhs)
33 {
34  if (lhs == rhs || lhs == Line::Unknown || rhs == Line::Unknown) {
35  return true;
36  }
37 
38  if (lhs == Line::Train) {
39  return rhs == Line::LocalTrain || rhs == Line::LongDistanceTrain || rhs == Line::RapidTransit;
40  }
41  if (rhs == Line::Train) {
42  return lhs == Line::LocalTrain || lhs == Line::LongDistanceTrain || lhs == Line::RapidTransit;
43  }
44 
45  return false;
46 }
47 
48 void LineUtil::applyMetaData(Line &line, const Location &loc, bool download)
49 {
50  if (line.name().isEmpty() || !loc.hasCoordinate()) {
51  return;
52  }
53 
54  auto metaData = LineMetaData::find(loc.latitude(), loc.longitude(), line.name(), line.mode());
55  setMetaData(line, metaData);
56 
57  if (download && AssetRepository::instance()) {
58  AssetRepository::instance()->download(metaData.logoUrl());
59  AssetRepository::instance()->download(metaData.modeLogoUrl());
60  }
61 }
62 
63 void LineUtil::setMetaData(Line& line, const LineMetaData &metaData)
64 {
65  line.setMetaData(metaData);
66 }
Query operations and data types for accessing realtime public transport information from online servi...
Definition: attribution.cpp:16
float latitude
Latitude of the location, in degree, NaN if unknown.
Definition: location.h:52
QString name
Name of the line.
Definition: line.h:54
Mode
Mode of transportation.
Definition: line.h:31
KCOREADDONS_EXPORT void setMetaData(const MetaDataMap &metaData, QMimeData *mimeData)
float longitude
Longitude of the location, in degree, NaN if unknown.
Definition: location.h:54
bool isEmpty() const const
KPublicTransport::Line::Mode mode
Type of transport.
Definition: line.h:64
static LineMetaData find(double latitude, double longitude, const QString &name, Line::Mode mode)
Attempts to find information about a line with the given name and a stop at the given coordinates...
Static information about a public transport line.
Definition: linemetadata.h:25
A public transport line.
Definition: line.h:23
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Oct 15 2021 23:07:28 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.