Mercurial > clickerconvert
annotate src/xlsx/xlsxrelationships.cpp @ 59:831f86c2cdda
Removed tag 1.1
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 09 Aug 2016 10:38:43 +0200 |
parents | 93d3106bb9a4 |
children |
rev | line source |
---|---|
1
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
1 /**************************************************************************** |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
2 ** Copyright (c) 2013-2014 Debao Zhang <hello@debao.me> |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
3 ** All right reserved. |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
4 ** |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
5 ** Permission is hereby granted, free of charge, to any person obtaining |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
6 ** a copy of this software and associated documentation files (the |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
7 ** "Software"), to deal in the Software without restriction, including |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
8 ** without limitation the rights to use, copy, modify, merge, publish, |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
9 ** distribute, sublicense, and/or sell copies of the Software, and to |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
10 ** permit persons to whom the Software is furnished to do so, subject to |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
11 ** the following conditions: |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
12 ** |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
13 ** The above copyright notice and this permission notice shall be |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
14 ** included in all copies or substantial portions of the Software. |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
15 ** |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
16 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
17 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
18 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
19 ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
20 ** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
21 ** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
22 ** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
23 ** |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
24 ****************************************************************************/ |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
25 #include "xlsxrelationships_p.h" |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
26 #include <QXmlStreamWriter> |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
27 #include <QXmlStreamReader> |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
28 #include <QDir> |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
29 #include <QFile> |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
30 #include <QBuffer> |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
31 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
32 namespace QXlsx { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
33 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
34 const QString schema_doc = QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
35 const QString schema_msPackage = QStringLiteral("http://schemas.microsoft.com/office/2006/relationships"); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
36 const QString schema_package = QStringLiteral("http://schemas.openxmlformats.org/package/2006/relationships"); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
37 //const QString schema_worksheet = QStringLiteral("http://schemas.openxmlformats.org/officeDocument/2006/relationships"); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
38 Relationships::Relationships() |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
39 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
40 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
41 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
42 QList<XlsxRelationship> Relationships::documentRelationships(const QString &relativeType) const |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
43 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
44 return relationships(schema_doc + relativeType); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
45 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
46 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
47 void Relationships::addDocumentRelationship(const QString &relativeType, const QString &target) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
48 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
49 addRelationship(schema_doc + relativeType, target); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
50 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
51 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
52 QList<XlsxRelationship> Relationships::msPackageRelationships(const QString &relativeType) const |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
53 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
54 return relationships(schema_msPackage + relativeType); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
55 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
56 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
57 void Relationships::addMsPackageRelationship(const QString &relativeType, const QString &target) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
58 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
59 addRelationship(schema_msPackage + relativeType, target); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
60 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
61 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
62 QList<XlsxRelationship> Relationships::packageRelationships(const QString &relativeType) const |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
63 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
64 return relationships(schema_package + relativeType); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
65 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
66 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
67 void Relationships::addPackageRelationship(const QString &relativeType, const QString &target) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
68 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
69 addRelationship(schema_package + relativeType, target); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
70 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
71 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
72 QList<XlsxRelationship> Relationships::worksheetRelationships(const QString &relativeType) const |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
73 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
74 return relationships(schema_doc + relativeType); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
75 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
76 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
77 void Relationships::addWorksheetRelationship(const QString &relativeType, const QString &target, const QString &targetMode) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
78 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
79 addRelationship(schema_doc + relativeType, target, targetMode); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
80 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
81 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
82 QList<XlsxRelationship> Relationships::relationships(const QString &type) const |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
83 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
84 QList<XlsxRelationship> res; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
85 foreach (XlsxRelationship ship, m_relationships) { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
86 if (ship.type == type) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
87 res.append(ship); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
88 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
89 return res; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
90 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
91 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
92 void Relationships::addRelationship(const QString &type, const QString &target, const QString &targetMode) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
93 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
94 XlsxRelationship relation; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
95 relation.id = QStringLiteral("rId%1").arg(m_relationships.size()+1); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
96 relation.type = type; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
97 relation.target = target; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
98 relation.targetMode = targetMode; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
99 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
100 m_relationships.append(relation); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
101 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
102 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
103 void Relationships::saveToXmlFile(QIODevice *device) const |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
104 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
105 QXmlStreamWriter writer(device); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
106 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
107 writer.writeStartDocument(QStringLiteral("1.0"), true); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
108 writer.writeStartElement(QStringLiteral("Relationships")); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
109 writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/package/2006/relationships")); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
110 foreach (XlsxRelationship relation, m_relationships) { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
111 writer.writeStartElement(QStringLiteral("Relationship")); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
112 writer.writeAttribute(QStringLiteral("Id"), relation.id); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
113 writer.writeAttribute(QStringLiteral("Type"), relation.type); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
114 writer.writeAttribute(QStringLiteral("Target"), relation.target); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
115 if (!relation.targetMode.isNull()) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
116 writer.writeAttribute(QStringLiteral("TargetMode"), relation.targetMode); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
117 writer.writeEndElement(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
118 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
119 writer.writeEndElement();//Relationships |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
120 writer.writeEndDocument(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
121 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
122 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
123 QByteArray Relationships::saveToXmlData() const |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
124 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
125 QByteArray data; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
126 QBuffer buffer(&data); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
127 buffer.open(QIODevice::WriteOnly); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
128 saveToXmlFile(&buffer); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
129 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
130 return data; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
131 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
132 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
133 bool Relationships::loadFromXmlFile(QIODevice *device) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
134 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
135 clear(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
136 QXmlStreamReader reader(device); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
137 while (!reader.atEnd()) { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
138 QXmlStreamReader::TokenType token = reader.readNext(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
139 if (token == QXmlStreamReader::StartElement) { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
140 if (reader.name() == QStringLiteral("Relationship")) { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
141 QXmlStreamAttributes attributes = reader.attributes(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
142 XlsxRelationship relationship; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
143 relationship.id = attributes.value(QLatin1String("Id")).toString(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
144 relationship.type = attributes.value(QLatin1String("Type")).toString(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
145 relationship.target = attributes.value(QLatin1String("Target")).toString(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
146 relationship.targetMode = attributes.value(QLatin1String("TargetMode")).toString(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
147 m_relationships.append(relationship); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
148 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
149 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
150 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
151 if (reader.hasError()) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
152 return false; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
153 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
154 return true; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
155 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
156 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
157 bool Relationships::loadFromXmlData(const QByteArray &data) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
158 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
159 QBuffer buffer; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
160 buffer.setData(data); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
161 buffer.open(QIODevice::ReadOnly); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
162 return loadFromXmlFile(&buffer); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
163 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
164 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
165 XlsxRelationship Relationships::getRelationshipById(const QString &id) const |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
166 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
167 foreach (XlsxRelationship ship, m_relationships) { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
168 if (ship.id == id) |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
169 return ship; |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
170 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
171 return XlsxRelationship(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
172 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
173 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
174 void Relationships::clear() |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
175 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
176 m_relationships.clear(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
177 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
178 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
179 int Relationships::count() const |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
180 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
181 return m_relationships.count(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
182 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
183 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
184 bool Relationships::isEmpty() const |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
185 { |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
186 return m_relationships.isEmpty(); |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
187 } |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
188 |
93d3106bb9a4
Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff
changeset
|
189 } //namespace |