From 4d5acc84612e3536b4665edb75aa5f074f2cad1c Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 22 Sep 2019 22:07:13 +0200 Subject: Import: remove DiveImportedModel::lastIndex This is redundant, as the actual size is stored in the dive table. Signed-off-by: Berthold Stoeger --- qt-models/diveimportedmodel.cpp | 24 ++++++++---------------- qt-models/diveimportedmodel.h | 1 - 2 files changed, 8 insertions(+), 17 deletions(-) (limited to 'qt-models') 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() << Qt::CheckStateRole << Selected); + dataChanged(index(0, 0), index(diveTable.nr - 1, 0), QVector() << 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() << Qt::CheckStateRole << Selected); + dataChanged(index(0, 0), index(diveTable.nr - 1, 0 ), QVector() << 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 DiveImportedModel::consumeT move_dive_site_table(&sitesTable, &sites); // Reset indexes - lastIndex = -1; checkStates.clear(); endResetModel(); diff --git a/qt-models/diveimportedmodel.h b/qt-models/diveimportedmodel.h index 7b0f9d2ed..612bee8c7 100644 --- a/qt-models/diveimportedmodel.h +++ b/qt-models/diveimportedmodel.h @@ -44,7 +44,6 @@ signals: void downloadFinished(); private: - int lastIndex; std::vector checkStates; // char instead of bool to avoid silly pessimization of std::vector. struct dive_table diveTable; struct dive_site_table sitesTable; -- cgit v1.2.3-70-g09d2