Loading...
Searching...
No Matches
TsvDirectoryWriter Class Reference

`#include <tsvdirectorywriter.h>`

Inheritance diagram for TsvDirectoryWriter:

## Public Member Functions

| TsvDirectoryWriter (const QDir &directory)
virtual | ~TsvDirectoryWriter ()
virtual void | close () override
virtual void | writeSheet (const QString &sheetName) override
| open a new sheet
void | writeLine () override
| open a new line
void | writeCell (const char *) override
| write a text cell
void | writeCell (const QString &) override
| write a text cell
void | writeEmptyCell () override
| write an empty cell
void | writeCell (std::size_t) override
| write an unsigned integer in a cell
void | writeCell (int) override
| write an integer in a cell
void | writeCell (float) override
| write a float in a cell
void | writeCell (double) override
| write a double in a cell
void | writeCellPercentage (double value) override
| write a double as a percentage
void | writeCell (bool) override
| write a boolean in a cell
void | writeCell (const QDate &) override
| write a date in a cell
void | writeCell (const QDateTime &) override
| write a timestamp in a cell
void | writeCell (const QUrl &, const QString &) override
| write a text cell with an URL link
void | setCellAnnotation (const QString &annotation) override
| set annotation to write in the next cell
void | setSeparator (TsvSeparator separator)
| sets the separator to use between values (cells)
TsvSeparator | getSeparator () const
| get the separator used between values (cells)
bool | setQuoteStrings (bool quote_strings)
| set a flag to quote strings
bool | isQuoteStrings () const
| tells if the quote string flag is enabled
bool | setFlushLines (bool flushOk)
| enable a physical flush on device at each new line enables this if you want to ensure that each line is written. This costs a little overhead
bool | isFlushLines () const
| tells if the flush lines flag is enabled
Public Member Functions inherited from CalcWriterInterface
virtual | ~CalcWriterInterface ()
virtual OdsTableCellStyleRef | getTableCellStyleRef (const OdsTableCellStyle &style)
virtual void | setTableCellStyleRef (OdsTableCellStyleRef style_ref)
void | clearTableCellStyleRef ()
virtual void | addColorScale (const OdsColorScale &ods_color_scale)
| apply solor scale conditional format on a cell range
virtual QString | getOdsCellCoordinate ()
| 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
virtual void | setCurrentOdsTableSettings (const OdsTableSettings &settings)
| set ODS table settings of the current sheet (table)
virtual void | writeCellVariant (const QVariant &var)
| write a cell for a given QVariant

## Protected Member Functions

| TsvDirectoryWriter ()
void | writeRawCell (const QString &text)
void | initializeSheet ()

## Protected Attributes

QString | m_separator = "\t"
QString | _end_of_line = "\n"
QTextStream * | mpa_otxtstream = nullptr
unsigned int | numFloatPrecision = 12

## Private Member Functions

void | ensureSheet ()

## Private Attributes

const QDir | _directory
QString | _file_extension = ".tsv"
bool | m_quoteStrings = false
bool | m_flushLines = false
TsvSeparator | m_tsvSeparatorEnum = TsvSeparator::tab
bool | _tableRowStart = true
bool | _startingSheet = false
QFile * | mpa_ofile = nullptr

## Detailed Description

Definition at line 32 of file tsvdirectorywriter.h.

## Constructor & Destructor Documentation

## TsvDirectoryWriter() [1/2]

TsvDirectoryWriter::TsvDirectoryWriter | ( | const QDir & | directory | ) |

Definition at line 30 of file tsvdirectorywriter.cpp.

: _directory(directory)
{
if(_directory.exists())
{
}
else
{
if(!_directory.mkdir(_directory.absolutePath()))
{
throw OdsException(QString("unable to create output directory %1")
.arg(_directory.absolutePath()));
}
}
}
TsvDirectoryWriter::_directory
const QDir _directory
Definition tsvdirectorywriter.h:109

References _directory.

Referenced by TsvOutputStream::TsvOutputStream(), and ZipTsvOutputStream::ZipTsvOutputStream().

## ~TsvDirectoryWriter()

TsvDirectoryWriter::~TsvDirectoryWriter | ( |  | ) |

virtual

Definition at line 46 of file tsvdirectorywriter.cpp.

{
close();
}
TsvDirectoryWriter::close
virtual void close() override
Definition tsvdirectorywriter.cpp:72

