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

#include <odsdocwriter.h>

Inheritance diagram for OdsDocWriter:
CalcWriterInterface

Public Member Functions

 OdsDocWriter (const QString &filename)
 
 OdsDocWriter (QIODevice *device)
 
virtual ~OdsDocWriter ()
 
void close () override
 
void writeSheet (const QString &sheetName) override
 
void writeLine () override
 
void writeCell (const char *) override
 write a text cell
 
void writeCell (const QString &) override
 
void writeEmptyCell () override
 
void writeCell (std::size_t) override
 
void writeCell (int) override
 
void writeCell (float) override
 
void writeCell (double) override
 
void writeCellPercentage (double value) override
 
void writeCell (bool) override
 
void writeCell (const QDate &) override
 
void writeCell (const QDateTime &) override
 
void writeCell (const QUrl &, const QString &) override
 
OdsTableCellStyleRef getTableCellStyleRef (const OdsTableCellStyle &style) override
 
void setTableCellStyleRef (OdsTableCellStyleRef style_ref) override
 
void setCellAnnotation (const QString &annotation) override
 set annotation to write in the next cell
 
void addColorScale (const OdsColorScale &ods_color_scale) override
 apply solor scale conditional format on a cell range
 
QString getOdsCellCoordinate () override
 get the last written cell coordinate in ODS coordinate format get the coordinate of the last written cell or an empty string if the writer is not an OdsDocWriter
 
void setCurrentOdsTableSettings (const OdsTableSettings &settings) override
 set ODS table settings of the current sheet (table)
 
- Public Member Functions inherited from CalcWriterInterface
virtual ~CalcWriterInterface ()
 
void clearTableCellStyleRef ()
 
virtual void writeCellVariant (const QVariant &var)
 write a cell for a given QVariant
 

Private Member Functions

void openDevice (QIODevice *device)
 
void clearAnnotation ()
 

Private Attributes

ContentXml_p_content
 
QuaZip * _p_quaZip
 
QIODevice * _p_device = nullptr
 
bool _p_device_delete = false
 
QString _next_annotation
 
SettingsXml _settings_xml
 

Detailed Description

Definition at line 31 of file odsdocwriter.h.

Constructor & Destructor Documentation

◆ OdsDocWriter() [1/2]

OdsDocWriter::OdsDocWriter ( const QString &  filename)

Definition at line 31 of file odsdocwriter.cpp.

32{
33 _p_device_delete = true;
34 QFile *p_file = new QFile(filename);
35 try
36 {
37 openDevice(p_file);
38 }
39 catch(const OdsException &ods_error)
40 {
41 throw OdsException(
42 QObject::tr("error opening ODS file. check file permission for %1")
43 .arg(QFileInfo(filename).absoluteFilePath()));
44 }
45}
bool _p_device_delete
void openDevice(QIODevice *device)

References _p_device_delete, and openDevice().

◆ OdsDocWriter() [2/2]

OdsDocWriter::OdsDocWriter ( QIODevice *  device)

Definition at line 47 of file odsdocwriter.cpp.

48{
49 openDevice(device);
50}

References openDevice().

◆ ~OdsDocWriter()

OdsDocWriter::~OdsDocWriter ( )
virtual

Definition at line 89 of file odsdocwriter.cpp.

90{
91 // this->close();
92 if(_p_content != nullptr)
93 {
94 this->close();
95 }
96}
void close() override
ContentXml * _p_content

References _p_content, and close().

Member Function Documentation

◆ addColorScale()

void OdsDocWriter::addColorScale ( const OdsColorScale ods_color_scale)
overridevirtual

apply solor scale conditional format on a cell range

Reimplemented from CalcWriterInterface.

Definition at line 389 of file odsdocwriter.cpp.

390{
391 _p_content->addColorScale(ods_color_scale);
392}
void addColorScale(const OdsColorScale &ods_color_scale)

References _p_content, and ContentXml::addColorScale().

◆ clearAnnotation()

void OdsDocWriter::clearAnnotation ( )
private

◆ close()

void OdsDocWriter::close ( )
overridevirtual

ends the document creation. It is required to obtain a correct output

Implements CalcWriterInterface.

Definition at line 103 of file odsdocwriter.cpp.

104{
105 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
106 if(_p_content != nullptr)
107 {
108 _p_content->close();
109 delete _p_content;
110 }
111 StylesXml stylesXml(_p_quaZip);
113 _p_quaZip->close();
114 delete _p_quaZip;
115
116 if(_p_device != nullptr)
117 {
118 //_p_device->flush();
119 _p_device->close();
120 }
121 _p_content = nullptr;
122 _p_quaZip = nullptr;
123 // zipOutputStream = null;
124
125 if(_p_device != nullptr)
126 {
128 {
129 qDebug() << "_p_device_delete";
130 delete _p_device;
131 }
132 }
133}
SettingsXml _settings_xml
QuaZip * _p_quaZip
QIODevice * _p_device
void write(QuaZip *p_quazip)

References _p_content, _p_device, _p_device_delete, _p_quaZip, _settings_xml, ContentXml::close(), and SettingsXml::write().

Referenced by ~OdsDocWriter().

◆ getOdsCellCoordinate()

QString OdsDocWriter::getOdsCellCoordinate ( )
overridevirtual

get the last written cell coordinate in ODS coordinate format get the coordinate of the last written cell or an empty string if the writer is not an OdsDocWriter

Returns
QString with ODS cell coordinate of the form : "classeur.A5"

Reimplemented from CalcWriterInterface.

Definition at line 396 of file odsdocwriter.cpp.

397{
399}
QString getCellCoordinate()

References _p_content, and ContentXml::getCellCoordinate().

◆ getTableCellStyleRef()

OdsTableCellStyleRef OdsDocWriter::getTableCellStyleRef ( const OdsTableCellStyle style)
overridevirtual

get a table cell style reference with a style definition

Parameters
styleOdsTableCellStyle
Returns
OdsTableCellStyleRef pointer on a style reference

Reimplemented from CalcWriterInterface.

Definition at line 369 of file odsdocwriter.cpp.

370{
371
372 return _p_content->getTableCellStyleRef(style);
373}
OdsTableCellStyleRef getTableCellStyleRef(const OdsTableCellStyle &style)

References _p_content, and ContentXml::getTableCellStyleRef().

◆ openDevice()

void OdsDocWriter::openDevice ( QIODevice *  device)
private

Definition at line 53 of file odsdocwriter.cpp.

54{
55 //_p_device_delete = false;
56 _p_device = device;
57 _p_quaZip = new QuaZip(device);
58 bool open_ok = _p_quaZip->open(QuaZip::mdCreate);
59
60 if(open_ok == false)
61 {
62 throw OdsException(QObject::tr("error opening ODS file."));
63 }
64 // QuaZipFile::open(): file open mode 2 incompatible with ZIP open mode 0
65 // QuaZip::close(): ZIP is not open
66
67
68 //_p_quaZip->setComment("application/vnd.oasis.opendocument.spreadsheet");
69 QByteArray *messageIn = new QByteArray();
70 *messageIn = "application/vnd.oasis.opendocument.spreadsheet";
71
72 QuaZipFile outFile(_p_quaZip);
73 QuaCrc32 crc32;
74 quint32 crc(crc32.calculate(*messageIn));
75 QuaZipNewInfo info("mimetype");
76 info.uncompressedSize = messageIn->length();
77 outFile.open(QIODevice::WriteOnly, info, NULL, crc, 0, 0, true);
78 outFile.write(*messageIn);
79 outFile.close();
80
81 delete(messageIn);
82
83 ManifestXml manifest(_p_quaZip);
84 MetaXml metaxml(_p_quaZip);
86}

References _p_content, _p_device, _p_quaZip, and _settings_xml.

Referenced by OdsDocWriter(), and OdsDocWriter().

◆ setCellAnnotation()

void OdsDocWriter::setCellAnnotation ( const QString &  annotation)
overridevirtual

set annotation to write in the next cell

Parameters
annotationany comment on this cell

Implements CalcWriterInterface.

Definition at line 383 of file odsdocwriter.cpp.

384{
385 _next_annotation = annotation;
386}

References _next_annotation.

◆ setCurrentOdsTableSettings()

void OdsDocWriter::setCurrentOdsTableSettings ( const OdsTableSettings settings)
overridevirtual

