libodsstream
Library for mass spectrometry
Loading...
Searching...
No Matches
odsdocreader.cpp
Go to the documentation of this file.
1/*
2 libodsstream is a library to read and write ODS documents as streams
3 Copyright (C) 2013 Olivier Langella <Olivier.Langella@moulon.inra.fr>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18*/
19
20#include "odsdocreader.h"
21#include "odsexception.h"
22#include <QDebug>
23#include <QFileInfo>
25//#include "./saxreader/saxhandlercontentxml.h"
26#include <quazipfile.h>
27
29{
30}
31
33{
34 qDebug();
35 if(_p_quaZip != nullptr)
36 {
37 if(_p_quaZip->isOpen())
38 {
39 _p_quaZip->close();
40 delete _p_quaZip;
41 _p_quaZip = nullptr;
42 }
43 }
44 qDebug();
45}
46
47
48void
49OdsDocReader::parse(QFile &odsFile)
50{
51 qDebug() << odsFile.fileName();
52 QFileInfo ods_file_info(odsFile.fileName());
53 if(!ods_file_info.exists())
54 {
55 throw OdsException(QObject::tr("ODS file %1 does not exists")
56 .arg(ods_file_info.absoluteFilePath()));
57 }
58 if(!ods_file_info.isReadable())
59 {
60 throw OdsException(QObject::tr("ODS file %1 is not readable")
61 .arg(ods_file_info.absoluteFilePath()));
62 }
63 if(!odsFile.open(QIODevice::ReadOnly))
64 {
65 throw OdsException(QObject::tr("Unable to read ODS file %1")
66 .arg(ods_file_info.absoluteFilePath()));
67 }
68 qDebug() << ods_file_info.absoluteFilePath();
69 parse(&odsFile);
70 odsFile.close();
71}
72
73void
74OdsDocReader::parse(QIODevice *p_inputstream)
75{
76 qDebug();
77 _p_quaZip = new QuaZip(p_inputstream);
78 _p_quaZip->open(QuaZip::mdUnzip);
79
80 qDebug();
81 for(bool more = _p_quaZip->goToFirstFile(); more;
82 more = _p_quaZip->goToNextFile())
83 {
84 qDebug() << _p_quaZip->getCurrentFileName();
85
86 if(_p_quaZip->getCurrentFileName() == "content.xml")
87 {
88
89
90 QuaZipFile zip_file(_p_quaZip);
91 QXmlStreamReaderContentXml content_reader(*this);
92 zip_file.open(QIODevice::ReadOnly);
93 content_reader.setDevice(&zip_file);
94 content_reader.setNamespaceProcessing(true);
95 content_reader.read();
96 if(content_reader.error())
97 {
98
99 zip_file.close();
100 qDebug() << " error " << content_reader.errorString();
101 throw OdsException(QObject::tr("error reading ODS input file :\n")
102 .append(content_reader.errorString()));
103 }
104 qDebug() << " contentXml : DONE on file '"
105 << _p_quaZip->getCurrentFileName() << "'";
106
107 zip_file.close();
108 }
109 }
110 if(_p_quaZip != nullptr)
111 {
112 if(_p_quaZip->isOpen())
113 {
114 _p_quaZip->close();
115 delete _p_quaZip;
116 _p_quaZip = nullptr;
117 }
118 }
119 this->endDocument();
120}
121
122void
128
129void
131{
133 qDebug() << cell.getOfficeValueType() << " " << cell.toString();
134 if(cell.isDate())
135 {
136 qDebug() << " date " << cell.getDateTimeValue().toString(Qt::ISODate)
137 << " " << cell.getDateTimeValue().date().day() << " "
138 << cell.getDateTimeValue().date().month();
139 }
140 else if(cell.isString())
141 {
142 qDebug() << " string " << cell.getStringValue();
143 }
144 else if(cell.isDouble())
145 {
146 qDebug() << " double " << cell.getDoubleValue();
147 }
148 setCell(cell);
149}
150
151
152void
153OdsDocReader::startSheet(const QString &sheet_name)
154{
155 _handler.startSheet(sheet_name);
156}
157
158void
163
164void
169
170void
175
176void
178{
179 _handler.setCell(cell);
180}
181void
const QDateTime & getDateTimeValue() const
Definition odscell.cpp:97
const QString & toString() const
Definition odscell.cpp:83
double getDoubleValue() const
Definition odscell.cpp:123
bool isDate() const
Definition odscell.cpp:154
bool isString() const
Definition odscell.cpp:168
bool isDouble() const
Definition odscell.cpp:161
const QString & getStringValue() const
Definition odscell.cpp:110
const QString & getOfficeValueType() const
Definition odscell.cpp:91
virtual void endSheet()=0
virtual void setCell(const OdsCell &)=0
virtual void endDocument()=0
virtual void startLine()=0
virtual void startSheet(const QString &sheet_name)=0
virtual void endLine()=0
OdsDocHandlerInterface & _handler
QuaZip * _p_quaZip
void startInsideLine()
void startSheet(const QString &sheet_name)
void setCell(const OdsCell &cell)
virtual ~OdsDocReader()
void parse(QFile &odsFile)
uint _column_number
void setInsideCell(const OdsCell &cell)
OdsDocReader(OdsDocHandlerInterface &handler)