summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-09-25 20:49:13 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-10-02 08:04:49 -0700
commitad7ffa0af03718829c62621aceaaac959932ac14 (patch)
tree2795ea847f2f1b0d35866faf3b999f3cd6c78db4 /qt-models
parent6e343c734af619e620962f2ab26862c5c416300a (diff)
downloadsubsurface-ad7ffa0af03718829c62621aceaaac959932ac14.tar.gz
Import: Make DownloadThread a subobject of DiveImportedModel
Currently, desktop and mobile are accessing the DownloadThread and the DiveImportedModel concurrently. This makes a big data flow mess. To achieve a more hierarchical data flow, start by making the DownloadThread a subobject of DiveImportedModel. Start the download by calling a function in DiveImportedModel. Route the finished signal through DiveImportedModel. Thus, the model can reload itself with the new data. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/diveimportedmodel.cpp12
-rw-r--r--qt-models/diveimportedmodel.h13
2 files changed, 24 insertions, 1 deletions
diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp
index c5180dda8..504931b85 100644
--- a/qt-models/diveimportedmodel.cpp
+++ b/qt-models/diveimportedmodel.cpp
@@ -8,6 +8,7 @@ DiveImportedModel::DiveImportedModel(QObject *o) : QAbstractTableModel(o),
diveTable(nullptr),
sitesTable(nullptr)
{
+ connect(&thread, &QThread::finished, this, &DiveImportedModel::downloadThreadFinished);
}
int DiveImportedModel::columnCount(const QModelIndex&) const
@@ -129,6 +130,17 @@ void DiveImportedModel::clearTable()
endRemoveRows();
}
+void DiveImportedModel::downloadThreadFinished()
+{
+ repopulate(thread.table(), thread.sites());
+ emit downloadFinished();
+}
+
+void DiveImportedModel::startDownload()
+{
+ thread.start();
+}
+
void DiveImportedModel::repopulate(dive_table_t *table, struct dive_site_table *sites)
{
beginResetModel();
diff --git a/qt-models/diveimportedmodel.h b/qt-models/diveimportedmodel.h
index 532f5b899..49cbdf10c 100644
--- a/qt-models/diveimportedmodel.h
+++ b/qt-models/diveimportedmodel.h
@@ -4,6 +4,7 @@
#include <QAbstractTableModel>
#include <vector>
#include "core/divesite.h"
+#include "core/downloadfromdcthread.h"
class DiveImportedModel : public QAbstractTableModel
{
@@ -20,8 +21,10 @@ 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, dive_site_table_t *sites);
Q_INVOKABLE void recordDives();
+ Q_INVOKABLE void startDownload();
+
+ DownloadThread thread;
public
slots:
void changeSelected(QModelIndex clickedIndex);
@@ -29,7 +32,15 @@ slots:
void selectAll();
void selectNone();
+private
+slots:
+ void downloadThreadFinished();
+
+signals:
+ void downloadFinished();
+
private:
+ void repopulate(dive_table_t *table, dive_site_table_t *sites);
int firstIndex;
int lastIndex;
std::vector<char> checkStates; // char instead of bool to avoid silly pessimization of std::vector.