summaryrefslogtreecommitdiffstats
path: root/qt-models
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-11-03 15:32:59 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-12-05 10:14:25 -0800
commit92b833a7d85f7d361f2b198782bb093c300ed59a (patch)
tree62825c5b20c68045158e4f96f0a4747cdcebcffc /qt-models
parent2cfb35b6d7b5bb7bb7275f078bf2aff959e6ecef (diff)
downloadsubsurface-92b833a7d85f7d361f2b198782bb093c300ed59a.tar.gz
Cleanup: remove redundant "row" member of WeightModel
Before undoization, the WeightModel could be out-of-sync with the actual dive and therefore had a row member variable. This became redundant. Therefore, remove it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models')
-rw-r--r--qt-models/weightmodel.cpp18
-rw-r--r--qt-models/weightmodel.h3
2 files changed, 8 insertions, 13 deletions
diff --git a/qt-models/weightmodel.cpp b/qt-models/weightmodel.cpp
index 4a931a4bb..c8903d069 100644
--- a/qt-models/weightmodel.cpp
+++ b/qt-models/weightmodel.cpp
@@ -9,8 +9,7 @@
WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent),
changed(false),
- d(nullptr),
- rows(0)
+ d(nullptr)
{
//enum Column {REMOVE, TYPE, WEIGHT};
setHeaderDataStrings(QStringList() << tr("") << tr("Type") << tr("Weight"));
@@ -19,7 +18,7 @@ WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent),
connect(&diveListNotifier, &DiveListNotifier::weightRemoved, this, &WeightModel::weightRemoved);
}
-weightsystem_t WeightModel::weightSystemAt(const QModelIndex &index)
+weightsystem_t WeightModel::weightSystemAt(const QModelIndex &index) const
{
int row = index.row();
if (row < 0 || row >= d->weightsystems.nr) {
@@ -39,7 +38,7 @@ QVariant WeightModel::data(const QModelIndex &index, int role) const
if (!index.isValid() || index.row() >= d->weightsystems.nr)
return QVariant();
- const weightsystem_t *ws = &d->weightsystems.weightsystems[index.row()];
+ const weightsystem_t ws = weightSystemAt(index);
switch (role) {
case Qt::FontRole:
@@ -50,9 +49,9 @@ QVariant WeightModel::data(const QModelIndex &index, int role) const
case Qt::EditRole:
switch (index.column()) {
case TYPE:
- return gettextFromC::tr(ws->description);
+ return gettextFromC::tr(ws.description);
case WEIGHT:
- return get_weight_string(ws->weight, true);
+ return get_weight_string(ws.weight, true);
}
break;
case Qt::DecorationRole:
@@ -133,14 +132,13 @@ Qt::ItemFlags WeightModel::flags(const QModelIndex &index) const
int WeightModel::rowCount(const QModelIndex&) const
{
- return rows;
+ return d ? d->weightsystems.nr : 0;
}
void WeightModel::updateDive(dive *dIn)
{
beginResetModel();
d = dIn;
- rows = d ? d->weightsystems.nr : 0;
endResetModel();
}
@@ -160,9 +158,8 @@ void WeightModel::weightAdded(struct dive *changed, int pos)
if (d != changed)
return;
- // The last row was already inserted by the undo command. Just inform the model.
+ // The row was already inserted by the undo command. Just inform the model.
beginInsertRows(QModelIndex(), pos, pos);
- rows++;
endInsertRows();
}
@@ -173,6 +170,5 @@ void WeightModel::weightRemoved(struct dive *changed, int pos)
// The row was already deleted by the undo command. Just inform the model.
beginRemoveRows(QModelIndex(), pos, pos);
- rows--;
endRemoveRows();
}
diff --git a/qt-models/weightmodel.h b/qt-models/weightmodel.h
index 2e5a190ba..f3002a1ae 100644
--- a/qt-models/weightmodel.h
+++ b/qt-models/weightmodel.h
@@ -25,7 +25,7 @@ public:
void passInData(const QModelIndex &index, const QVariant &value);
void clear();
void updateDive(dive *d);
- weightsystem_t weightSystemAt(const QModelIndex &index);
+ weightsystem_t weightSystemAt(const QModelIndex &index) const;
bool changed;
public
@@ -36,7 +36,6 @@ slots:
private:
dive *d;
- int rows;
};
#endif