set ODS table settings of the current sheet (table)

Reimplemented from CalcWriterInterface.

Definition at line 402 of file odsdocwriter.cpp.

403{
405}
void setCurrentOdsTableSettings(const OdsTableSettings &settings)

References _settings_xml, and SettingsXml::setCurrentOdsTableSettings().

◆ setTableCellStyleRef()

void OdsDocWriter::setTableCellStyleRef ( OdsTableCellStyleRef  style_ref)
overridevirtual

set the cell table style. This is applied to in the stream to following cells. This ends by using an other style reference or by using setTableCellStyleRef function

Parameters
style_refOdsTableCellStyleRef

Reimplemented from CalcWriterInterface.

Definition at line 376 of file odsdocwriter.cpp.

377{
379}
void setTableCellStyleRef(OdsTableCellStyleRef style_ref)

References _p_content, and ContentXml::setTableCellStyleRef().

◆ writeCell() [1/10]

void OdsDocWriter::writeCell ( bool  value)
overridevirtual

adds a new cell containing a boolean

Parameters
value
Exceptions
XMLStreamException

Implements CalcWriterInterface.

Definition at line 287 of file odsdocwriter.cpp.

288{
291 // this.content.writeCell(value);
292}
void writeCell(double value, const QString &annotation)
void clearAnnotation()

References _next_annotation, _p_content, clearAnnotation(), and ContentXml::writeCell().

◆ writeCell() [2/10]

void OdsDocWriter::writeCell ( const char *  cell_text)
overridevirtual

write a text cell

Parameters
cell_textcell text

Implements CalcWriterInterface.

Definition at line 184 of file odsdocwriter.cpp.

185{
186 QString textQt(text);
189 // if (text == null) {
190 // this.writeEmptyCell();
191 // return;
192 // }
193 // this.content.writeCell(text);
194}

References _next_annotation, _p_content, clearAnnotation(), and ContentXml::writeCell().

◆ writeCell() [3/10]

void OdsDocWriter::writeCell ( const QDate &  date)
overridevirtual

adds a new cell containing a date

Parameters
date
Exceptions
XMLStreamException
DatatypeConfigurationException

Implements CalcWriterInterface.

Definition at line 302 of file odsdocwriter.cpp.

303{
306 // if (date == null) {
307 // this.writeEmptyCell();
308 // return;
309 // }
310 // this.content.writeCell(date);
311}

References _next_annotation, _p_content, clearAnnotation(), and ContentXml::writeCell().

◆ writeCell() [4/10]

void OdsDocWriter::writeCell ( const QDateTime &  date)
overridevirtual

adds a new cell containing a timestamp

Parameters
date
Exceptions
XMLStreamException
DatatypeConfigurationException

Implements CalcWriterInterface.

Definition at line 321 of file odsdocwriter.cpp.

322{
325 // if (date == null) {
326 // this.writeEmptyCell();
327 // return;
328 // }
329 // this.content.writeCell(new Date(date.getTime()));
330}

References _next_annotation, _p_content, clearAnnotation(), and ContentXml::writeCell().

◆ writeCell() [5/10]

void OdsDocWriter::writeCell ( const QString &  text)
overridevirtual

adds a new text cell to the document

Parameters
text
Exceptions
XMLStreamException

Implements CalcWriterInterface.

Definition at line 172 of file odsdocwriter.cpp.

173{
176 // if (text == null) {
177 // this.writeEmptyCell();
178 // return;
179 // }
180 // this.content.writeCell(text);
181}

References _next_annotation, _p_content, clearAnnotation(), and ContentXml::writeCell().

◆ writeCell() [6/10]

void OdsDocWriter::writeCell ( const QUrl &  theUri,
const QString &  text 
)
overridevirtual

NOT WORKING, adds a new cell containing a duration

Parameters
duration
Exceptions
XMLStreamException
DatatypeConfigurationExceptionadds a new cell containing a text inside an href link
Parameters
theUri
text
Exceptions
XMLStreamException

Implements CalcWriterInterface.

Definition at line 355 of file odsdocwriter.cpp.

356{
357 _p_content->writeCell(theUri, text, _next_annotation);
359}

References _next_annotation, _p_content, clearAnnotation(), and ContentXml::writeCell().

