mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-01 02:03:24 +00:00
cleanup: remove CylindersModels::rows
Access the number of cylinders in the dive directly instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
30d289e4a8
commit
a37939889b
2 changed files with 7 additions and 14 deletions
|
@ -12,8 +12,7 @@
|
||||||
|
|
||||||
CylindersModel::CylindersModel(QObject *parent) : CleanerTableModel(parent),
|
CylindersModel::CylindersModel(QObject *parent) : CleanerTableModel(parent),
|
||||||
changed(false),
|
changed(false),
|
||||||
d(nullptr),
|
d(nullptr)
|
||||||
rows(0)
|
|
||||||
{
|
{
|
||||||
// enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH, MOD, MND, USE, IS_USED};
|
// enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH, MOD, MND, USE, IS_USED};
|
||||||
setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("Work press.") << tr("Start press.") << tr("End press.") << tr("O₂%") << tr("He%")
|
setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("Work press.") << tr("Start press.") << tr("End press.") << tr("O₂%") << tr("He%")
|
||||||
|
@ -147,7 +146,7 @@ bool CylindersModel::cylinderUsed(int i) const
|
||||||
|
|
||||||
QVariant CylindersModel::data(const QModelIndex &index, int role) const
|
QVariant CylindersModel::data(const QModelIndex &index, int role) const
|
||||||
{
|
{
|
||||||
if (!d || !index.isValid() || index.row() >= rows)
|
if (!d || !index.isValid() || index.row() >= d->cylinders.nr)
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
||||||
if (index.row() >= d->cylinders.nr) {
|
if (index.row() >= d->cylinders.nr) {
|
||||||
|
@ -446,18 +445,17 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
|
||||||
|
|
||||||
int CylindersModel::rowCount(const QModelIndex&) const
|
int CylindersModel::rowCount(const QModelIndex&) const
|
||||||
{
|
{
|
||||||
return rows;
|
return d ? d->cylinders.nr : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CylindersModel::add()
|
void CylindersModel::add()
|
||||||
{
|
{
|
||||||
if (!d)
|
if (!d)
|
||||||
return;
|
return;
|
||||||
int row = rows;
|
int row = d->cylinders.nr;
|
||||||
cylinder_t cyl = create_new_cylinder(d);
|
cylinder_t cyl = create_new_cylinder(d);
|
||||||
beginInsertRows(QModelIndex(), row, row);
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
add_to_cylinder_table(&d->cylinders, row, cyl);
|
add_to_cylinder_table(&d->cylinders, row, cyl);
|
||||||
rows++;
|
|
||||||
changed = true;
|
changed = true;
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
emit dataChanged(createIndex(row, 0), createIndex(row, COLUMNS - 1));
|
emit dataChanged(createIndex(row, 0), createIndex(row, COLUMNS - 1));
|
||||||
|
@ -465,10 +463,9 @@ void CylindersModel::add()
|
||||||
|
|
||||||
void CylindersModel::clear()
|
void CylindersModel::clear()
|
||||||
{
|
{
|
||||||
if (rows > 0) {
|
beginResetModel();
|
||||||
beginRemoveRows(QModelIndex(), 0, rows - 1);
|
d = nullptr;
|
||||||
endRemoveRows();
|
endResetModel();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CylindersModel::updateDive(dive *dIn)
|
void CylindersModel::updateDive(dive *dIn)
|
||||||
|
@ -479,7 +476,6 @@ void CylindersModel::updateDive(dive *dIn)
|
||||||
#endif
|
#endif
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
d = dIn;
|
d = dIn;
|
||||||
rows = d ? d->cylinders.nr : 0;
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,7 +509,6 @@ void CylindersModel::remove(QModelIndex index)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
beginRemoveRows(QModelIndex(), index.row(), index.row());
|
beginRemoveRows(QModelIndex(), index.row(), index.row());
|
||||||
rows--;
|
|
||||||
remove_cylinder(d, index.row());
|
remove_cylinder(d, index.row());
|
||||||
changed = true;
|
changed = true;
|
||||||
endRemoveRows();
|
endRemoveRows();
|
||||||
|
@ -630,7 +625,6 @@ void CylindersModel::cylindersReset(const QVector<dive *> &dives)
|
||||||
|
|
||||||
// And update the model (the actual change was already performed in the backend)..
|
// And update the model (the actual change was already performed in the backend)..
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
rows = d->cylinders.nr;
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,6 @@ slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
dive *d;
|
dive *d;
|
||||||
int rows;
|
|
||||||
cylinder_t *cylinderAt(const QModelIndex &index);
|
cylinder_t *cylinderAt(const QModelIndex &index);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue