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

Split path description parsing and path assembly

For transfers we only get the necessary polygon for assembly later, so
we can't do both in one go.
parent 0f7e6930
......@@ -304,6 +304,7 @@ std::vector<JourneySection> EfaXmlParser::parseTripPartialRoute(ScopedXmlStreamR
}
QPolygonF sectionPoly, transferPoly;
std::vector<PathDescription> pathDesc;
while (reader.readNextSibling()) {
if (reader.name() == QLatin1String("itdPoint")) {
const auto type = reader.attributes().value(QLatin1String("usage"));
......@@ -360,12 +361,15 @@ std::vector<JourneySection> EfaXmlParser::parseTripPartialRoute(ScopedXmlStreamR
auto subreader = reader.subReader();
while (subreader.readNextSibling()) {
if (subreader.name() == QLatin1String("itdITPathDescriptionList")) {
section.setPath(parsePathDescriptionList(subreader.subReader(), sectionPoly));
pathDesc = parsePathDescriptionList(subreader.subReader());
}
}
}
}
if (!pathDesc.empty()) {
section.setPath(assemblePath(pathDesc, sectionPoly));
}
if (!sectionPoly.isEmpty() && section.path().isEmpty()) {
section.setPath(polygonToPath(sectionPoly));
}
......@@ -427,37 +431,49 @@ QPolygonF EfaXmlParser::parsePathCoordinates(ScopedXmlStreamReader &&reader) con
return poly;
}
Path EfaXmlParser::parsePathDescriptionList(ScopedXmlStreamReader &&reader, const QPolygonF &poly) const
std::vector<EfaXmlParser::PathDescription> EfaXmlParser::parsePathDescriptionList(ScopedXmlStreamReader &&reader) const
{
Path path;
std::vector<PathSection> sections;
std::vector<PathDescription> descs;
while (reader.readNextSibling()) {
if (reader.name() == QLatin1String("itdITPathDescriptionElem")) {
PathSection section;
int fromIdx = -1; int toIdx = -1;
PathDescription desc;
auto elemReader = reader.subReader();
while (elemReader.readNextSibling()) {
if (elemReader.name() == QLatin1String("fromPathCoordIdx")) {
fromIdx = elemReader.readElementText().toInt();
if (elemReader.name() == QLatin1String("itdCoord")) {
desc.point.setX(elemReader.attributes().value(QLatin1String("x")).toDouble());
desc.point.setY(elemReader.attributes().value(QLatin1String("y")).toDouble());
} else if (elemReader.name() == QLatin1String("fromPathCoordIdx")) {
desc.fromIndex = elemReader.readElementText().toInt();
} else if (elemReader.name() == QLatin1String("toPathCoordIdx")) {
toIdx = elemReader.readElementText().toInt();
desc.toIndex = elemReader.readElementText().toInt();
} else if (elemReader.name() == QLatin1String("streetname")) {
section.setDescription(elemReader.readElementText());
desc.description = elemReader.readElementText();
}
// turnDirection, turningManoeuvre, from/toPathLink??, skyDirection, traveltime, distance, niveau, genAttrList
}
descs.push_back(std::move(desc));
}
}
return descs;
}
if (fromIdx < 0 || toIdx < 0 || fromIdx >= poly.size() || toIdx >= poly.size() || toIdx < fromIdx) {
qWarning() << "weird polygon indexes?" << fromIdx << toIdx << poly.size();
continue;
}
QPolygonF subPoly;
subPoly.reserve(toIdx - fromIdx + 1);
std::copy(poly.begin() + fromIdx, poly.begin() + toIdx, std::back_inserter(subPoly));
section.setPath(subPoly);
sections.push_back(std::move(section));
Path EfaXmlParser::assemblePath(const std::vector<PathDescription> &descs, const QPolygonF &poly) const
{
Path path;
std::vector<PathSection> sections;
for (const auto &desc : descs) {
if (desc.fromIndex < 0 || desc.toIndex < 0 || desc.fromIndex >= poly.size() || desc.toIndex >= poly.size() || desc.toIndex < desc.fromIndex) {
qCWarning(Log) << "weird polygon indexes?" << desc.fromIndex << desc.toIndex << poly.size();
continue;
}
PathSection section;
QPolygonF subPoly;
subPoly.reserve(desc.toIndex - desc.fromIndex + 1);
std::copy(poly.begin() + desc.fromIndex, poly.begin() + desc.toIndex, std::back_inserter(subPoly));
section.setPath(subPoly);
section.setDescription(desc.description);
sections.push_back(std::move(section));
}
path.setSections(std::move(sections));
......
......@@ -9,6 +9,8 @@
#include "efaparser.h"
#include <QPointF>
class QPolygonF;
namespace KPublicTransport {
......@@ -40,8 +42,18 @@ private:
std::vector<JourneySection> parseTripPartialRoute(ScopedXmlStreamReader &&reader) const;
Journey parseTripRoute(ScopedXmlStreamReader &&reader) const;
QStringList parseInfoLink(ScopedXmlStreamReader &&reader) const;
Path parsePathCoordinates(ScopedXmlStreamReader &&reader) const;
Path parsePathDescriptionList(ScopedXmlStreamReader &&reader, const QPolygonF &poly) const;
QPolygonF parsePathCoordinates(ScopedXmlStreamReader &&reader) const;
struct PathDescription {
QPointF point;
int fromIndex = -1;
int toIndex = -1;
QString description;
};
std::vector<PathDescription> parsePathDescriptionList(ScopedXmlStreamReader &&reader) const;
Path assemblePath(const std::vector<PathDescription> &descs, const QPolygonF &poly) const;
mutable QHash<QString, Location> m_locations;
};
......
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