From 8f3c85f58d0693a07df70a87b265cde0cdc860ac Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 22 Sep 2019 20:23:37 +0200 Subject: Import: get tables from DiveImportedModel not DownloadThread When importing dives, consume the tables from DiveImportedModel and not the DownloadThread. This appears more logical and avoids an inconsistent state of the DiveImportedModel: On import the tables would be reset, but the DiveImportedModel wasn't informed of that. Signed-off-by: Berthold Stoeger --- qt-models/diveimportedmodel.cpp | 20 ++++++++++++++++++++ qt-models/diveimportedmodel.h | 1 + 2 files changed, 21 insertions(+) (limited to 'qt-models') diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp index 34c247c0c..6342972a7 100644 --- a/qt-models/diveimportedmodel.cpp +++ b/qt-models/diveimportedmodel.cpp @@ -155,6 +155,26 @@ void DiveImportedModel::repopulate(dive_table_t *table, struct dive_site_table * endResetModel(); } +std::pair DiveImportedModel::consumeTables() +{ + beginResetModel(); + + // Move tables to result + struct dive_table dives; + struct dive_site_table sites; + move_dive_table(diveTable, &dives); + move_dive_site_table(sitesTable, &sites); + + // Reset indexes + firstIndex = 0; + lastIndex = -1; + checkStates.clear(); + + endResetModel(); + + return std::make_pair(dives, sites); +} + // Delete non-selected dives void DiveImportedModel::deleteDeselected() { diff --git a/qt-models/diveimportedmodel.h b/qt-models/diveimportedmodel.h index 5f2575bce..db0f813b2 100644 --- a/qt-models/diveimportedmodel.h +++ b/qt-models/diveimportedmodel.h @@ -22,6 +22,7 @@ public: Q_INVOKABLE void clearTable(); QHash roleNames() const; void deleteDeselected(); + std::pair consumeTables(); // Returns dives and sites and resets model. Q_INVOKABLE void recordDives(); Q_INVOKABLE void startDownload(); -- cgit v1.2.3-70-g09d2