-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCsvWriter.cpp
46 lines (31 loc) · 1.09 KB
/
CsvWriter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "CsvWriter.h"
#include <QDebug>
CsvWriter::CsvWriter()
{
}
void CsvWriter::writeFile(QString filePath, QList<AccountingEntry> entries)
{
QFile file(filePath);
if (!file.open(QIODevice::WriteOnly)) {
qDebug() << file.errorString();
return ;
}
QTextStream out(&file);
// Eintraege nach Datum sortieren
// TODO: std::sort verwenden
qSort(entries);
for (int i = AccountingEntry::Categorie::GEHALT; i <= AccountingEntry::Categorie::NONE; i++) {
AccountingEntry::Categorie categorie = static_cast<AccountingEntry::Categorie>(i);
out << "" << ";" << "" << ";" << AccountingEntry::categorieToString(categorie) << "\n";
for (auto entry : entries) {
qDebug() << entry.getAmount();
if (entry.getCategorie() == categorie) {
out << entry.getAccountingDate().toString("dd.MM.yyyy") << ";"
<< QString::number(entry.getAmount()).replace(".", ",") << ";"
<< entry.getDescription() << "\n";
}
}
out << "\n";
}
file.close();
}