Commit e0741a7b authored by Volker Krause's avatar Volker Krause
Browse files

Don't hardcode the IFOPT identifier type all over the place

parent a07ec8de
......@@ -33,12 +33,12 @@ static void parseCompactIfopt(ScopedXmlStreamReader &reader, Location &loc)
if (reader.name() == QLatin1String("pgid")) {
const auto id = reader.readElementText();
if (IfoptUtil::isValid(id)) {
loc.setIdentifier(QStringLiteral("ifopt"), id);
loc.setIdentifier(IfoptUtil::identifierType(), id);
}
} else if (reader.name() == QLatin1String("gid")) {
const auto id = reader.readElementText();
if (IfoptUtil::isValid(id) && loc.identifier(QStringLiteral("ifopt")).isEmpty()) {
loc.setIdentifier(QStringLiteral("ifopt"), id);
if (IfoptUtil::isValid(id) && loc.identifier(IfoptUtil::identifierType()).isEmpty()) {
loc.setIdentifier(IfoptUtil::identifierType(), id);
}
}
}
......@@ -350,9 +350,9 @@ JourneySection EfaCompactParser::parseTripSection(ScopedXmlStreamReader &&reader
loc.setCoordinate(coord[1].toFloat(), coord[0].toFloat());
if (IfoptUtil::isValid(stopParams[13])) {
loc.setIdentifier(QStringLiteral("ifopt"), stopParams[13]);
loc.setIdentifier(IfoptUtil::identifierType(), stopParams[13]);
} else if (IfoptUtil::isValid(stopParams[12])) {
loc.setIdentifier(QStringLiteral("ifopt"), stopParams[12]);
loc.setIdentifier(IfoptUtil::identifierType(), stopParams[12]);
}
const auto dt = QDateTime::fromString(stopParams[2] + stopParams[3], QStringLiteral("yyyyMMddhhmm"));
......
......@@ -45,7 +45,7 @@ void EfaXmlParser::parseLocationCommon(Location &loc, const ScopedXmlStreamReade
for (const auto &attr : {QLatin1String("pointGid"), QLatin1String("areaGid"), QLatin1String("gid")}) {
const auto id = reader.attributes().value(attr);
if (IfoptUtil::isValid(id)) {
loc.setIdentifier(QStringLiteral("ifopt"), id.toString());
loc.setIdentifier(IfoptUtil::identifierType(), id.toString());
break;
}
}
......
......@@ -7,6 +7,7 @@
#include "ivvassbackend.h"
#include "ivvassparser.h"
#include "cache.h"
#include "ifopt/ifoptutil.h"
#include <KPublicTransport/Journey>
#include <KPublicTransport/JourneyReply>
......@@ -34,7 +35,7 @@ AbstractBackend::Capabilities IvvAssBackend::capabilities() const
bool IvvAssBackend::needsLocationQuery(const Location &loc, AbstractBackend::QueryType type) const
{
Q_UNUSED(type);
return !loc.hasCoordinate() && loc.identifier(QStringLiteral("ifopt")).isEmpty();
return !loc.hasCoordinate() && loc.identifier(IfoptUtil::identifierType()).isEmpty();
}
bool IvvAssBackend::queryLocation(const LocationRequest &req, LocationReply *reply, QNetworkAccessManager *nam) const
......@@ -94,7 +95,7 @@ bool IvvAssBackend::queryStopover(const StopoverRequest &req, StopoverReply *rep
if (req.stop().hasCoordinate()) {
query.addQueryItem(QStringLiteral("r"), QString::number(req.stop().latitude()) + QLatin1Char(',') + QString::number(req.stop().longitude()));
} else {
query.addQueryItem(QStringLiteral("i"), req.stop().identifier(QStringLiteral("ifopt")));
query.addQueryItem(QStringLiteral("i"), req.stop().identifier(IfoptUtil::identifierType()));
}
query.addQueryItem(QStringLiteral("c"), QString::number(req.maximumResults()));
......@@ -138,7 +139,7 @@ static QString locationParameter(const Location &loc)
if (loc.hasCoordinate()) {
return QString::number(loc.latitude()) + QLatin1Char(',') + QString::number(loc.longitude());
}
return loc.identifier(QStringLiteral("ifopt"));
return loc.identifier(IfoptUtil::identifierType());
}
bool IvvAssBackend::queryJourney(const JourneyRequest &req, JourneyReply *reply, QNetworkAccessManager *nam) const
......
......@@ -52,9 +52,9 @@ IvvAssParser::LocationData IvvAssParser::parseLocation(const QJsonObject &stopOb
return r;
}
const auto id = stopObj.value(QLatin1String("ifopt")).toString();
const auto id = stopObj.value(IfoptUtil::identifierType()).toString();
if (IfoptUtil::isValid(id)) {
r.loc.setIdentifier(QStringLiteral("ifopt"), id);
r.loc.setIdentifier(IfoptUtil::identifierType(), id);
} else {
r.loc.setIdentifier(m_locationIdentifier, id);
}
......
......@@ -92,7 +92,7 @@ bool OpenTripPlannerParser::parseLocationFragment(const QJsonObject &obj, Locati
if (!m_ifoptPrefix.isEmpty() && id.size() > m_ifoptPrefix.size() + 1 && id.startsWith(m_ifoptPrefix) && id.at(m_ifoptPrefix.size()) == QLatin1Char(':')) {
const auto ifopt = QStringView(id).mid(m_ifoptPrefix.size() + 1);
if (IfoptUtil::isValid(ifopt)) {
loc.setIdentifier(QStringLiteral("ifopt"), ifopt.toString());
loc.setIdentifier(IfoptUtil::identifierType(), ifopt.toString());
}
}
......
......@@ -272,8 +272,8 @@ bool Location::isSame(const Location &lhs, const Location &rhs)
}
// ids - IFOPT takes priority here due to its special hierarchical handling, but only for stations
const auto lhsIfopt = lhs.identifier(QStringLiteral("ifopt"));
const auto rhsIfopt = rhs.identifier(QStringLiteral("ifopt"));
const auto lhsIfopt = lhs.identifier(IfoptUtil::identifierType());
const auto rhsIfopt = rhs.identifier(IfoptUtil::identifierType());
if (!lhsIfopt.isEmpty() && !rhsIfopt.isEmpty() && (lhs.type() == Location::Stop || rhs.type() == Location::Stop)) {
return IfoptUtil::isSameStopPlace(lhsIfopt, rhsIfopt);
}
......@@ -373,8 +373,8 @@ Location Location::merge(const Location &lhs, const Location &rhs)
// merge identifiers
const auto rhsIds = rhs.identifiers();
for (auto it = rhsIds.constBegin(); it != rhsIds.constEnd(); ++it) {
if (it.key() == QLatin1String("ifopt")) {
l.setIdentifier(QStringLiteral("ifopt"), IfoptUtil::merge(l.identifier(QStringLiteral("ifopt")), it.value()).toString());
if (it.key() == IfoptUtil::identifierType()) {
l.setIdentifier(IfoptUtil::identifierType(), IfoptUtil::merge(l.identifier(IfoptUtil::identifierType()), it.value()).toString());
continue;
}
if (lhs.identifier(it.key()).isEmpty()) {
......
......@@ -79,3 +79,8 @@ QStringView IfoptUtil::merge(QStringView lhs, QStringView rhs)
return stopPlace(lhs);
}
QString IfoptUtil::identifierType()
{
return QStringLiteral("ifopt");
}
......@@ -7,6 +7,7 @@
#ifndef KPUBLICTRANSPORT_IFOPTUTIL_H
#define KPUBLICTRANSPORT_IFOPTUTIL_H
class QString;
class QStringView;
namespace KPublicTransport {
......@@ -38,6 +39,9 @@ bool isSameStopPlace(QStringView lhs, QStringView rhs);
*/
QStringView merge(QStringView lhs, QStringView rhs);
/** The identifier type for use in @c Location::identifer for IFOPT ids. */
QString identifierType();
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment