From 9ee8807af7276ee8a910561f671a8cd1936babf9 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 30 Apr 2021 15:51:13 +0200 Subject: export: show progress dialog for TeX exports The TeX exports may hang the UI for a long time. Show a progress-dialog that is updated after every exported dive and allows the user to cancel the export. This is pretty lame, because it is synchronous (export still runs in UI thread) and therefore the UI still is sluggish. But it is an improvement. Since the TeX-exporting code is in a shared directory (desktop and mobile), this uses a slim interface class. Mobile does not yet use TeX export, but you never know. Better than #ifdefs sprinkled all around, I reckon. Signed-off-by: Berthold Stoeger --- desktop-widgets/divelogexportdialog.cpp | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/divelogexportdialog.cpp b/desktop-widgets/divelogexportdialog.cpp index f0ee82337..7d9a6d6ca 100644 --- a/desktop-widgets/divelogexportdialog.cpp +++ b/desktop-widgets/divelogexportdialog.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 #include +#include #include #include #include // Allows string comparisons and substitutions in TeX export @@ -14,6 +15,7 @@ #include "core/divesite.h" #include "core/errorhelper.h" #include "core/file.h" +#include "core/gettextfromc.h" #include "core/tag.h" #include "backend-shared/exportfuncs.h" #include "desktop-widgets/mainwindow.h" @@ -131,6 +133,32 @@ void DiveLogExportDialog::on_exportGroup_buttonClicked(QAbstractButton*) showExplanation(); } +// Use a QProgressDialog to show export-progress +// Default implementation of the export callback: do nothing / never cancel +struct ProgressDialogCallback : public ExportCallback { + ProgressDialogCallback(); + QProgressDialog dialog; + virtual void setProgress(int progress) override; + virtual bool canceled() const override; +}; + +ProgressDialogCallback::ProgressDialogCallback() : + dialog(gettextFromC::tr("Exporting..."), gettextFromC::tr("Cancel"), 0, 1000, MainWindow::instance()) +{ + dialog.setWindowModality(Qt::WindowModal); + dialog.setMinimumDuration(0); // Show dialog immediately +} + +void ProgressDialogCallback::setProgress(int progress) +{ + dialog.setValue(progress); +} + +bool ProgressDialogCallback::canceled() const +{ + return dialog.wasCanceled(); +} + void DiveLogExportDialog::on_buttonBox_accepted() { QString filename; @@ -188,8 +216,10 @@ void DiveLogExportDialog::on_buttonBox_accepted() export_depths(qPrintable(filename), ui->exportSelected->isChecked()); } else if (ui->exportTeX->isChecked() || ui->exportLaTeX->isChecked()) { filename = QFileDialog::getSaveFileName(this, tr("Export to TeX file"), lastDir, tr("TeX files") + " (*.tex)"); - if (!filename.isEmpty()) - export_TeX(qPrintable(filename), ui->exportSelected->isChecked(), ui->exportTeX->isChecked()); + if (!filename.isEmpty()) { + ProgressDialogCallback cb; + export_TeX(qPrintable(filename), ui->exportSelected->isChecked(), ui->exportTeX->isChecked(), cb); + } } else if (ui->exportProfile->isChecked()) { filename = QFileDialog::getSaveFileName(this, tr("Save profile image"), lastDir); if (!filename.isEmpty()) -- cgit v1.2.3-70-g09d2