5#include "GeoDataRelation.h"
7#include "GeoDataTypes.h"
8#include "OsmPlacemarkData.h"
15class GeoDataRelationPrivate
19 OsmPlacemarkData m_osmData;
22 mutable GeoDataRelation::RelationType m_relationType = GeoDataRelation::UnknownType;
23 mutable bool m_relationTypeDirty =
true;
29GeoDataRelation::GeoDataRelation()
31 , d_ptr(new GeoDataRelationPrivate)
36GeoDataRelation::~GeoDataRelation()
41GeoDataRelation::GeoDataRelation(
const GeoDataRelation &other)
42 : GeoDataFeature(other)
43 , d_ptr(new GeoDataRelationPrivate)
46 d->m_features = other.d_func()->m_features;
47 d->m_osmData = other.d_func()->m_osmData;
48 d->m_memberIds = other.d_func()->m_memberIds;
49 d->m_relationType = other.d_func()->m_relationType;
50 d->m_relationTypeDirty = other.d_func()->m_relationTypeDirty;
53GeoDataRelation &GeoDataRelation::operator=(GeoDataRelation other)
55 GeoDataFeature::operator=(other);
56 std::swap(*this->d_ptr, *other.d_ptr);
60bool GeoDataRelation::operator<(
const GeoDataRelation &other)
const
62 if (relationType() == other.relationType()) {
63 Q_D(
const GeoDataRelation);
64 auto const refA = d->m_osmData.tagValue(QStringLiteral(
"ref"));
65 auto const refB = other.osmData().tagValue(QStringLiteral(
"ref"));
67 return name() < other.name();
71 return relationType() < other.relationType();
74const char *GeoDataRelation::nodeType()
const
76 return GeoDataTypes::GeoDataRelationType;
79GeoDataFeature *GeoDataRelation::clone()
const
81 return new GeoDataRelation(*
this);
84void GeoDataRelation::addMember(
const GeoDataFeature *feature, qint64
id, OsmType type,
const QString &role)
87 d->m_features << feature;
88 d->m_osmData.addRelation(
id, type, role);
94 Q_D(
const GeoDataRelation);
98OsmPlacemarkData &GeoDataRelation::osmData()
100 Q_D(GeoDataRelation);
101 d->m_relationTypeDirty =
true;
105const OsmPlacemarkData &GeoDataRelation::osmData()
const
107 Q_D(
const GeoDataRelation);
111GeoDataRelation::RelationType GeoDataRelation::relationType()
const
113 Q_D(
const GeoDataRelation);
114 if (!d->m_relationTypeDirty) {
115 return d->m_relationType;
118 if (GeoDataRelationPrivate::s_relationTypes.isEmpty()) {
119 auto &
map = GeoDataRelationPrivate::s_relationTypes;
120 map[QStringLiteral(
"road")] = RouteRoad;
121 map[QStringLiteral(
"detour")] = RouteDetour;
122 map[QStringLiteral(
"ferry")] = RouteFerry;
123 map[QStringLiteral(
"train")] = RouteTrain;
124 map[QStringLiteral(
"subway")] = RouteSubway;
125 map[QStringLiteral(
"tram")] = RouteTram;
126 map[QStringLiteral(
"bus")] = RouteBus;
127 map[QStringLiteral(
"trolleybus")] = RouteTrolleyBus;
128 map[QStringLiteral(
"bicycle")] = RouteBicycle;
129 map[QStringLiteral(
"mtb")] = RouteMountainbike;
130 map[QStringLiteral(
"foot")] = RouteFoot;
131 map[QStringLiteral(
"hiking")] = GeoDataRelation::RouteHiking;
132 map[QStringLiteral(
"horse")] = RouteHorse;
133 map[QStringLiteral(
"inline_skates")] = RouteInlineSkates;
136 d->m_relationType = GeoDataRelation::UnknownType;
137 d->m_relationTypeDirty =
false;
138 if (d->m_osmData.containsTag(QStringLiteral(
"type"), QStringLiteral(
"route"))) {
139 auto const route = d->m_osmData.tagValue(QStringLiteral(
"route"));
140 if (route == QStringLiteral(
"piste")) {
141 auto const piste = d->m_osmData.tagValue(QStringLiteral(
"piste:type"));
142 if (piste == QStringLiteral(
"downhill")) {
143 d->m_relationType = RouteSkiDownhill;
144 }
else if (piste == QStringLiteral(
"nordic")) {
145 d->m_relationType = RouteSkiNordic;
146 }
else if (piste == QStringLiteral(
"skitour")) {
147 d->m_relationType = RouteSkitour;
148 }
else if (piste == QStringLiteral(
"sled")) {
149 d->m_relationType = RouteSled;
152 d->m_relationType = GeoDataRelationPrivate::s_relationTypes.
value(route, UnknownType);
156 return d->m_relationType;
161 Q_D(
const GeoDataRelation);
162 return d->m_memberIds;
165bool GeoDataRelation::containsAnyOf(
const QSet<qint64> &memberIds)
const
167 Q_D(
const GeoDataRelation);
168 return d->m_memberIds.intersects(memberIds);
171Q_DECLARE_OPERATORS_FOR_FLAGS(GeoDataRelation::RelationTypes)
QString name(StandardAction id)
Binds a QML item to a specific geodetic location in screen coordinates.
T value(const Key &key) const const
QFuture< void > map(Iterator begin, Iterator end, MapFunctor &&function)