Cleanup: remove DiveImportedModel::firstIndex

This index was never set to anything else than 0. Might as
well remove it.

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

View file

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

View file

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