Implemented parsing of mappings and shapes.

This commit is contained in:
Tats
2016-01-28 12:28:19 -05:00
parent f6fc556b3e
commit cf11335c1d
5 changed files with 78 additions and 21 deletions
+51 -15
View File
@@ -89,21 +89,23 @@ void ProjectReader::parseProject(const QDomElement& project)
paintNode = paintNode.nextSibling();
}
// // Parse mappings.
// QDomNode mappingNode = mappings.firstChild();
// while (!mappingNode.isNull())
// {
// Mapping::ptr mapping = parseMapping(mappingNode.toElement());
// if (mapping.isNull())
// {
// qDebug() << "Problem creating mapping." << endl;
// }
// else
// {
// }
//
// mappingNode = mappingNode.nextSibling();
// }
// Parse mappings.
QDomNode mappingNode = mappings.firstChild();
while (!mappingNode.isNull())
{
Mapping::ptr mapping = parseMapping(mappingNode.toElement());
if (mapping.isNull())
{
qDebug() << "Problem creating mapping." << endl;
}
else
{
manager.addMapping(mapping);
_window->addMappingItem(mapping->getId());
}
mappingNode = mappingNode.nextSibling();
}
}
Paint::ptr ProjectReader::parsePaint(const QDomElement& paintElem)
@@ -137,6 +139,40 @@ Paint::ptr ProjectReader::parsePaint(const QDomElement& paintElem)
return Paint::ptr();
}
}
Mapping::ptr ProjectReader::parseMapping(const QDomElement& mappingElem)
{
// Get attributes.
QString className = mappingElem.attribute(ProjectAttributes::CLASS_NAME);
int id = mappingElem.attribute(ProjectAttributes::ID, QString::number(NULL_UID)).toInt();
qDebug() << "Found mapping with classname: " << className << endl;
const QMetaObject* metaObject = MetaObjectRegistry::instance().getMetaObject(className);
if (metaObject)
{
// Create new instance.
Mapping::ptr mapping (qobject_cast<Mapping*>(metaObject->newInstance( Q_ARG(int, id)) ));
if (mapping.isNull())
{
qDebug() << QObject::tr("Problem at creation of mapping.") << endl;
// _xml.raiseError(QObject::tr("Problem at creation of paint."));
}
else
qDebug() << "Created new instance with id: " << mapping->getId();
mapping->read(mappingElem);
return mapping;
}
else
{
_xml.raiseError(QObject::tr("Unable to create paint of type '%1'.").arg(className));
return Mapping::ptr();
}
}
//
//Mapping::ptr ProjectReader::parseMapping(const QDomElement& mappingElem)
//{