summaryrefslogtreecommitdiffstats
path: root/qt-models/diveimportedmodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-09-22 22:07:13 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-10-02 08:04:49 -0700
commit4d5acc84612e3536b4665edb75aa5f074f2cad1c (patch)
tree3d09d8d21fee734c94bcc2ddf24f49a16e663663 /qt-models/diveimportedmodel.cpp
parenta33f381dc6e71abc231992e95bfcf7b4d0cd145a (diff)
downloadsubsurface-4d5acc84612e3536b4665edb75aa5f074f2cad1c.tar.gz
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>
Diffstat (limited to 'qt-models/diveimportedmodel.cpp')
-rw-r--r--qt-models/diveimportedmodel.cpp24
1 files changed, 8 insertions, 16 deletions
diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp
index ad2c804e8..cfadef9b8 100644
--- a/qt-models/diveimportedmodel.cpp
+++ b/qt-models/diveimportedmodel.cpp
@@ -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();