annotate src/xlsx/xlsxsharedstrings.cpp @ 69:dab9c19252bd

Set wordwrap exiplicitly for multiple choice answers
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 29 Sep 2016 14:40:06 +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 "xlsxrichstring.h"
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
26 #include "xlsxsharedstrings_p.h"
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
27 #include "xlsxutility_p.h"
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
28 #include "xlsxformat_p.h"
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
29 #include "xlsxcolor_p.h"
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
30 #include <QXmlStreamWriter>
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
31 #include <QXmlStreamReader>
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
32 #include <QDir>
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
33 #include <QFile>
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
34 #include <QDebug>
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
35 #include <QBuffer>
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
36
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
37 namespace QXlsx {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
38
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 * Note that, when we open an existing .xlsx file (broken file?),
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
41 * duplicated string items may exist in the shared string table.
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
42 *
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
43 * In such case, the size of stringList will larger than stringTable.
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
44 * Duplicated items can be removed once we loaded all the worksheets.
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 SharedStrings::SharedStrings(CreateFlag flag)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
48 :AbstractOOXmlFile(flag)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
49 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
50 m_stringCount = 0;
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
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
53 int SharedStrings::count() const
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
54 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
55 return m_stringCount;
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
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
58 bool SharedStrings::isEmpty() const
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
59 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
60 return m_stringList.isEmpty();
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
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
63 int SharedStrings::addSharedString(const QString &string)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
64 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
65 return addSharedString(RichString(string));
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
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
68 int SharedStrings::addSharedString(const RichString &string)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
69 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
70 m_stringCount += 1;
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 if (m_stringTable.contains(string)) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
73 XlsxSharedStringInfo &item = m_stringTable[string];
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
74 item.count += 1;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
75 return item.index;
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
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
78 int index = m_stringList.size();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
79 m_stringTable[string] = XlsxSharedStringInfo(index);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
80 m_stringList.append(string);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
81 return index;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
82 }
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 void SharedStrings::incRefByStringIndex(int idx)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
85 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
86 if (idx <0 || idx >= m_stringList.size()) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
87 qDebug("SharedStrings: invlid index");
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
88 return;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
89 }
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 addSharedString(m_stringList[idx]);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
92 }
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 /*
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
95 * Broken, don't use.
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
96 */
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
97 void SharedStrings::removeSharedString(const QString &string)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
98 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
99 removeSharedString(RichString(string));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
100 }
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 * Broken, don't use.
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 void SharedStrings::removeSharedString(const RichString &string)
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 if (!m_stringTable.contains(string))
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
108 return;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
109
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
110 m_stringCount -= 1;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
111
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
112 XlsxSharedStringInfo &item = m_stringTable[string];
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
113 item.count -= 1;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
114
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
115 if (item.count <= 0) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
116 for (int i=item.index+1; i<m_stringList.size(); ++i)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
117 m_stringTable[m_stringList[i]].index -= 1;
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 m_stringList.removeAt(item.index);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
120 m_stringTable.remove(string);
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
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
124 int SharedStrings::getSharedStringIndex(const QString &string) const
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
125 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
126 return getSharedStringIndex(RichString(string));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
127 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
128
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
129 int SharedStrings::getSharedStringIndex(const RichString &string) const
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
130 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
131 if (m_stringTable.contains(string))
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
132 return m_stringTable[string].index;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
133 return -1;
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
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
136 RichString SharedStrings::getSharedString(int index) const
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
137 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
138 if (index < m_stringList.count() && index >= 0)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
139 return m_stringList[index];
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
140 return RichString();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
141 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
142
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
143 QList<RichString> SharedStrings::getSharedStrings() const
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
144 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
145 return m_stringList;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
146 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
147
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
148 void SharedStrings::writeRichStringPart_rPr(QXmlStreamWriter &writer, const Format &format) const
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 if (!format.hasFontData())
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
151 return;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
152
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
153 if (format.fontBold())
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
154 writer.writeEmptyElement(QStringLiteral("b"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
155 if (format.fontItalic())
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
156 writer.writeEmptyElement(QStringLiteral("i"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
157 if (format.fontStrikeOut())
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
158 writer.writeEmptyElement(QStringLiteral("strike"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
159 if (format.fontOutline())
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
160 writer.writeEmptyElement(QStringLiteral("outline"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
161 if (format.boolProperty(FormatPrivate::P_Font_Shadow))
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
162 writer.writeEmptyElement(QStringLiteral("shadow"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
163 if (format.hasProperty(FormatPrivate::P_Font_Underline)) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
164 Format::FontUnderline u = format.fontUnderline();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
165 if (u != Format::FontUnderlineNone) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
166 writer.writeEmptyElement(QStringLiteral("u"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
167 if (u== Format::FontUnderlineDouble)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
168 writer.writeAttribute(QStringLiteral("val"), QStringLiteral("double"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
169 else if (u == Format::FontUnderlineSingleAccounting)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
170 writer.writeAttribute(QStringLiteral("val"), QStringLiteral("singleAccounting"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
171 else if (u == Format::FontUnderlineDoubleAccounting)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
172 writer.writeAttribute(QStringLiteral("val"), QStringLiteral("doubleAccounting"));
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 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
175 if (format.hasProperty(FormatPrivate::P_Font_Script)) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
176 Format::FontScript s = format.fontScript();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
177 if (s != Format::FontScriptNormal) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
178 writer.writeEmptyElement(QStringLiteral("vertAlign"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
179 if (s == Format::FontScriptSuper)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
180 writer.writeAttribute(QStringLiteral("val"), QStringLiteral("superscript"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
181 else
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
182 writer.writeAttribute(QStringLiteral("val"), QStringLiteral("subscript"));
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 }
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 if (format.hasProperty(FormatPrivate::P_Font_Size)) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
187 writer.writeEmptyElement(QStringLiteral("sz"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
188 writer.writeAttribute(QStringLiteral("val"), QString::number(format.fontSize()));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
189 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
190
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
191 if (format.hasProperty(FormatPrivate::P_Font_Color)) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
192 XlsxColor color = format.property(FormatPrivate::P_Font_Color).value<XlsxColor>();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
193 color.saveToXml(writer);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
194 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
195
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
196 if (!format.fontName().isEmpty()) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
197 writer.writeEmptyElement(QStringLiteral("rFont"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
198 writer.writeAttribute(QStringLiteral("val"), format.fontName());
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
199 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
200 if (format.hasProperty(FormatPrivate::P_Font_Family)) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
201 writer.writeEmptyElement(QStringLiteral("family"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
202 writer.writeAttribute(QStringLiteral("val"), QString::number(format.intProperty(FormatPrivate::P_Font_Family)));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
203 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
204
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
205 if (format.hasProperty(FormatPrivate::P_Font_Scheme)) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
206 writer.writeEmptyElement(QStringLiteral("scheme"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
207 writer.writeAttribute(QStringLiteral("val"), format.stringProperty(FormatPrivate::P_Font_Scheme));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
208 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
209 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
210
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
211 void SharedStrings::saveToXmlFile(QIODevice *device) const
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
212 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
213 QXmlStreamWriter writer(device);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
214
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
215 if (m_stringList.size() != m_stringTable.size()) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
216 //Duplicated string items exist in m_stringList
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
217 //Clean up can not be done here, as the indices
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
218 //have been used when we save the worksheets part.
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
219 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
220
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
221 writer.writeStartDocument(QStringLiteral("1.0"), true);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
222 writer.writeStartElement(QStringLiteral("sst"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
223 writer.writeAttribute(QStringLiteral("xmlns"), QStringLiteral("http://schemas.openxmlformats.org/spreadsheetml/2006/main"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
224 writer.writeAttribute(QStringLiteral("count"), QString::number(m_stringCount));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
225 writer.writeAttribute(QStringLiteral("uniqueCount"), QString::number(m_stringList.size()));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
226
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
227 foreach (RichString string, m_stringList) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
228 writer.writeStartElement(QStringLiteral("si"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
229 if (string.isRichString()) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
230 //Rich text string
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
231 for (int i=0; i<string.fragmentCount(); ++i) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
232 writer.writeStartElement(QStringLiteral("r"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
233 if (string.fragmentFormat(i).hasFontData()) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
234 writer.writeStartElement(QStringLiteral("rPr"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
235 writeRichStringPart_rPr(writer, string.fragmentFormat(i));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
236 writer.writeEndElement();// rPr
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
237 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
238 writer.writeStartElement(QStringLiteral("t"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
239 if (isSpaceReserveNeeded(string.fragmentText(i)))
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
240 writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
241 writer.writeCharacters(string.fragmentText(i));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
242 writer.writeEndElement();// t
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
243
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
244 writer.writeEndElement(); //r
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
245 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
246 } else {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
247 writer.writeStartElement(QStringLiteral("t"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
248 QString pString = string.toPlainString();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
249 if (isSpaceReserveNeeded(pString))
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
250 writer.writeAttribute(QStringLiteral("xml:space"), QStringLiteral("preserve"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
251 writer.writeCharacters(pString);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
252 writer.writeEndElement();//t
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
253 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
254 writer.writeEndElement();//si
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
255 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
256
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
257 writer.writeEndElement(); //sst
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
258 writer.writeEndDocument();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
259 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
260
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
261 void SharedStrings::readString(QXmlStreamReader &reader)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
262 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
263 Q_ASSERT(reader.name() == QLatin1String("si"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
264
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
265 RichString richString;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
266
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
267 while (!reader.atEnd() && !(reader.name() == QLatin1String("si") && reader.tokenType() == QXmlStreamReader::EndElement)) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
268 reader.readNextStartElement();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
269 if (reader.tokenType() == QXmlStreamReader::StartElement) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
270 if (reader.name() == QLatin1String("r"))
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
271 readRichStringPart(reader, richString);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
272 else if (reader.name() == QLatin1String("t"))
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
273 readPlainStringPart(reader, richString);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
274 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
275 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
276
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
277 int idx = m_stringList.size();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
278 m_stringTable[richString] = XlsxSharedStringInfo(idx, 0);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
279 m_stringList.append(richString);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
280 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
281
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
282 void SharedStrings::readRichStringPart(QXmlStreamReader &reader, RichString &richString)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
283 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
284 Q_ASSERT(reader.name() == QLatin1String("r"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
285
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
286 QString text;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
287 Format format;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
288 while (!reader.atEnd() && !(reader.name() == QLatin1String("r") && reader.tokenType() == QXmlStreamReader::EndElement)) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
289 reader.readNextStartElement();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
290 if (reader.tokenType() == QXmlStreamReader::StartElement) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
291 if (reader.name() == QLatin1String("rPr")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
292 format = readRichStringPart_rPr(reader);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
293 } else if (reader.name() == QLatin1String("t")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
294 text = reader.readElementText();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
295 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
296 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
297 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
298 richString.addFragment(text, format);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
299 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
300
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
301 void SharedStrings::readPlainStringPart(QXmlStreamReader &reader, RichString &richString)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
302 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
303 Q_ASSERT(reader.name() == QLatin1String("t"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
304
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
305 //QXmlStreamAttributes attributes = reader.attributes();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
306
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
307 QString text = reader.readElementText();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
308 richString.addFragment(text, Format());
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
309 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
310
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
311 Format SharedStrings::readRichStringPart_rPr(QXmlStreamReader &reader)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
312 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
313 Q_ASSERT(reader.name() == QLatin1String("rPr"));
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
314 Format format;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
315 while (!reader.atEnd() && !(reader.name() == QLatin1String("rPr") && reader.tokenType() == QXmlStreamReader::EndElement)) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
316 reader.readNextStartElement();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
317 if (reader.tokenType() == QXmlStreamReader::StartElement) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
318 QXmlStreamAttributes attributes = reader.attributes();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
319 if (reader.name() == QLatin1String("rFont")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
320 format.setFontName(attributes.value(QLatin1String("val")).toString());
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
321 } else if (reader.name() == QLatin1String("charset")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
322 format.setProperty(FormatPrivate::P_Font_Charset, attributes.value(QLatin1String("val")).toString().toInt());
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
323 } else if (reader.name() == QLatin1String("family")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
324 format.setProperty(FormatPrivate::P_Font_Family, attributes.value(QLatin1String("val")).toString().toInt());
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
325 } else if (reader.name() == QLatin1String("b")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
326 format.setFontBold(true);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
327 } else if (reader.name() == QLatin1String("i")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
328 format.setFontItalic(true);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
329 } else if (reader.name() == QLatin1String("strike")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
330 format.setFontStrikeOut(true);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
331 } else if (reader.name() == QLatin1String("outline")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
332 format.setFontOutline(true);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
333 } else if (reader.name() == QLatin1String("shadow")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
334 format.setProperty(FormatPrivate::P_Font_Shadow, true);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
335 } else if (reader.name() == QLatin1String("condense")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
336 format.setProperty(FormatPrivate::P_Font_Condense, attributes.value(QLatin1String("val")).toString().toInt());
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
337 } else if (reader.name() == QLatin1String("extend")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
338 format.setProperty(FormatPrivate::P_Font_Extend, attributes.value(QLatin1String("val")).toString().toInt());
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
339 } else if (reader.name() == QLatin1String("color")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
340 XlsxColor color;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
341 color.loadFromXml(reader);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
342 format.setProperty(FormatPrivate::P_Font_Color, color);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
343 } else if (reader.name() == QLatin1String("sz")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
344 format.setFontSize(attributes.value(QLatin1String("val")).toString().toInt());
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
345 } else if (reader.name() == QLatin1String("u")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
346 QString value = attributes.value(QLatin1String("val")).toString();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
347 if (value == QLatin1String("double"))
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
348 format.setFontUnderline(Format::FontUnderlineDouble);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
349 else if (value == QLatin1String("doubleAccounting"))
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
350 format.setFontUnderline(Format::FontUnderlineDoubleAccounting);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
351 else if (value == QLatin1String("singleAccounting"))
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
352 format.setFontUnderline(Format::FontUnderlineSingleAccounting);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
353 else
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
354 format.setFontUnderline(Format::FontUnderlineSingle);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
355 } else if (reader.name() == QLatin1String("vertAlign")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
356 QString value = attributes.value(QLatin1String("val")).toString();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
357 if (value == QLatin1String("superscript"))
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
358 format.setFontScript(Format::FontScriptSuper);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
359 else if (value == QLatin1String("subscript"))
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
360 format.setFontScript(Format::FontScriptSub);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
361 } else if (reader.name() == QLatin1String("scheme")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
362 format.setProperty(FormatPrivate::P_Font_Scheme, attributes.value(QLatin1String("val")).toString());
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
363 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
364 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
365 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
366 return format;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
367 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
368
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
369 bool SharedStrings::loadFromXmlFile(QIODevice *device)
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
370 {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
371 QXmlStreamReader reader(device);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
372 int count = 0;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
373 bool hasUniqueCountAttr=true;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
374 while (!reader.atEnd()) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
375 QXmlStreamReader::TokenType token = reader.readNext();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
376 if (token == QXmlStreamReader::StartElement) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
377 if (reader.name() == QLatin1String("sst")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
378 QXmlStreamAttributes attributes = reader.attributes();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
379 if ((hasUniqueCountAttr = attributes.hasAttribute(QLatin1String("uniqueCount"))))
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
380 count = attributes.value(QLatin1String("uniqueCount")).toString().toInt();
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
381 } else if (reader.name() == QLatin1String("si")) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
382 readString(reader);
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
383 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
384 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
385 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
386
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
387 if (hasUniqueCountAttr && m_stringList.size() != count) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
388 qDebug("Error: Shared string count");
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
389 return false;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
390 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
391
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
392 if (m_stringList.size() != m_stringTable.size()) {
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
393 //qDebug("Warning: Duplicated items exist in shared string table.");
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
394 //Nothing we can do here, as indices of the strings will be used when loading sheets.
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
395 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
396
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
397 return true;
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
398 }
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
399
93d3106bb9a4 Add qt xlsx library
Andre Heinecke <andre.heinecke@intevation.de>
parents:
diff changeset
400 } //namespace
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)