6#include "RouteRelationModel.h"
8#include "GeoDataColorStyle.h"
10#include "osm/OsmPlacemarkData.h"
16RouteRelationModel::RouteRelationModel(
QObject *parent)
19 m_networks[QStringLiteral(
"iwn")] = tr(
"International walking route");
20 m_networks[QStringLiteral(
"nwn")] = tr(
"National walking route");
21 m_networks[QStringLiteral(
"rwn")] = tr(
"Regional walking route");
22 m_networks[QStringLiteral(
"lwn")] = tr(
"Local walking route");
23 m_networks[QStringLiteral(
"icn")] = tr(
"International cycling route");
24 m_networks[QStringLiteral(
"ncn")] = tr(
"National cycling route");
25 m_networks[QStringLiteral(
"rcn")] = tr(
"Regional cycling route");
26 m_networks[QStringLiteral(
"lcn")] = tr(
"Local cycling route");
27 m_networks[QStringLiteral(
"US:TX:FM")] = tr(
"Farm to Market Road",
"State or county road in Texas, USA");
28 m_networks[QStringLiteral(
"regional")] = tr(
"Regional route");
29 m_networks[QStringLiteral(
"national")] = tr(
"National route");
30 m_networks[QStringLiteral(
"municipal")] = tr(
"Municipal route");
31 m_networks[QStringLiteral(
"territorial")] = tr(
"Territorial route");
32 m_networks[QStringLiteral(
"local")] = tr(
"Local route");
33 m_networks[QStringLiteral(
"prefectural")] = tr(
"Prefectural route");
34 m_networks[QStringLiteral(
"US")] = tr(
"United States route");
39 if (!m_relations.isEmpty()) {
40 beginRemoveRows(
QModelIndex(), 0, m_relations.count() - 1);
47 m_relations.reserve(relations.
size());
48 for (
auto relation : relations) {
49 if (relation->relationType() >= GeoDataRelation::RouteRoad && relation->relationType() <= GeoDataRelation::RouteSled) {
50 m_relations <<
new GeoDataRelation(*relation);
53 std::sort(m_relations.begin(), m_relations.end(), [](
const GeoDataRelation *a,
const GeoDataRelation *b) {
60int RouteRelationModel::rowCount(
const QModelIndex &parent)
const
62 return parent.
isValid() ? 0 : m_relations.count();
67 if (!index.
isValid() || index.
row() < 0 || index.
row() >= m_relations.count()) {
72 return m_relations.at(index.
row())->name();
73 }
else if (role == IconSource) {
74 switch (m_relations.at(index.
row())->relationType()) {
75 case GeoDataRelation::RouteRoad:
76 return QStringLiteral(
"material/directions-car.svg");
77 case GeoDataRelation::RouteDetour:
78 return QStringLiteral(
"material/directions-car.svg");
79 case GeoDataRelation::RouteFerry:
80 return QStringLiteral(
"material/directions-boat.svg");
81 case GeoDataRelation::RouteTrain:
82 return QStringLiteral(
"material/directions-railway.svg");
83 case GeoDataRelation::RouteSubway:
84 return QStringLiteral(
"material/directions-subway.svg");
85 case GeoDataRelation::RouteTram:
86 return QStringLiteral(
"material/directions-tram.svg");
87 case GeoDataRelation::RouteBus:
88 return QStringLiteral(
"material/directions-bus.svg");
89 case GeoDataRelation::RouteTrolleyBus:
90 return QStringLiteral(
"material/directions-bus.svg");
91 case GeoDataRelation::RouteBicycle:
92 return QStringLiteral(
"material/directions-bike.svg");
93 case GeoDataRelation::RouteMountainbike:
94 return QStringLiteral(
"material/directions-bike.svg");
95 case GeoDataRelation::RouteFoot:
96 return QStringLiteral(
"material/directions-walk.svg");
97 case GeoDataRelation::RouteHiking:
98 return QStringLiteral(
"thenounproject/204712-hiker.svg");
99 case GeoDataRelation::RouteHorse:
100 return QStringLiteral(
"thenounproject/78374-horse-riding.svg");
101 case GeoDataRelation::RouteInlineSkates:
102 return QStringLiteral(
"thenounproject/101965-inline-skater.svg");
103 case GeoDataRelation::RouteSkiDownhill:
104 return QStringLiteral(
"thenounproject/2412-skiing-downhill.svg");
105 case GeoDataRelation::RouteSkiNordic:
106 return QStringLiteral(
"thenounproject/30231-skiing-cross-country.svg");
107 case GeoDataRelation::RouteSkitour:
108 return QStringLiteral(
"thenounproject/29366-skitour.svg");
109 case GeoDataRelation::RouteSled:
110 return QStringLiteral(
"thenounproject/365217-sled.svg");
111 case GeoDataRelation::UnknownType:
114 }
else if (role == Description) {
115 return m_relations.at(index.
row())->osmData().tagValue(QStringLiteral(
"description"));
116 }
else if (role == Network) {
117 auto const network = m_relations.at(index.
row())->osmData().tagValue(QStringLiteral(
"network"));
118 auto iter = m_networks.find(network);
119 if (iter != m_networks.end()) {
123 for (
auto const &field : fields) {
124 auto iter = m_networks.find(field);
125 if (iter != m_networks.end()) {
130 }
else if (role == RouteColor) {
131 auto const color = m_relations.at(index.
row())->osmData().tagValue(QStringLiteral(
"colour"));
132 return color.isEmpty() ? QStringLiteral(
"white") : color;
133 }
else if (role == TextColor) {
134 auto const colorValue = m_relations.at(index.
row())->osmData().tagValue(QStringLiteral(
"colour"));
135 auto const color =
QColor(colorValue.isEmpty() ? QStringLiteral(
"white") : colorValue);
136 return GeoDataColorStyle::contrastColor(color);
137 }
else if (role == RouteFrom) {
138 return m_relations.at(index.
row())->osmData().tagValue(QStringLiteral(
"from"));
139 }
else if (role == RouteTo) {
140 return m_relations.at(index.
row())->osmData().tagValue(QStringLiteral(
"to"));
141 }
else if (role == RouteRef) {
142 auto const ref = m_relations.at(index.
row())->osmData().tagValue(QStringLiteral(
"ref"));
143 return ref.isEmpty() ? m_relations.at(index.
row())->name() : ref;
144 }
else if (role == RouteVia) {
145 auto const viaValue = m_relations.at(index.
row())->osmData().tagValue(QStringLiteral(
"via"));
147 for (
auto &via : viaList) {
151 }
else if (role == OsmId) {
152 return m_relations.at(index.
row())->osmData().oid();
153 }
else if (role == RouteVisible) {
154 return m_relations.at(index.
row())->isVisible();
164 roles[IconSource] =
"iconSource";
166 roles[Network] =
"network";
167 roles[RouteColor] =
"routeColor";
168 roles[TextColor] =
"textColor";
169 roles[RouteFrom] =
"routeFrom";
170 roles[RouteTo] =
"routeTo";
171 roles[RouteRef] =
"routeRef";
172 roles[RouteVia] =
"routeVia";
173 roles[OsmId] =
"oid";
174 roles[RouteVisible] =
"routeVisible";
181 return MarbleDirs::path(QStringLiteral(
"svg/%1").arg(path));
183 return QStringLiteral(
"file:///") + MarbleDirs::path(QStringLiteral(
"svg/%1").arg(path));
189#include "moc_RouteRelationModel.cpp"
Binds a QML item to a specific geodetic location in screen coordinates.
bool isValid() const const
qsizetype count() const const
bool isEmpty() const const
qsizetype size() const const