Cleanup: remove exportFunc class

exportFunc was a collections of functions for exporting dive data.
It had no state, therefore there is no reason for it to ever be
instantiated.

Simply remove the class. Rename the saveProfile function to
exportProfile so that all export functions start with "export".

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-02-06 22:38:29 +01:00 committed by Dirk Hohndel
parent 5b302235f4
commit 2ec570098b
4 changed files with 41 additions and 58 deletions

View file

@ -4,6 +4,7 @@
#include <QtConcurrent> #include <QtConcurrent>
#include "core/membuffer.h" #include "core/membuffer.h"
#include "core/divesite.h" #include "core/divesite.h"
#include "core/gettextfromc.h"
#include "core/tag.h" #include "core/tag.h"
#include "core/file.h" #include "core/file.h"
#include "core/errorhelper.h" #include "core/errorhelper.h"
@ -11,14 +12,7 @@
#include "core/divesite.h" #include "core/divesite.h"
#include "exportfuncs.h" #include "exportfuncs.h"
void exportProfile(QString filename, const bool selected_only)
exportFuncs *exportFuncs::instance()
{
static exportFuncs *self = new exportFuncs;
return self;
}
void exportFuncs::exportProfile(QString filename, const bool selected_only)
{ {
struct dive *dive; struct dive *dive;
int i; int i;
@ -31,15 +25,15 @@ void exportFuncs::exportProfile(QString filename, const bool selected_only)
if (selected_only && !dive->selected) if (selected_only && !dive->selected)
continue; continue;
if (count) if (count)
saveProfile(dive, fi.path() + QDir::separator() + fi.completeBaseName().append(QString("-%1.").arg(count)) + fi.suffix()); exportProfile(dive, fi.path() + QDir::separator() + fi.completeBaseName().append(QString("-%1.").arg(count)) + fi.suffix());
else else
saveProfile(dive, filename); exportProfile(dive, filename);
++count; ++count;
} }
} }
void exportFuncs::export_TeX(const char *filename, const bool selected_only, bool plain) void export_TeX(const char *filename, const bool selected_only, bool plain)
{ {
FILE *f; FILE *f;
QDir texdir = QFileInfo(filename).dir(); QDir texdir = QFileInfo(filename).dir();
@ -96,7 +90,7 @@ void exportFuncs::export_TeX(const char *filename, const bool selected_only, boo
if (selected_only && !dive->selected) if (selected_only && !dive->selected)
continue; continue;
saveProfile(dive, texdir.filePath(QString("profile%1.png").arg(dive->number))); exportProfile(dive, texdir.filePath(QString("profile%1.png").arg(dive->number)));
struct tm tm; struct tm tm;
utc_mkdate(dive->when, &tm); utc_mkdate(dive->when, &tm);
@ -230,7 +224,7 @@ void exportFuncs::export_TeX(const char *filename, const bool selected_only, boo
f = subsurface_fopen(filename, "w+"); f = subsurface_fopen(filename, "w+");
if (!f) { if (!f) {
report_error(qPrintable(tr("Can't open file %s")), filename); report_error(qPrintable(gettextFromC::tr("Can't open file %s")), filename);
} else { } else {
flush_buffer(&buf, f); /*check for writing errors? */ flush_buffer(&buf, f); /*check for writing errors? */
fclose(f); fclose(f);
@ -239,7 +233,7 @@ void exportFuncs::export_TeX(const char *filename, const bool selected_only, boo
} }
void exportFuncs::export_depths(const char *filename, const bool selected_only) void export_depths(const char *filename, const bool selected_only)
{ {
FILE *f; FILE *f;
struct dive *dive; struct dive *dive;
@ -268,7 +262,7 @@ void exportFuncs::export_depths(const char *filename, const bool selected_only)
f = subsurface_fopen(filename, "w+"); f = subsurface_fopen(filename, "w+");
if (!f) { if (!f) {
report_error(qPrintable(tr("Can't open file %s")), filename); report_error(qPrintable(gettextFromC::tr("Can't open file %s")), filename);
} else { } else {
flush_buffer(&buf, f); /*check for writing errors? */ flush_buffer(&buf, f); /*check for writing errors? */
fclose(f); fclose(f);
@ -276,7 +270,7 @@ void exportFuncs::export_depths(const char *filename, const bool selected_only)
free_buffer(&buf); free_buffer(&buf);
} }
std::vector<const dive_site *> exportFuncs::getDiveSitesToExport(bool selectedOnly) std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly)
{ {
std::vector<const dive_site *> res; std::vector<const dive_site *> res;
#ifndef SUBSURFACE_MOBILE #ifndef SUBSURFACE_MOBILE
@ -311,7 +305,7 @@ std::vector<const dive_site *> exportFuncs::getDiveSitesToExport(bool selectedOn
return res; return res;
} }
QFuture<int> exportFuncs::exportUsingStyleSheet(QString filename, bool doExport, int units, QFuture<int> exportUsingStyleSheet(QString filename, bool doExport, int units,
QString stylesheet, bool anonymize) QString stylesheet, bool anonymize)
{ {
return 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);

View file

@ -6,33 +6,22 @@
#include <QFuture> #include <QFuture>
#include "core/dive.h" #include "core/dive.h"
class exportFuncs: public QObject { void exportProfile(QString filename, const bool selected_only);
Q_OBJECT void export_TeX(const char *filename, const bool selected_only, bool plain);
void export_depths(const char *filename, const bool selected_only);
std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly);
QFuture<int> exportUsingStyleSheet(QString filename, bool doExport, int units, QString stylesheet, bool anonymize);
public: // prepareDivesForUploadDiveLog
static exportFuncs *instance(); // prepareDivesForUploadDiveShare
void exportProfile(QString filename, const bool selected_only); // WARNING
void export_TeX(const char *filename, const bool selected_only, bool plain); // exportProfile uses the UI and are therefore different between
void export_depths(const char *filename, const bool selected_only); // Desktop (UI) and Mobile (QML)
std::vector<const dive_site *> getDiveSitesToExport(bool selectedOnly); // In order to solve this difference, the actual implementations
QFuture<int> exportUsingStyleSheet(QString filename, bool doExport, int units, // are done in
QString stylesheet, bool anonymize); // desktop-widgets/divelogexportdialog.cpp and
// mobile-widgets/qmlmanager.cpp
// prepareDivesForUploadDiveLog void exportProfile(const struct dive *dive, const QString filename);
// prepareDivesForUploadDiveShare
private:
exportFuncs() {}
// WARNING
// saveProfile 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 saveProfile(const struct dive *dive, const QString filename);
};
#endif // EXPORT_FUNCS_H #endif // EXPORT_FUNCS_H

View file

@ -179,21 +179,21 @@ void DiveLogExportDialog::on_buttonBox_accepted()
if (!filename.contains('.')) if (!filename.contains('.'))
filename.append(".xml"); filename.append(".xml");
QByteArray bt = QFile::encodeName(filename); QByteArray bt = QFile::encodeName(filename);
std::vector<const dive_site *> sites = exportFuncs::instance()->getDiveSitesToExport(ui->exportSelected->isChecked()); std::vector<const dive_site *> sites = getDiveSitesToExport(ui->exportSelected->isChecked());
save_dive_sites_logic(bt.data(), &sites[0], (int)sites.size(), ui->anonymize->isChecked()); save_dive_sites_logic(bt.data(), &sites[0], (int)sites.size(), ui->anonymize->isChecked());
} }
} else if (ui->exportImageDepths->isChecked()) { } else if (ui->exportImageDepths->isChecked()) {
filename = QFileDialog::getSaveFileName(this, tr("Save image depths"), lastDir); filename = QFileDialog::getSaveFileName(this, tr("Save image depths"), lastDir);
if (!filename.isNull() && !filename.isEmpty()) if (!filename.isNull() && !filename.isEmpty())
exportFuncs::instance()->export_depths(qPrintable(filename), ui->exportSelected->isChecked()); export_depths(qPrintable(filename), ui->exportSelected->isChecked());
} else if (ui->exportTeX->isChecked() || ui->exportLaTeX->isChecked()) { } else if (ui->exportTeX->isChecked() || ui->exportLaTeX->isChecked()) {
filename = QFileDialog::getSaveFileName(this, tr("Export to TeX file"), lastDir, tr("TeX files") + " (*.tex)"); filename = QFileDialog::getSaveFileName(this, tr("Export to TeX file"), lastDir, tr("TeX files") + " (*.tex)");
if (!filename.isNull() && !filename.isEmpty()) if (!filename.isNull() && !filename.isEmpty())
exportFuncs::instance()->export_TeX(qPrintable(filename), ui->exportSelected->isChecked(), ui->exportTeX->isChecked()); export_TeX(qPrintable(filename), ui->exportSelected->isChecked(), ui->exportTeX->isChecked());
} else if (ui->exportProfile->isChecked()) { } else if (ui->exportProfile->isChecked()) {
filename = QFileDialog::getSaveFileName(this, tr("Save profile image"), lastDir); filename = QFileDialog::getSaveFileName(this, tr("Save profile image"), lastDir);
if (!filename.isNull() && !filename.isEmpty()) if (!filename.isNull() && !filename.isEmpty())
exportFuncs::instance()->exportProfile(qPrintable(filename), ui->exportSelected->isChecked()); exportProfile(qPrintable(filename), ui->exportSelected->isChecked());
} else if (ui->exportProfileData->isChecked()) { } else if (ui->exportProfileData->isChecked()) {
filename = QFileDialog::getSaveFileName(this, tr("Save profile data"), lastDir); filename = QFileDialog::getSaveFileName(this, tr("Save profile data"), lastDir);
if (!filename.isNull() && !filename.isEmpty()) if (!filename.isNull() && !filename.isEmpty())
@ -214,7 +214,7 @@ void DiveLogExportDialog::on_buttonBox_accepted()
qPrefDisplay::set_lastDir(fileInfo.dir().path()); qPrefDisplay::set_lastDir(fileInfo.dir().path());
// the non XSLT exports are called directly above, the XSLT based ons are called here // the non XSLT exports are called directly above, the XSLT based ons are called here
if (!stylesheet.isEmpty()) { if (!stylesheet.isEmpty()) {
QFuture<void> future = exportFuncs::instance()->exportUsingStyleSheet(filename, ui->exportSelected->isChecked(), QFuture<void> future = exportUsingStyleSheet(filename, ui->exportSelected->isChecked(),
ui->CSVUnits_2->currentIndex(), stylesheet.toUtf8(), ui->anonymize->isChecked()); ui->CSVUnits_2->currentIndex(), stylesheet.toUtf8(), ui->anonymize->isChecked());
MainWindow::instance()->getNotificationWidget()->showNotification(tr("Please wait, exporting..."), KMessageWidget::Information); MainWindow::instance()->getNotificationWidget()->showNotification(tr("Please wait, exporting..."), KMessageWidget::Information);
MainWindow::instance()->getNotificationWidget()->setFuture(future); MainWindow::instance()->getNotificationWidget()->setFuture(future);
@ -222,7 +222,7 @@ void DiveLogExportDialog::on_buttonBox_accepted()
} }
} }
void exportFuncs::saveProfile(const struct dive *dive, const QString filename) void exportProfile(const struct dive *dive, const QString filename)
{ {
ProfileWidget2 *profile = MainWindow::instance()->graphics; ProfileWidget2 *profile = MainWindow::instance()->graphics;
profile->plotDive(dive, true, false, true); profile->plotDive(dive, true, false, true);

View file

@ -2137,36 +2137,36 @@ void QMLManager::exportToFile(export_types type, QString dir, bool anonymize)
break; break;
case EX_DIVE_SITES_XML: case EX_DIVE_SITES_XML:
{ {
std::vector<const dive_site *> sites = exportFuncs::instance()->getDiveSitesToExport(false); std::vector<const dive_site *> sites = getDiveSitesToExport(false);
save_dive_sites_logic(qPrintable(fileName + ".xml"), &sites[0], (int)sites.size(), anonymize); save_dive_sites_logic(qPrintable(fileName + ".xml"), &sites[0], (int)sites.size(), anonymize);
break; break;
} }
case EX_UDDF: case EX_UDDF:
exportFuncs::instance()->exportUsingStyleSheet(fileName + ".uddf", true, 0, "uddf-export.xslt", anonymize); exportUsingStyleSheet(fileName + ".uddf", true, 0, "uddf-export.xslt", anonymize);
break; break;
case EX_CSV_DIVE_PROFILE: case EX_CSV_DIVE_PROFILE:
exportFuncs::instance()->exportUsingStyleSheet(fileName + ".uddf", true, 0, "xml2csv.xslt", anonymize); exportUsingStyleSheet(fileName + ".uddf", true, 0, "xml2csv.xslt", anonymize);
break; break;
case EX_CSV_DETAILS: case EX_CSV_DETAILS:
exportFuncs::instance()->exportUsingStyleSheet(fileName + ".uddf", true, 0, "xml2manualcsv.xslt", anonymize); exportUsingStyleSheet(fileName + ".uddf", true, 0, "xml2manualcsv.xslt", anonymize);
break; break;
case EX_CSV_PROFILE: case EX_CSV_PROFILE:
save_profiledata(qPrintable(fileName + ".csv"), true); save_profiledata(qPrintable(fileName + ".csv"), true);
break; break;
case EX_PROFILE_PNG: case EX_PROFILE_PNG:
exportFuncs::instance()->exportProfile(qPrintable(fileName + ".png"), false); exportProfile(qPrintable(fileName + ".png"), false);
break; break;
case EX_WORLD_MAP: case EX_WORLD_MAP:
export_worldmap_HTML(qPrintable(fileName + ".html"), true); export_worldmap_HTML(qPrintable(fileName + ".html"), true);
break; break;
case EX_TEX: case EX_TEX:
exportFuncs::instance()->export_TeX(qPrintable(fileName + ".tex"), true, true); export_TeX(qPrintable(fileName + ".tex"), true, true);
break; break;
case EX_LATEX: case EX_LATEX:
exportFuncs::instance()->export_TeX(qPrintable(fileName + ".tex"), true, false); export_TeX(qPrintable(fileName + ".tex"), true, false);
break; break;
case EX_IMAGE_DEPTHS: case EX_IMAGE_DEPTHS:
exportFuncs::instance()->export_depths(qPrintable(fileName), false); export_depths(qPrintable(fileName), false);
break; break;
default: default:
qDebug() << "export to unknown type " << type << " using " << dir << " remove names " << anonymize; qDebug() << "export to unknown type " << type << " using " << dir << " remove names " << anonymize;
@ -2174,7 +2174,7 @@ void QMLManager::exportToFile(export_types type, QString dir, bool anonymize)
} }
} }
void exportFuncs::saveProfile(const struct dive *dive, const QString filename) void exportProfile(const struct dive *, const QString)
{ {
// TBD // TBD
} }