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>
This commit is contained in:
Berthold Stoeger 2019-09-25 20:49:13 +02:00 committed by Dirk Hohndel
parent 6e343c734a
commit ad7ffa0af0
5 changed files with 45 additions and 33 deletions

View file

@ -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();