References close().

## TsvDirectoryWriter() [2/2]

TsvDirectoryWriter::TsvDirectoryWriter | ( |  | ) |

protected

Definition at line 26 of file tsvdirectorywriter.cpp.

{
}

## Member Function Documentation

## close()

void TsvDirectoryWriter::close | ( |  | ) |

override virtual

Implements CalcWriterInterface.

Reimplemented in TsvOutputStream, and ZipTsvOutputStream.

Definition at line 72 of file tsvdirectorywriter.cpp.

{
if(mpa_otxtstream != nullptr)
{
*mpa_otxtstream << _end_of_line;
mpa_otxtstream->flush();
//_p_otxtstream->close();
delete(mpa_otxtstream);
mpa_otxtstream = nullptr;
}
if(mpa_ofile != nullptr)
{
mpa_ofile->flush();
mpa_ofile->close();
delete(mpa_ofile);
mpa_ofile = nullptr;
}
}
TsvDirectoryWriter::mpa_otxtstream
QTextStream * mpa_otxtstream
Definition tsvdirectorywriter.h:105
TsvDirectoryWriter::mpa_ofile
QFile * mpa_ofile
Definition tsvdirectorywriter.h:120
TsvDirectoryWriter::_end_of_line
QString _end_of_line
Definition tsvdirectorywriter.h:104

References _end_of_line, mpa_ofile, and mpa_otxtstream.

Referenced by ~TsvDirectoryWriter(), ZipTsvOutputStream::close(), and writeSheet().

## ensureSheet()

void TsvDirectoryWriter::ensureSheet | ( |  | ) |

private

Definition at line 125 of file tsvdirectorywriter.cpp.

{
if(mpa_otxtstream == nullptr)
{
writeSheet("default");
}
}
TsvDirectoryWriter::writeSheet
virtual void writeSheet(const QString &sheetName) override
open a new sheet
Definition tsvdirectorywriter.cpp:92

References mpa_otxtstream, and writeSheet().

Referenced by writeCell(), writeEmptyCell(), writeLine(), and writeRawCell().

## getSeparator()

TsvSeparator TsvDirectoryWriter::getSeparator | ( |  | ) | const

get the separator used between values (cells)

Returns
  TsvSeparator used

Definition at line 293 of file tsvdirectorywriter.cpp.

{
return m_tsvSeparatorEnum;
}
TsvDirectoryWriter::m_tsvSeparatorEnum
TsvSeparator m_tsvSeparatorEnum
Definition tsvdirectorywriter.h:115

References m_tsvSeparatorEnum.

## initializeSheet()

void TsvDirectoryWriter::initializeSheet | ( |  | ) |

protected

Definition at line 116 of file tsvdirectorywriter.cpp.

{
_tableRowStart = true;
_startingSheet = true;
}
TsvDirectoryWriter::_tableRowStart
bool _tableRowStart
Definition tsvdirectorywriter.h:117
TsvDirectoryWriter::_startingSheet
bool _startingSheet
Definition tsvdirectorywriter.h:118

References _startingSheet, and _tableRowStart.

Referenced by writeSheet(), and ZipTsvOutputStream::writeSheet().

## isFlushLines()

bool TsvDirectoryWriter::isFlushLines | ( |  | ) | const

tells if the flush lines flag is enabled

Definition at line 280 of file tsvdirectorywriter.cpp.

{
return m_flushLines;
}
TsvDirectoryWriter::m_flushLines
bool m_flushLines
Definition tsvdirectorywriter.h:114

References m_flushLines.

## isQuoteStrings()

bool TsvDirectoryWriter::isQuoteStrings | ( |  | ) | const

tells if the quote string flag is enabled

Definition at line 274 of file tsvdirectorywriter.cpp.

{
return m_quoteStrings;
}
TsvDirectoryWriter::m_quoteStrings
bool m_quoteStrings
Definition tsvdirectorywriter.h:113

References m_quoteStrings.

## setCellAnnotation()

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

inline override virtual

set annotation to write in the next cell

Parameters

  annotation | any comment on this cell

Implements CalcWriterInterface.

Definition at line 55 of file tsvdirectorywriter.h.

{};

## setFlushLines()

bool TsvDirectoryWriter::setFlushLines | ( | bool | flushOk | ) |

