Save and load image paints

This commit is contained in:
Tats
2014-06-26 00:13:12 -04:00
parent 376c7e4983
commit 054a6d2b37
2 changed files with 24 additions and 14 deletions
+2 -13
View File
@@ -90,25 +90,14 @@ void ProjectReader::parsePaint(const QDomElement& paint)
QString paintAttrName = paint.attribute("name", "");
QString paintAttrType = paint.attribute("type", "");
if (paintAttrType == "media")
if (paintAttrType == "media" || paintAttrType == "image")
{
QString uri = paint.firstChildElement("uri").text();
QString x = paint.firstChildElement("x").text();
QString y = paint.firstChildElement("y").text();
uid id = _window->createMediaPaint(paintAttrId.toInt(), uri, x.toFloat(), y.toFloat(),
std::tr1::shared_ptr<Paint>(static_cast<Paint*>(0)), false);
if (id == NULL_UID)
_xml.raiseError(QObject::tr("Cannot create media with uri %1.").arg(uri));
}
else if (paintAttrType == "image")
{
QString uri = paint.firstChildElement("uri").text();
QString x = paint.firstChildElement("x").text();
QString y = paint.firstChildElement("y").text();
uid id = _window->createMediaPaint(paintAttrId.toInt(), uri, x.toFloat(), y.toFloat(),
std::tr1::shared_ptr<Paint>(static_cast<Paint*>(0)), true);
std::tr1::shared_ptr<Paint>(static_cast<Paint*>(0)), paintAttrType == "image");
if (id == NULL_UID)
_xml.raiseError(QObject::tr("Cannot create media with uri %1.").arg(uri));
}
+22 -1
View File
@@ -59,7 +59,7 @@ void ProjectWriter::writeItem(Paint *item)
if (item->getType() == "media")
{
// FIXME: check paint type before casting to Image
// FIXME: check paint type before casting to Media
Media *media = (Media *) item;
_xml.writeTextElement("uri", media->getUri());
@@ -78,6 +78,27 @@ void ProjectWriter::writeItem(Paint *item)
_xml.writeEndElement();
//_xml.writeEmptyElement("hello");
}
else if (item->getType() == "image")
{
// FIXME: check paint type before casting to Image
Image *media = (Image *) item;
_xml.writeTextElement("uri", media->getUri());
{
std::ostringstream os;
os << media->getX();
_xml.writeTextElement("x", os.str().c_str());
}
{
std::ostringstream os;
os << media->getY();
_xml.writeTextElement("y", os.str().c_str());
}
_xml.writeEndElement();
//_xml.writeEmptyElement("hello");
}
else if (item->getType() == "color")
{
// FIXME: check paint type before casting to Image