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  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 
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  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;
115  TsvSeparator m_tsvSeparatorEnum = TsvSeparator::tab;
116  void ensureSheet();
117  bool _tableRowStart = true;
118  bool _startingSheet = false;
119 
120  QFile *mpa_ofile = nullptr;
121 };
Definition: calcwriterinterface.h:49
Definition: tsvdirectorywriter.h:33
void writeLine() override
open a new line
Definition: tsvdirectorywriter.cpp:134
virtual void writeSheet(const QString &sheetName) override
open a new sheet
Definition: tsvdirectorywriter.cpp:92
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
TsvSeparator getSeparator() const
get the separator used between values (cells)
Definition: tsvdirectorywriter.cpp:293
void writeEmptyCell() override
write an empty cell
Definition: tsvdirectorywriter.cpp:200
bool isQuoteStrings() const
tells if the quote string flag is enabled
Definition: tsvdirectorywriter.cpp:274
bool setQuoteStrings(bool quote_strings)
set a flag to quote strings
Definition: tsvdirectorywriter.cpp:267
void writeCellPercentage(double value) override
write a double as a percentage
Definition: tsvdirectorywriter.cpp:232
void setSeparator(TsvSeparator separator)
sets the separator to use between values (cells)
Definition: tsvdirectorywriter.cpp:52
void writeCell(const char *) override
write a text cell
Definition: tsvdirectorywriter.cpp:151
bool isFlushLines() const
tells if the flush lines flag is enabled
Definition: tsvdirectorywriter.cpp:280
void writeCell(const QUrl &, const QString &) override
write a text cell with an URL link