enable a physical flush on device at each new line enables this if you want to ensure that each line is written. This costs a little overhead

Parameters

  bool | if true, lines will be flushed, choose false otherwise

Returns
  bool state of the modified flag

Definition at line 286 of file tsvdirectorywriter.cpp.

{
m_flushLines = flushOk;
return m_flushLines;
}

References m_flushLines.

## setQuoteStrings()

bool TsvDirectoryWriter::setQuoteStrings | ( | bool | quote_strings | ) |

set a flag to quote strings

Parameters

  bool | if true, strings will be quoted, choose false otherwise

Returns
  bool state of the modified flag

Definition at line 267 of file tsvdirectorywriter.cpp.

{
m_quoteStrings = quote_strings;
return m_quoteStrings;
}

References m_quoteStrings.

## setSeparator()

void TsvDirectoryWriter::setSeparator | ( | TsvSeparator | separator | ) |

sets the separator to use between values (cells)

Parameters

  TsvSeparator | enumeration to choose between possible choices

Definition at line 52 of file tsvdirectorywriter.cpp.

{
qDebug();
m_tsvSeparatorEnum = separator;
switch(separator)
{
case TsvSeparator::tab:
m_separator = "\t";
break;
case TsvSeparator::comma:
m_separator = ",";
break;
case TsvSeparator::semicolon:
m_separator = ";";
break;
}
qDebug();
}
TsvDirectoryWriter::m_separator
QString m_separator
Definition tsvdirectorywriter.h:103
TsvSeparator::semicolon
@ semicolon
Definition config.h:11
TsvSeparator::comma
@ comma
Definition config.h:11
TsvSeparator::tab
@ tab
Definition config.h:11

References comma, m_separator, m_tsvSeparatorEnum, semicolon, and tab.

## writeCell() [1/10]

void TsvDirectoryWriter::writeCell | ( | bool | true_or_false | ) |

override virtual

write a boolean in a cell

Parameters

  true_or_false | boolean to write

Implements CalcWriterInterface.

Definition at line 237 of file tsvdirectorywriter.cpp.

{
if(isOk)
{
writeRawCell(QString("T"));
}
else
{
writeRawCell(QString("F"));
}
}
TsvDirectoryWriter::writeRawCell
void writeRawCell(const QString &text)
Definition tsvdirectorywriter.cpp:188

References writeRawCell().

## writeCell() [2/10]

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

override virtual

write a text cell

Parameters

  cell_text | cell text

Implements CalcWriterInterface.

Definition at line 151 of file tsvdirectorywriter.cpp.

{
writeCell(QString(cstr));
}
TsvDirectoryWriter::writeCell
void writeCell(const char *) override
write a text cell
Definition tsvdirectorywriter.cpp:151

References writeCell().

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

## writeCell() [3/10]

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

override virtual

write a date in a cell

Parameters

  date | date to write

Implements CalcWriterInterface.

Definition at line 249 of file tsvdirectorywriter.cpp.

{
writeRawCell(date.toString("yyyy-MM-dd"));
}

References writeRawCell().

## writeCell() [4/10]

void TsvDirectoryWriter::writeCell | ( | const QDateTime & | datetime | ) |

override virtual

write a timestamp in a cell

Parameters

  datetime | timestamp to write

Implements CalcWriterInterface.

Definition at line 254 of file tsvdirectorywriter.cpp.

{
writeRawCell(date.toString("yyyy-MM-ddThh:mm:ss"));
}

References writeRawCell().

## writeCell() [5/10]

void TsvDirectoryWriter::writeCell | ( | const QString & | cell_text | ) |

override virtual

write a text cell

Parameters

  cell_text | cell text

Implements CalcWriterInterface.

Definition at line 156 of file tsvdirectorywriter.cpp.

{
ensureSheet();
if(!_tableRowStart)
{
*mpa_otxtstream << m_separator;
}
_tableRowStart = false;
if(m_quoteStrings)
{
*mpa_otxtstream << QString("\"%1\"").arg(
QString(text).replace("\"", "\"\""));
}
else
{
if(text.contains(_end_of_line) || text.contains(m_separator) ||
text.contains("\""))
{
*mpa_otxtstream << QString("\"%1\"").arg(
QString(text).replace("\"", "\"\""));
}
else
{
*mpa_otxtstream << text;
}
}
_startingSheet = false;
}
TsvDirectoryWriter::ensureSheet
void ensureSheet()
Definition tsvdirectorywriter.cpp:125

