Loading...
Searching...
No Matches
OdsDocWriter Class Reference

`#include <odsdocwriter.h>`

Inheritance diagram for OdsDocWriter:

## 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.

{
_p_device_delete = true;
QFile *p_file = new QFile(filename);
try
{
openDevice(p_file);
}
catch(const OdsException &ods_error)
{
throw OdsException(
QObject::tr("error opening ODS file. check file permission for %1")
.arg(QFileInfo(filename).absoluteFilePath()));
}
}
OdsDocWriter::_p_device_delete
bool _p_device_delete
Definition odsdocwriter.h:71
OdsDocWriter::openDevice
void openDevice(QIODevice *device)
Definition odsdocwriter.cpp:53

References _p_device_delete, and openDevice().

## OdsDocWriter() [2/2]

OdsDocWriter::OdsDocWriter | ( | QIODevice * | device | ) |

Definition at line 47 of file odsdocwriter.cpp.

{
openDevice(device);
}

References openDevice().

## ~OdsDocWriter()

OdsDocWriter::~OdsDocWriter | ( |  | ) |

virtual

Definition at line 89 of file odsdocwriter.cpp.

{
// this->close();
if(_p_content != nullptr)
{
this->close();
}
}
OdsDocWriter::close
void close() override
Definition odsdocwriter.cpp:103
OdsDocWriter::_p_content
ContentXml * _p_content
Definition odsdocwriter.h:68

References _p_content, and close().

## Member Function Documentation

## addColorScale()

void OdsDocWriter::addColorScale | ( | const OdsColorScale & | ods_color_scale | ) |

override virtual

apply solor scale conditional format on a cell range

Reimplemented from CalcWriterInterface.

Definition at line 389 of file odsdocwriter.cpp.

{
_p_content->addColorScale(ods_color_scale);
}

References _p_content.

## clearAnnotation()

void OdsDocWriter::clearAnnotation | ( |  | ) |

private

Definition at line 161 of file odsdocwriter.cpp.

{
_next_annotation = "";
}
OdsDocWriter::_next_annotation
QString _next_annotation
Definition odsdocwriter.h:72

References _next_annotation.

Referenced by writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCellPercentage(), and writeEmptyCell().

## close()

void OdsDocWriter::close | ( |  | ) |

override virtual

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

Implements CalcWriterInterface.

Definition at line 103 of file odsdocwriter.cpp.

{
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
if(_p_content != nullptr)
{
_p_content->close();
delete _p_content;
}
StylesXml stylesXml(_p_quaZip);
_settings_xml.write(_p_quaZip);
_p_quaZip->close();
delete _p_quaZip;
if(_p_device != nullptr)
{
//_p_device->flush();
_p_device->close();
}
_p_content = nullptr;
_p_quaZip = nullptr;
// zipOutputStream = null;
if(_p_device != nullptr)
{
if(_p_device_delete)
{
qDebug() << "_p_device_delete";
delete _p_device;
}
}
}
OdsDocWriter::_settings_xml
SettingsXml _settings_xml
Definition odsdocwriter.h:73
OdsDocWriter::_p_quaZip
QuaZip * _p_quaZip
Definition odsdocwriter.h:69
OdsDocWriter::_p_device
QIODevice * _p_device
Definition odsdocwriter.h:70

References _p_content, _p_device, _p_device_delete, _p_quaZip, and _settings_xml.

Referenced by ~OdsDocWriter().

## getOdsCellCoordinate()

QString OdsDocWriter::getOdsCellCoordinate | ( |  | ) |

override virtual

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.

{
return _p_content->getCellCoordinate();
}

References _p_content.

## getTableCellStyleRef()

OdsTableCellStyleRef OdsDocWriter::getTableCellStyleRef | ( | const OdsTableCellStyle & | style | ) |

override virtual

get a table cell style reference with a style definition

Parameters

  style | OdsTableCellStyle

Returns
  OdsTableCellStyleRef pointer on a style reference

Reimplemented from CalcWriterInterface.

Definition at line 369 of file odsdocwriter.cpp.

{
return _p_content->getTableCellStyleRef(style);
}

References _p_content.

## openDevice()

void OdsDocWriter::openDevice | ( | QIODevice * | device | ) |

private

Definition at line 53 of file odsdocwriter.cpp.

