mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
2cfb35b6d7
commit
92b833a7d8
2 changed files with 8 additions and 13 deletions
|
@ -9,8 +9,7 @@
|
||||||
|
|
||||||
WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent),
|
WeightModel::WeightModel(QObject *parent) : CleanerTableModel(parent),
|
||||||
changed(false),
|
changed(false),
|
||||||
d(nullptr),
|
d(nullptr)
|
||||||
rows(0)
|
|
||||||
{
|
{
|
||||||
//enum Column {REMOVE, TYPE, WEIGHT};
|
//enum Column {REMOVE, TYPE, WEIGHT};
|
||||||
setHeaderDataStrings(QStringList() << tr("") << tr("Type") << tr("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);
|
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();
|
int row = index.row();
|
||||||
if (row < 0 || row >= d->weightsystems.nr) {
|
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)
|
if (!index.isValid() || index.row() >= d->weightsystems.nr)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
const weightsystem_t *ws = &d->weightsystems.weightsystems[index.row()];
|
const weightsystem_t ws = weightSystemAt(index);
|
||||||
|
|
||||||
switch (role) {
|
switch (role) {
|
||||||
case Qt::FontRole:
|
case Qt::FontRole:
|
||||||
|
@ -50,9 +49,9 @@ QVariant WeightModel::data(const QModelIndex &index, int role) const
|
||||||
case Qt::EditRole:
|
case Qt::EditRole:
|
||||||
switch (index.column()) {
|
switch (index.column()) {
|
||||||
case TYPE:
|
case TYPE:
|
||||||
return gettextFromC::tr(ws->description);
|
return gettextFromC::tr(ws.description);
|
||||||
case WEIGHT:
|
case WEIGHT:
|
||||||
return get_weight_string(ws->weight, true);
|
return get_weight_string(ws.weight, true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Qt::DecorationRole:
|
case Qt::DecorationRole:
|
||||||
|
@ -133,14 +132,13 @@ Qt::ItemFlags WeightModel::flags(const QModelIndex &index) const
|
||||||
|
|
||||||
int WeightModel::rowCount(const QModelIndex&) const
|
int WeightModel::rowCount(const QModelIndex&) const
|
||||||
{
|
{
|
||||||
return rows;
|
return d ? d->weightsystems.nr : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WeightModel::updateDive(dive *dIn)
|
void WeightModel::updateDive(dive *dIn)
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
d = dIn;
|
d = dIn;
|
||||||
rows = d ? d->weightsystems.nr : 0;
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,9 +158,8 @@ void WeightModel::weightAdded(struct dive *changed, int pos)
|
||||||
if (d != changed)
|
if (d != changed)
|
||||||
return;
|
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);
|
beginInsertRows(QModelIndex(), pos, pos);
|
||||||
rows++;
|
|
||||||
endInsertRows();
|
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.
|
// The row was already deleted by the undo command. Just inform the model.
|
||||||
beginRemoveRows(QModelIndex(), pos, pos);
|
beginRemoveRows(QModelIndex(), pos, pos);
|
||||||
rows--;
|
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ public:
|
||||||
void passInData(const QModelIndex &index, const QVariant &value);
|
void passInData(const QModelIndex &index, const QVariant &value);
|
||||||
void clear();
|
void clear();
|
||||||
void updateDive(dive *d);
|
void updateDive(dive *d);
|
||||||
weightsystem_t weightSystemAt(const QModelIndex &index);
|
weightsystem_t weightSystemAt(const QModelIndex &index) const;
|
||||||
bool changed;
|
bool changed;
|
||||||
|
|
||||||
public
|
public
|
||||||
|
@ -36,7 +36,6 @@ slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
dive *d;
|
dive *d;
|
||||||
int rows;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue