From 054a6d2b37b034b03bdc731a37a44534ad5b1fd5 Mon Sep 17 00:00:00 2001 From: Tats Date: Thu, 26 Jun 2014 00:13:12 -0400 Subject: [PATCH] Save and load image paints --- ProjectReader.cpp | 15 ++------------- ProjectWriter.cpp | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/ProjectReader.cpp b/ProjectReader.cpp index 3cb4d4d..7448d4e 100644 --- a/ProjectReader.cpp +++ b/ProjectReader.cpp @@ -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(static_cast(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(static_cast(0)), true); + std::tr1::shared_ptr(static_cast(0)), paintAttrType == "image"); if (id == NULL_UID) _xml.raiseError(QObject::tr("Cannot create media with uri %1.").arg(uri)); } diff --git a/ProjectWriter.cpp b/ProjectWriter.cpp index 5c4bd3d..51d29d9 100644 --- a/ProjectWriter.cpp +++ b/ProjectWriter.cpp @@ -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