X-Git-Url: https://git.sven.stormbind.net/?a=blobdiff_plain;f=src%2Fexport-csv.cpp;fp=src%2Fexport-csv.cpp;h=52840b9eb32b2d065fbef9fb0a9c1ac4339a3d5a;hb=d483bd8e6523c23c6f1d8908a2e0611c2bc9ff4f;hp=0000000000000000000000000000000000000000;hpb=7dfa3fe589d1722d49681f42cdb0bf1e6efb5223;p=sven%2Fvym.git diff --git a/src/export-csv.cpp b/src/export-csv.cpp new file mode 100644 index 0000000..52840b9 --- /dev/null +++ b/src/export-csv.cpp @@ -0,0 +1,73 @@ +#include "mainwindow.h" +#include + +#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(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->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); + + displayedDestination = filePath; + + result = ExportBase::Success; + completeExport(); +}