andre@1: /**************************************************************************** andre@1: ** Copyright (c) 2013-2014 Debao Zhang andre@1: ** All right reserved. andre@1: ** andre@1: ** Permission is hereby granted, free of charge, to any person obtaining andre@1: ** a copy of this software and associated documentation files (the andre@1: ** "Software"), to deal in the Software without restriction, including andre@1: ** without limitation the rights to use, copy, modify, merge, publish, andre@1: ** distribute, sublicense, and/or sell copies of the Software, and to andre@1: ** permit persons to whom the Software is furnished to do so, subject to andre@1: ** the following conditions: andre@1: ** andre@1: ** The above copyright notice and this permission notice shall be andre@1: ** included in all copies or substantial portions of the Software. andre@1: ** andre@1: ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, andre@1: ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF andre@1: ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND andre@1: ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE andre@1: ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION andre@1: ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION andre@1: ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. andre@1: ** andre@1: ****************************************************************************/ andre@1: andre@1: #include "xlsxdrawing_p.h" andre@1: #include "xlsxdrawinganchor_p.h" andre@1: #include "xlsxabstractsheet.h" andre@1: andre@1: #include andre@1: #include andre@1: #include andre@1: andre@1: namespace QXlsx { andre@1: andre@1: Drawing::Drawing(AbstractSheet *sheet, CreateFlag flag) andre@1: :AbstractOOXmlFile(flag), sheet(sheet) andre@1: { andre@1: workbook = sheet->workbook(); andre@1: } andre@1: andre@1: Drawing::~Drawing() andre@1: { andre@1: qDeleteAll(anchors); andre@1: } andre@1: andre@1: void Drawing::saveToXmlFile(QIODevice *device) const andre@1: { andre@1: relationships()->clear(); andre@1: andre@1: QXmlStreamWriter writer(device); andre@1: andre@1: writer.writeStartDocument(QStringLiteral("1.0"), true); andre@1: writer.writeStartElement(QStringLiteral("xdr:wsDr")); andre@1: writer.writeAttribute(QStringLiteral("xmlns:xdr"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing")); andre@1: writer.writeAttribute(QStringLiteral("xmlns:a"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/main")); andre@1: andre@1: foreach (DrawingAnchor *anchor, anchors) andre@1: anchor->saveToXml(writer); andre@1: andre@1: writer.writeEndElement();//xdr:wsDr andre@1: writer.writeEndDocument(); andre@1: } andre@1: andre@1: bool Drawing::loadFromXmlFile(QIODevice *device) andre@1: { andre@1: QXmlStreamReader reader(device); andre@1: while (!reader.atEnd()) { andre@1: reader.readNextStartElement(); andre@1: if (reader.tokenType() == QXmlStreamReader::StartElement) { andre@1: if (reader.name() == QLatin1String("absoluteAnchor")) { andre@1: DrawingAbsoluteAnchor * anchor = new DrawingAbsoluteAnchor(this); andre@1: anchor->loadFromXml(reader); andre@1: } else if (reader.name() == QLatin1String("oneCellAnchor")) { andre@1: DrawingOneCellAnchor * anchor = new DrawingOneCellAnchor(this); andre@1: anchor->loadFromXml(reader); andre@1: } else if (reader.name() == QLatin1String("twoCellAnchor")) { andre@1: DrawingTwoCellAnchor * anchor = new DrawingTwoCellAnchor(this); andre@1: anchor->loadFromXml(reader); andre@1: } andre@1: } andre@1: } andre@1: andre@1: return true; andre@1: } andre@1: andre@1: } // namespace QXlsx