Commit 46ba6c68 authored by Volker Krause's avatar Volker Krause
Browse files

Prepare PlatformSection to become proper public API

parent 8fd9ad71
......@@ -131,9 +131,9 @@ private Q_SLOTS:
if (!platform.sections().empty()) {
outFile.write(" sections:\n");
for (const auto &section : platform.sections()) {
outFile.write(" name: " + section.name.toUtf8() + "\n");
outFile.write(" name: " + section.name().toUtf8() + "\n");
outFile.write(" position: ");
writeElement(&outFile, section.position);
writeElement(&outFile, section.position());
outFile.write("\n");
}
}
......
......@@ -13,9 +13,51 @@
using namespace KOSMIndoorMap;
namespace KOSMIndoorMap {
class PlatformSectionPrivate : public QSharedData
{
public:
QString name;
OSM::Element position;
};
}
PlatformSection::PlatformSection()
: d(new PlatformSectionPrivate)
{
}
PlatformSection::PlatformSection(const PlatformSection&) = default;
PlatformSection::PlatformSection(PlatformSection&&) = default;
PlatformSection::~PlatformSection() = default;
PlatformSection& PlatformSection::operator=(const PlatformSection&) = default;
PlatformSection& PlatformSection::operator=(PlatformSection&&) = default;
QString PlatformSection::name() const
{
return d->name;
}
void PlatformSection::setName(const QString &name)
{
d.detach();
d->name = name;
}
OSM::Element PlatformSection::position() const
{
return d->position;
}
void PlatformSection::setPosition(const OSM::Element &position)
{
d.detach();
d->position = position;
}
bool PlatformSection::isValid() const
{
return !name.isEmpty() && position;
return !d->name.isEmpty() && d->position;
}
......@@ -161,7 +203,7 @@ static double maxSectionDistance(const std::vector<const OSM::Node*> &path, cons
{
auto dist = std::numeric_limits<double>::lowest();
for (const auto &section : sections) {
dist = std::max(dist, OSM::distance(path, section.position.center()));
dist = std::max(dist, OSM::distance(path, section.position().center()));
}
return dist;
}
......@@ -344,15 +386,15 @@ bool Platform::isSame(const Platform &lhs, const Platform &rhs, const OSM::DataS
static bool compareSection(const PlatformSection &lhs, const PlatformSection &rhs)
{
if (lhs.name == rhs.name) {
return lhs.position < rhs.position;
if (lhs.name() == rhs.name()) {
return lhs.position() < rhs.position();
}
return lhs.name < rhs.name;
return lhs.name() < rhs.name();
}
void Platform::appendSection(std::vector<PlatformSection> &sections, const Platform &p, PlatformSection &&sec, std::vector<const OSM::Node*> &edgePath, const OSM::DataSet &dataSet)
{
if (sections.empty() || sections.back().name != sec.name) {
if (sections.empty() || sections.back().name() != sec.name()) {
sections.push_back(std::move(sec));
return;
}
......@@ -365,8 +407,8 @@ void Platform::appendSection(std::vector<PlatformSection> &sections, const Platf
OSM::assemblePath(dataSet, p.m_track, edgePath);
}
}
const auto dist1 = OSM::distance(edgePath, sections.back().position.center());
const auto dist2 = OSM::distance(edgePath, sec.position.center());
const auto dist1 = OSM::distance(edgePath, sections.back().position().center());
const auto dist2 = OSM::distance(edgePath, sec.position().center());
if (dist2 < dist1) {
sections.back() = std::move(sec);
}
......@@ -423,7 +465,7 @@ Platform Platform::merge(const Platform &lhs, const Platform &rhs, const OSM::Da
}
// both are equal
if ((*lit).position == (*rit).position) {
if ((*lit).position() == (*rit).position()) {
appendSection(sections, p, std::move(*lit++), edgePath, dataSet);
++rit;
continue;
......
......@@ -11,6 +11,7 @@
#include <KOSM/Element>
#include <QExplicitlySharedDataPointer>
#include <QMetaType>
#include <QStringList>
......@@ -19,15 +20,31 @@
namespace KOSMIndoorMap {
class PlatformSectionPrivate;
/** A railway platform section. */
class KOSMINDOORMAP_EXPORT PlatformSection
{
public:
explicit PlatformSection();
PlatformSection(const PlatformSection&);
PlatformSection(PlatformSection&&);
~PlatformSection();
PlatformSection& operator=(const PlatformSection&);
PlatformSection& operator=(PlatformSection&&);
/** Platform section has enough data to work with. */
bool isValid() const;
QString name;
OSM::Element position;
/** Platform section name. */
QString name() const;
void setName(const QString &name);
/** Platform section position. */
OSM::Element position() const;
void setPosition(const OSM::Element &position);
private:
QExplicitlySharedDataPointer<PlatformSectionPrivate> d;
};
/** A railway platform/track. */
......
......@@ -57,8 +57,8 @@ std::vector<Platform> PlatformFinder::find(const MapData &data)
p.setLevel(levelForPlatform((*it).first, e));
p.setName(name);
PlatformSection section;
section.name = QString::fromUtf8(e.tagValue("local_ref", "ref"));
section.position = e;
section.setName(QString::fromUtf8(e.tagValue("local_ref", "ref")));
section.setPosition(e);
p.setSections({section});
m_floatingSections.push_back(std::move(p)); // can't merge this reliably until we have the full area geometry
}
......@@ -218,16 +218,16 @@ std::vector<PlatformSection> PlatformFinder::sectionsForPath(const std::vector<c
const auto pt = OSM::tagValue(*n, m_tagKeys.public_transport);
if (pt == "platform_section_sign") {
PlatformSection sec;
sec.position = OSM::Element(n);
sec.name = QString::fromUtf8(sec.position.tagValue("platform_section_sign_value", "local_ref", "ref"));
sec.setPosition(OSM::Element(n));
sec.setName(QString::fromUtf8(sec.position().tagValue("platform_section_sign_value", "local_ref", "ref")));
sections.push_back(std::move(sec));
continue;
}
const auto railway_platform_section = OSM::tagValue(*n, m_tagKeys.railway_platform_section);
if (!railway_platform_section.isEmpty()) {
PlatformSection sec;
sec.position = OSM::Element(n);
sec.name = QString::fromUtf8(railway_platform_section);
sec.setPosition(OSM::Element(n));
sec.setName(QString::fromUtf8(railway_platform_section));
sections.push_back(std::move(sec));
continue;
}
......@@ -340,7 +340,7 @@ void PlatformFinder::finalizeResult()
auto sections = p.takeSections();
sections.erase(std::remove_if(sections.begin(), sections.end(), [](const auto &s) { return !s.isValid(); }), sections.end());
std::sort(sections.begin(), sections.end(), [this](const auto &lhs, const auto &rhs) {
return m_collator.compare(lhs.name, rhs.name) < 0;
return m_collator.compare(lhs.name(), rhs.name()) < 0;
});
p.setSections(std::move(sections));
}
......
......@@ -104,9 +104,9 @@ QVariant PlatformModel::data(const QModelIndex &index, int role) const
const auto &section = platform.sections()[index.row()];
switch (role) {
case Qt::DisplayRole:
return section.name;
return section.name();
case CoordinateRole:
return QPointF(section.position.center().lonF(), section.position.center().latF());
return QPointF(section.position().center().lonF(), section.position().center().latF());
case ElementRole:
return QVariant::fromValue(OSM::Element(m_sectionsLabels[index.internalId()][index.row()]));
case LevelRole:
......@@ -249,8 +249,8 @@ void PlatformModel::createLabels()
for (const auto &sec : p.sections()) {
auto node = new OSM::Node;
node->id = m_data.dataSet().nextInternalId();
node->coordinate = sec.position.center();
OSM::setTagValue(*node, sectionTag, sec.name.toUtf8());
node->coordinate = sec.position().center();
OSM::setTagValue(*node, sectionTag, sec.name().toUtf8());
m_sectionsLabels[i].push_back(OSM::UniqueElement(node));
}
}
......
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