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>
This commit is contained in:
Berthold Stoeger 2020-10-17 16:07:39 +02:00 committed by Dirk Hohndel
parent fadea413cd
commit 39a4090c0a
17 changed files with 113 additions and 40 deletions

View file

@ -143,22 +143,24 @@ void DiveImportedModel::startDownload()
thread.start();
}
std::pair<struct dive_table, struct dive_site_table> DiveImportedModel::consumeTables()
std::tuple<struct dive_table, struct dive_site_table, struct device_table> DiveImportedModel::consumeTables()
{
beginResetModel();
// Move tables to result
struct dive_table dives = empty_dive_table;
struct dive_site_table sites = empty_dive_site_table;
struct device_table devices;
move_dive_table(&diveTable, &dives);
move_dive_site_table(&sitesTable, &sites);
devices = std::move(deviceTable);
// Reset indices
checkStates.clear();
endResetModel();
return std::make_pair(dives, sites);
return std::make_tuple(dives, sites, devices);
}
int DiveImportedModel::numDives() const
@ -191,17 +193,18 @@ void DiveImportedModel::recordDives(int flags)
deleteDeselected();
// TODO: use structured bindings once we go C++17
std::pair<struct dive_table, struct dive_site_table> tables = consumeTables();
if (tables.first.nr > 0) {
std::tuple<struct dive_table, struct dive_site_table, struct device_table> tables = consumeTables();
if (std::get<0>(tables).nr > 0) {
auto data = thread.data();
Command::importDives(&tables.first, nullptr, &tables.second, nullptr, flags, data->devName());
Command::importDives(&std::get<0>(tables), nullptr, &std::get<1>(tables),
&std::get<2>(tables), nullptr, flags, data->devName());
} else {
clear_dive_site_table(&tables.second);
clear_dive_site_table(&std::get<1>(tables));
}
// The dives and dive sites have been consumed, but the arrays of the tables
// still exist. Free them.
free(tables.first.dives);
free(tables.second.dive_sites);
free(std::get<0>(tables).dives);
free(std::get<1>(tables).dive_sites);
}
QHash<int, QByteArray> DiveImportedModel::roleNames() const {