Skip to content

Commit

Permalink
Provide an option to cancel while saving the results table
Browse files Browse the repository at this point in the history
  • Loading branch information
mdimura committed May 4, 2020
1 parent 4a8b269 commit a22b13b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/TrajectoriesTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 11 additions & 1 deletion src/gui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,16 +410,26 @@ 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...");
dlg.setWindowTitle("Saving the file...");
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);
}
Expand Down

0 comments on commit a22b13b

Please sign in to comment.