Cleanup: remove DiveImportedModel::setImportedDivesIndexes()

This function resets the DiveImportedModel. It takes two
arguments: first and last index. All callers passed in 0
and number-of dives anyway, so remove the arguments.
Since this now does the same as repopulate(), merge the
two functions.

Moreover, implement Qt-model semantics by using a
beginResetModel()/endResetModel() pair. This simplifies the
code.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2018-12-09 18:56:51 +01:00 committed by Dirk Hohndel
parent abf942f303
commit 6febe22b6b
2 changed files with 10 additions and 22 deletions

View file

@ -492,10 +492,7 @@ void DownloadFromDCWidget::onDownloadThreadFinished()
}
ui.downloadCancelRetryButton->setText(tr("Retry download"));
ui.downloadCancelRetryButton->setEnabled(true);
// regardless, if we got dives, we should show them to the user
if (downloadTable.nr) {
diveImportedModel->setImportedDivesIndexes(0, downloadTable.nr - 1);
}
diveImportedModel->repopulate();
}
void DownloadFromDCWidget::on_cancel_clicked()

View file

@ -135,26 +135,17 @@ void DiveImportedModel::clearTable()
endRemoveRows();
}
void DiveImportedModel::setImportedDivesIndexes(int first, int last)
{
if (lastIndex >= firstIndex) {
beginRemoveRows(QModelIndex(), 0, lastIndex - firstIndex);
endRemoveRows();
}
if (last >= first)
beginInsertRows(QModelIndex(), 0, last - first);
lastIndex = last;
firstIndex = first;
delete[] checkStates;
checkStates = new bool[last - first + 1];
memset(checkStates, true, last - first + 1);
if (last >= first)
endInsertRows();
}
void DiveImportedModel::repopulate()
{
setImportedDivesIndexes(0, diveTable->nr-1);
beginResetModel();
firstIndex = 0;
lastIndex = diveTable->nr - 1;
delete[] checkStates;
checkStates = new bool[diveTable->nr];
memset(checkStates, true, diveTable->nr);
endResetModel();
}
void DiveImportedModel::recordDives()