{
//_p_device_delete = false;
_p_device = device;
_p_quaZip = new QuaZip(device);
bool open_ok = _p_quaZip->open(QuaZip::mdCreate);
if(open_ok == false)
{
throw OdsException(QObject::tr("error opening ODS file."));
}
// QuaZipFile::open(): file open mode 2 incompatible with ZIP open mode 0
// QuaZip::close(): ZIP is not open
//_p_quaZip->setComment("application/vnd.oasis.opendocument.spreadsheet");
QByteArray *messageIn = new QByteArray();
*messageIn = "application/vnd.oasis.opendocument.spreadsheet";
QuaZipFile outFile(_p_quaZip);
QuaCrc32 crc32;
quint32 crc(crc32.calculate(*messageIn));
QuaZipNewInfo info("mimetype");
info.uncompressedSize = messageIn->length();
outFile.open(QIODevice::WriteOnly, info, NULL, crc, 0, 0, true);
outFile.write(*messageIn);
outFile.close();
delete(messageIn);
ManifestXml manifest(_p_quaZip);
MetaXml metaxml(_p_quaZip);
_p_content = new ContentXml(_p_quaZip, &_settings_xml);
}

References _p_content, _p_device, _p_quaZip, and _settings_xml.

Referenced by OdsDocWriter(), and OdsDocWriter().

## setCellAnnotation()

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

override virtual

set annotation to write in the next cell

Parameters

  annotation | any comment on this cell

Implements CalcWriterInterface.

Definition at line 383 of file odsdocwriter.cpp.

{
_next_annotation = annotation;
}

References _next_annotation.

## setCurrentOdsTableSettings()

void OdsDocWriter::setCurrentOdsTableSettings | ( | const OdsTableSettings & | settings | ) |

override virtual

set ODS table settings of the current sheet (table)

Reimplemented from CalcWriterInterface.

Definition at line 402 of file odsdocwriter.cpp.

{
_settings_xml.setCurrentOdsTableSettings(settings_in);
}

References _settings_xml.

## setTableCellStyleRef()

void OdsDocWriter::setTableCellStyleRef | ( | OdsTableCellStyleRef | style_ref | ) |

override virtual

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_ref | OdsTableCellStyleRef

Reimplemented from CalcWriterInterface.

Definition at line 376 of file odsdocwriter.cpp.

{
_p_content->setTableCellStyleRef(style_ref);
}

References _p_content.

## writeCell() [1/10]

void OdsDocWriter::writeCell | ( | bool | value | ) |

override virtual

adds a new cell containing a boolean

Parameters

  value |

Exceptions

  XMLStreamException |

Implements CalcWriterInterface.

Definition at line 287 of file odsdocwriter.cpp.

{
_p_content->writeCell(value, _next_annotation);
clearAnnotation();
// this.content.writeCell(value);
}
OdsDocWriter::clearAnnotation
void clearAnnotation()
Definition odsdocwriter.cpp:161

References _next_annotation, _p_content, and clearAnnotation().

## writeCell() [2/10]

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

override virtual

write a text cell

Parameters

  cell_text | cell text

Implements CalcWriterInterface.

Definition at line 184 of file odsdocwriter.cpp.

{
QString textQt(text);
_p_content->writeCell(textQt, _next_annotation);
clearAnnotation();
// if (text == null) {
// this.writeEmptyCell();
// return;
// }
// this.content.writeCell(text);
}

References _next_annotation, _p_content, and clearAnnotation().

## writeCell() [3/10]

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

override virtual

adds a new cell containing a date

Parameters

  date |

Exceptions

  XMLStreamException |
  DatatypeConfigurationException |

Implements CalcWriterInterface.

Definition at line 302 of file odsdocwriter.cpp.

{
_p_content->writeCell(date, _next_annotation);
clearAnnotation();
// if (date == null) {
// this.writeEmptyCell();
// return;
// }
// this.content.writeCell(date);
}

References _next_annotation, _p_content, and clearAnnotation().

## writeCell() [4/10]

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

override virtual

adds a new cell containing a timestamp

Parameters

  date |

Exceptions

  XMLStreamException |
  DatatypeConfigurationException |

Implements CalcWriterInterface.

Definition at line 321 of file odsdocwriter.cpp.

{
_p_content->writeCell(date, _next_annotation);
clearAnnotation();
// if (date == null) {
// this.writeEmptyCell();
// return;
// }
// this.content.writeCell(new Date(date.getTime()));
}

References _next_annotation, _p_content, and clearAnnotation().

## writeCell() [5/10]

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

override virtual

adds a new text cell to the document

Parameters

  text |

Exceptions

  XMLStreamException |

Implements CalcWriterInterface.

Definition at line 172 of file odsdocwriter.cpp.

{
_p_content->writeCell(text, _next_annotation);
clearAnnotation();
// if (text == null) {
// this.writeEmptyCell();
// return;
// }
// this.content.writeCell(text);
}

