From 5b302235f4a7c3a5c8bf1bc6404171ebef1b321c Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 6 Feb 2020 22:18:42 +0100 Subject: [PATCH] Cleanup: Remove global QFuture from exportFuncs When exporting dives we show a message. The message is closed when the export is finished. This is coordinated by a QFuture. Instead of keeping a global QFuture in the export-code, pass it around as a local variable. This is supported according to Qt's documentation: "QFuture is a lightweight reference counted class that can be passed by value." and the source code indicates the same. Not only does this remove a global, it also makes the code more flexible: Now we could show one notification per export, for example. Signed-off-by: Berthold Stoeger --- backend-shared/exportfuncs.cpp | 4 ++-- backend-shared/exportfuncs.h | 3 +-- desktop-widgets/divelogexportdialog.cpp | 7 ++++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend-shared/exportfuncs.cpp b/backend-shared/exportfuncs.cpp index 839c0bf1d..eea20ef5b 100644 --- a/backend-shared/exportfuncs.cpp +++ b/backend-shared/exportfuncs.cpp @@ -311,8 +311,8 @@ std::vector exportFuncs::getDiveSitesToExport(bool selectedOn return res; } -void exportFuncs::exportUsingStyleSheet(QString filename, bool doExport, int units, +QFuture exportFuncs::exportUsingStyleSheet(QString filename, bool doExport, int units, QString stylesheet, bool anonymize) { - future = QtConcurrent::run(export_dives_xslt, filename.toUtf8(), doExport, units, stylesheet.toUtf8(), anonymize); + return QtConcurrent::run(export_dives_xslt, filename.toUtf8(), doExport, units, stylesheet.toUtf8(), anonymize); } diff --git a/backend-shared/exportfuncs.h b/backend-shared/exportfuncs.h index a378e152d..530cde7e0 100644 --- a/backend-shared/exportfuncs.h +++ b/backend-shared/exportfuncs.h @@ -16,9 +16,8 @@ public: void export_TeX(const char *filename, const bool selected_only, bool plain); void export_depths(const char *filename, const bool selected_only); std::vector getDiveSitesToExport(bool selectedOnly); - void exportUsingStyleSheet(QString filename, bool doExport, int units, + QFuture exportUsingStyleSheet(QString filename, bool doExport, int units, QString stylesheet, bool anonymize); - QFuture future; // prepareDivesForUploadDiveLog // prepareDivesForUploadDiveShare diff --git a/desktop-widgets/divelogexportdialog.cpp b/desktop-widgets/divelogexportdialog.cpp index dc0928e8f..0e85bc6bd 100644 --- a/desktop-widgets/divelogexportdialog.cpp +++ b/desktop-widgets/divelogexportdialog.cpp @@ -214,9 +214,10 @@ void DiveLogExportDialog::on_buttonBox_accepted() qPrefDisplay::set_lastDir(fileInfo.dir().path()); // the non XSLT exports are called directly above, the XSLT based ons are called here if (!stylesheet.isEmpty()) { - exportFuncs::instance()->exportUsingStyleSheet(filename, ui->exportSelected->isChecked(), ui->CSVUnits_2->currentIndex(), stylesheet.toUtf8(), ui->anonymize->isChecked()); - MainWindow::instance()->getNotificationWidget()->showNotification(tr("Please wait, exporting..."), KMessageWidget::Information); - MainWindow::instance()->getNotificationWidget()->setFuture(exportFuncs::instance()->future); + QFuture future = exportFuncs::instance()->exportUsingStyleSheet(filename, ui->exportSelected->isChecked(), + ui->CSVUnits_2->currentIndex(), stylesheet.toUtf8(), ui->anonymize->isChecked()); + MainWindow::instance()->getNotificationWidget()->showNotification(tr("Please wait, exporting..."), KMessageWidget::Information); + MainWindow::instance()->getNotificationWidget()->setFuture(future); } } }