◆ writeCell() [7/10]

void OdsDocWriter::writeCell ( double  value)
overridevirtual

adds a new cell containing a double

Parameters
value
Exceptions
XMLStreamException

Implements CalcWriterInterface.

Definition at line 259 of file odsdocwriter.cpp.

260{
263 // this.content.writeCell(value);
264}

References _next_annotation, _p_content, clearAnnotation(), and ContentXml::writeCell().

◆ writeCell() [8/10]

void OdsDocWriter::writeCell ( float  value)
overridevirtual

adds a new cell containing a float

Parameters
value
Exceptions
XMLStreamException

Implements CalcWriterInterface.

Definition at line 245 of file odsdocwriter.cpp.

246{
249 // this.content.writeCell(value);
250}

References _next_annotation, _p_content, clearAnnotation(), and ContentXml::writeCell().

◆ writeCell() [9/10]

void OdsDocWriter::writeCell ( int  value)
overridevirtual

adds a new cell containing an integer

Parameters
value
Exceptions
XMLStreamException

Implements CalcWriterInterface.

Definition at line 231 of file odsdocwriter.cpp.

232{
235 // this.content.writeCell(value);
236}

References _next_annotation, _p_content, clearAnnotation(), and ContentXml::writeCell().

◆ writeCell() [10/10]

void OdsDocWriter::writeCell ( std::size_t  value)
overridevirtual

adds a new cell containing an integer

Parameters
value
Exceptions
XMLStreamException

Implements CalcWriterInterface.

Definition at line 216 of file odsdocwriter.cpp.

217{
220 // this.content.writeCell(value);
221}

References _next_annotation, _p_content, clearAnnotation(), and ContentXml::writeCell().

◆ writeCellPercentage()

void OdsDocWriter::writeCellPercentage ( double  value)
overridevirtual

adds a new cell containing a percentage

Parameters
value
Exceptions
XMLStreamException

Implements CalcWriterInterface.

Definition at line 274 of file odsdocwriter.cpp.

275{
278}
void writeCellPercentage(double value, const QString &annotation)

References _next_annotation, _p_content, clearAnnotation(), and ContentXml::writeCellPercentage().

◆ writeEmptyCell()

void OdsDocWriter::writeEmptyCell ( )
overridevirtual

writes an empty cell

Exceptions
XMLStreamException

Implements CalcWriterInterface.

Definition at line 202 of file odsdocwriter.cpp.

203{
206 // this.content.writeCell("");
207}
void writeEmptyCell(const QString &annotation)

References _next_annotation, _p_content, clearAnnotation(), and ContentXml::writeEmptyCell().

◆ writeLine()

void OdsDocWriter::writeLine ( )
overridevirtual

adds a new line to the document

Exceptions
XMLStreamException

Implements CalcWriterInterface.

Definition at line 154 of file odsdocwriter.cpp.

155{
157}
void writeLine()

References _p_content, and ContentXml::writeLine().

◆ writeSheet()

void OdsDocWriter::writeSheet ( const QString &  sheetName)
overridevirtual

adds a new datasheet to the document

Parameters
sheetName
Exceptions
XMLStreamException

Implements CalcWriterInterface.

Definition at line 143 of file odsdocwriter.cpp.

144{
145 _p_content->writeSheet(sheetName);
146}
void writeSheet(const QString &sheetName)

References _p_content, and ContentXml::writeSheet().

Member Data Documentation

◆ _next_annotation

◆ _p_content

◆ _p_device

QIODevice* OdsDocWriter::_p_device = nullptr
private

Definition at line 70 of file odsdocwriter.h.

Referenced by close(), and openDevice().

◆ _p_device_delete

bool OdsDocWriter::_p_device_delete = false
private

Definition at line 71 of file odsdocwriter.h.

Referenced by OdsDocWriter(), and close().

◆ _p_quaZip

QuaZip* OdsDocWriter::_p_quaZip
private

Definition at line 69 of file odsdocwriter.h.

Referenced by close(), and openDevice().

◆ _settings_xml

SettingsXml OdsDocWriter::_settings_xml
private

Definition at line 73 of file odsdocwriter.h.

Referenced by close(), openDevice(), and setCurrentOdsTableSettings().


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