libodsstream
Library for mass spectrometry
Loading...
Searching...
No Matches
OdsDocReader Class Reference

#include <odsdocreader.h>

Public Member Functions

 OdsDocReader (OdsDocHandlerInterface &handler)
 
virtual ~OdsDocReader ()
 
void parse (QFile &odsFile)
 
void parse (QIODevice *p_inputstream)
 

Private Member Functions

void setInsideCell (const OdsCell &cell)
 
void startInsideLine ()
 
void startSheet (const QString &sheet_name)
 
void endSheet ()
 
void startLine ()
 
void endLine ()
 
void setCell (const OdsCell &cell)
 
void endDocument ()
 

Private Attributes

friend QXmlStreamReaderContentXml
 
QuaZip * _p_quaZip = nullptr
 
uint _column_number
 
OdsDocHandlerInterface_handler
 

Detailed Description

Definition at line 29 of file odsdocreader.h.

Constructor & Destructor Documentation

◆ OdsDocReader()

OdsDocReader::OdsDocReader ( OdsDocHandlerInterface handler)

creates an ODS reader with a reader handler

@Param OdsDocHandlerInterface & the interface to implement to read ODS files

Definition at line 28 of file odsdocreader.cpp.

28 : _handler(handler)
29{
30}
OdsDocHandlerInterface & _handler

◆ ~OdsDocReader()

OdsDocReader::~OdsDocReader ( )
virtual

Definition at line 32 of file odsdocreader.cpp.

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}
QuaZip * _p_quaZip

References _p_quaZip.

Member Function Documentation

◆ endDocument()

void OdsDocReader::endDocument ( )
private

Definition at line 182 of file odsdocreader.cpp.

183{
185}
virtual void endDocument()=0

References _handler, and OdsDocHandlerInterface::endDocument().

Referenced by parse().

◆ endLine()

void OdsDocReader::endLine ( )
private

Definition at line 171 of file odsdocreader.cpp.

172{
174}
virtual void endLine()=0

References _handler, and OdsDocHandlerInterface::endLine().

Referenced by QXmlStreamReaderContentXml::readTableRow().

◆ endSheet()

void OdsDocReader::endSheet ( )
private

Definition at line 159 of file odsdocreader.cpp.

160{
162}
virtual void endSheet()=0

References _handler, and OdsDocHandlerInterface::endSheet().

◆ parse() [1/2]

void OdsDocReader::parse ( QFile &  odsFile)

Definition at line 49 of file odsdocreader.cpp.

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}
void parse(QFile &odsFile)

References parse().

Referenced by parse().

◆ parse() [2/2]

void OdsDocReader::parse ( QIODevice *  p_inputstream)

Definition at line 74 of file odsdocreader.cpp.

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}

References _p_quaZip, endDocument(), and QXmlStreamReaderContentXml::read().

◆ setCell()

void OdsDocReader::setCell ( const OdsCell cell)
private

Definition at line 177 of file odsdocreader.cpp.

178{
179 _handler.setCell(cell);
180}
virtual void setCell(const OdsCell &)=0

References _handler, and OdsDocHandlerInterface::setCell().

Referenced by setInsideCell().

◆ setInsideCell()

void OdsDocReader::setInsideCell ( const OdsCell cell)
private

Definition at line 130 of file odsdocreader.cpp.

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}
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
void setCell(const OdsCell &cell)
uint _column_number

References _column_number, OdsCell::getDateTimeValue(), OdsCell::getDoubleValue(), OdsCell::getOfficeValueType(), OdsCell::getStringValue(), OdsCell::isDate(), OdsCell::isDouble(), OdsCell::isString(), setCell(), and OdsCell::toString().

Referenced by QXmlStreamReaderContentXml::readTableLine().

◆ startInsideLine()

void OdsDocReader::startInsideLine ( )
private

Definition at line 123 of file odsdocreader.cpp.

124{
125 _column_number = 0;
126 startLine();
127}

References _column_number, and startLine().

◆ startLine()

void OdsDocReader::startLine ( )
private

Definition at line 165 of file odsdocreader.cpp.

166{
168}
virtual void startLine()=0

References _handler, and OdsDocHandlerInterface::startLine().

Referenced by QXmlStreamReaderContentXml::readTableRow(), and startInsideLine().

◆ startSheet()

void OdsDocReader::startSheet ( const QString &  sheet_name)
private

Definition at line 153 of file odsdocreader.cpp.

154{
155 _handler.startSheet(sheet_name);
156}
virtual void startSheet(const QString &sheet_name)=0

References _handler, and OdsDocHandlerInterface::startSheet().

Referenced by QXmlStreamReaderContentXml::readTable().

Member Data Documentation

◆ _column_number

uint OdsDocReader::_column_number
private

Definition at line 67 of file odsdocreader.h.

Referenced by setInsideCell(), and startInsideLine().

◆ _handler

OdsDocHandlerInterface& OdsDocReader::_handler
private

Definition at line 69 of file odsdocreader.h.

Referenced by endDocument(), endLine(), endSheet(), setCell(), startLine(), and startSheet().

◆ _p_quaZip

QuaZip* OdsDocReader::_p_quaZip = nullptr
private

Definition at line 65 of file odsdocreader.h.

Referenced by ~OdsDocReader(), and parse().

◆ QXmlStreamReaderContentXml

friend OdsDocReader::QXmlStreamReaderContentXml
private

Definition at line 31 of file odsdocreader.h.


The documentation for this class was generated from the following files: