aboutsummaryrefslogtreecommitdiffstats
path: root/qt-models/diveplannermodel.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-01-30 20:12:11 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-02-11 20:37:09 -0800
commit6622f42aab937e72cc11cb5512012394aa687767 (patch)
tree42302a42594b78b99111e98c6fd9325a0b9c5959 /qt-models/diveplannermodel.cpp
parentb37c261c95761cb5762e91b5d43277d2b0181678 (diff)
downloadsubsurface-6622f42aab937e72cc11cb5512012394aa687767.tar.gz
Cylinders: Add CylindersModelFiltered
When the show_unused_cylinders flag is not set, the cylinder tables in the equipment tab and the planner should not show unused cylinders. However, the code in CylindersModel is fundamentally broken if the unused cylinders are not at the end of the list: The correct number of cylinders is shown, but not the correct cylinders. Therefore, add a higher-level CylindersModelFiltered model on top of CylindersModel that does the actual filtering. Some calls are routed through to the base model (notably those that take indexes, as these have to be mapped), for some calls the caller has to get access to the source model first. We might want to adjust this. For filtering, reuse the already existing show_cylinder function and export it via CylindersModel. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'qt-models/diveplannermodel.cpp')
-rw-r--r--qt-models/diveplannermodel.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index 65773e13c..3d3f1d0bc 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -37,7 +37,7 @@ void DivePlannerPointsModel::removeSelectedPoints(const QVector<int> &rows)
divepoints.remove(v2[i]);
}
endRemoveRows();
- CylindersModel::instance()->updateTrashIcon();
+ CylindersModelFiltered::instance()->model()->updateTrashIcon();
}
void DivePlannerPointsModel::createSimpleDive()
@@ -89,7 +89,7 @@ void DivePlannerPointsModel::loadFromDive(dive *d)
const struct event *evd = NULL;
enum divemode_t current_divemode = UNDEF_COMP_TYPE;
recalc = false;
- CylindersModel::instance()->updateDive();
+ CylindersModelFiltered::instance()->updateDive();
duration_t lasttime = { 0 };
duration_t lastrecordedtime = {};
duration_t newtime = {};
@@ -162,7 +162,7 @@ void DivePlannerPointsModel::setupCylinders()
reset_cylinders(&displayed_dive, true);
if (displayed_dive.cylinders.nr > 0) {
- CylindersModel::instance()->updateDive();
+ CylindersModelFiltered::instance()->updateDive();
return; // We have at least one cylinder
}
}
@@ -180,7 +180,7 @@ void DivePlannerPointsModel::setupCylinders()
add_to_cylinder_table(&displayed_dive.cylinders, 0, cyl);
}
reset_cylinders(&displayed_dive, false);
- CylindersModel::instance()->updateDive();
+ CylindersModelFiltered::instance()->updateDive();
}
// Update the dive's maximum depth. Returns true if max. depth changed
@@ -209,7 +209,7 @@ void DivePlannerPointsModel::removeDeco()
void DivePlannerPointsModel::addCylinder_clicked()
{
- CylindersModel::instance()->add();
+ CylindersModelFiltered::instance()->add();
}
@@ -317,7 +317,7 @@ bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &v
if (value.toInt() >= 0) {
p.depth = units_to_depth(value.toInt());
if (updateMaxDepth())
- CylindersModel::instance()->updateBestMixes();
+ CylindersModelFiltered::instance()->model()->updateBestMixes();
}
break;
case RUNTIME:
@@ -343,8 +343,8 @@ bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &v
p.cylinderid = value.toInt();
/* Did we change the start (dp 0) cylinder to another cylinderid than 0? */
if (value.toInt() != 0 && index.row() == 0)
- CylindersModel::instance()->moveAtFirst(value.toInt());
- CylindersModel::instance()->updateTrashIcon();
+ CylindersModelFiltered::instance()->model()->moveAtFirst(value.toInt());
+ CylindersModelFiltered::instance()->model()->updateTrashIcon();
break;
case DIVEMODE:
if (value.toInt() < FREEDIVE) {
@@ -799,9 +799,9 @@ void DivePlannerPointsModel::editStop(int row, divedatapoint newData)
divepoints[row] = newData;
std::sort(divepoints.begin(), divepoints.end(), divePointsLessThan);
if (updateMaxDepth())
- CylindersModel::instance()->updateBestMixes();
+ CylindersModelFiltered::instance()->model()->updateBestMixes();
if (divepoints[0].cylinderid != old_first_cylid)
- CylindersModel::instance()->moveAtFirst(divepoints[0].cylinderid);
+ CylindersModelFiltered::instance()->model()->moveAtFirst(divepoints[0].cylinderid);
emitDataChanged();
}
@@ -850,9 +850,9 @@ void DivePlannerPointsModel::remove(const QModelIndex &index)
divepoints.remove(index.row());
}
endRemoveRows();
- CylindersModel::instance()->updateTrashIcon();
+ CylindersModelFiltered::instance()->model()->updateTrashIcon();
if (divepoints[0].cylinderid != old_first_cylid)
- CylindersModel::instance()->moveAtFirst(divepoints[0].cylinderid);
+ CylindersModelFiltered::instance()->model()->moveAtFirst(divepoints[0].cylinderid);
}
struct diveplan &DivePlannerPointsModel::getDiveplan()
@@ -907,13 +907,13 @@ void DivePlannerPointsModel::clear()
{
bool oldRecalc = setRecalc(false);
- CylindersModel::instance()->updateDive();
+ CylindersModelFiltered::instance()->updateDive();
if (rowCount() > 0) {
beginRemoveRows(QModelIndex(), 0, rowCount() - 1);
divepoints.clear();
endRemoveRows();
}
- CylindersModel::instance()->clear();
+ CylindersModelFiltered::instance()->clear();
setRecalc(oldRecalc);
}