libodsstream
Library for mass spectrometry
Loading...
Searching...
No Matches
tsvdirectorywriter.h
Go to the documentation of this file.
1/*
2 libodsstream is a library to read and write ODS documents as streams
3 Copyright (C) 2013 Olivier Langella <Olivier.Langella@moulon.inra.fr>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18*/
19
20#pragma once
21
22
23#include <QString>
24#include <QUrl>
25#include <QDate>
26#include <QDir>
27#include <QTextStream>
28#include <QFile>
29#include "calcwriterinterface.h"
30#include "config.h"
31
33{
34 public:
35 TsvDirectoryWriter(const QDir &directory);
36 virtual ~TsvDirectoryWriter();
37
38
39 virtual void close() override;
40
41 virtual void writeSheet(const QString &sheetName) override;
42 void writeLine() override;
43 void writeCell(const char *) override;
44 void writeCell(const QString &) override;
45 void writeEmptyCell() override;
46 void writeCell(std::size_t) override;
47 void writeCell(int) override;
48 void writeCell(float) override;
49 void writeCell(double) override;
50 void writeCellPercentage(double value) override;
51 void writeCell(bool) override;
52 void writeCell(const QDate &) override;
53 void writeCell(const QDateTime &) override;
54 void writeCell(const QUrl &, const QString &) override;
55 void setCellAnnotation([[maybe_unused]] const QString &annotation) override{};
56
57
58 /** @brief sets the separator to use between values (cells)
59 *
60 * @param TsvSeparator enumeration to choose between possible choices
61 */
62 void setSeparator(TsvSeparator separator);
63
64 /** @brief get the separator used between values (cells)
65 *
66 * @return TsvSeparator used
67 */
69
70 /** @brief set a flag to quote strings
71 *
72 * @param bool if true, strings will be quoted, choose false otherwise
73 * @return bool state of the modified flag
74 */
75 bool setQuoteStrings(bool quote_strings);
76
77
78 /** @brief tells if the quote string flag is enabled
79 */
80 bool isQuoteStrings() const;
81
82
83 /** @brief enable a physical flush on device at each new line
84 * enables this if you want to ensure that each line is written. This costs a
85 * little overhead
86 *
87 * @param bool if true, lines will be flushed, choose false otherwise
88 * @return bool state of the modified flag
89
90 * */
91 bool setFlushLines(bool flushOk);
92
93 /** @brief tells if the flush lines flag is enabled
94 */
95 bool isFlushLines() const;
96
97 protected:
99 void writeRawCell(const QString &text);
100 void initializeSheet();
101
102 protected:
103 QString m_separator = "\t";
104 QString _end_of_line = "\n";
105 QTextStream *mpa_otxtstream = nullptr;
106 unsigned int numFloatPrecision = 12;
107
108 private:
109 const QDir _directory;
110
111 QString _file_extension = ".tsv";
112
113 bool m_quoteStrings = false;
114 bool m_flushLines = false;
116 void ensureSheet();
117 bool _tableRowStart = true;
118 bool _startingSheet = false;
119
120 QFile *mpa_ofile = nullptr;
121};
void writeLine() override
open a new line
virtual void writeSheet(const QString &sheetName) override
open a new sheet
bool setFlushLines(bool flushOk)
enable a physical flush on device at each new line enables this if you want to ensure that each line ...
TsvSeparator getSeparator() const
get the separator used between values (cells)
void writeEmptyCell() override
write an empty cell
QTextStream * mpa_otxtstream
bool isQuoteStrings() const
tells if the quote string flag is enabled
virtual void close() override
bool setQuoteStrings(bool quote_strings)
set a flag to quote strings
void setCellAnnotation(const QString &annotation) override
set annotation to write in the next cell
void writeCellPercentage(double value) override
write a double as a percentage
void writeRawCell(const QString &text)
void setSeparator(TsvSeparator separator)
sets the separator to use between values (cells)
unsigned int numFloatPrecision
void writeCell(const char *) override
write a text cell
bool isFlushLines() const
tells if the flush lines flag is enabled
TsvSeparator m_tsvSeparatorEnum
TsvSeparator
Definition config.h:11