Loading...
Searching...
No Matches
tsvdirectorywriter.h
Go to the documentation of this file.
/*
libodsstream is a library to read and write ODS documents as streams
Copyright (C) 2013 Olivier Langella <Olivier.Langella@moulon.inra.fr>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <QString>
#include <QUrl>
#include <QDate>
#include <QDir>
#include <QTextStream>
#include <QFile>
#include "calcwriterinterface.h"
#include "config.h"
class TsvDirectoryWriter : public CalcWriterInterface
{
public:
TsvDirectoryWriter(const QDir &directory);
virtual ~TsvDirectoryWriter();
virtual void close() override;
virtual void writeSheet(const QString &sheetName) override;
void writeLine() override;
void writeCell(const char *) override;
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;
void setCellAnnotation([[maybe_unused]] const QString &annotation) override{};
/** @brief sets the separator to use between values (cells)
*
* @param TsvSeparator enumeration to choose between possible choices
*/
void setSeparator(TsvSeparator separator);
/** @brief get the separator used between values (cells)
*
* @return TsvSeparator used
*/
TsvSeparator getSeparator() const;
/** @brief set a flag to quote strings
*
* @param bool if true, strings will be quoted, choose false otherwise
* @return bool state of the modified flag
*/
bool setQuoteStrings(bool quote_strings);
/** @brief tells if the quote string flag is enabled
*/
bool isQuoteStrings() const;
/** @brief 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
*
* @param bool if true, lines will be flushed, choose false otherwise
* @return bool state of the modified flag
* */
bool setFlushLines(bool flushOk);
/** @brief tells if the flush lines flag is enabled
*/
bool isFlushLines() const;
protected:
TsvDirectoryWriter();
void writeRawCell(const QString &text);
void initializeSheet();
protected:
QString m_separator = "\t";
QString _end_of_line = "\n";
QTextStream *mpa_otxtstream = nullptr;
unsigned int numFloatPrecision = 12;
private:
const QDir _directory;
QString _file_extension = ".tsv";
bool m_quoteStrings = false;
bool m_flushLines = false;
TsvSeparator m_tsvSeparatorEnum = TsvSeparator::tab;
void ensureSheet();
bool _tableRowStart = true;
bool _startingSheet = false;
QFile *mpa_ofile = nullptr;
};
calcwriterinterface.h
CalcWriterInterface
Definition calcwriterinterface.h:49
TsvDirectoryWriter::writeLine
void writeLine() override
open a new line
Definition tsvdirectorywriter.cpp:134
TsvDirectoryWriter::writeSheet
virtual void writeSheet(const QString &sheetName) override
open a new sheet
Definition tsvdirectorywriter.cpp:92
TsvDirectoryWriter::m_separator
QString m_separator
Definition tsvdirectorywriter.h:103
TsvDirectoryWriter::setFlushLines
bool setFlushLines(bool flushOk)
enable a physical flush on device at each new line enables this if you want to ensure that each line ...
Definition tsvdirectorywriter.cpp:286
TsvDirectoryWriter::m_flushLines
bool m_flushLines
Definition tsvdirectorywriter.h:114
TsvDirectoryWriter::_file_extension
QString _file_extension
Definition tsvdirectorywriter.h:111
TsvDirectoryWriter::TsvDirectoryWriter
TsvDirectoryWriter()
Definition tsvdirectorywriter.cpp:26
TsvDirectoryWriter::getSeparator
TsvSeparator getSeparator() const
get the separator used between values (cells)
Definition tsvdirectorywriter.cpp:293
TsvDirectoryWriter::m_quoteStrings
bool m_quoteStrings
Definition tsvdirectorywriter.h:113
TsvDirectoryWriter::writeEmptyCell
void writeEmptyCell() override
write an empty cell
Definition tsvdirectorywriter.cpp:200
TsvDirectoryWriter::_directory
const QDir _directory
Definition tsvdirectorywriter.h:109
TsvDirectoryWriter::mpa_otxtstream
QTextStream * mpa_otxtstream
Definition tsvdirectorywriter.h:105
TsvDirectoryWriter::isQuoteStrings
bool isQuoteStrings() const
tells if the quote string flag is enabled
Definition tsvdirectorywriter.cpp:274
TsvDirectoryWriter::close
virtual void close() override
Definition tsvdirectorywriter.cpp:72
TsvDirectoryWriter::~TsvDirectoryWriter
virtual ~TsvDirectoryWriter()
Definition tsvdirectorywriter.cpp:46
TsvDirectoryWriter::setQuoteStrings
bool setQuoteStrings(bool quote_strings)
set a flag to quote strings
Definition tsvdirectorywriter.cpp:267
TsvDirectoryWriter::setCellAnnotation
void setCellAnnotation(const QString &annotation) override
set annotation to write in the next cell
Definition tsvdirectorywriter.h:55
TsvDirectoryWriter::writeCellPercentage
void writeCellPercentage(double value) override
write a double as a percentage
Definition tsvdirectorywriter.cpp:232
TsvDirectoryWriter::writeRawCell
void writeRawCell(const QString &text)
Definition tsvdirectorywriter.cpp:188
TsvDirectoryWriter::setSeparator
void setSeparator(TsvSeparator separator)
sets the separator to use between values (cells)
Definition tsvdirectorywriter.cpp:52
TsvDirectoryWriter::numFloatPrecision
unsigned int numFloatPrecision
Definition tsvdirectorywriter.h:106
TsvDirectoryWriter::writeCell
void writeCell(const char *) override
write a text cell
Definition tsvdirectorywriter.cpp:151
TsvDirectoryWriter::ensureSheet
void ensureSheet()
Definition tsvdirectorywriter.cpp:125
TsvDirectoryWriter::_tableRowStart
bool _tableRowStart
Definition tsvdirectorywriter.h:117
TsvDirectoryWriter::isFlushLines
bool isFlushLines() const
tells if the flush lines flag is enabled
Definition tsvdirectorywriter.cpp:280
TsvDirectoryWriter::mpa_ofile
QFile * mpa_ofile
Definition tsvdirectorywriter.h:120
TsvDirectoryWriter::m_tsvSeparatorEnum
TsvSeparator m_tsvSeparatorEnum
Definition tsvdirectorywriter.h:115
TsvDirectoryWriter::_startingSheet
bool _startingSheet
Definition tsvdirectorywriter.h:118
TsvDirectoryWriter::_end_of_line
QString _end_of_line
Definition tsvdirectorywriter.h:104
TsvDirectoryWriter::TsvDirectoryWriter
TsvDirectoryWriter(const QDir &directory)
Definition tsvdirectorywriter.cpp:30
TsvDirectoryWriter::initializeSheet
void initializeSheet()
Definition tsvdirectorywriter.cpp:116
config.h
TsvSeparator
TsvSeparator
Definition config.h:11
TsvSeparator::tab
@ tab
Definition config.h:11