References _end_of_line, _startingSheet, _tableRowStart, ensureSheet(), m_quoteStrings, m_separator, and mpa_otxtstream.

## writeCell() [6/10]

void TsvDirectoryWriter::writeCell | ( | const QUrl & | url_link,
|  | const QString & | text )

override virtual

write a text cell with an URL link

Parameters

  url_link | URL link
  text | text to write

Implements CalcWriterInterface.

Definition at line 259 of file tsvdirectorywriter.cpp.

{
writeCell(text);
}

References writeCell().

## writeCell() [7/10]

void TsvDirectoryWriter::writeCell | ( | double | number | ) |

override virtual

write a double in a cell

Parameters

  number | double to write

Implements CalcWriterInterface.

Definition at line 226 of file tsvdirectorywriter.cpp.

{
writeRawCell(QString::number(num, 'g', numFloatPrecision));
}
TsvDirectoryWriter::numFloatPrecision
unsigned int numFloatPrecision
Definition tsvdirectorywriter.h:106

References numFloatPrecision, and writeRawCell().

## writeCell() [8/10]

void TsvDirectoryWriter::writeCell | ( | float | number | ) |

override virtual

write a float in a cell

Parameters

  number | float to write

Implements CalcWriterInterface.

Definition at line 221 of file tsvdirectorywriter.cpp.

{
writeRawCell(QString::number(num, 'g', numFloatPrecision));
}

References numFloatPrecision, and writeRawCell().

## writeCell() [9/10]

void TsvDirectoryWriter::writeCell | ( | int | number | ) |

override virtual

write an integer in a cell

Parameters

  number | integer to write

Implements CalcWriterInterface.

Definition at line 216 of file tsvdirectorywriter.cpp.

{
writeRawCell(QString::number(num, 'g', 10));
}

References writeRawCell().

## writeCell() [10/10]

void TsvDirectoryWriter::writeCell | ( | std::size_t | number | ) |

override virtual

write an unsigned integer in a cell

Parameters

  number | integer to write

Implements CalcWriterInterface.

Definition at line 211 of file tsvdirectorywriter.cpp.

{
writeRawCell(QString::number(num, 'g', 10));
}

References writeRawCell().

## writeCellPercentage()

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

override virtual

write a double as a percentage

Parameters

  number | double to write must be a ratio (0.5 == 50%)

Implements CalcWriterInterface.

Definition at line 232 of file tsvdirectorywriter.cpp.

{
writeCell(value);
}

References writeCell().

## writeEmptyCell()

void TsvDirectoryWriter::writeEmptyCell | ( |  | ) |

override virtual

write an empty cell

Implements CalcWriterInterface.

Definition at line 200 of file tsvdirectorywriter.cpp.

{
ensureSheet();
if(!_tableRowStart)
{
*mpa_otxtstream << m_separator;
}
_tableRowStart = false;
_startingSheet = false;
}

References _startingSheet, _tableRowStart, ensureSheet(), m_separator, and mpa_otxtstream.

## writeLine()

void TsvDirectoryWriter::writeLine | ( |  | ) |

override virtual

open a new line

Implements CalcWriterInterface.

Definition at line 134 of file tsvdirectorywriter.cpp.

{
ensureSheet();
if(_startingSheet)
{
}
else
{
*mpa_otxtstream << _end_of_line;
}
_startingSheet = false;
_tableRowStart = true;
if(m_flushLines)
mpa_otxtstream->flush();
}

References _end_of_line, _startingSheet, _tableRowStart, ensureSheet(), m_flushLines, and mpa_otxtstream.

## writeRawCell()

void TsvDirectoryWriter::writeRawCell | ( | const QString & | text | ) |

protected

Definition at line 188 of file tsvdirectorywriter.cpp.

{
ensureSheet();
if(!_tableRowStart)
{
*mpa_otxtstream << m_separator;
}
_tableRowStart = false;
*mpa_otxtstream << text;
_startingSheet = false;
}

References _startingSheet, _tableRowStart, ensureSheet(), m_separator, and mpa_otxtstream.

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

## writeSheet()

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

override virtual

open a new sheet

Parameters

  sheetName | the sheet name

