Commit 0f7e6930 authored by Volker Krause's avatar Volker Krause
Browse files

Split up EFA parse polygon parsing

Needed for handling transfer sections.
parent e354c250
......@@ -379,7 +379,7 @@ JourneySection EfaCompactParser::parseTripSection(ScopedXmlStreamReader &&reader
}
section.setIntermediateStops(std::move(stops));
} else if (reader.name() == QLatin1String("pt")) {
section.setPath(parsePathCoordinatesElement(reader));
section.setPath(polygonToPath(parsePathCoordinatesElement(reader)));
}
// TODO interchange tag - should we turn this into transfer sections?
}
......
......@@ -60,7 +60,7 @@ Line::Mode EfaParser::motTypeToLineMode(int mot)
return Line::Unknown;
}
Path EfaParser::parsePathCoordinatesElement(ScopedXmlStreamReader &reader)
QPolygonF EfaParser::parsePathCoordinatesElement(ScopedXmlStreamReader &reader)
{
QPolygonF poly;
// TODO do we need to support the format attributes, or is this always the same anyway?
......@@ -72,7 +72,11 @@ Path EfaParser::parsePathCoordinatesElement(ScopedXmlStreamReader &reader)
poly.push_back({p[0].toDouble(), p[1].toDouble()});
}
}
return poly;
}
Path EfaParser::polygonToPath(const QPolygonF &poly)
{
PathSection section;
section.setPath(poly);
Path path;
......
......@@ -18,6 +18,7 @@
#include <vector>
class QByteArray;
class QPolygonF;
namespace KPublicTransport {
......@@ -53,7 +54,9 @@ protected:
static Line::Mode motTypeToLineMode(int mot);
/** Parse path encoded as a space separated string of coordinate pairs. */
static Path parsePathCoordinatesElement(ScopedXmlStreamReader &reader);
static QPolygonF parsePathCoordinatesElement(ScopedXmlStreamReader &reader);
/** Turn a polygon into a section path. */
static Path polygonToPath(const QPolygonF &poly);
/** Returns @c true if the given stop id is a dummy value used for non-stops. */
static bool isDummyStopId(QStringView id);
......
......@@ -303,6 +303,7 @@ std::vector<JourneySection> EfaXmlParser::parseTripPartialRoute(ScopedXmlStreamR
section.setMode(JourneySection::Walking);
}
QPolygonF sectionPoly, transferPoly;
while (reader.readNextSibling()) {
if (reader.name() == QLatin1String("itdPoint")) {
const auto type = reader.attributes().value(QLatin1String("usage"));
......@@ -347,18 +348,28 @@ std::vector<JourneySection> EfaXmlParser::parseTripPartialRoute(ScopedXmlStreamR
} else if (reader.name() == QLatin1String("itdStopSeq")) {
section.setIntermediateStops(parsePartialTripStopSequence(reader.subReader()));
} else if (reader.name() == QLatin1String("itdPathCoordinates")) {
section.setPath(parsePathCoordinates(reader.subReader()));
} else if (reader.name() == QLatin1String("itdITPathDescription") && !section.path().isEmpty()) {
sectionPoly = parsePathCoordinates(reader.subReader());
} else if (reader.name() == QLatin1String("itdInterchangePathCoordinates")) {
auto subreader = reader.subReader();
while (subreader.readNextSibling()) {
if (subreader.name() == QLatin1String("itdPathCoordinates")) {
transferPoly = parsePathCoordinates(subreader.subReader());
}
}
} else if (reader.name() == QLatin1String("itdITPathDescription") && !sectionPoly.isEmpty()) {
auto subreader = reader.subReader();
while (subreader.readNextSibling()) {
if (subreader.name() == QLatin1String("itdITPathDescriptionList")) {
const auto fullPath = section.path();
section.setPath(parsePathDescriptionList(subreader.subReader(), fullPath.sections()[0].path()));
section.setPath(parsePathDescriptionList(subreader.subReader(), sectionPoly));
}
}
}
}
if (!sectionPoly.isEmpty() && section.path().isEmpty()) {
section.setPath(polygonToPath(sectionPoly));
}
return result;
}
......@@ -405,15 +416,15 @@ QStringList EfaXmlParser::parseInfoLink(ScopedXmlStreamReader &&reader) const
return l;
}
Path EfaXmlParser::parsePathCoordinates(ScopedXmlStreamReader &&reader) const
QPolygonF EfaXmlParser::parsePathCoordinates(ScopedXmlStreamReader &&reader) const
{
Path path;
QPolygonF poly;
while (reader.readNextSibling()) {
if (reader.name() == QLatin1String("itdCoordinateString")) {
path = parsePathCoordinatesElement(reader);
poly = parsePathCoordinatesElement(reader);
}
}
return path;
return poly;
}
Path EfaXmlParser::parsePathDescriptionList(ScopedXmlStreamReader &&reader, const QPolygonF &poly) const
......
Supports Markdown
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