1 #include "export-ascii.h"
3 #include "mainwindow.h"
6 extern QString vymName;
7 extern Main *mainWindow;
9 ExportASCII::ExportASCII()
12 filter = "TXT (*.txt);;All (* *.*)";
13 caption = vymName + " -" + QObject::tr("Export as ASCII");
16 void ExportASCII::doExport()
19 if (!file.open(QIODevice::WriteOnly)) {
20 QMessageBox::critical(
21 0, QObject::tr("Critical Export Error"),
22 QObject::tr("Could not export as ASCII to %1").arg(filePath));
23 mainWindow->statusMessage(QString(QObject::tr("Export failed.")));
29 // Main loop over all branches
34 BranchItem *cur = NULL;
35 BranchItem *prev = NULL;
41 model->nextBranch(cur, prev);
43 if (cur->getType() == TreeItem::Branch ||
44 cur->getType() == TreeItem::MapCenter) {
45 if (!cur->hasHiddenExportParent()) {
46 // qDebug() << "ExportASCII::
47 // "<<curIndent.toStdString()<<cur->getHeadingPlain().toStdString();
49 // Insert newline after previous list
50 if (cur->depth() < lastDepth)
55 for (i = 1; i < cur->depth() - 1; i++)
56 curIndent += indentPerDepth;
59 switch (cur->depth()) {
61 out += underline(cur->getHeadingPlain(), QString("="));
66 out += (underline(getSectionString(cur) +
67 cur->getHeadingPlain(),
72 out += (curIndent + "- " + cur->getHeadingPlain());
77 out += (curIndent + "- " + cur->getHeadingPlain());
83 // If there is a task, save it for potential later display
84 if (listTasks && cur->getTask()) {
85 tasks.append(QString("[%1]: %2")
86 .arg(cur->getTask()->getStatusString())
87 .arg(cur->getHeadingPlain()));
90 // If necessary, write URL
91 if (!cur->getURL().isEmpty())
92 out += (curIndent + dashIndent + cur->getURL()) + "\n";
94 // If necessary, write vymlink
95 if (!cur->getVymLink().isEmpty())
96 out += (curIndent + dashIndent + cur->getVymLink()) +
99 // If necessary, write note
100 if (!cur->isNoteEmpty()) {
101 // curIndent +=" | ";
102 // Only indent for bullet points
103 if (cur->depth() > 2)
105 out += '\n' + cur->getNoteASCII(curIndent, 80);
107 lastDepth = cur->depth();
110 model->nextBranch(cur, prev);
114 out += "\n\nTasks\n-----\n\n";
116 foreach (QString t, tasks) {
117 out += " - " + t + "\n";
121 QTextStream ts(&file);
122 ts.setCodec("UTF-8");
126 QClipboard *clipboard = QGuiApplication::clipboard();
127 clipboard->setText(out);
129 QString listTasksString = listTasks ? "true" : "false";
131 displayedDestination = filePath;
133 result = ExportBase::Success;
137 args << listTasksString;
139 completeExport(args);
142 QString ExportASCII::underline(const QString &text, const QString &line)
144 QString r = text + "\n";
145 for (int j = 0; j < text.length(); j++)