5 #include "GeoDataRelation.h"
7 #include "GeoDataTypes.h"
8 #include "OsmPlacemarkData.h"
15 class GeoDataRelationPrivate
19 OsmPlacemarkData m_osmData;
22 mutable GeoDataRelation::RelationType m_relationType = GeoDataRelation::UnknownType;
23 mutable bool m_relationTypeDirty =
true;
29 GeoDataRelation::GeoDataRelation() :
31 d_ptr(new GeoDataRelationPrivate)
36 GeoDataRelation::~GeoDataRelation()
41 GeoDataRelation::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;
53 GeoDataRelation &GeoDataRelation::operator=(GeoDataRelation other)
55 GeoDataFeature::operator=(other);
56 std::swap(*this->d_ptr, *other.d_ptr);
60 bool 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();
74 const char *GeoDataRelation::nodeType()
const
76 return GeoDataTypes::GeoDataRelationType;
79 GeoDataFeature *GeoDataRelation::clone()
const
81 return new GeoDataRelation(*
this);
84 void 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);
98 OsmPlacemarkData &GeoDataRelation::osmData()
100 Q_D(GeoDataRelation);
101 d->m_relationTypeDirty =
true;
105 const OsmPlacemarkData &GeoDataRelation::osmData()
const
107 Q_D(
const GeoDataRelation);
111 GeoDataRelation::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[
"road"] = RouteRoad;
121 map[
"detour"] = RouteDetour;
122 map[
"ferry"] = RouteFerry;
123 map[
"train"] = RouteTrain;
124 map[
"subway"] = RouteSubway;
125 map[
"tram"] = RouteTram;
126 map[
"bus"] = RouteBus;
127 map[
"trolleybus"] = RouteTrolleyBus;
128 map[
"bicycle"] = RouteBicycle;
129 map[
"mtb"] = RouteMountainbike;
130 map[
"foot"] = RouteFoot;
131 map[
"hiking"] = GeoDataRelation::RouteHiking;
132 map[
"horse"] = RouteHorse;
133 map[
"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;
165 bool GeoDataRelation::containsAnyOf(
const QSet<qint64> &memberIds)
const
167 Q_D(
const GeoDataRelation);
168 return d->m_memberIds.intersects(memberIds);
171 Q_DECLARE_OPERATORS_FOR_FLAGS(GeoDataRelation::RelationTypes)