References _next_annotation, _p_content, and clearAnnotation().

## writeCell() [6/10]

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

override virtual

NOT WORKING, adds a new cell containing a duration

Parameters

  duration |

Exceptions

  XMLStreamException |
  DatatypeConfigurationException | adds 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.

{
_p_content->writeCell(theUri, text, _next_annotation);
clearAnnotation();
}

References _next_annotation, _p_content, and clearAnnotation().

## writeCell() [7/10]

void OdsDocWriter::writeCell | ( | double | value | ) |

override virtual

adds a new cell containing a double

Parameters

  value |

Exceptions

  XMLStreamException |

Implements CalcWriterInterface.

Definition at line 259 of file odsdocwriter.cpp.

{
_p_content->writeCell(value, _next_annotation);
clearAnnotation();
// this.content.writeCell(value);
}

References _next_annotation, _p_content, and clearAnnotation().

## writeCell() [8/10]

void OdsDocWriter::writeCell | ( | float | value | ) |

override virtual

adds a new cell containing a float

Parameters

  value |

Exceptions

  XMLStreamException |

Implements CalcWriterInterface.

Definition at line 245 of file odsdocwriter.cpp.

{
_p_content->writeCell(value, _next_annotation);
clearAnnotation();
// this.content.writeCell(value);
}

References _next_annotation, _p_content, and clearAnnotation().

## writeCell() [9/10]

void OdsDocWriter::writeCell | ( | int | value | ) |

override virtual

adds a new cell containing an integer

Parameters

  value |

Exceptions

  XMLStreamException |

Implements CalcWriterInterface.

Definition at line 231 of file odsdocwriter.cpp.

{
_p_content->writeCell(value, _next_annotation);
clearAnnotation();
// this.content.writeCell(value);
}

References _next_annotation, _p_content, and clearAnnotation().

## writeCell() [10/10]

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

override virtual

adds a new cell containing an integer

Parameters

  value |

Exceptions

  XMLStreamException |

Implements CalcWriterInterface.

Definition at line 216 of file odsdocwriter.cpp.

{
_p_content->writeCell(value, _next_annotation);
clearAnnotation();
// this.content.writeCell(value);
}

References _next_annotation, _p_content, and clearAnnotation().

## writeCellPercentage()

void OdsDocWriter::writeCellPercentage | ( | double | value | ) |

override virtual

adds a new cell containing a percentage

Parameters

  value |

Exceptions

  XMLStreamException |

Implements CalcWriterInterface.

Definition at line 274 of file odsdocwriter.cpp.

{
_p_content->writeCellPercentage(value, _next_annotation);
clearAnnotation();
}

References _next_annotation, _p_content, and clearAnnotation().

## writeEmptyCell()

void OdsDocWriter::writeEmptyCell | ( |  | ) |

override virtual

writes an empty cell

Exceptions

  XMLStreamException |

Implements CalcWriterInterface.

Definition at line 202 of file odsdocwriter.cpp.

{
_p_content->writeEmptyCell(_next_annotation);
clearAnnotation();
// this.content.writeCell("");
}

References _next_annotation, _p_content, and clearAnnotation().

## writeLine()

void OdsDocWriter::writeLine | ( |  | ) |

override virtual

adds a new line to the document

Exceptions

  XMLStreamException |

Implements CalcWriterInterface.

Definition at line 154 of file odsdocwriter.cpp.

{
_p_content->writeLine();
}

References _p_content.

## writeSheet()

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

override virtual

adds a new datasheet to the document

Parameters

  sheetName |

Exceptions

  XMLStreamException |

Implements CalcWriterInterface.

Definition at line 143 of file odsdocwriter.cpp.

{
_p_content->writeSheet(sheetName);
}

References _p_content.

## Member Data Documentation

## _next_annotation

QString OdsDocWriter::_next_annotation

private

Definition at line 72 of file odsdocwriter.h.

Referenced by clearAnnotation(), setCellAnnotation(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCellPercentage(), and writeEmptyCell().

## _p_content

ContentXml* OdsDocWriter::_p_content

private

Definition at line 68 of file odsdocwriter.h.

Referenced by ~OdsDocWriter(), addColorScale(), close(), getOdsCellCoordinate(), getTableCellStyleRef(), openDevice(), setTableCellStyleRef(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCell(), writeCellPercentage(), writeEmptyCell(), writeLine(), and writeSheet().

## _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:

- odsstream/odsdocwriter.h
- odsstream/odsdocwriter.cpp