parser: add device_table to parser state

If we want to avoid the parsers to directly modify global data,
we have to provide a device_table to parse into. This adds such
a state and the corresponding function parameters. However,
for now this is unused.

Adding new parameters is very painful and this commit shows that
we urgently need a "struct divelog" collecting all those tables!

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-10-17 12:32:22 +02:00 committed by Dirk Hohndel
parent 41975435a2
commit a261466594
25 changed files with 242 additions and 139 deletions

View file

@ -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, &filter_preset_table))
if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table))
setCurrentFile(fileNamePtr.data());
process_loaded_dives();
hideProgressBar();
@ -1549,11 +1549,12 @@ 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;
struct device_table devices;
struct filter_preset_table filter_presets;
for (int i = 0; i < fileNames.size(); ++i) {
fileNamePtr = QFile::encodeName(fileNames.at(i));
parse_file(fileNamePtr.data(), &table, &trips, &sites, &filter_presets);
parse_file(fileNamePtr.data(), &table, &trips, &sites, &devices, &filter_presets);
}
QString source = fileNames.size() == 1 ? fileNames[0] : tr("multiple files");
Command::importDives(&table, &trips, &sites, &filter_presets, IMPORT_MERGE_ALL_TRIPS, source);
@ -1570,7 +1571,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, &filter_preset_table)) {
if (!parse_file(fileNamePtr.data(), &dive_table, &trip_table, &dive_site_table, &device_table, &filter_preset_table)) {
setCurrentFile(fileNamePtr.data());
addRecentFile(fileNamePtr, false);
}
@ -1644,11 +1645,12 @@ void MainWindow::on_actionImportDiveSites_triggered()
struct dive_table table = empty_dive_table;
struct trip_table trips = empty_trip_table;
struct dive_site_table sites = empty_dive_site_table;
struct device_table devices;
struct filter_preset_table filter_presets;
for (const QString &s: fileNames) {
QByteArray fileNamePtr = QFile::encodeName(s);
parse_file(fileNamePtr.data(), &table, &trips, &sites, &filter_presets);
parse_file(fileNamePtr.data(), &table, &trips, &sites, &devices, &filter_presets);
}
// The imported dive sites still have pointers to imported dives - remove them
for (int i = 0; i < sites.nr; ++i)