MCPcopy Create free account
hub / github.com/KDE/labplot / load

Method load

src/backend/core/Project.cpp:533–638  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

531}
532
533bool Project::load(const QString& filename, bool preview) {
534 setFileName(filename);
535 DEBUG(Q_FUNC_INFO << ", LOADING file " << STDSTRING(filename))
536 QIODevice* file;
537 if (filename.endsWith(QLatin1String(".lml"), Qt::CaseInsensitive)) {
538 DEBUG(Q_FUNC_INFO << ", filename ends with .lml")
539
540 // check compression
541 file = new QFile(filename);
542 if (!file->open(QIODevice::ReadOnly)) {
543 KMessageBox::error(nullptr, i18n("Sorry. Could not open file for reading."));
544 delete file;
545 return false;
546 }
547 QDataStream in(file);
548 quint16 magic;
549 in >> magic;
550 file->close();
551 delete file;
552
553 if (!magic) {
554 KMessageBox::error(nullptr, i18n("The project file is empty."), i18n("Error opening project"));
555 return false;
556 }
557 QDEBUG(Q_FUNC_INFO << ", got magic: " << magic << Qt::hex << "0x" << magic)
558
559 if (magic == 0xfd37) // XZ compressed data
560 file = new KCompressionDevice(filename, KCompressionDevice::Xz);
561 else // gzip or not compressed data
562 file = new KCompressionDevice(filename, KCompressionDevice::GZip);
563 } else { // opens filename using file ending
564 // DEBUG(Q_FUNC_INFO << ", filename does not end with .lml. Guessing by extension")
565 file = new KCompressionDevice(filename);
566 DEBUG(Q_FUNC_INFO << ", found compression type " << ((KCompressionDevice*)file)->compressionType())
567 }
568
569 if (!file)
570 file = new QFile(filename);
571
572 if (!file->open(QIODevice::ReadOnly)) {
573 KMessageBox::error(nullptr, i18n("Sorry. Could not open file for reading."));
574 return false;
575 }
576
577 char c;
578 bool rc = file->getChar(&c);
579 if (!rc) {
580 KMessageBox::error(nullptr, i18n("The project file is empty."), i18n("Error opening project"));
581 file->close();
582 delete file;
583 return false;
584 }
585 file->seek(0);
586
587 // parse XML
588 XmlStreamReader reader(file);
589 setIsLoading(true);
590 ProjectPrivate::mXmlVersion =

Callers

nothing calls this directly

Calls 15

debugTraceEnabledFunction · 0.85
hasWarningsMethod · 0.80
hasMissingCASWarningsMethod · 0.80
missingCASWarningMethod · 0.80
atEndMethod · 0.80
skipToNextTagMethod · 0.80
raiseWarningMethod · 0.80
setVersionMethod · 0.80
skipToEndElementMethod · 0.80
raiseErrorMethod · 0.80
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected