From 8f0e2245c2bb8489d485921bfb583d66d0b0204c Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Wed, 7 Apr 2021 08:35:35 +0200 Subject: [PATCH] export: move exportProfile() function to exportfuncs.cpp The exportProfile function uses the UI and therefore was supposed to be declared in backend-shared/* but defined separately for desktop and mobile. Currently, only the desktop version exists. The goal however should be that there is no need of the UI for this function. In a first step, move the function to the common backend-shared/* code and conditionally compile for desktop. In upcoming commits, the function will be made independent of the UI. Signed-off-by: Berthold Stoeger --- backend-shared/exportfuncs.cpp | 32 +++++++++++++++++++++---- backend-shared/exportfuncs.h | 9 ------- desktop-widgets/divelogexportdialog.cpp | 19 --------------- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/backend-shared/exportfuncs.cpp b/backend-shared/exportfuncs.cpp index 7ed13cf83..4a3f4d4ac 100644 --- a/backend-shared/exportfuncs.cpp +++ b/backend-shared/exportfuncs.cpp @@ -1,7 +1,5 @@ // SPDX-License-Identifier: GPL-2.0 -#include -#include -#include +#include "exportfuncs.h" #include "core/membuffer.h" #include "core/dive.h" #include "core/divesite.h" @@ -17,7 +15,11 @@ #include "core/sample.h" #include "core/selection.h" #include "core/taxonomy.h" -#include "exportfuncs.h" +#include "core/sample.h" +#include "profile-widget/profilewidget2.h" +#include +#include +#include // Default implementation of the export callback: do nothing / never cancel void ExportCallback::setProgress(int) @@ -30,6 +32,28 @@ bool ExportCallback::canceled() const } #if !defined(SUBSURFACE_MOBILE) + +#include "desktop-widgets/mainwindow.h" // Currently needed for profile printing. TODO: remove. + +static void exportProfile(const struct dive *dive, const QString filename) +{ + ProfileWidget2 *profile = MainWindow::instance()->graphics; + profile->setToolTipVisibile(false); + profile->setPrintMode(true); + double scale = profile->getFontPrintScale(); + profile->setFontPrintScale(4 * scale); + profile->plotDive(dive, 0, false, true); + QImage image = QImage(profile->size() * 4, QImage::Format_RGB32); + QPainter paint; + paint.begin(&image); + profile->render(&paint); + image.save(filename); + profile->setToolTipVisibile(true); + profile->setFontPrintScale(scale); + profile->setPrintMode(false); + profile->plotDive(dive, 0, true); // TODO: Shouldn't this plot the current dive? +} + void exportProfile(QString filename, bool selected_only, ExportCallback &cb) { struct dive *dive; diff --git a/backend-shared/exportfuncs.h b/backend-shared/exportfuncs.h index ed483f90d..716a740e4 100644 --- a/backend-shared/exportfuncs.h +++ b/backend-shared/exportfuncs.h @@ -22,13 +22,4 @@ QFuture exportUsingStyleSheet(QString filename, bool doExport, int units, Q // prepareDivesForUploadDiveLog // prepareDivesForUploadDiveShare -// WARNING -// exportProfile uses the UI and are therefore different between -// Desktop (UI) and Mobile (QML) -// In order to solve this difference, the actual implementations -// are done in -// desktop-widgets/divelogexportdialog.cpp and -// mobile-widgets/qmlmanager.cpp -void exportProfile(const struct dive *dive, const QString filename); - #endif // EXPORT_FUNCS_H diff --git a/desktop-widgets/divelogexportdialog.cpp b/desktop-widgets/divelogexportdialog.cpp index 164ae0434..391960c12 100644 --- a/desktop-widgets/divelogexportdialog.cpp +++ b/desktop-widgets/divelogexportdialog.cpp @@ -253,22 +253,3 @@ void DiveLogExportDialog::on_buttonBox_accepted() } } } - -void exportProfile(const struct dive *dive, const QString filename) -{ - ProfileWidget2 *profile = MainWindow::instance()->graphics; - profile->setToolTipVisibile(false); - profile->setPrintMode(true); - double scale = profile->getFontPrintScale(); - profile->setFontPrintScale(4 * scale); - profile->plotDive(dive, 0, false, true); - QImage image = QImage(profile->size() * 4, QImage::Format_RGB32); - QPainter paint; - paint.begin(&image); - profile->render(&paint); - image.save(filename); - profile->setToolTipVisibile(true); - profile->setFontPrintScale(scale); - profile->setPrintMode(false); - profile->plotDive(dive, 0); // TODO: Shouldn't this plot the current dive? -}