diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-09-28 10:21:23 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-06 19:47:06 -0700 |
commit | 810903bdb9db84997dc3d32bb8e934e320784a4d (patch) | |
tree | 8002aad04364e23e598ab84eee8eb96e96770599 /desktop-widgets/downloadfromdivecomputer.cpp | |
parent | c32e71e64d97016d201aea26f0623de6cd65d74d (diff) | |
download | subsurface-810903bdb9db84997dc3d32bb8e934e320784a4d.tar.gz |
Import: pass a dive table to process_imported_dives()
Dives were directly imported into the global dive table and then
merged in process_imported_dives(). Make this interface more flexible,
by passing an independent dive table.
The dive table of the to-be-imported dives will be sorted and merged.
Then each dive is inserted in a one-by-one manner to into the global
dive table.
This actually introduces (at least) two functional changes:
1) If a new dive spans two old dives, it will only be merged to the
first dive. But this seems like a pathological case, which is of
dubious value anyway.
2) Dives unrelated to the import will not be merged. The old code
would happily merge dives that were not even close to the
newly imported dives. A surprising behavior.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets/downloadfromdivecomputer.cpp')
-rw-r--r-- | desktop-widgets/downloadfromdivecomputer.cpp | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index 561ff2998..46cb0418b 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -487,34 +487,30 @@ void DownloadFromDCWidget::on_cancel_clicked() void DownloadFromDCWidget::on_ok_clicked() { - struct dive *dive; - if (currentState != DONE && currentState != ERROR) return; - // record all the dives in the 'real' dive_table - for (int i = 0; i < downloadTable.nr; i++) { + // delete non-selected dives + int total = downloadTable.nr; + int j = 0; + for (int i = 0; i < total; i++) { if (diveImportedModel->data(diveImportedModel->index(i, 0), Qt::CheckStateRole) == Qt::Checked) - record_dive(downloadTable.dives[i]); + j++; else - clear_dive(downloadTable.dives[i]); - downloadTable.dives[i] = NULL; + delete_dive_from_table(&downloadTable, j); } - downloadTable.nr = 0; - int uniqId, idx; - // remember the last downloaded dive (on most dive computers this will be the chronologically - // first new dive) and select it again after processing all the dives MainWindow::instance()->dive_list()->unselectDives(); - dive = get_dive(dive_table.nr - 1); - if (dive != NULL) { - uniqId = get_dive(dive_table.nr - 1)->id; - process_imported_dives(preferDownloaded()); + if (downloadTable.nr > 0) { + // remember the last downloaded dive (on most dive computers this will be the chronologically + // first new dive) and select it again after processing all the dives + int uniqId = downloadTable.dives[downloadTable.nr - 1]->id; + process_imported_dives(&downloadTable, preferDownloaded()); // after process_imported_dives does any merging or resorting needed, we need // to recreate the model for the dive list so we can select the newest dive MainWindow::instance()->recreateDiveList(); - idx = get_idx_by_uniq_id(uniqId); + int idx = get_idx_by_uniq_id(uniqId); // this shouldn't be necessary - but there are reports that somehow existing dives stay selected // (but not visible as selected) MainWindow::instance()->dive_list()->unselectDives(); |