Import: remove DiveImportedModel::lastIndex

This is redundant, as the actual size is stored in the dive table.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2019-09-22 22:07:13 +02:00 committed by Dirk Hohndel
parent a33f381dc6
commit 4d5acc8461
2 changed files with 8 additions and 17 deletions

View file

@ -3,7 +3,6 @@
#include "core/divelist.h"
DiveImportedModel::DiveImportedModel(QObject *o) : QAbstractTableModel(o),
lastIndex(-1),
diveTable({ 0 }),
sitesTable({ 0 })
{
@ -17,7 +16,7 @@ int DiveImportedModel::columnCount(const QModelIndex&) const
int DiveImportedModel::rowCount(const QModelIndex&) const
{
return lastIndex + 1;
return diveTable.nr;
}
QVariant DiveImportedModel::headerData(int section, Qt::Orientation orientation, int role) const
@ -50,7 +49,7 @@ QVariant DiveImportedModel::data(const QModelIndex &index, int role) const
if (!index.isValid())
return QVariant();
if (index.row() > lastIndex)
if (index.row() >= diveTable.nr)
return QVariant();
struct dive *d = get_dive_from_table(index.row(), &diveTable);
@ -92,7 +91,7 @@ void DiveImportedModel::changeSelected(QModelIndex clickedIndex)
void DiveImportedModel::selectAll()
{
std::fill(checkStates.begin(), checkStates.end(), true);
dataChanged(index(0, 0), index(lastIndex, 0), QVector<int>() << Qt::CheckStateRole << Selected);
dataChanged(index(0, 0), index(diveTable.nr - 1, 0), QVector<int>() << Qt::CheckStateRole << Selected);
}
void DiveImportedModel::selectRow(int row)
@ -104,7 +103,7 @@ void DiveImportedModel::selectRow(int row)
void DiveImportedModel::selectNone()
{
std::fill(checkStates.begin(), checkStates.end(), false);
dataChanged(index(0, 0), index(lastIndex, 0 ), QVector<int>() << Qt::CheckStateRole << Selected);
dataChanged(index(0, 0), index(diveTable.nr - 1, 0 ), QVector<int>() << Qt::CheckStateRole << Selected);
}
Qt::ItemFlags DiveImportedModel::flags(const QModelIndex &index) const
@ -116,15 +115,10 @@ Qt::ItemFlags DiveImportedModel::flags(const QModelIndex &index) const
void DiveImportedModel::clearTable()
{
if (lastIndex < 0) {
// just to be sure it's the right numbers
// but don't call RemoveRows or Qt in debug mode with trigger an ASSERT
lastIndex = -1;
return;
}
beginRemoveRows(QModelIndex(), 0, lastIndex);
lastIndex = -1;
endRemoveRows();
beginResetModel();
clear_dive_table(&diveTable);
clear_dive_site_table(&sitesTable);
endResetModel();
}
void DiveImportedModel::downloadThreadFinished()
@ -135,7 +129,6 @@ void DiveImportedModel::downloadThreadFinished()
move_dive_table(&thread.downloadTable, &diveTable);
move_dive_site_table(&thread.diveSiteTable, &sitesTable);
lastIndex = diveTable.nr - 1;
checkStates.resize(diveTable.nr);
std::fill(checkStates.begin(), checkStates.end(), true);
@ -160,7 +153,6 @@ std::pair<struct dive_table, struct dive_site_table> DiveImportedModel::consumeT
move_dive_site_table(&sitesTable, &sites);
// Reset indexes
lastIndex = -1;
checkStates.clear();
endResetModel();

View file

@ -44,7 +44,6 @@ signals:
void downloadFinished();
private:
int lastIndex;
std::vector<char> checkStates; // char instead of bool to avoid silly pessimization of std::vector.
struct dive_table diveTable;
struct dive_site_table sitesTable;