Import: unglobalize downloadTable

To make data flow more clear, unglobalize the downloadTable object.
Make it a subobject of DownloadThread. The difficult part was making
this compatible with QML, because somehow the pointer to the
download-table has to be passed to the DiveImportedModel. Desktop would
simply pass it to the constructor. But with objects generated in QML
this is not possible. Instead, pass the table in the repopulate()
function. This seems to make sense, but for this to work, we have to
declare pointer-to-dive-table as a Q_METATYPE. And this only works
if we use a typedef, because MOC removes the "struct" from "struct
dive_table". This leads to compilation errors, because dive_table is
the symbol-name of the global dive table! Sigh.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-12-10 14:49:32 +01:00 committed by Dirk Hohndel
parent a6a5cf61e2
commit bfe69239df
9 changed files with 38 additions and 35 deletions

View file

@ -6,8 +6,6 @@ DiveImportedModel::DiveImportedModel(QObject *o) : QAbstractTableModel(o),
lastIndex(-1),
diveTable(nullptr)
{
// Defaults to downloadTable, can be changed later.
diveTable = &downloadTable;
}
int DiveImportedModel::columnCount(const QModelIndex&) const
@ -45,11 +43,6 @@ QVariant DiveImportedModel::headerData(int section, Qt::Orientation orientation,
return QVariant();
}
void DiveImportedModel::setDiveTable(struct dive_table* table)
{
diveTable = table;
}
QVariant DiveImportedModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
@ -134,10 +127,11 @@ void DiveImportedModel::clearTable()
endRemoveRows();
}
void DiveImportedModel::repopulate()
void DiveImportedModel::repopulate(dive_table_t *table)
{
beginResetModel();
diveTable = table;
firstIndex = 0;
lastIndex = diveTable->nr - 1;
checkStates.resize(diveTable->nr);
@ -159,7 +153,7 @@ void DiveImportedModel::recordDives()
if (checkStates[i])
j++;
else
delete_dive_from_table(&downloadTable, j);
delete_dive_from_table(diveTable, j);
}
process_imported_dives(diveTable, true, true);