mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
planner: remove DivePlannerPointsModel::setRecalc()
The only external user of setRecalc() was turning recalculation on. In fact, this happened when constructing the planner-widget. However, for example editing of the profile only works when the recalc flag is on. This is all very confusing, let's just turn the flag on by default and remove the accessor. Internally, the planner can simply use the std::exchange function to set and reset the recalc flag. Perhaps the setting/resetting can be replaced by simple recalc = true; ... recalc = false; pairs. It is unclear whether there is need for recursion. Something to be investigated. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
457be51ff6
commit
4009d4c87f
3 changed files with 7 additions and 17 deletions
|
@ -32,7 +32,6 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent) : QWidget(parent, QFlag(0)
|
||||||
ui.tableWidget->setTitle(tr("Dive planner points"));
|
ui.tableWidget->setTitle(tr("Dive planner points"));
|
||||||
ui.tableWidget->setModel(plannerModel);
|
ui.tableWidget->setModel(plannerModel);
|
||||||
connect(ui.tableWidget, &TableView::itemClicked, plannerModel, &DivePlannerPointsModel::remove);
|
connect(ui.tableWidget, &TableView::itemClicked, plannerModel, &DivePlannerPointsModel::remove);
|
||||||
plannerModel->setRecalc(true);
|
|
||||||
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
|
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this));
|
||||||
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DIVEMODE, new DiveTypesDelegate(this));
|
ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DIVEMODE, new DiveTypesDelegate(this));
|
||||||
ui.cylinderTableWidget->setTitle(tr("Available gases"));
|
ui.cylinderTableWidget->setTitle(tr("Available gases"));
|
||||||
|
|
|
@ -221,13 +221,13 @@ bool DivePlannerPointsModel::updateMaxDepth()
|
||||||
|
|
||||||
void DivePlannerPointsModel::removeDeco()
|
void DivePlannerPointsModel::removeDeco()
|
||||||
{
|
{
|
||||||
bool oldrec = setRecalc(false);
|
bool oldrec = std::exchange(recalc, false);
|
||||||
QVector<int> computedPoints;
|
QVector<int> computedPoints;
|
||||||
for (int i = 0; i < rowCount(); i++)
|
for (int i = 0; i < rowCount(); i++)
|
||||||
if (!at(i).entered)
|
if (!at(i).entered)
|
||||||
computedPoints.push_back(i);
|
computedPoints.push_back(i);
|
||||||
removeSelectedPoints(computedPoints);
|
removeSelectedPoints(computedPoints);
|
||||||
setRecalc(oldrec);
|
recalc = oldrec;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivePlannerPointsModel::addCylinder_clicked()
|
void DivePlannerPointsModel::addCylinder_clicked()
|
||||||
|
@ -254,13 +254,6 @@ bool DivePlannerPointsModel::isPlanner() const
|
||||||
/* When the planner adds deco stops to the model, adding those should not trigger a new deco calculation.
|
/* When the planner adds deco stops to the model, adding those should not trigger a new deco calculation.
|
||||||
* We thus start the planner only when recalc is true. */
|
* We thus start the planner only when recalc is true. */
|
||||||
|
|
||||||
bool DivePlannerPointsModel::setRecalc(bool rec)
|
|
||||||
{
|
|
||||||
bool old = recalc;
|
|
||||||
recalc = rec;
|
|
||||||
return old;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DivePlannerPointsModel::recalcQ() const
|
bool DivePlannerPointsModel::recalcQ() const
|
||||||
{
|
{
|
||||||
return recalc;
|
return recalc;
|
||||||
|
@ -456,7 +449,7 @@ DivePlannerPointsModel::DivePlannerPointsModel(QObject *parent) : QAbstractTable
|
||||||
d(nullptr),
|
d(nullptr),
|
||||||
cylinders(true),
|
cylinders(true),
|
||||||
mode(NOTHING),
|
mode(NOTHING),
|
||||||
recalc(false)
|
recalc(true)
|
||||||
{
|
{
|
||||||
memset(&diveplan, 0, sizeof(diveplan));
|
memset(&diveplan, 0, sizeof(diveplan));
|
||||||
startTime.setTimeSpec(Qt::UTC);
|
startTime.setTimeSpec(Qt::UTC);
|
||||||
|
@ -996,14 +989,14 @@ bool DivePlannerPointsModel::tankInUse(int cylinderid) const
|
||||||
|
|
||||||
void DivePlannerPointsModel::clear()
|
void DivePlannerPointsModel::clear()
|
||||||
{
|
{
|
||||||
bool oldRecalc = setRecalc(false);
|
bool oldrec = std::exchange(recalc, false);
|
||||||
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
divepoints.clear();
|
divepoints.clear();
|
||||||
endResetModel();
|
endResetModel();
|
||||||
cylinders.clear();
|
cylinders.clear();
|
||||||
preserved_until.seconds = 0;
|
preserved_until.seconds = 0;
|
||||||
setRecalc(oldRecalc);
|
recalc = oldrec;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivePlannerPointsModel::createTemporaryPlan()
|
void DivePlannerPointsModel::createTemporaryPlan()
|
||||||
|
@ -1240,7 +1233,6 @@ finish:
|
||||||
free(save);
|
free(save);
|
||||||
free(cache);
|
free(cache);
|
||||||
free(dive);
|
free(dive);
|
||||||
// setRecalc(oldRecalc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DivePlannerPointsModel::computeVariationsDone(QString variations)
|
void DivePlannerPointsModel::computeVariationsDone(QString variations)
|
||||||
|
@ -1255,10 +1247,10 @@ void DivePlannerPointsModel::createPlan(bool replanCopy)
|
||||||
{
|
{
|
||||||
// Ok, so, here the diveplan creates a dive
|
// Ok, so, here the diveplan creates a dive
|
||||||
struct deco_state *cache = NULL;
|
struct deco_state *cache = NULL;
|
||||||
bool oldRecalc = setRecalc(false);
|
bool oldrec = std::exchange(recalc, false);
|
||||||
removeDeco();
|
removeDeco();
|
||||||
createTemporaryPlan();
|
createTemporaryPlan();
|
||||||
setRecalc(oldRecalc);
|
recalc = oldrec;
|
||||||
|
|
||||||
//TODO: C-based function here?
|
//TODO: C-based function here?
|
||||||
struct decostop stoptable[60];
|
struct decostop stoptable[60];
|
||||||
|
|
|
@ -41,7 +41,6 @@ public:
|
||||||
bool isPlanner() const;
|
bool isPlanner() const;
|
||||||
void createSimpleDive(struct dive *d);
|
void createSimpleDive(struct dive *d);
|
||||||
Mode currentMode() const;
|
Mode currentMode() const;
|
||||||
bool setRecalc(bool recalc);
|
|
||||||
bool recalcQ() const;
|
bool recalcQ() const;
|
||||||
bool tankInUse(int cylinderid) const;
|
bool tankInUse(int cylinderid) const;
|
||||||
CylindersModel *cylindersModel();
|
CylindersModel *cylindersModel();
|
||||||
|
|
Loading…
Add table
Reference in a new issue