diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-12-23 12:46:25 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-01-09 20:58:04 -0800 |
commit | f542dc4030dda5dac1da1cc928f7a40a50919c4d (patch) | |
tree | eb7f77bc9701c3180082da7f0435b9d467c565e7 | |
parent | 7e33369dc8b27b20385ab055b662e06bbf369784 (diff) | |
download | subsurface-f542dc4030dda5dac1da1cc928f7a40a50919c4d.tar.gz |
Import: add trip_table argument to DiveImportedModel::repopulate()
In the future we want to download trips into a distinct trip-table
instead of the global trip-table to allow for undo of import.
Therefore add a trip_table argument to DiveImportedModel::repopulate()
and a trip_table member to DiveImportedModel. To correctly set these,
add a DownloadThread::trips() function, which currently simply returns
the global trip table.
Finally, make "struct trip_table *" a Q_METATYPE, so that the corresponding
arguments can be passed from QML.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | core/dive.h | 7 | ||||
-rw-r--r-- | core/downloadfromdcthread.cpp | 6 | ||||
-rw-r--r-- | core/downloadfromdcthread.h | 2 | ||||
-rw-r--r-- | desktop-widgets/downloadfromdivecomputer.cpp | 2 | ||||
-rw-r--r-- | mobile-widgets/qml/DownloadFromDiveComputer.qml | 2 | ||||
-rw-r--r-- | qt-models/diveimportedmodel.cpp | 3 | ||||
-rw-r--r-- | qt-models/diveimportedmodel.h | 3 |
7 files changed, 18 insertions, 7 deletions
diff --git a/core/dive.h b/core/dive.h index f7cf060b7..b13d16e57 100644 --- a/core/dive.h +++ b/core/dive.h @@ -288,10 +288,10 @@ typedef struct dive_trip bool autogen; } dive_trip_t; -struct trip_table { +typedef struct trip_table { int nr, allocated; struct dive_trip **trips; -}; +} trip_table_t; struct picture; struct dive { @@ -762,10 +762,11 @@ extern void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_de * be passed through QVariants and through QML. * Note: we have to use the typedef "dive_table_t" instead of "struct dive_table", * because MOC removes the "struct", but dive_table is already the name of a global - * variable, leading to compilation errors. */ + * variable, leading to compilation errors. Likewise for "struct trip_table". */ Q_DECLARE_METATYPE(struct dive *); Q_DECLARE_METATYPE(struct dive_trip *); Q_DECLARE_METATYPE(dive_table_t *); +Q_DECLARE_METATYPE(trip_table_t *); #endif diff --git a/core/downloadfromdcthread.cpp b/core/downloadfromdcthread.cpp index 2fdebf129..adcdea02b 100644 --- a/core/downloadfromdcthread.cpp +++ b/core/downloadfromdcthread.cpp @@ -307,6 +307,12 @@ struct dive_table *DownloadThread::table() return &downloadTable; } +struct trip_table *DownloadThread::trips() +{ + // TODO: Replace by local trip-table + return &trip_table; +} + QString DCDeviceData::vendor() const { return data.vendor; diff --git a/core/downloadfromdcthread.h b/core/downloadfromdcthread.h index b380a88a1..426a807d9 100644 --- a/core/downloadfromdcthread.h +++ b/core/downloadfromdcthread.h @@ -61,6 +61,7 @@ private: class DownloadThread : public QThread { Q_OBJECT Q_PROPERTY(dive_table_t *table READ table CONSTANT) + Q_PROPERTY(trip_table_t *trips READ trips CONSTANT) public: DownloadThread(); @@ -68,6 +69,7 @@ public: DCDeviceData *data(); struct dive_table *table(); + struct trip_table *trips(); QString error; private: diff --git a/desktop-widgets/downloadfromdivecomputer.cpp b/desktop-widgets/downloadfromdivecomputer.cpp index 4221f5bf4..4e4c6a43c 100644 --- a/desktop-widgets/downloadfromdivecomputer.cpp +++ b/desktop-widgets/downloadfromdivecomputer.cpp @@ -490,7 +490,7 @@ void DownloadFromDCWidget::onDownloadThreadFinished() } ui.downloadCancelRetryButton->setText(tr("Retry download")); ui.downloadCancelRetryButton->setEnabled(true); - diveImportedModel->repopulate(thread.table()); + diveImportedModel->repopulate(thread.table(), thread.trips()); } void DownloadFromDCWidget::on_cancel_clicked() diff --git a/mobile-widgets/qml/DownloadFromDiveComputer.qml b/mobile-widgets/qml/DownloadFromDiveComputer.qml index a1403b07d..332a978dd 100644 --- a/mobile-widgets/qml/DownloadFromDiveComputer.qml +++ b/mobile-widgets/qml/DownloadFromDiveComputer.qml @@ -28,7 +28,7 @@ Kirigami.Page { id: downloadThread onFinished : { - importModel.repopulate(table) + importModel.repopulate(table, trips) progressBar.visible = false if (dcImportModel.rowCount() > 0) { console.log(dcImportModel.rowCount() + " dive downloaded") diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp index ec450d53f..11d644950 100644 --- a/qt-models/diveimportedmodel.cpp +++ b/qt-models/diveimportedmodel.cpp @@ -127,11 +127,12 @@ void DiveImportedModel::clearTable() endRemoveRows(); } -void DiveImportedModel::repopulate(dive_table_t *table) +void DiveImportedModel::repopulate(dive_table_t *table, trip_table_t *trips) { beginResetModel(); diveTable = table; + tripTable = trips; firstIndex = 0; lastIndex = diveTable->nr - 1; checkStates.resize(diveTable->nr); diff --git a/qt-models/diveimportedmodel.h b/qt-models/diveimportedmodel.h index 0c5ba34cd..ede40431b 100644 --- a/qt-models/diveimportedmodel.h +++ b/qt-models/diveimportedmodel.h @@ -20,7 +20,7 @@ public: Qt::ItemFlags flags(const QModelIndex &index) const; Q_INVOKABLE void clearTable(); QHash<int, QByteArray> roleNames() const; - Q_INVOKABLE void repopulate(dive_table_t *table); + Q_INVOKABLE void repopulate(dive_table_t *table, trip_table_t *trips); Q_INVOKABLE void recordDives(); public slots: @@ -34,6 +34,7 @@ private: int lastIndex; std::vector<char> checkStates; // char instead of bool to avoid silly pessimization of std::vector. struct dive_table *diveTable; + struct trip_table *tripTable; }; #endif |