mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
6febe22b6b
commit
a6a5cf61e2
2 changed files with 6 additions and 7 deletions
|
@ -4,7 +4,6 @@
|
||||||
DiveImportedModel::DiveImportedModel(QObject *o) : QAbstractTableModel(o),
|
DiveImportedModel::DiveImportedModel(QObject *o) : QAbstractTableModel(o),
|
||||||
firstIndex(0),
|
firstIndex(0),
|
||||||
lastIndex(-1),
|
lastIndex(-1),
|
||||||
checkStates(nullptr),
|
|
||||||
diveTable(nullptr)
|
diveTable(nullptr)
|
||||||
{
|
{
|
||||||
// Defaults to downloadTable, can be changed later.
|
// Defaults to downloadTable, can be changed later.
|
||||||
|
@ -97,7 +96,7 @@ void DiveImportedModel::changeSelected(QModelIndex clickedIndex)
|
||||||
|
|
||||||
void DiveImportedModel::selectAll()
|
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);
|
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()
|
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);
|
dataChanged(index(0, 0), index(lastIndex - firstIndex,0 ), QVector<int>() << Qt::CheckStateRole << Selected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,9 +140,8 @@ void DiveImportedModel::repopulate()
|
||||||
|
|
||||||
firstIndex = 0;
|
firstIndex = 0;
|
||||||
lastIndex = diveTable->nr - 1;
|
lastIndex = diveTable->nr - 1;
|
||||||
delete[] checkStates;
|
checkStates.resize(diveTable->nr);
|
||||||
checkStates = new bool[diveTable->nr];
|
std::fill(checkStates.begin(), checkStates.end(), true);
|
||||||
memset(checkStates, true, diveTable->nr);
|
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define DIVEIMPORTEDMODEL_H
|
#define DIVEIMPORTEDMODEL_H
|
||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class DiveImportedModel : public QAbstractTableModel
|
class DiveImportedModel : public QAbstractTableModel
|
||||||
{
|
{
|
||||||
|
@ -31,7 +32,7 @@ slots:
|
||||||
private:
|
private:
|
||||||
int firstIndex;
|
int firstIndex;
|
||||||
int lastIndex;
|
int lastIndex;
|
||||||
bool *checkStates;
|
std::vector<char> checkStates; // char instead of bool to avoid silly pessimization of std::vector.
|
||||||
struct dive_table *diveTable;
|
struct dive_table *diveTable;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue