Load from XML
| 398 | |
| 399 | //! Load from XML |
| 400 | bool Notebook::load(XmlStreamReader* reader, bool preview) { |
| 401 | // reset the status of the reader differentiating between |
| 402 | //"failed because of the missing CAS" and "failed because of the broken XML" |
| 403 | reader->setFailedCASMissing(false); |
| 404 | |
| 405 | if (!readBasicAttributes(reader)) |
| 406 | return false; |
| 407 | |
| 408 | QXmlStreamAttributes attribs; |
| 409 | bool rc = false; |
| 410 | |
| 411 | QString name; |
| 412 | if (Project::xmlVersion() < 14) |
| 413 | name = QLatin1String("cantorWorksheet"); |
| 414 | else |
| 415 | name = QLatin1String("notebook"); |
| 416 | |
| 417 | while (!reader->atEnd()) { |
| 418 | reader->readNext(); |
| 419 | if (reader->isEndElement() && reader->name() == name) |
| 420 | break; |
| 421 | |
| 422 | if (!reader->isStartElement()) |
| 423 | continue; |
| 424 | |
| 425 | if (reader->name() == QLatin1String("comment")) { |
| 426 | if (!readCommentElement(reader)) |
| 427 | return false; |
| 428 | } else if (!preview && reader->name() == QLatin1String("general")) { |
| 429 | attribs = reader->attributes(); |
| 430 | |
| 431 | m_backendName = attribs.value(QStringLiteral("backend_name")).toString().trimmed(); |
| 432 | if (m_backendName.isEmpty()) |
| 433 | reader->raiseMissingAttributeWarning(QStringLiteral("backend_name")); |
| 434 | } else if (!preview && reader->name() == QLatin1String("worksheet")) { |
| 435 | attribs = reader->attributes(); |
| 436 | |
| 437 | QString str = attribs.value(QStringLiteral("content")).toString().trimmed(); |
| 438 | if (str.isEmpty()) |
| 439 | reader->raiseMissingAttributeWarning(QStringLiteral("content")); |
| 440 | |
| 441 | QByteArray content = QByteArray::fromBase64(str.toLatin1()); |
| 442 | rc = init(&content); |
| 443 | if (!rc) { |
| 444 | reader->raiseMissingCASWarning(m_backendName); |
| 445 | |
| 446 | // failed to load this object because of the missing CAS plugin |
| 447 | // and not because of the broken project XML. Set this flag to |
| 448 | // handle this case correctly. |
| 449 | // TODO: we also can fail in the limit in cases where Cantor's content is broken |
| 450 | // and not because of the missing CAS plugin. This also needs to be treated accrodingly... |
| 451 | reader->setFailedCASMissing(true); |
| 452 | return false; |
| 453 | } |
| 454 | } else if (!preview && reader->name() == QLatin1String("column")) { |
| 455 | Column* column = new Column(QString()); |
| 456 | column->setUndoAware(false); |
| 457 | if (!column->load(reader, preview)) { |
nothing calls this directly
no test coverage detected