diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-12-09 19:10:55 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-12-17 07:37:32 -0800 |
commit | a6a5cf61e2f45eb54721c7ee2dbcc05afe8939f9 (patch) | |
tree | 9234c47ba08a4668070516fd8fe5841b4ed12772 | |
parent | 6febe22b6b0b03a99a2b1f08df8e75f43f5ba867 (diff) | |
download | subsurface-a6a5cf61e2f45eb54721c7ee2dbcc05afe8939f9.tar.gz |
Cleanup: make DiveImportedModel::checkStates a std::vector
To not have to bother with memory-management. Moreover, the
old code was in principle wrong, since it assumed that
sizeof(bool) == 1. Of course, this is true for all supported
platforms, but let's not depend on such implementation-defined
behavior anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | qt-models/diveimportedmodel.cpp | 10 | ||||
-rw-r--r-- | qt-models/diveimportedmodel.h | 3 |
2 files changed, 6 insertions, 7 deletions
diff --git a/qt-models/diveimportedmodel.cpp b/qt-models/diveimportedmodel.cpp index 3c5a4a76b..be9b4275d 100644 --- a/qt-models/diveimportedmodel.cpp +++ b/qt-models/diveimportedmodel.cpp @@ -4,7 +4,6 @@ DiveImportedModel::DiveImportedModel(QObject *o) : QAbstractTableModel(o), firstIndex(0), lastIndex(-1), - checkStates(nullptr), diveTable(nullptr) { // Defaults to downloadTable, can be changed later. @@ -97,7 +96,7 @@ void DiveImportedModel::changeSelected(QModelIndex clickedIndex) void DiveImportedModel::selectAll() { - memset(checkStates, true, lastIndex - firstIndex + 1); + std::fill(checkStates.begin(), checkStates.end(), true); dataChanged(index(0, 0), index(lastIndex - firstIndex, 0), QVector<int>() << Qt::CheckStateRole << Selected); } @@ -109,7 +108,7 @@ void DiveImportedModel::selectRow(int row) void DiveImportedModel::selectNone() { - memset(checkStates, false, lastIndex - firstIndex + 1); + std::fill(checkStates.begin(), checkStates.end(), false); dataChanged(index(0, 0), index(lastIndex - firstIndex,0 ), QVector<int>() << Qt::CheckStateRole << Selected); } @@ -141,9 +140,8 @@ void DiveImportedModel::repopulate() firstIndex = 0; lastIndex = diveTable->nr - 1; - delete[] checkStates; - checkStates = new bool[diveTable->nr]; - memset(checkStates, true, diveTable->nr); + checkStates.resize(diveTable->nr); + std::fill(checkStates.begin(), checkStates.end(), true); endResetModel(); } diff --git a/qt-models/diveimportedmodel.h b/qt-models/diveimportedmodel.h index eeea0b82c..fc4d9147b 100644 --- a/qt-models/diveimportedmodel.h +++ b/qt-models/diveimportedmodel.h @@ -2,6 +2,7 @@ #define DIVEIMPORTEDMODEL_H #include <QAbstractTableModel> +#include <vector> class DiveImportedModel : public QAbstractTableModel { @@ -31,7 +32,7 @@ slots: private: int firstIndex; int lastIndex; - bool *checkStates; + std::vector<char> checkStates; // char instead of bool to avoid silly pessimization of std::vector. struct dive_table *diveTable; }; |