diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-06-17 22:45:33 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-09-29 16:13:03 -0700 |
commit | 41cf83583d129edde607654592a52fe7bff57dc7 (patch) | |
tree | 7127476f88358f2248b22684c01f127997380d43 /desktop-widgets | |
parent | cef15c978d466af37a0f453c50f2e8942ed7cdc2 (diff) | |
download | subsurface-41cf83583d129edde607654592a52fe7bff57dc7.tar.gz |
filter: load filter presets from XML files
This is a bit painful: since we don't want to modify the filter
presets when the user imports (as opposed to opens) a log,
we have to provide a table where the parser stores the presets.
Calling the parser is getting quite unwieldy, since many tables
are passed. We probably should introduce a structure representing
a full log-book at one point, which collects all the things that
are saved to the log.
Apart from that, this is simply the counterpart to saving to XML.
The interpretation of the string data is performed by core
functions, not the parser itself to avoid code duplication with
the git parser.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/divelogimportdialog.cpp | 10 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 9 | ||||
-rw-r--r-- | desktop-widgets/subsurfacewebservices.cpp | 3 |
3 files changed, 13 insertions, 9 deletions
diff --git a/desktop-widgets/divelogimportdialog.cpp b/desktop-widgets/divelogimportdialog.cpp index 877c6f7c8..f3d512009 100644 --- a/desktop-widgets/divelogimportdialog.cpp +++ b/desktop-widgets/divelogimportdialog.cpp @@ -10,6 +10,7 @@ #include <QRegExp> #include <QUndoStack> #include <QPainter> +#include "core/filterpreset.h" #include "core/qthelper.h" #include "core/divesite.h" #include "core/trip.h" @@ -908,11 +909,12 @@ void DiveLogImportDialog::on_buttonBox_accepted() struct dive_table table = empty_dive_table; struct trip_table trips = empty_trip_table; struct dive_site_table sites = empty_dive_site_table; + filter_preset_table_t filter_presets; QStringList r = resultModel->result(); if (ui->knownImports->currentText() != "Manual import") { for (int i = 0; i < fileNames.size(); ++i) { if (ui->knownImports->currentText() == "Seabear CSV") { - parse_seabear_log(qPrintable(fileNames[i]), &table, &trips, &sites); + parse_seabear_log(qPrintable(fileNames[i]), &table, &trips, &sites, &filter_presets); } else if (ui->knownImports->currentText() == "Poseidon MkVI") { QPair<QString, QString> pair = poseidonFileNames(fileNames[i]); parse_txt_file(qPrintable(pair.second), qPrintable(pair.first), &table, &trips, &sites); @@ -932,7 +934,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() pnr = setup_csv_params(r, params, pnr); parse_csv_file(qPrintable(fileNames[i]), params, pnr - 1, specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv", - &table, &trips, &sites); + &table, &trips, &sites, &filter_presets); } } } else { @@ -998,7 +1000,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() params[pnr++] = intdup(r.indexOf(tr("Rating"))); params[pnr++] = NULL; - parse_manual_file(qPrintable(fileNames[i]), params, pnr - 1, &table, &trips, &sites); + parse_manual_file(qPrintable(fileNames[i]), params, pnr - 1, &table, &trips, &sites, &filter_presets); } else { char *params[53]; int pnr = 0; @@ -1015,7 +1017,7 @@ void DiveLogImportDialog::on_buttonBox_accepted() pnr = setup_csv_params(r, params, pnr); parse_csv_file(qPrintable(fileNames[i]), params, pnr - 1, specialCSV.contains(ui->knownImports->currentIndex()) ? qPrintable(CSVApps[ui->knownImports->currentIndex()].name) : "csv", - &table, &trips, &sites); + &table, &trips, &sites, &filter_presets); } } } diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 75f3abebf..d4bbc1384 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -530,7 +530,7 @@ void MainWindow::on_actionCloudstorageopen_triggered() showProgressBar(); QByteArray fileNamePtr = QFile::encodeName(filename); - if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table)) + if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table, &filter_preset_table)) setCurrentFile(fileNamePtr.data()); process_loaded_dives(); hideProgressBar(); @@ -1549,10 +1549,11 @@ void MainWindow::importFiles(const QStringList fileNames) struct dive_table table = empty_dive_table; struct trip_table trips = empty_trip_table; struct dive_site_table sites = empty_dive_site_table; + filter_preset_table_t filter_presets; for (int i = 0; i < fileNames.size(); ++i) { fileNamePtr = QFile::encodeName(fileNames.at(i)); - parse_file(fileNamePtr.data(), &table, &trips, &sites); + parse_file(fileNamePtr.data(), &table, &trips, &sites, &filter_presets); } QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files"); Command::importDives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS, source); @@ -1569,7 +1570,7 @@ void MainWindow::loadFiles(const QStringList fileNames) showProgressBar(); for (int i = 0; i < fileNames.size(); ++i) { fileNamePtr = QFile::encodeName(fileNames.at(i)); - if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table)) { + if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table, &filter_preset_table)) { setCurrentFile(fileNamePtr.data()); addRecentFile(fileNamePtr, false); } @@ -1646,7 +1647,7 @@ void MainWindow::on_actionImportDiveSites_triggered() for (const QString &s: fileNames) { QByteArray fileNamePtr = QFile::encodeName(s); - parse_file(fileNamePtr.data(), &table, &trips, &sites); + parse_file(fileNamePtr.data(), &table, &trips, &sites, &filter_preset_table); } // The imported dive sites still have pointers to imported dives - remove them for (int i = 0; i < sites.nr; ++i) diff --git a/desktop-widgets/subsurfacewebservices.cpp b/desktop-widgets/subsurfacewebservices.cpp index fa5ee7164..fa1b003da 100644 --- a/desktop-widgets/subsurfacewebservices.cpp +++ b/desktop-widgets/subsurfacewebservices.cpp @@ -456,7 +456,8 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton *button) struct dive_table table = empty_dive_table; struct trip_table trips = empty_trip_table; struct dive_site_table sites = empty_dive_site_table; - parse_file(QFile::encodeName(zipFile.fileName()), &table, &trips, &sites); + filter_preset_table_t filter_presets; + parse_file(QFile::encodeName(zipFile.fileName()), &table, &trips, &sites, &filter_presets); Command::importDives(&table, &trips, &sites, IMPORT_MERGE_ALL_TRIPS, QStringLiteral("divelogs.de")); /* store last entered user/pass in config */ |