From 39a4090c0a6e1d8fe12516be06ee7b31dd4bc96d Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 17 Oct 2020 16:07:39 +0200 Subject: 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 --- qt-models/diveimportedmodel.cpp | 19 +++++++++++-------- qt-models/diveimportedmodel.h | 7 ++++--- 2 files changed, 15 insertions(+), 11 deletions(-) (limited to 'qt-models') diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp index 3413e03a5..0541d32d3 100644 --- a/qt-models/diveimportedmodel.cpp +++ b/qt-models/diveimportedmodel.cpp @@ -143,22 +143,24 @@ void DiveImportedModel::startDownload() thread.start(); } -std::pair DiveImportedModel::consumeTables() +std::tuple 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 tables = consumeTables(); - if (tables.first.nr > 0) { + std::tuple 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 DiveImportedModel::roleNames() const { diff --git a/qt-models/diveimportedmodel.h b/qt-models/diveimportedmodel.h index 920bd57c6..f43057d26 100644 --- a/qt-models/diveimportedmodel.h +++ b/qt-models/diveimportedmodel.h @@ -1,11 +1,11 @@ #ifndef DIVEIMPORTEDMODEL_H #define DIVEIMPORTEDMODEL_H -#include -#include +#include "core/device.h" #include "core/divesite.h" #include "core/divelist.h" #include "core/downloadfromdcthread.h" +#include class DiveImportedModel : public QAbstractTableModel { @@ -23,7 +23,7 @@ public: Q_INVOKABLE void clearTable(); QHash roleNames() const; void deleteDeselected(); - std::pair consumeTables(); // Returns dives and sites and resets model. + std::tuple consumeTables(); // Returns downloaded tables and resets model. int numDives() const; Q_INVOKABLE void recordDives(int flags = IMPORT_PREFER_IMPORTED | IMPORT_IS_DOWNLOADED); @@ -48,6 +48,7 @@ private: std::vector checkStates; // char instead of bool to avoid silly pessimization of std::vector. struct dive_table diveTable; struct dive_site_table sitesTable; + struct device_table deviceTable; }; #endif -- cgit v1.2.3-70-g09d2