| 281 | |
| 282 | |
| 283 | void XmlElementReader::readForText(MapCoordVector& coords) |
| 284 | { |
| 285 | namespace literal = XmlStreamLiteral; |
| 286 | |
| 287 | coords.clear(); |
| 288 | coords.reserve(2); |
| 289 | |
| 290 | const auto num_coords = attribute<unsigned int>(literal::count); |
| 291 | |
| 292 | QScopedValueRollback<MapCoord::BoundsOffset> offset{MapCoord::boundsOffset()}; |
| 293 | |
| 294 | try |
| 295 | { |
| 296 | for( xml.readNext(); xml.tokenType() != QXmlStreamReader::EndElement; xml.readNext() ) |
| 297 | { |
| 298 | const QXmlStreamReader::TokenType token = xml.tokenType(); |
| 299 | if (xml.error() || token == QXmlStreamReader::EndDocument) |
| 300 | { |
| 301 | throw FileFormatException(::OpenOrienteering::ImportExport::tr("Could not parse the coordinates.")); |
| 302 | } |
| 303 | else if (token == QXmlStreamReader::Characters && !xml.isWhitespace()) |
| 304 | { |
| 305 | QStringRef text = xml.text(); |
| 306 | try |
| 307 | { |
| 308 | while (text.length()) |
| 309 | { |
| 310 | if (coords.size() == 1) |
| 311 | { |
| 312 | // Don't apply an offset to text box size. |
| 313 | offset.commit(); |
| 314 | MapCoord::boundsOffset().reset(false); |
| 315 | } |
| 316 | coords.emplace_back(text); |
| 317 | } |
| 318 | } |
| 319 | catch (std::exception& e) |
| 320 | { |
| 321 | Q_UNUSED(e) |
| 322 | qDebug("Could not parse the coordinates: %s", e.what()); |
| 323 | throw FileFormatException(::OpenOrienteering::ImportExport::tr("Could not parse the coordinates.")); |
| 324 | } |
| 325 | } |
| 326 | else if (token == QXmlStreamReader::StartElement) |
| 327 | { |
| 328 | if (xml.name() == literal::coord) |
| 329 | { |
| 330 | if (coords.size() == 1) |
| 331 | { |
| 332 | // Don't apply an offset to text box size. |
| 333 | offset.commit(); |
| 334 | MapCoord::boundsOffset().reset(false); |
| 335 | } |
| 336 | coords.emplace_back(MapCoord::load(xml)); |
| 337 | } |
| 338 | else |
| 339 | { |
| 340 | xml.skipCurrentElement(); |