aboutsummaryrefslogtreecommitdiffstats
path: root/commands/command_divelist.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-10-17 16:07:39 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-24 09:51:37 -0700
commit39a4090c0a6e1d8fe12516be06ee7b31dd4bc96d (patch)
tree7587930b64bf95ec3a652cf761e6ded573931364 /commands/command_divelist.cpp
parentfadea413cdb4644b821369b27fad6e5f019d32c2 (diff)
downloadsubsurface-39a4090c0a6e1d8fe12516be06ee7b31dd4bc96d.tar.gz
devices: add devices in Command::importTable()
Add a device_table parameters to Command::importTable() and add_imported_dives(). The content of this table will be added to the global device list (respectively removed on undo). This is currently a no-op, as the parser doesn't yet fill out the device table, but adds devices directly to the global device table. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'commands/command_divelist.cpp')
-rw-r--r--commands/command_divelist.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/commands/command_divelist.cpp b/commands/command_divelist.cpp
index 54dc0983c..c5322f709 100644
--- a/commands/command_divelist.cpp
+++ b/commands/command_divelist.cpp
@@ -470,7 +470,8 @@ void AddDive::undoit()
}
ImportDives::ImportDives(struct dive_table *dives, struct trip_table *trips, struct dive_site_table *sites,
- struct filter_preset_table *filter_presets, int flags, const QString &source)
+ struct device_table *devices, struct filter_preset_table *filter_presets, int flags,
+ const QString &source)
{
setText(Command::Base::tr("import %n dive(s) from %1", "", dives->nr).arg(source));
@@ -481,7 +482,9 @@ ImportDives::ImportDives(struct dive_table *dives, struct trip_table *trips, str
struct dive_table dives_to_remove = empty_dive_table;
struct trip_table trips_to_add = empty_trip_table;
struct dive_site_table sites_to_add = empty_dive_site_table;
- process_imported_dives(dives, trips, sites, flags, &dives_to_add, &dives_to_remove, &trips_to_add, &sites_to_add);
+ process_imported_dives(dives, trips, sites, devices, flags,
+ &dives_to_add, &dives_to_remove, &trips_to_add,
+ &sites_to_add, &devicesToAddAndRemove);
// Add trips to the divesToAdd.trips structure
divesToAdd.trips.reserve(trips_to_add.nr);
@@ -550,6 +553,12 @@ void ImportDives::redoit()
// Remember dives and sites to remove
divesAndSitesToRemove = std::move(divesAndSitesToRemoveNew);
+ // Add devices
+ for (const device &dev: devicesToAddAndRemove.devices) {
+ int idx = add_to_device_table(&device_table, &dev);
+ emit diveListNotifier.deviceAdded(idx);
+ }
+
// Add new filter presets
for (auto &it: filterPresetsToAdd) {
filterPresetsToRemove.push_back(filter_preset_add(it.first, it.second));
@@ -572,6 +581,13 @@ void ImportDives::undoit()
// ...and restore the selection
setSelection(selection, currentDive);
+ // Remove devices
+ for (const device &dev: devicesToAddAndRemove.devices) {
+ int idx = remove_device(&device_table, &dev);
+ if (idx >= 0)
+ emit diveListNotifier.deviceDeleted(idx);
+ }
+
// Remove filter presets. Do this in reverse order.
for (auto it = filterPresetsToRemove.rbegin(); it != filterPresetsToRemove.rend(); ++it) {
int index = *it;