From a22b13b773e48b3366fb52703f03b27bddc68a9b Mon Sep 17 00:00:00 2001 From: Mykola Dimura Date: Mon, 4 May 2020 23:33:23 +0200 Subject: [PATCH] Provide an option to cancel while saving the results table --- src/TrajectoriesTreeModel.cpp | 3 ++- src/gui/mainwindow.cpp | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/TrajectoriesTreeModel.cpp b/src/TrajectoriesTreeModel.cpp index 656fb61..28550fe 100644 --- a/src/TrajectoriesTreeModel.cpp +++ b/src/TrajectoriesTreeModel.cpp @@ -307,10 +307,11 @@ QString TrajectoriesTreeModel::dumpTabSeparatedData() const QProgressDialog progress("Generating the table...", "Cancel", 0, indexes.size()); progress.setWindowModality(Qt::ApplicationModal); - progress.setWindowTitle("Saving results..."); + progress.setWindowTitle("Generating the table..."); progress.setValue(0); for (const auto &idx : indexes) { if (progress.wasCanceled()) { + result.clear(); break; } TrajectoriesTreeItem *parentItem; diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 8279853..11e7bb8 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -410,6 +410,12 @@ bool MainWindow::exportData(const QString &fileName) return false; } QString s = trajectoriesModel.dumpTabSeparatedData(); + if (s.isEmpty()) { + file.remove(); + statusBar()->showMessage(tr("Export cancelled").arg(fileName), + 5000); + return false; + } QStringList lines = s.split('\n'); QProgressDialog dlg; dlg.setLabelText("Saving the file..."); @@ -417,9 +423,13 @@ bool MainWindow::exportData(const QString &fileName) dlg.setRange(0, lines.size()); dlg.setWindowModality(Qt::WindowModal); dlg.show(); - dlg.setCancelButton(0); QTextStream out(&file); for (int i = 0; i < lines.size(); ++i) { + if (dlg.wasCanceled()) { + statusBar()->showMessage( + tr("Export cancelled").arg(fileName), 5000); + return false; + } out << lines[i] << "\n"; dlg.setValue(i); }