From 6622f42aab937e72cc11cb5512012394aa687767 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Thu, 30 Jan 2020 20:12:11 +0100 Subject: 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 --- backend-shared/plannershared.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'backend-shared') diff --git a/backend-shared/plannershared.cpp b/backend-shared/plannershared.cpp index 51f7a3a74..606dbb9d2 100644 --- a/backend-shared/plannershared.cpp +++ b/backend-shared/plannershared.cpp @@ -126,7 +126,7 @@ void PlannerShared::set_o2narcotic(bool value) { qPrefDivePlanner::set_o2narcotic(value); DivePlannerPointsModel::instance()->emitDataChanged(); - CylindersModel::instance()->updateBestMixes(); + CylindersModelFiltered::instance()->model()->updateBestMixes(); } double PlannerShared::bottompo2() @@ -136,7 +136,7 @@ double PlannerShared::bottompo2() void PlannerShared::set_bottompo2(double value) { qPrefDivePlanner::set_bottompo2((int) (value * 1000.0)); - CylindersModel::instance()->updateBestMixes(); + CylindersModelFiltered::instance()->model()->updateBestMixes(); } double PlannerShared::decopo2() @@ -148,8 +148,8 @@ void PlannerShared::set_decopo2(double value) pressure_t olddecopo2; olddecopo2.mbar = prefs.decopo2; qPrefDivePlanner::instance()->set_decopo2((int) (value * 1000.0)); - CylindersModel::instance()->updateDecoDepths(olddecopo2); - CylindersModel::instance()->updateBestMixes(); + CylindersModelFiltered::instance()->model()->updateDecoDepths(olddecopo2); + CylindersModelFiltered::instance()->model()->updateBestMixes(); } int PlannerShared::bestmixend() @@ -159,5 +159,5 @@ int PlannerShared::bestmixend() void PlannerShared::set_bestmixend(int value) { qPrefDivePlanner::set_bestmixend(units_to_depth(value).mm); - CylindersModel::instance()->updateBestMixes(); + CylindersModelFiltered::instance()->model()->updateBestMixes(); } -- cgit v1.2.3-70-g09d2