Equipment: Include Unused Tanks in Merge if Preference is Enabled.

Include unused tanks in merges of multiple logs into a single dive if
the 'Show unused cylinders' preference is enabled.
Also rename the preference (in code) to `include_unused_tanks` to
reflect the fact that it is already used in more places than just the
display (exporting, cloning dives).
Simplified the cylinder model to make forced inclusion of unused tanks
dependent on use of the model in planner.
Leaving the persisted name of the preference as `display_unused_tanks`
to avoid resetting this for all users - is there a good way to migrate
preference names?

Signed-off-by: Michael Keller <github@ike.ch>
This commit is contained in:
Michael Keller 2023-07-09 12:14:27 +12:00
parent cb6f768865
commit 5fae7ce7a0
17 changed files with 50 additions and 47 deletions

View file

@ -13,10 +13,9 @@
#include "core/subsurface-string.h"
#include <string>
CylindersModel::CylindersModel(bool planner, bool hideUnused, QObject *parent) : CleanerTableModel(parent),
CylindersModel::CylindersModel(bool planner, QObject *parent) : CleanerTableModel(parent),
d(nullptr),
inPlanner(planner),
hideUnused(hideUnused),
numRows(0),
tempRow(-1),
tempCyl(empty_cylinder)
@ -134,13 +133,14 @@ static QVariant percent_string(fraction_t fraction)
return QString("%L1%").arg(permille / 10.0, 0, 'f', 1);
}
// Calculate the number of displayed cylinders: If hideUnused
// is set, we don't show unused cylinders at the end of the list.
// Calculate the number of displayed cylinders: If we are in planner
// or prefs.include_unused_tanks is set we show unused cylinders
// at the end of the list.
int CylindersModel::calcNumRows() const
{
if (!d)
return 0;
if (!hideUnused || prefs.display_unused_tanks)
if (inPlanner || prefs.include_unused_tanks)
return d->cylinders.nr;
return first_hidden_cylinder(d);
}

View file

@ -36,7 +36,7 @@ public:
COMMIT_ROLE, // Save the temporary data to the dive. Must be set with Column == TYPE.
REVERT_ROLE // Revert to original data from dive. Must be set with Column == TYPE.
};
explicit CylindersModel(bool planner, bool hideUnused, QObject *parent = 0); // First argument: true if this model is used for the planner
explicit CylindersModel(bool planner, QObject *parent = 0); // First argument: true if this model is used for the planner
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
@ -67,7 +67,6 @@ private:
dive *d;
int dcNr;
bool inPlanner;
bool hideUnused;
int numRows; // Does not include unused cylinders at the end
// Used if we temporarily change a line because the user is selecting a weight type
int tempRow;

View file

@ -191,7 +191,7 @@ void DivePlannerPointsModel::setupCylinders()
clear_cylinder_table(&d->cylinders);
if (mode == PLAN && current_dive) {
// take the displayed cylinders from the selected dive as starting point
copy_used_cylinders(current_dive, d, !prefs.display_unused_tanks);
copy_used_cylinders(current_dive, d, !prefs.include_unused_tanks);
reset_cylinders(d, true);
if (d->cylinders.nr > 0) {
@ -445,7 +445,7 @@ int DivePlannerPointsModel::rowCount(const QModelIndex&) const
DivePlannerPointsModel::DivePlannerPointsModel(QObject *parent) : QAbstractTableModel(parent),
d(nullptr),
cylinders(true, false),
cylinders(true),
mode(NOTHING)
{
memset(&diveplan, 0, sizeof(diveplan));