libodsstream
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 #ifndef TSVDIRECTORYWRITER_H
21 #define TSVDIRECTORYWRITER_H
22 
23 
24 #include <QString>
25 #include <QUrl>
26 #include <QDate>
27 #include <QDir>
28 #include <QTextStream>
29 #include <QFile>
30 #include "calcwriterinterface.h"
31 #include "config.h"
32 
34 {
35  public:
36  TsvDirectoryWriter(const QDir &directory);
37  virtual ~TsvDirectoryWriter();
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(int) override;
47  void writeCell(float) override;
48  void writeCell(double) override;
49  void writeCellPercentage(double value) override;
50  void writeCell(bool) override;
51  void writeCell(const QDate &) override;
52  void writeCell(const QDateTime &) override;
53  void writeCell(const QUrl &, const QString &) override;
54  void setCellAnnotation(const QString &annotation) override{};
55 
56  virtual void setSeparator(TsvSeparator separator);
57  virtual void setQuoteStrings(bool quote_strings);
58 
59  protected:
61  void writeRawCell(const QString &text);
62 
63  QString _separator = "\t";
64  QString _end_of_line = "\n";
65  QTextStream *_p_otxtstream = nullptr;
66  unsigned int numFloatPrecision = 12;
67 
68  private:
69  const QDir _directory;
70 
71  QString _file_extension = ".tsv";
72 
73  bool _tableRowStart = true;
74  bool _startingSheet = false;
75  bool m_quoteStrings = false;
76 
77  QFile *_p_ofile = nullptr;
78  void ensureSheet();
79 };
80 
81 #endif // TSVDIRECTORYWRITER_H
TsvDirectoryWriter::writeSheet
void writeSheet(const QString &sheetName) override
open a new sheet
Definition: tsvdirectorywriter.cpp:91
TsvDirectoryWriter::writeCell
void writeCell(const char *) override
write a text cell
Definition: tsvdirectorywriter.cpp:140
TsvDirectoryWriter::setCellAnnotation
void setCellAnnotation(const QString &annotation) override
set annotation to write in the next cell
Definition: tsvdirectorywriter.h:54
TsvDirectoryWriter::writeEmptyCell
void writeEmptyCell() override
write an empty cell
Definition: tsvdirectorywriter.cpp:189
CalcWriterInterface
Definition: calcwriterinterface.h:49
TsvDirectoryWriter::writeCellPercentage
void writeCellPercentage(double value) override
write a double as a percentage
Definition: tsvdirectorywriter.cpp:216
TsvDirectoryWriter
Definition: tsvdirectorywriter.h:33
TsvDirectoryWriter::writeLine
void writeLine() override
open a new line
Definition: tsvdirectorywriter.cpp:126