Menu

[efa3d9]: / src / export-csv.cpp  Maximize  Restore  History

Download this file

78 lines (63 with data), 1.9 kB

 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "export-csv.h"
#include <QClipboard>
#include <QGuiApplication>
#include <QMessageBox>
#include "branchitem.h"
#include "mainwindow.h"
#include "vymmodel.h"
extern QString vymName;
extern Main *mainWindow;
ExportCSV::ExportCSV()
{
exportName = "CSV";
filter = "CSV (*.csv);;All (* *.*)";
caption = vymName + " -" + QObject::tr("Export as CSV");
}
void ExportCSV::doExport()
{
QFile file(filePath);
if (!file.open(QIODevice::WriteOnly)) {
QMessageBox::critical(
0, QObject::tr("Critical Export Error"),
QObject::tr("Could not export as CSV to %1").arg(filePath));
mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
return;
}
QString out;
// Write header
// out += "\"Note\"\n";
// Main loop over all branches
QString s;
QString curIndent("");
int i;
BranchItem *cur = nullptr;
BranchItem *prev = nullptr;
model->nextBranch(cur, prev);
while (cur) {
if (!cur->hasHiddenParent()) {
// If necessary, write note
if (!cur->isNoteEmpty()) {
s = cur->getNoteASCII(0, 0);
s = s.replace("\n", "\n" + curIndent);
out += ("\"" + s + "\",");
}
else
out += "\"\",";
// Make indentstring
for (i = 0; i < cur->depth(); i++)
curIndent += "\"\",";
// Write heading
out += curIndent + "\"" + cur->headingPlain() + "\"\n";
}
model->nextBranch(cur, prev);
curIndent = "";
}
QTextStream ts(&file);
ts << out;
file.close();
QClipboard *clipboard = QGuiApplication::clipboard();
clipboard->setText(out);
displayedDestination = filePath;
result = ExportBase::Success;
completeExport();
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.