| 305 | } |
| 306 | |
| 307 | Object* Object::load(QXmlStreamReader& xml, Map* map, const SymbolDictionary& symbol_dict, const Symbol* symbol) |
| 308 | { |
| 309 | Q_ASSERT(xml.name() == literal::object); |
| 310 | |
| 311 | XmlElementReader object_element(xml); |
| 312 | |
| 313 | Object::Type object_type = object_element.attribute<Object::Type>(literal::type); |
| 314 | Object* object = Object::getObjectForType(object_type); |
| 315 | if (!object) |
| 316 | throw FileFormatException(::OpenOrienteering::ImportExport::tr("Error while loading an object of type %1.").arg(object_type)); |
| 317 | |
| 318 | object->map = map; |
| 319 | |
| 320 | if (symbol) |
| 321 | object->symbol = symbol; |
| 322 | else |
| 323 | { |
| 324 | QString symbol_id = object_element.attribute<QString>(literal::symbol); |
| 325 | bool conversion_ok; |
| 326 | const auto id_converted = symbol_id.toInt(&conversion_ok); |
| 327 | if (!symbol_id.isEmpty() && !conversion_ok) |
| 328 | { |
| 329 | delete object; |
| 330 | throw FileFormatException(::OpenOrienteering::ImportExport::tr("Malformed symbol ID '%1' at line %2 column %3.") |
| 331 | .arg(symbol_id).arg(xml.lineNumber()) |
| 332 | .arg(xml.columnNumber())); |
| 333 | } |
| 334 | object->symbol = symbol_dict[id_converted]; // FIXME: cannot work for forward references |
| 335 | // NOTE: object->symbol may be nullptr. |
| 336 | } |
| 337 | |
| 338 | if (!object->symbol || !object->symbol->isTypeCompatibleTo(object)) |
| 339 | { |
| 340 | // Throwing an exception will cause loading to fail. |
| 341 | // Rather than not loading the broken file at all, |
| 342 | // use the same symbols which are used for importing GPS tracks etc. |
| 343 | // FIXME: Implement a way to send a warning to the user. |
| 344 | switch (object_type) |
| 345 | { |
| 346 | case Point: |
| 347 | object->symbol = Map::getUndefinedPoint(); |
| 348 | break; |
| 349 | case Path: |
| 350 | object->symbol = Map::getUndefinedLine(); |
| 351 | break; |
| 352 | case Text: |
| 353 | object->symbol = Map::getUndefinedText(); |
| 354 | break; |
| 355 | default: |
| 356 | throw FileFormatException( |
| 357 | ::OpenOrienteering::ImportExport::tr("Unable to find symbol for object at %1:%2."). |
| 358 | arg(xml.lineNumber()).arg(xml.columnNumber()) ); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | if (object->symbol->isRotatable()) |
| 363 | { |
| 364 | object->rotation = object_element.attribute<qreal>(literal::rotation); |
nothing calls this directly
no test coverage detected