planner: remove dc_number access from models

Instead of accessing the global dc_number from the
DivePlannerPointsModel and the CylinderModel, pass them
in the respective initialization functions.

The dc_number global might not make sense on mobile.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-05-21 22:08:46 +02:00 committed by bstoeger
parent d057af43b4
commit 832398180c
7 changed files with 20 additions and 14 deletions

View file

@ -571,7 +571,7 @@ void PlannerWidgets::replanDive()
return; return;
copy_dive(current_dive, &displayed_dive); // Planning works on a copy of the dive (for now). copy_dive(current_dive, &displayed_dive); // Planning works on a copy of the dive (for now).
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN);
DivePlannerPointsModel::instance()->loadFromDive(&displayed_dive); DivePlannerPointsModel::instance()->loadFromDive(&displayed_dive, dc_number);
plannerWidget.setReplanButton(true); plannerWidget.setReplanButton(true);
plannerWidget.setupStartTime(timestampToDateTime(displayed_dive.when)); plannerWidget.setupStartTime(timestampToDateTime(displayed_dive.when));
@ -580,7 +580,7 @@ void PlannerWidgets::replanDive()
if (displayed_dive.salinity) if (displayed_dive.salinity)
plannerWidget.setSalinity(displayed_dive.salinity); plannerWidget.setSalinity(displayed_dive.salinity);
reset_cylinders(&displayed_dive, true); reset_cylinders(&displayed_dive, true);
DivePlannerPointsModel::instance()->cylindersModel()->updateDive(&displayed_dive); DivePlannerPointsModel::instance()->cylindersModel()->updateDive(&displayed_dive, dc_number);
} }
void PlannerWidgets::printDecoPlan() void PlannerWidgets::printDecoPlan()

View file

@ -226,7 +226,7 @@ void ProfileWidget::divesChanged(const QVector<dive *> &dives, DiveField field)
if (editedDive) { if (editedDive) {
copy_dive(current_dive, editedDive.get()); copy_dive(current_dive, editedDive.get());
// TODO: Holy moly that function sends too many signals. Fix it! // TODO: Holy moly that function sends too many signals. Fix it!
DivePlannerPointsModel::instance()->loadFromDive(editedDive.get()); DivePlannerPointsModel::instance()->loadFromDive(editedDive.get(), editedDc);
} }
plotCurrentDive(); plotCurrentDive();
@ -258,7 +258,7 @@ void ProfileWidget::editDive()
copy_dive(current_dive, editedDive.get()); // Work on a copy of the dive copy_dive(current_dive, editedDive.get()); // Work on a copy of the dive
originalDive = current_dive; originalDive = current_dive;
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD); DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::ADD);
DivePlannerPointsModel::instance()->loadFromDive(editedDive.get()); DivePlannerPointsModel::instance()->loadFromDive(editedDive.get(), editedDc);
view->setEditState(editedDive.get(), editedDc); view->setEditState(editedDive.get(), editedDc);
} }

View file

