| 302 | } |
| 303 | |
| 304 | bool Track::loadGpxFrom(QIODevice& device, bool project_points) |
| 305 | { |
| 306 | TrackPoint point; |
| 307 | QString point_name; |
| 308 | |
| 309 | QXmlStreamReader stream(&device); |
| 310 | while (!stream.atEnd()) |
| 311 | { |
| 312 | stream.readNext(); |
| 313 | if (stream.tokenType() == QXmlStreamReader::StartElement) |
| 314 | { |
| 315 | if (stream.name().compare(QLatin1String("wpt"), Qt::CaseInsensitive) == 0 |
| 316 | || stream.name().compare(QLatin1String("trkpt"), Qt::CaseInsensitive) == 0 |
| 317 | || stream.name().compare(QLatin1String("rtept"), Qt::CaseInsensitive) == 0) |
| 318 | { |
| 319 | point = TrackPoint{LatLon{stream.attributes().value(QLatin1String("lat")).toDouble(), |
| 320 | stream.attributes().value(QLatin1String("lon")).toDouble()}}; |
| 321 | if (project_points) |
| 322 | point.map_coord = map_georef.toMapCoordF(point.latlon); // TODO: check for errors |
| 323 | point_name.clear(); |
| 324 | } |
| 325 | else if (stream.name().compare(QLatin1String("trkseg"), Qt::CaseInsensitive) == 0 |
| 326 | || stream.name().compare(QLatin1String("rte"), Qt::CaseInsensitive) == 0) |
| 327 | { |
| 328 | if (segment_starts.empty() |
| 329 | || segment_starts.back() < (int)segment_points.size()) |
| 330 | { |
| 331 | segment_starts.push_back(segment_points.size()); |
| 332 | } |
| 333 | } |
| 334 | else if (stream.name().compare(QLatin1String("ele"), Qt::CaseInsensitive) == 0) |
| 335 | point.elevation = stream.readElementText().toFloat(); |
| 336 | else if (stream.name().compare(QLatin1String("time"), Qt::CaseInsensitive) == 0) |
| 337 | point.datetime = QDateTime::fromString(stream.readElementText(), Qt::ISODate); |
| 338 | else if (stream.name().compare(QLatin1String("hdop"), Qt::CaseInsensitive) == 0) |
| 339 | point.hDOP = stream.readElementText().toFloat(); |
| 340 | else if (stream.name().compare(QLatin1String("name"), Qt::CaseInsensitive) == 0) |
| 341 | point_name = stream.readElementText(); |
| 342 | } |
| 343 | else if (stream.tokenType() == QXmlStreamReader::EndElement) |
| 344 | { |
| 345 | if (stream.name().compare(QLatin1String("wpt"), Qt::CaseInsensitive) == 0) |
| 346 | { |
| 347 | waypoints.push_back(point); |
| 348 | waypoint_names.push_back(point_name); |
| 349 | } |
| 350 | else if (stream.name().compare(QLatin1String("trkpt"), Qt::CaseInsensitive) == 0 |
| 351 | || stream.name().compare(QLatin1String("rtept"), Qt::CaseInsensitive) == 0) |
| 352 | { |
| 353 | segment_points.push_back(point); |
| 354 | } |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | if (!segment_starts.empty() |
| 359 | && segment_starts.back() == (int)segment_points.size()) |
| 360 | { |
| 361 | segment_starts.pop_back(); |
nothing calls this directly
no test coverage detected