Implements CalcWriterInterface.

Reimplemented in TsvOutputStream, and ZipTsvOutputStream.

Definition at line 92 of file tsvdirectorywriter.cpp.

{
close();
// qDebug() << " TsvDirectoryWriter::writeSheet " <<
// _directory.absolutePath();
mpa_ofile = new QFile(QString(_directory.absolutePath())
.append("/")
.append(sheetName)
.append(this->_file_extension));
// qDebug() << " TsvDirectoryWriter::writeSheet " <<
// QFileInfo(*_p_ofile).absoluteFilePath();
if(mpa_ofile->open(QIODevice::WriteOnly))
{
mpa_otxtstream = new QTextStream(mpa_ofile);
}
else
{
throw OdsException(QString("unable to write into file %1")
.arg(QFileInfo(*mpa_ofile).absoluteFilePath()));
}
initializeSheet();
}
TsvDirectoryWriter::initializeSheet
void initializeSheet()
Definition tsvdirectorywriter.cpp:116

References _directory, close(), initializeSheet(), mpa_ofile, and mpa_otxtstream.

Referenced by ensureSheet().

## Member Data Documentation

## _directory

const QDir TsvDirectoryWriter::_directory

private

Definition at line 109 of file tsvdirectorywriter.h.

Referenced by TsvDirectoryWriter(), and writeSheet().

## _end_of_line

QString TsvDirectoryWriter::_end_of_line = "\n"

protected

Definition at line 104 of file tsvdirectorywriter.h.

Referenced by close(), writeCell(), writeLine(), and TsvOutputStream::writeSheet().

## _file_extension

QString TsvDirectoryWriter::_file_extension = ".tsv"

private

Definition at line 111 of file tsvdirectorywriter.h.

## _startingSheet

bool TsvDirectoryWriter::_startingSheet = false

private

Definition at line 118 of file tsvdirectorywriter.h.

Referenced by initializeSheet(), writeCell(), writeEmptyCell(), writeLine(), and writeRawCell().

## _tableRowStart

bool TsvDirectoryWriter::_tableRowStart = true

private

Definition at line 117 of file tsvdirectorywriter.h.

Referenced by initializeSheet(), writeCell(), writeEmptyCell(), writeLine(), and writeRawCell().

## m_flushLines

bool TsvDirectoryWriter::m_flushLines = false

private

Definition at line 114 of file tsvdirectorywriter.h.

Referenced by isFlushLines(), setFlushLines(), and writeLine().

## m_quoteStrings

bool TsvDirectoryWriter::m_quoteStrings = false

private

Definition at line 113 of file tsvdirectorywriter.h.

Referenced by isQuoteStrings(), setQuoteStrings(), and writeCell().

## m_separator

QString TsvDirectoryWriter::m_separator = "\t"

protected

Definition at line 103 of file tsvdirectorywriter.h.

Referenced by setSeparator(), writeCell(), writeEmptyCell(), and writeRawCell().

## m_tsvSeparatorEnum

TsvSeparator TsvDirectoryWriter::m_tsvSeparatorEnum = TsvSeparator::tab

private

Definition at line 115 of file tsvdirectorywriter.h.

Referenced by getSeparator(), and setSeparator().

## mpa_ofile

QFile* TsvDirectoryWriter::mpa_ofile = nullptr

private

Definition at line 120 of file tsvdirectorywriter.h.

Referenced by close(), and writeSheet().

## mpa_otxtstream

QTextStream* TsvDirectoryWriter::mpa_otxtstream = nullptr

protected

Definition at line 105 of file tsvdirectorywriter.h.

Referenced by TsvOutputStream::TsvOutputStream(), TsvOutputStream::~TsvOutputStream(), close(), TsvOutputStream::close(), ZipTsvOutputStream::closeCurrentZipSheet(), ensureSheet(), writeCell(), writeEmptyCell(), writeLine(), writeRawCell(), writeSheet(), TsvOutputStream::writeSheet(), and ZipTsvOutputStream::writeSheet().

## numFloatPrecision

unsigned int TsvDirectoryWriter::numFloatPrecision = 12

protected

Definition at line 106 of file tsvdirectorywriter.h.

Referenced by writeCell(), and writeCell().

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

- odsstream/tsvdirectorywriter.h
- odsstream/tsvdirectorywriter.cpp