@ -139,7 +139,7 @@ void TabDiveEquipment::toggleTriggeredColumn()
void TabDiveEquipment::updateData() void TabDiveEquipment::updateData()
{ {
cylindersModel->updateDive(current_dive); cylindersModel->updateDive(current_dive, dc_number);
weightModel->updateDive(current_dive); weightModel->updateDive(current_dive);
if (current_dive && current_dive->suit) if (current_dive && current_dive->suit)

View file

@ -241,7 +241,8 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
case SIZE_INT: case SIZE_INT:
return static_cast<int>(cyl->type.size.mliter); return static_cast<int>(cyl->type.size.mliter);
case SENSORS: { case SENSORS: {
const struct divecomputer *currentdc = get_dive_dc(current_dive, dc_number); std::vector<int16_t> sensors;
const struct divecomputer *currentdc = get_dive_dc(d, dcNr);
for (int i = 0; i < currentdc->samples; ++i) { for (int i = 0; i < currentdc->samples; ++i) {
auto &sample = currentdc->sample[i]; auto &sample = currentdc->sample[i];
for (int s = 0; s < MAX_SENSORS; ++s) { for (int s = 0; s < MAX_SENSORS; ++s) {
@ -475,7 +476,7 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
bool ok = false; bool ok = false;
int s = vString.toInt(&ok); int s = vString.toInt(&ok);
if (ok) { if (ok) {
Command::editSensors(index.row(), s, dc_number); Command::editSensors(index.row(), s, dcNr);
// We don't use the edit cylinder command and editing sensors is not relevant for planner // We don't use the edit cylinder command and editing sensors is not relevant for planner
return true; return true;
} }
@ -521,10 +522,11 @@ void CylindersModel::clear()
{ {
beginResetModel(); beginResetModel();
d = nullptr; d = nullptr;
dcNr = -1;
endResetModel(); endResetModel();
} }
void CylindersModel::updateDive(dive *dIn) void CylindersModel::updateDive(dive *dIn, int dcNrIn)
{ {
#ifdef DEBUG_CYL #ifdef DEBUG_CYL
if (d) if (d)
@ -532,6 +534,7 @@ void CylindersModel::updateDive(dive *dIn)
#endif #endif
beginResetModel(); beginResetModel();
d = dIn; d = dIn;
dcNr = dcNrIn;
numRows = calcNumRows(); numRows = calcNumRows();
endResetModel(); endResetModel();
} }

View file

@ -44,7 +44,7 @@ public:
void add(); void add();
void clear(); void clear();
void updateDive(dive *d); void updateDive(dive *d, int dcNr);
void updateDecoDepths(pressure_t olddecopo2); void updateDecoDepths(pressure_t olddecopo2);
void updateTrashIcon(); void updateTrashIcon();
void moveAtFirst(int cylid); void moveAtFirst(int cylid);
@ -65,6 +65,7 @@ slots:
private: private:
dive *d; dive *d;
int dcNr;
bool inPlanner; bool inPlanner;
bool hideUnused; bool hideUnused;
int numRows; // Does not include unused cylinders at the end int numRows; // Does not include unused cylinders at the end

View file

@ -105,9 +105,10 @@ void DivePlannerPointsModel::setupStartTime()
} }
} }
void DivePlannerPointsModel::loadFromDive(dive *dIn) void DivePlannerPointsModel::loadFromDive(dive *dIn, int dcNrIn)
{ {
d = dIn; d = dIn;
dcNr = dcNrIn;
int depthsum = 0; int depthsum = 0;
int samplecount = 0; int samplecount = 0;
@ -115,7 +116,7 @@ void DivePlannerPointsModel::loadFromDive(dive *dIn)
struct divecomputer *dc = &(d->dc); struct divecomputer *dc = &(d->dc);
const struct event *evd = NULL; const struct event *evd = NULL;
enum divemode_t current_divemode = UNDEF_COMP_TYPE; enum divemode_t current_divemode = UNDEF_COMP_TYPE;
cylinders.updateDive(d); cylinders.updateDive(d, dcNr);
duration_t lasttime = { 0 }; duration_t lasttime = { 0 };
duration_t lastrecordedtime = {}; duration_t lastrecordedtime = {};
duration_t newtime = {}; duration_t newtime = {};
@ -197,7 +198,7 @@ void DivePlannerPointsModel::setupCylinders()
reset_cylinders(d, true); reset_cylinders(d, true);
if (d->cylinders.nr > 0) { if (d->cylinders.nr > 0) {
cylinders.updateDive(d); cylinders.updateDive(d, dcNr);
return; // We have at least one cylinder return; // We have at least one cylinder
} }
} }
@ -215,7 +216,7 @@ void DivePlannerPointsModel::setupCylinders()
add_cylinder(&d->cylinders, 0, cyl); add_cylinder(&d->cylinders, 0, cyl);
} }
reset_cylinders(d, false); reset_cylinders(d, false);
cylinders.updateDive(d); cylinders.updateDive(d, dcNr);
} }
// Update the dive's maximum depth. Returns true if max. depth changed // Update the dive's maximum depth. Returns true if max. depth changed

View file

@ -60,7 +60,7 @@ public:
struct diveplan &getDiveplan(); struct diveplan &getDiveplan();
struct deco_state final_deco_state; struct deco_state final_deco_state;
void loadFromDive(dive *d); void loadFromDive(dive *d, int dcNr);
void addStop(int millimeters, int seconds); void addStop(int millimeters, int seconds);
public public
slots: slots:
@ -132,6 +132,7 @@ private:
void computeVariationsFreeDeco(struct diveplan *diveplan, struct deco_state *ds); void computeVariationsFreeDeco(struct diveplan *diveplan, struct deco_state *ds);
int analyzeVariations(struct decostop *min, struct decostop *mid, struct decostop *max, const char *unit); int analyzeVariations(struct decostop *min, struct decostop *mid, struct decostop *max, const char *unit);
struct dive *d; struct dive *d;
int dcNr;
CylindersModel cylinders; CylindersModel cylinders;
Mode mode; Mode mode;
QVector<divedatapoint> divepoints; QVector<divedatapoint> divepoints;