odsstream
tsvdirectorywriter.h
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  void close() override;
40 
41  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 
62  void setSeparator(TsvSeparator separator);
63 
68  TsvSeparator getSeparator() const;
69 
75  bool setQuoteStrings(bool quote_strings);
76 
77 
80  bool isQuoteStrings() const;
81 
82 
91  bool setFlushLines(bool flushOk);
92 
95  bool isFlushLines() const;
96 
97  protected:
99  void writeRawCell(const QString &text);
100 
101  QString m_separator = "\t";
102  QString _end_of_line = "\n";
103  QTextStream *_p_otxtstream = nullptr;
104  unsigned int numFloatPrecision = 12;
105 
106  private:
107  const QDir _directory;
108 
109  QString _file_extension = ".tsv";
110 
111  bool _tableRowStart = true;
112  bool _startingSheet = false;
113  bool m_quoteStrings = false;
114  bool m_flushLines = false;
115  TsvSeparator m_tsvSeparatorEnum = TsvSeparator::tab;
116 
117  QFile *_p_ofile = nullptr;
118  void ensureSheet();
119 };
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:279
TsvDirectoryWriter::writeSheet
void writeSheet(const QString &sheetName) override
open a new sheet
Definition: tsvdirectorywriter.cpp:92
TsvDirectoryWriter::isQuoteStrings
bool isQuoteStrings() const
tells if the quote string flag is enabled
Definition: tsvdirectorywriter.cpp:267
TsvDirectoryWriter::writeCell
void writeCell(const char *) override
write a text cell
Definition: tsvdirectorywriter.cpp:144
TsvDirectoryWriter::setQuoteStrings
bool setQuoteStrings(bool quote_strings)
set a flag to quote strings
Definition: tsvdirectorywriter.cpp:260
TsvDirectoryWriter::getSeparator
TsvSeparator getSeparator() const
get the separator used between values (cells)
Definition: tsvdirectorywriter.cpp:286
TsvDirectoryWriter::writeEmptyCell
void writeEmptyCell() override
write an empty cell
Definition: tsvdirectorywriter.cpp:193
TsvDirectoryWriter::isFlushLines
bool isFlushLines() const
tells if the flush lines flag is enabled
Definition: tsvdirectorywriter.cpp:273
CalcWriterInterface
Definition: calcwriterinterface.h:49
TsvDirectoryWriter::writeCellPercentage
void writeCellPercentage(double value) override
write a double as a percentage
Definition: tsvdirectorywriter.cpp:225
TsvDirectoryWriter
Definition: tsvdirectorywriter.h:33
TsvDirectoryWriter::writeLine
void writeLine() override
open a new line
Definition: tsvdirectorywriter.cpp:127
TsvDirectoryWriter::writeCell
void writeCell(const QUrl &, const QString &) override
write a text cell with an URL link
TsvDirectoryWriter::setSeparator
void setSeparator(TsvSeparator separator)
sets the separator to use between values (cells)
Definition: tsvdirectorywriter.cpp:52