libodsstream
Library for mass spectrometry
Loading...
Searching...
No Matches
qxmlstreamreadercontentxml.cpp
Go to the documentation of this file.
1/**
2 * \file src/saxreader/qxmlstreamreadercontentxml.h
3 * \date 28/4/2022
4 * \author Olivier Langella
5 * \brief ODS content XML parser
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2022 Olivier Langella <Olivier.Langella@u-psud.fr>.
10 *
11 * This file is part of libodsstream.
12 *
13 * libodsstream is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * libodsstream is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with libodsstream. If not, see <http://www.gnu.org/licenses/>.
25 *
26 ******************************************************************************/
27
29#include <QDebug>
30
32 : m_odsReader(ods_reader)
33{
34}
35
39
40bool
42{
43
44 if(readNextStartElement())
45 {
46 qDebug() << qualifiedName();
47 /*
48 * <office:document-content
49 * xmlns:anim="urn:oasis:names:tc:opendocument:xmlns:animation:1.0"
50 * xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
51 * xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
52 * xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
53 * xmlns:db="urn:oasis:names:tc:opendocument:xmlns:database:1.0"
54 * xmlns:dc="http://purl.org/dc/elements/1.1/"
55 * xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
56 * xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
57 * xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
58 * xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
59 * xmlns:grddl="http://www.w3.org/2003/g/data-view#"
60 * xmlns:math="http://www.w3.org/1998/Math/MathML"
61 * xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
62 * xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
63 * xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
64 * xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
65 * xmlns:ooo="http://openoffice.org/2004/office"
66 * xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0"
67 * xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
68 * xmlns:smil="urn:oasis:names:tc:opendocument:xmlns:smil-compatible:1.0"
69 * xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
70 * xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
71 * xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
72 * xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
73 * xmlns:xforms="http://www.w3.org/2002/xforms"
74 * xmlns:xhtml="http://www.w3.org/1999/xhtml"
75 * xmlns:xlink="http://www.w3.org/1999/xlink"
76 * xmlns:xsd="http://www.w3.org/2001/XMLSchema"
77 * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
78 * office:version="1.2">
79 * */
80 if(qualifiedName().toString() == "office:document-content")
81 {
82 //<office:body>
83
84 //<note type="input" label="output, histogram column width">30</note>
85 while(readNextStartElement())
86 {
87 qDebug() << qualifiedName();
88 if(qualifiedName().toString() == "office:body")
89 {
90
91 //<office:spreadsheet>
92 while(readNextStartElement())
93 {
94 qDebug() << qualifiedName();
95 if(qualifiedName().toString() == "office:spreadsheet")
96 {
97 //<table:table table:name="classeur"
98 // table:style-name="ta1" table:print="false">
99 qDebug() << qualifiedName();
100 readTable();
101 }
102 else
103 {
104 skipCurrentElement();
105 }
106 }
107 }
108 else
109 {
110 skipCurrentElement();
111 }
112 }
113 }
114 else
115 {
116 raiseError(QObject::tr("Not an OASIS content XML"));
117 skipCurrentElement();
118 }
119 }
120 return !error();
121}
122
123
124bool
126{
127
128 qDebug() << qualifiedName();
129 while(readNextStartElement())
130 {
131
132 qDebug() << qualifiedName();
133 if(qualifiedName().toString() == "table:table")
134 {
135 QString spread_sheet_name =
136 attributes().value("table:name").toString();
137 if(spread_sheet_name.isEmpty())
138 {
139 //_errorStr = QObject::tr("spread_sheet_name is
140 // empty.");
141 // return false;
142 }
143 m_odsReader.startSheet(spread_sheet_name);
144
145 readTableRow();
146 }
147 else
148 {
149 // raiseError(QObject::tr("Not an OASIS content XML"));
150 skipCurrentElement();
151 }
152 }
153
154 return !error();
155}
156
157
158bool
160{
161
162 //<table:table-row table:style-name="ro1">
163 qDebug() << qualifiedName();
164 while(readNextStartElement())
165 {
166
167 qDebug() << qualifiedName();
168 if(qualifiedName().toString() == "table:table-row")
169 {
173 }
174 else
175 {
176 // raiseError(QObject::tr("Not an OASIS content XML"));
177 skipCurrentElement();
178 }
179 }
180
181 return !error();
182}
183
184
185bool
187{
188
189 //<table:table-cell office:value-type="string" table:style-name="ce1">
190 // <text:p>truc</text:p>
191 // </table:table-cell>
192 qDebug() << qualifiedName();
193 while(readNextStartElement())
194 {
195
196 qDebug() << qualifiedName();
197 if(qualifiedName().toString() == "table:table-cell")
198 {
199
202 attributes().value("office:value-type").toString());
203 if(m_currentCell.getOfficeValueType().isEmpty())
204 {
206 attributes().value("calcext:value-type").toString());
207 }
208
209
210 // table:number-columns-repeated="2"
211 // <table:table-cell table:number-columns-repeated="2"
212 // office:value-type="string"><text:p>N.A.</text:p></table:table-cell>
213
214 if(!attributes()
215 .value("table:number-columns-repeated")
216 .toString()
217 .isEmpty())
218 {
220 attributes().value("table:number-columns-repeated").toUInt();
221 // System.out.println("coucou " + numberColumnsRepeated);
222 }
223
224 if(!m_currentCell.getOfficeValueType().isEmpty())
225 {
226
227 QString dateStr =
228 attributes().value("office:date-value").toString();
229 if(!dateStr.isEmpty())
230 {
231 // qDebug() << "dateStr " << dateStr;
232 QDateTime date(QDateTime::fromString(dateStr, Qt::ISODate));
233 // date.fromString(dateStr,Qt::ISODate);
234 // qDebug() << " date.fromString " <<
235 // date.toString(Qt::ISODate);
237 }
238
239
240 if(m_currentCell.getOfficeValueType() == "float")
241 {
242 /*
243 * writer.writeAttribute("office",
244 * hashNamespaceURI.get("office"), "value-type",
245 * "float"); writer.writeAttribute("office",
246 * hashNamespaceURI.get("office"), "value", value);
247 */
248 QString valueStr =
249 attributes().value("office:value").toString();
250 if(valueStr.isEmpty())
251 {
252 raiseError(QObject::tr("office:value is null"));
253 }
254 m_currentCell.setValueDouble(valueStr.toDouble());
255 }
256 else if(m_currentCell.getOfficeValueType() == "boolean")
257 {
258 // office:boolean-value="false" calcext:value-type="boolean"
259 // office:value-type="boolean"
260 QString valueStr =
261 attributes().value("office:boolean-value").toString();
263 if(valueStr.isEmpty())
264 {
266 }
267 else if(valueStr == "true")
268 {
270 }
271 }
272 }
273
274 // content cell
275
277
278 // skipCurrentElement();
279
280 // end table cell
281 while(m_numberColumnsRepeated > 0)
282 {
285 }
286 }
287
288
289 else
290 {
291 // raiseError(QObject::tr("Not an OASIS content XML"));
292 skipCurrentElement();
293 }
294 }
295
296 return !error();
297}
298
299
300bool
302{
303
304 while(readNextStartElement())
305 {
306
307 qDebug() << qualifiedName();
308 if(qualifiedName().toString() == "office:annotation")
309 {
310 //dc:date
311 skipCurrentElement();
312 }
313 else if(qualifiedName().toString() == "text:p")
314 {
315 readTextP();
316 }
317 else
318 {
319 raiseError(
320 QObject::tr("Not an OASIS content XML %1").arg(qualifiedName()));
321 }
322 }
323
324
325 return !error();
326}
327
328
329bool
331{
333 readElementText(QXmlStreamReader::IncludeChildElements));
334
335 return !error();
336}
void setOfficeValueType(const QString &type)
Definition odscell.cpp:33
void setValueBoolean(bool value_bool)
Definition odscell.cpp:76
void setValueDouble(double value_num)
Definition odscell.cpp:70
void setDateValue(const QDateTime &date)
Definition odscell.cpp:56
const QString & getOfficeValueType() const
Definition odscell.cpp:91
QString _string_value
Definition odscell.h:57
void startSheet(const QString &sheet_name)
void setInsideCell(const OdsCell &cell)
QXmlStreamReaderContentXml(OdsDocReader &ods_reader)