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 "core/membuffer.h"
#include "core/divesite.h"
#include "core/gettextfromc.h"
#include "core/tag.h"
#include "core/file.h"
#include "core/errorhelper.h"
@ -11,14 +12,7 @@
#include "core/divesite.h"
#include "exportfuncs.h"
exportFuncs *exportFuncs::instance()
{
static exportFuncs *self = new exportFuncs;
return self;
}
void exportFuncs::exportProfile(QString filename, const bool selected_only)
void exportProfile(QString filename, const bool selected_only)
{
struct dive *dive;
int i;
@ -31,15 +25,15 @@ void exportFuncs::exportProfile(QString filename, const bool selected_only)
if (selected_only && !dive->selected)
continue;
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
saveProfile(dive, filename);
exportProfile(dive, filename);
++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;
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)
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;
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+");
if (!f) {
report_error(qPrintable(tr("Can't open file %s")), filename);
report_error(qPrintable(gettextFromC::tr("Can't open file %s")), filename);
} else {
flush_buffer(&buf, f); /*check for writing errors? */
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;
struct dive *dive;
@ -268,7 +262,7 @@ void exportFuncs::export_depths(const char *filename, const bool selected_only)
f = subsurface_fopen(filename, "w+");
if (!f) {
report_error(qPrintable(tr("Can't open file %s")), filename);
report_error(qPrintable(gettextFromC::tr("Can't open file %s")), filename);
} else {
flush_buffer(&buf, f); /*check for writing errors? */
fclose(f);
@ -276,7 +270,7 @@ void exportFuncs::export_depths(const char *filename, const bool selected_only)
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;
#ifndef SUBSURFACE_MOBILE
@ -311,7 +305,7 @@ std::vector<const dive_site *> exportFuncs::getDiveSitesToExport(bool selectedOn
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)
{
return QtConcurrent::run(export_dives_xslt, filename.toUtf8(), doExport, units, stylesheet.toUtf8(), anonymize);

View file

@ -6,33 +6,22 @@
#include <QFuture>
#include "core/dive.h"
class exportFuncs: public QObject {
Q_OBJECT
void exportProfile(QString filename, const bool selected_only);
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:
static exportFuncs *instance();
// prepareDivesForUploadDiveLog
// prepareDivesForUploadDiveShare
void exportProfile(QString filename, const bool selected_only);
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);
// prepareDivesForUploadDiveLog
// 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);
};
// 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

View file

@ -179,21 +179,21 @@ void DiveLogExportDialog::on_buttonBox_accepted()
if (!filename.contains('.'))
filename.append(".xml");
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());
}
} else if (ui->exportImageDepths->isChecked()) {
filename = QFileDialog::getSaveFileName(this, tr("Save image depths"), lastDir);
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()) {
filename = QFileDialog::getSaveFileName(this, tr("Export to TeX file"), lastDir, tr("TeX files") + " (*.tex)");
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()) {
filename = QFileDialog::getSaveFileName(this, tr("Save profile image"), lastDir);
if (!filename.isNull() && !filename.isEmpty())
exportFuncs::instance()->exportProfile(qPrintable(filename), ui->exportSelected->isChecked());
exportProfile(qPrintable(filename), ui->exportSelected->isChecked());
} else if (ui->exportProfileData->isChecked()) {
filename = QFileDialog::getSaveFileName(this, tr("Save profile data"), lastDir);
if (!filename.isNull() && !filename.isEmpty())
@ -214,7 +214,7 @@ 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()) {
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());
MainWindow::instance()->getNotificationWidget()->showNotification(tr("Please wait, exporting..."), KMessageWidget::Information);
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;
profile->plotDive(dive, true, false, true);

View file

@ -2137,36 +2137,36 @@ void QMLManager::exportToFile(export_types type, QString dir, bool anonymize)
break;
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);
break;
}
case EX_UDDF:
exportFuncs::instance()->exportUsingStyleSheet(fileName + ".uddf", true, 0, "uddf-export.xslt", anonymize);
exportUsingStyleSheet(fileName + ".uddf", true, 0, "uddf-export.xslt", anonymize);
break;
case EX_CSV_DIVE_PROFILE:
exportFuncs::instance()->exportUsingStyleSheet(fileName + ".uddf", true, 0, "xml2csv.xslt", anonymize);
exportUsingStyleSheet(fileName + ".uddf", true, 0, "xml2csv.xslt", anonymize);
break;
case EX_CSV_DETAILS:
exportFuncs::instance()->exportUsingStyleSheet(fileName + ".uddf", true, 0, "xml2manualcsv.xslt", anonymize);
exportUsingStyleSheet(fileName + ".uddf", true, 0, "xml2manualcsv.xslt", anonymize);
break;
case EX_CSV_PROFILE:
save_profiledata(qPrintable(fileName + ".csv"), true);
break;
case EX_PROFILE_PNG:
exportFuncs::instance()->exportProfile(qPrintable(fileName + ".png"), false);
exportProfile(qPrintable(fileName + ".png"), false);
break;
case EX_WORLD_MAP:
export_worldmap_HTML(qPrintable(fileName + ".html"), true);
break;
case EX_TEX:
exportFuncs::instance()->export_TeX(qPrintable(fileName + ".tex"), true, true);
export_TeX(qPrintable(fileName + ".tex"), true, true);
break;
case EX_LATEX:
exportFuncs::instance()->export_TeX(qPrintable(fileName + ".tex"), true, false);
export_TeX(qPrintable(fileName + ".tex"), true, false);
break;
case EX_IMAGE_DEPTHS:
exportFuncs::instance()->export_depths(qPrintable(fileName), false);
export_depths(qPrintable(fileName), false);
break;
default:
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
}