You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
3.1 KiB
88 lines
3.1 KiB
9 years ago
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
/**
|
||
|
* \file xmlparser.cpp
|
||
|
* \version v1.0
|
||
|
* \author Ing. Dominik Malcik
|
||
|
*/
|
||
|
////////////////////////////////////////////////////////////////////////////////
|
||
|
|
||
|
#include "xmlparser.h"
|
||
|
#include "project.h"
|
||
|
#include "mainwindow.h"
|
||
|
|
||
|
XMLparser::XMLparser(QWidget *parent) :
|
||
|
QMainWindow(parent)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
bool XMLparser::read(QIODevice *device) {
|
||
|
|
||
|
QString errorStr;
|
||
|
int errorLine;
|
||
|
int errorColumn;
|
||
|
|
||
|
if (!domDocument.setContent(device, true, &errorStr, &errorLine, &errorColumn)) {
|
||
|
QMessageBox::information(this, tr("microAnalyzer :: ERROR"),
|
||
|
tr("Project file parse error at line %1, column %2:\n%3")
|
||
|
.arg(errorLine)
|
||
|
.arg(errorColumn)
|
||
|
.arg(errorStr));
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
QDomElement root = domDocument.documentElement();
|
||
|
|
||
|
if (root.tagName() != "ma_project") {
|
||
|
QMessageBox::critical(window(), tr("microAnalyzer :: ERROR"), tr("The file is not a microAnalyzer project file."));
|
||
|
return false;
|
||
|
} else if (root.hasAttribute("version") && root.attribute("version") != "1.0") {
|
||
|
QMessageBox::critical(window(), tr("microAnalyzer :: ERROR"), tr("The file is not a microAnalyzer project file version 1.0."));
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
// basic values
|
||
|
QString childName = root.firstChildElement("name").text();
|
||
|
QString childFileImported = root.firstChildElement("fileImported").text();
|
||
|
QString childImagesDir = root.firstChildElement("imagesDir").text();
|
||
|
QString childLayersDir = root.firstChildElement("layersDir").text();
|
||
|
|
||
|
// load information from xml to the project instance
|
||
|
cProject::Instance()->setProjectName(childName);
|
||
|
cProject::Instance()->setFileImported((childFileImported == Project::XML_TRUE) ? true : false);
|
||
|
cProject::Instance()->setImagesDir(childImagesDir);
|
||
|
cProject::Instance()->setLayersDir(childLayersDir);
|
||
|
cProject::Instance()->setProjectFileName(cProject::Instance()->getProjectName() + Project::PROJ_FILE_EXT);
|
||
|
|
||
|
// load imported images for backgrounds
|
||
|
std::vector<QString> imgVect;
|
||
|
if (childFileImported == Project::XML_TRUE) {
|
||
|
|
||
|
QDomElement childImagesRoot = root.firstChildElement("images");
|
||
|
if (!childImagesRoot.isNull()) {
|
||
|
|
||
|
QDomElement childImages = childImagesRoot.firstChildElement("image");
|
||
|
while (!childImages.isNull()) {
|
||
|
imgVect.push_back(childImages.text());
|
||
|
childImages = childImages.nextSiblingElement("image");
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
cProject::Instance()->setImages(imgVect);
|
||
|
|
||
|
// load imported layers
|
||
|
std::vector<QString> layers;
|
||
|
QDomElement childLayersRoot = root.firstChildElement("layers");
|
||
|
if (!childLayersRoot.isNull()) {
|
||
|
|
||
|
QDomElement childLayers = childLayersRoot.firstChildElement("layer");
|
||
|
while (!childLayers.isNull()) {
|
||
|
layers.push_back(childLayers.text());
|
||
|
childLayers = childLayers.nextSiblingElement("layer");
|
||
|
}
|
||
|
}
|
||
|
cProject::Instance()->setLayers(layers);
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|