comparison src/xlsx/xlsxdrawing.cpp @ 1:93d3106bb9a4

Add qt xlsx library
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 22 Mar 2016 10:38:08 +0100
parents
children
comparison
equal deleted inserted replaced
0:49cd5cc0b072 1:93d3106bb9a4
1 /****************************************************************************
2 ** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me>
3 ** All right reserved.
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining
6 ** a copy of this software and associated documentation files (the
7 ** "Software"), to deal in the Software without restriction, including
8 ** without limitation the rights to use, copy, modify, merge, publish,
9 ** distribute, sublicense, and/or sell copies of the Software, and to
10 ** permit persons to whom the Software is furnished to do so, subject to
11 ** the following conditions:
12 **
13 ** The above copyright notice and this permission notice shall be
14 ** included in all copies or substantial portions of the Software.
15 **
16 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 **
24 ****************************************************************************/
25
26 #include "xlsxdrawing_p.h"
27 #include "xlsxdrawinganchor_p.h"
28 #include "xlsxabstractsheet.h"
29
30 #include <QXmlStreamWriter>
31 #include <QXmlStreamReader>
32 #include <QBuffer>
33
34 namespace QXlsx {
35
36 Drawing::Drawing(AbstractSheet *sheet, CreateFlag flag)
37 :AbstractOOXmlFile(flag), sheet(sheet)
38 {
39 workbook = sheet->workbook();
40 }
41
42 Drawing::~Drawing()
43 {
44 qDeleteAll(anchors);
45 }
46
47 void Drawing::saveToXmlFile(QIODevice *device) const
48 {
49 relationships()->clear();
50
51 QXmlStreamWriter writer(device);
52
53 writer.writeStartDocument(QStringLiteral("1.0"), true);
54 writer.writeStartElement(QStringLiteral("xdr:wsDr"));
55 writer.writeAttribute(QStringLiteral("xmlns:xdr"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing"));
56 writer.writeAttribute(QStringLiteral("xmlns:a"), QStringLiteral("http://schemas.openxmlformats.org/drawingml/2006/main"));
57
58 foreach (DrawingAnchor *anchor, anchors)
59 anchor->saveToXml(writer);
60
61 writer.writeEndElement();//xdr:wsDr
62 writer.writeEndDocument();
63 }
64
65 bool Drawing::loadFromXmlFile(QIODevice *device)
66 {
67 QXmlStreamReader reader(device);
68 while (!reader.atEnd()) {
69 reader.readNextStartElement();
70 if (reader.tokenType() == QXmlStreamReader::StartElement) {
71 if (reader.name() == QLatin1String("absoluteAnchor")) {
72 DrawingAbsoluteAnchor * anchor = new DrawingAbsoluteAnchor(this);
73 anchor->loadFromXml(reader);
74 } else if (reader.name() == QLatin1String("oneCellAnchor")) {
75 DrawingOneCellAnchor * anchor = new DrawingOneCellAnchor(this);
76 anchor->loadFromXml(reader);
77 } else if (reader.name() == QLatin1String("twoCellAnchor")) {
78 DrawingTwoCellAnchor * anchor = new DrawingTwoCellAnchor(this);
79 anchor->loadFromXml(reader);
80 }
81 }
82 }
83
84 return true;
85 }
86
87 } // namespace QXlsx
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)