-
Notifications
You must be signed in to change notification settings - Fork 6
/
export-ao.cpp
169 lines (143 loc) · 5.38 KB
/
export-ao.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <QMessageBox>
#include "export-ao.h"
#include "mainwindow.h"
extern QString vymName;
extern Main *mainWindow;
extern Settings settings;
ExportAO::ExportAO()
{
exportName = "AO";
filter = "TXT (*.txt);;All (* *.*)";
caption = vymName + " -" +QObject::tr("Export as ASCII")+" "+QObject::tr("(still experimental)");
indentPerDepth=" ";
bulletPoints.clear();
for (int i=0; i<10; i++)
bulletPoints << "-";
}
void ExportAO::doExport()
{
QFile file (filePath);
if ( !file.open( QIODevice::WriteOnly ) )
{
QMessageBox::critical (0, QObject::tr("Critical Export Error"), QObject::tr("Could not export as AO to %1").arg(filePath));
mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
return;
}
settings.setLocalValue ( model->getFilePath(), "/export/last/command","exportAO");
settings.setLocalValue ( model->getFilePath(), "/export/last/description","A&O report");
QString out;
// Main loop over all branches
QString s;
QString curIndent;
QString dashIndent;
int i;
BranchItem *cur = NULL;
BranchItem *prev = NULL;
model->nextBranch (cur,prev);
while (cur)
{
QString line;
QString colString = "";
QString noColString;
QString statusString = "";
QColor col;
if (cur->getType() == TreeItem::Branch || cur->getType() == TreeItem::MapCenter)
{
// Make indentstring
curIndent = indent(cur->depth()-4, true);
if (!cur->hasHiddenExportParent() )
{
col = cur->getHeadingColor();
if (col == QColor (255,0,0))
colString = "[R] ";
else if (col == QColor (217,81,0))
colString = "[O] ";
else if (col == QColor (0,85,0))
colString = "[G] ";
else if (cur->depth() == 4)
colString = " * ";
else
colString = " ";
noColString = QString(" ").repeated(colString.length() );
dashIndent = "";
switch (cur->depth())
{
case 0: break; // Mapcenter (Ignored)
case 1: break; // Mainbranch "Archive" (Ignored)
case 2: // Title: "Current week number..."
out += "\n";
out += underline ( cur->getHeadingPlain(), QString("=") );
out += "\n";
break;
case 3: // Headings: "Achievement", "Bonus", "Objective", ...
out += "\n";
out += underline ( cur->getHeadingPlain(), "-");
out += "\n";
break;
default: // depth 4 and higher are the items we need to know
Task *task=cur->getTask();
if (task)
{
// Task status overrides other flags
switch ( task->getStatus() )
{
case Task::NotStarted:
statusString="[NOT STARTED]";
break;
case Task::WIP:
statusString="[WIP]";
break;
case Task::Finished:
statusString="[DONE]";
break;
}
} else
{
if (cur->hasActiveStandardFlag ("hook-green") )
statusString="[DONE]";
else if (cur->hasActiveStandardFlag ("wip"))
statusString="[WIP]";
else if (cur->hasActiveStandardFlag ("cross-red"))
statusString="[NOT STARTED]";
}
line += colString;
line += curIndent;
if (cur->depth() >3)
line += cur->getHeadingPlain();
// Pad line width before status
i = 80 - line.length() - statusString.length() -1;
for (int j=0; j<i; j++) line += " ";
line += " " + statusString + "\n";
out += line;
// If necessary, write URL
if (!cur->getURL().isEmpty())
out += noColString + indent(cur->depth()-4, false) + cur->getURL() + "\n";
// If necessary, write note
if (!cur->isNoteEmpty())
{
curIndent = noColString + indent(cur->depth() - 4, false) + "| ";
s=cur->getNoteASCII( curIndent, 80);
out += s + "\n";
}
break;
}
}
}
model->nextBranch(cur,prev);
}
QTextStream ts( &file );
ts.setCodec("UTF-8");
ts << out;
file.close();
QClipboard *clipboard = QGuiApplication::clipboard();
clipboard->setText(out);
destination = filePath;
success = true;
completeExport();
}
QString ExportAO::underline (const QString &text, const QString &line)
{
QString r=text + "\n";
for (int j=0;j<text.length();j++) r+=line;
return r;
}