Files
oak-editor/app/project/projectloadmanager.cpp
T
itsmattkc 16904c976f serialize rationals correctly and move block name to a node input
Since rationals aren't a known Qt format, the QVariant container can't
automatically convert them to and from strings (for XML serialization). We have
to hijack these functions and do the conversion manually for those types.

Also moved the block name type to a node input, which means it's serialized
and copied by default (I'm not sure why it wasn't already like this).
2020-01-14 00:59:49 +11:00

51 lines
1.1 KiB
C++

#include "projectloadmanager.h"
#include <QApplication>
#include <QFile>
#include <QXmlStreamReader>
ProjectLoadManager::ProjectLoadManager(const QString &filename) :
filename_(filename)
{
}
void ProjectLoadManager::Start()
{
QFile project_file(filename_);
if (project_file.open(QFile::ReadOnly | QFile::Text)) {
QXmlStreamReader reader(&project_file);
while (!reader.atEnd()) {
reader.readNext();
if (reader.isStartElement()) {
if (reader.name() == "version") {
reader.readNext();
qDebug() << "Project version:" << reader.text();
} else if (reader.name() == "project") {
ProjectPtr project = std::make_shared<Project>();
project->set_filename(filename_);
project->Load(&reader);
// Ensure project is in main thread
moveToThread(qApp->thread());
emit ProjectLoaded(project);
}
}
}
if (reader.hasError()) {
qDebug() << "Found XML error:" << reader.errorString();
}
project_file.close();
}
emit Finished();
}