-
Notifications
You must be signed in to change notification settings - Fork 6
/
export-csv.cpp
73 lines (60 loc) · 1.68 KB
/
export-csv.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
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
#include <QMessageBox>
#include "mainwindow.h"
#include "export-csv.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=NULL;
BranchItem *prev=NULL;
model->nextBranch (cur,prev);
while (cur)
{
if (!cur->hasHiddenExportParent() )
{
// If necessary, write note
if (!cur->isNoteEmpty())
{
s =cur->getNoteASCII();
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->getHeadingPlain() + "\"\n";
}
model->nextBranch(cur,prev);
curIndent="";
}
QTextStream ts( &file );
ts.setCodec("UTF-8");
ts << out;
file.close();
QClipboard *clipboard = QGuiApplication::clipboard();
clipboard->setText(out);
destination = filePath;
success = true;
completeExport();
}