mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: turn M_OR_FT macro into a function
No point in this being a macro. Make it return a depth_t - it was unclear that this returns a depth in mm. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
64945a1c96
commit
e9c14c523c
11 changed files with 105 additions and 97 deletions
|
@ -237,13 +237,13 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
|
|||
} else {
|
||||
pressure_t modpO2;
|
||||
modpO2.mbar = inPlanner ? prefs.bottompo2 : (int)(prefs.modpO2 * 1000.0);
|
||||
return get_depth_string(d->gas_mod(cyl->gasmix, modpO2, M_OR_FT(1,1)), true);
|
||||
return get_depth_string(d->gas_mod(cyl->gasmix, modpO2, m_or_ft(1, 1).mm), true);
|
||||
}
|
||||
case MND:
|
||||
if (cyl->bestmix_he)
|
||||
return QStringLiteral("*");
|
||||
else
|
||||
return get_depth_string(d->gas_mnd(cyl->gasmix, prefs.bestmixend, M_OR_FT(1,1)), true);
|
||||
return get_depth_string(d->gas_mnd(cyl->gasmix, prefs.bestmixend, m_or_ft(1, 1).mm), true);
|
||||
break;
|
||||
case USE:
|
||||
return gettextFromC::tr(cylinderuse_text[cyl->cylinder_use]);
|
||||
|
@ -414,7 +414,7 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
|
|||
prefs.o2consumption / prefs.decosac / prefs.pscr_ratio;
|
||||
else
|
||||
modpO2.mbar = prefs.decopo2;
|
||||
cyl.depth = d->gas_mod(cyl.gasmix, modpO2, M_OR_FT(3, 10));
|
||||
cyl.depth = d->gas_mod(cyl.gasmix, modpO2, m_or_ft(3, 10).mm);
|
||||
cyl.bestmix_o2 = false;
|
||||
}
|
||||
type = Command::EditCylinderType::GASMIX;
|
||||
|
@ -443,7 +443,7 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
|
|||
}
|
||||
pressure_t modpO2;
|
||||
modpO2.mbar = prefs.decopo2;
|
||||
cyl.depth = d->gas_mod(cyl.gasmix, modpO2, M_OR_FT(3, 10));
|
||||
cyl.depth = d->gas_mod(cyl.gasmix, modpO2, m_or_ft(3, 10).mm);
|
||||
}
|
||||
type = Command::EditCylinderType::GASMIX;
|
||||
break;
|
||||
|
@ -649,8 +649,8 @@ void CylindersModel::updateDecoDepths(pressure_t olddecopo2)
|
|||
for (auto &cyl: d->cylinders) {
|
||||
/* If the gas's deco MOD matches the old pO2, it will have been automatically calculated and should be updated.
|
||||
* If they don't match, we should leave the user entered depth as it is */
|
||||
if (cyl.depth.mm == d->gas_mod(cyl.gasmix, olddecopo2, M_OR_FT(3, 10)).mm) {
|
||||
cyl.depth = d->gas_mod(cyl.gasmix, decopo2, M_OR_FT(3, 10));
|
||||
if (cyl.depth.mm == d->gas_mod(cyl.gasmix, olddecopo2, m_or_ft(3, 10).mm).mm) {
|
||||
cyl.depth = d->gas_mod(cyl.gasmix, decopo2, m_or_ft(3, 10).mm);
|
||||
}
|
||||
}
|
||||
emit dataChanged(createIndex(0, 0), createIndex(numRows - 1, COLUMNS - 1));
|
||||
|
@ -680,7 +680,7 @@ bool CylindersModel::updateBestMixes()
|
|||
cyl.gasmix.he.permille = 1000 - get_o2(cyl.gasmix);
|
||||
pressure_t modpO2;
|
||||
modpO2.mbar = prefs.decopo2;
|
||||
cyl.depth = d->gas_mod(cyl.gasmix, modpO2, M_OR_FT(3, 10));
|
||||
cyl.depth = d->gas_mod(cyl.gasmix, modpO2, m_or_ft(3, 10).mm);
|
||||
gasUpdated = true;
|
||||
}
|
||||
if (cyl.bestmix_he) {
|
||||
|
|
|
@ -90,12 +90,12 @@ void DivePlannerPointsModel::createSimpleDive(struct dive *dIn)
|
|||
// If we're in drop_stone_mode, don't add a first point.
|
||||
// It will be added implicitly.
|
||||
if (!prefs.drop_stone_mode)
|
||||
addStop(M_OR_FT(15, 45), 1 * 60, cylinderid, prefs.defaultsetpoint, true, UNDEF_COMP_TYPE);
|
||||
addStop(m_or_ft(15, 45), 1 * 60, cylinderid, prefs.defaultsetpoint, true, UNDEF_COMP_TYPE);
|
||||
|
||||
addStop(M_OR_FT(15, 45), 20 * 60, 0, prefs.defaultsetpoint, true, UNDEF_COMP_TYPE);
|
||||
addStop(m_or_ft(15, 45), 20 * 60, 0, prefs.defaultsetpoint, true, UNDEF_COMP_TYPE);
|
||||
if (!isPlanner()) {
|
||||
addStop(M_OR_FT(5, 15), 42 * 60, cylinderid, prefs.defaultsetpoint, true, UNDEF_COMP_TYPE);
|
||||
addStop(M_OR_FT(5, 15), 45 * 60, cylinderid, prefs.defaultsetpoint, true, UNDEF_COMP_TYPE);
|
||||
addStop(m_or_ft(5, 15), 42 * 60, cylinderid, prefs.defaultsetpoint, true, UNDEF_COMP_TYPE);
|
||||
addStop(m_or_ft(5, 15), 45 * 60, cylinderid, prefs.defaultsetpoint, true, UNDEF_COMP_TYPE);
|
||||
}
|
||||
updateDiveProfile();
|
||||
}
|
||||
|
@ -173,7 +173,8 @@ void DivePlannerPointsModel::loadFromDive(dive *dIn, int dcNrIn)
|
|||
if (newtime.seconds == lastrecordedtime.seconds)
|
||||
newtime.seconds += 10;
|
||||
divemode_t current_divemode = loop.at(newtime.seconds - 1);
|
||||
addStop(depthsum / samplecount, newtime.seconds, cylinderid, last_sp.mbar, true, current_divemode);
|
||||
depth_t depth { .mm = depthsum / samplecount };
|
||||
addStop(depth, newtime.seconds, cylinderid, last_sp.mbar, true, current_divemode);
|
||||
lastrecordedtime = newtime;
|
||||
}
|
||||
lasttime = newtime;
|
||||
|
@ -184,7 +185,7 @@ void DivePlannerPointsModel::loadFromDive(dive *dIn, int dcNrIn)
|
|||
// make sure we get the last point right so the duration is correct
|
||||
divemode_t current_divemode = loop.at(dc->duration.seconds);
|
||||
if (!hasMarkedSamples && !dc->last_manual_time.seconds)
|
||||
addStop(0, dc->duration.seconds,cylinderid, last_sp.mbar, true, current_divemode);
|
||||
addStop(0_m, dc->duration.seconds,cylinderid, last_sp.mbar, true, current_divemode);
|
||||
preserved_until = d->duration;
|
||||
|
||||
updateDiveProfile();
|
||||
|
@ -808,19 +809,19 @@ int DivePlannerPointsModel::lastEnteredPoint() const
|
|||
void DivePlannerPointsModel::addDefaultStop()
|
||||
{
|
||||
removeDeco();
|
||||
addStop(0, 0, -1, prefs.defaultsetpoint, true, UNDEF_COMP_TYPE);
|
||||
addStop(0_m, 0, -1, prefs.defaultsetpoint, true, UNDEF_COMP_TYPE);
|
||||
}
|
||||
|
||||
void DivePlannerPointsModel::addStop(int milimeters, int seconds)
|
||||
void DivePlannerPointsModel::addStop(depth_t depth, int seconds)
|
||||
{
|
||||
removeDeco();
|
||||
addStop(milimeters, seconds, -1, prefs.defaultsetpoint, true, UNDEF_COMP_TYPE);
|
||||
addStop(depth, seconds, -1, prefs.defaultsetpoint, true, UNDEF_COMP_TYPE);
|
||||
updateDiveProfile();
|
||||
}
|
||||
|
||||
// cylinderid_in == -1 means same gas as before.
|
||||
// divemode == UNDEF_COMP_TYPE means determine from previous point.
|
||||
int DivePlannerPointsModel::addStop(int milimeters, int seconds, int cylinderid_in, int ccpoint, bool entered, enum divemode_t divemode)
|
||||
int DivePlannerPointsModel::addStop(depth_t depth, int seconds, int cylinderid_in, int ccpoint, bool entered, enum divemode_t divemode)
|
||||
{
|
||||
int cylinderid = 0;
|
||||
bool usePrevious = false;
|
||||
|
@ -830,16 +831,16 @@ int DivePlannerPointsModel::addStop(int milimeters, int seconds, int cylinderid_
|
|||
usePrevious = true;
|
||||
|
||||
int row = divepoints.count();
|
||||
if (seconds == 0 && milimeters == 0) {
|
||||
if (seconds == 0 && depth.mm == 0) {
|
||||
if (row == 0) {
|
||||
milimeters = M_OR_FT(5, 15); // 5m / 15ft
|
||||
depth = m_or_ft(5, 15); // 5m / 15ft
|
||||
seconds = 600; // 10 min
|
||||
// Default to the first cylinder
|
||||
cylinderid = 0;
|
||||
} else {
|
||||
/* this is only possible if the user clicked on the 'plus' sign on the DivePoints Table */
|
||||
const divedatapoint t = divepoints.at(lastEnteredPoint());
|
||||
milimeters = t.depth.mm;
|
||||
depth = t.depth;
|
||||
seconds = t.time + 600; // 10 minutes.
|
||||
cylinderid = t.cylinderid;
|
||||
ccpoint = t.setpoint;
|
||||
|
@ -881,7 +882,7 @@ int DivePlannerPointsModel::addStop(int milimeters, int seconds, int cylinderid_
|
|||
|
||||
// add the new stop
|
||||
beginInsertRows(QModelIndex(), row, row);
|
||||
divedatapoint point(seconds, milimeters, cylinderid, ccpoint, entered);
|
||||
divedatapoint point(seconds, depth.mm, cylinderid, ccpoint, entered);
|
||||
point.divemode = divemode;
|
||||
divepoints.insert(divepoints.begin() + row, point);
|
||||
endInsertRows();
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
struct deco_state final_deco_state;
|
||||
|
||||
void loadFromDive(dive *d, int dcNr);
|
||||
void addStop(int millimeters, int seconds);
|
||||
void addStop(depth_t depth, int seconds);
|
||||
void cylindersChanged();
|
||||
public
|
||||
slots:
|
||||
|
@ -120,7 +120,7 @@ signals:
|
|||
private:
|
||||
explicit DivePlannerPointsModel(QObject *parent = 0);
|
||||
void clear();
|
||||
int addStop(int millimeters, int seconds, int cylinderid_in, int ccpoint, bool entered, enum divemode_t);
|
||||
int addStop(depth_t depth, int seconds, int cylinderid_in, int ccpoint, bool entered, enum divemode_t);
|
||||
void removePoints(const std::vector<int> &rows);
|
||||
void setupStartTime();
|
||||
void setupCylinders();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue