mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 23:03:23 +00:00
Connect changes in the tanks with the dive that is being added
- you can no longer delete a tank when its gas is in use - therefore you can no longer delete the last tank - when you change the gas mix of a tank, the corresponding segments in the dive change as well - when changing gas for a segment the correct available gases are offered Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
aa76d35923
commit
d7fb6853a3
3 changed files with 83 additions and 2 deletions
|
@ -1263,6 +1263,64 @@ DivePlannerPointsModel::Mode DivePlannerPointsModel::currentMode() const
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<QPair<int, int> > DivePlannerPointsModel::collectGases(struct dive *d)
|
||||||
|
{
|
||||||
|
QList<QPair<int, int> > l;
|
||||||
|
for (int i = 0; i < MAX_CYLINDERS; i++) {
|
||||||
|
cylinder_t *cyl = &d->cylinder[i];
|
||||||
|
if (!cylinder_nodata(cyl))
|
||||||
|
l.push_back(QPair<int, int>(cyl->gasmix.o2.permille, cyl->gasmix.he.permille));
|
||||||
|
}
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
void DivePlannerPointsModel::rememberTanks()
|
||||||
|
{
|
||||||
|
oldGases = collectGases(stagingDive);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DivePlannerPointsModel::tankInUse(int o2, int he)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < rowCount(); j++) {
|
||||||
|
divedatapoint& p = divepoints[j];
|
||||||
|
if (p.time == 0) // special entries that hold the available gases
|
||||||
|
continue;
|
||||||
|
if ((p.o2 == o2 && p.he == he) ||
|
||||||
|
(is_air(p.o2, p.he) && is_air(o2, he)))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DivePlannerPointsModel::tanksUpdated()
|
||||||
|
{
|
||||||
|
if (mode == ADD) {
|
||||||
|
// we don't know exactly what changed - what we care about is
|
||||||
|
// "did a gas change on us". So we look through the diveplan to
|
||||||
|
// see if there is a gas that is now missing and if there is, we
|
||||||
|
// replace it with the matching new gas.
|
||||||
|
QList<QPair<int,int> > gases = collectGases(stagingDive);
|
||||||
|
if (gases.length() == oldGases.length()) {
|
||||||
|
// either nothing relevant changed, or exactly ONE gasmix changed
|
||||||
|
for (int i = 0; i < gases.length(); i++) {
|
||||||
|
if (gases.at(i) != oldGases.at(i)) {
|
||||||
|
for (int j = 0; j < rowCount(); j++) {
|
||||||
|
divedatapoint& p = divepoints[j];
|
||||||
|
int o2 = oldGases.at(i).first;
|
||||||
|
int he = oldGases.at(i).second;
|
||||||
|
if (p.o2 == o2 && p.he == he ||
|
||||||
|
(is_air(p.o2, p.he) && (is_air(o2, he) || (o2 == 0 && he == 0)))) {
|
||||||
|
p.o2 = gases.at(i).first;
|
||||||
|
p.he = gases.at(i).second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emit dataChanged(createIndex(0, 0), createIndex(rowCount()-1, COLUMNS-1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DivePlannerPointsModel::clear()
|
void DivePlannerPointsModel::clear()
|
||||||
{
|
{
|
||||||
if (mode == ADD) {
|
if (mode == ADD) {
|
||||||
|
@ -1312,8 +1370,8 @@ void DivePlannerPointsModel::createTemporaryPlan()
|
||||||
#endif
|
#endif
|
||||||
plan(&diveplan, &cache, &tempDive, isPlanner(), &errorString);
|
plan(&diveplan, &cache, &tempDive, isPlanner(), &errorString);
|
||||||
if (mode == ADD) {
|
if (mode == ADD) {
|
||||||
|
// copy the samples and events, but don't overwrite the cylinders
|
||||||
copy_samples(tempDive, current_dive);
|
copy_samples(tempDive, current_dive);
|
||||||
copy_cylinders(tempDive, current_dive);
|
|
||||||
copy_events(tempDive, current_dive);
|
copy_events(tempDive, current_dive);
|
||||||
}
|
}
|
||||||
#if DEBUG_PLAN
|
#if DEBUG_PLAN
|
||||||
|
|
|
@ -34,6 +34,9 @@ public:
|
||||||
void createSimpleDive();
|
void createSimpleDive();
|
||||||
void clear();
|
void clear();
|
||||||
Mode currentMode() const;
|
Mode currentMode() const;
|
||||||
|
void tanksUpdated();
|
||||||
|
void rememberTanks();
|
||||||
|
bool tankInUse(int o2, int he);
|
||||||
/**
|
/**
|
||||||
* @return the row number.
|
* @return the row number.
|
||||||
*/
|
*/
|
||||||
|
@ -42,6 +45,8 @@ public:
|
||||||
int size();
|
int size();
|
||||||
struct diveplan getDiveplan();
|
struct diveplan getDiveplan();
|
||||||
QStringList &getGasList();
|
QStringList &getGasList();
|
||||||
|
QList<QPair<int, int> > collectGases(dive *d);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
int addStop(int meters = 0, int minutes = 0, int o2 = 0, int he = 0, int ccpoint = 0 );
|
int addStop(int meters = 0, int minutes = 0, int o2 = 0, int he = 0, int ccpoint = 0 );
|
||||||
void addCylinder_clicked();
|
void addCylinder_clicked();
|
||||||
|
@ -73,6 +78,7 @@ private:
|
||||||
void deleteTemporaryPlan(struct divedatapoint *dp);
|
void deleteTemporaryPlan(struct divedatapoint *dp);
|
||||||
QVector<sample> backupSamples; // For editing added dives.
|
QVector<sample> backupSamples; // For editing added dives.
|
||||||
struct dive *stagingDive;
|
struct dive *stagingDive;
|
||||||
|
QList<QPair<int, int> > oldGases;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Button : public QObject, public QGraphicsRectItem {
|
class Button : public QObject, public QGraphicsRectItem {
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#include "models.h"
|
#include "models.h"
|
||||||
|
#include "diveplanner.h"
|
||||||
|
#include "mainwindow.h"
|
||||||
#include "../helpers.h"
|
#include "../helpers.h"
|
||||||
#include "../dive.h"
|
#include "../dive.h"
|
||||||
#include "../device.h"
|
#include "../device.h"
|
||||||
|
@ -17,6 +19,7 @@
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
#include <QFont>
|
#include <QFont>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
QFont defaultModelFont()
|
QFont defaultModelFont()
|
||||||
{
|
{
|
||||||
|
@ -196,6 +199,10 @@ void CylindersModel::passInData(const QModelIndex& index, const QVariant& value)
|
||||||
|
|
||||||
bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, int role)
|
||||||
{
|
{
|
||||||
|
bool addDiveMode = DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING;
|
||||||
|
if (addDiveMode)
|
||||||
|
DivePlannerPointsModel::instance()->rememberTanks();
|
||||||
|
|
||||||
cylinder_t *cyl = cylinderAt(index);
|
cylinder_t *cyl = cylinderAt(index);
|
||||||
switch(index.column()) {
|
switch(index.column()) {
|
||||||
case TYPE:
|
case TYPE:
|
||||||
|
@ -296,6 +303,8 @@ bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, in
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dataChanged(index, index);
|
dataChanged(index, index);
|
||||||
|
if (addDiveMode)
|
||||||
|
DivePlannerPointsModel::instance()->tanksUpdated();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +320,7 @@ void CylindersModel::add()
|
||||||
}
|
}
|
||||||
|
|
||||||
int row = rows;
|
int row = rows;
|
||||||
|
fill_default_cylinder(¤t->cylinder[row]);
|
||||||
beginInsertRows(QModelIndex(), row, row);
|
beginInsertRows(QModelIndex(), row, row);
|
||||||
rows++;
|
rows++;
|
||||||
changed = true;
|
changed = true;
|
||||||
|
@ -366,6 +375,14 @@ void CylindersModel::remove(const QModelIndex& index)
|
||||||
if (index.column() != REMOVE) {
|
if (index.column() != REMOVE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
cylinder_t *cyl = ¤t->cylinder[index.row()];
|
||||||
|
if (DivePlannerPointsModel::instance()->tankInUse(cyl->gasmix.o2.permille, cyl->gasmix.he.permille)) {
|
||||||
|
QMessageBox::warning(mainWindow(),
|
||||||
|
tr("Cylinder cannot be removed"),
|
||||||
|
tr("This gas in use. Only cylinders that are not used in the dive can be removed."),
|
||||||
|
QMessageBox::Ok);
|
||||||
|
return;
|
||||||
|
}
|
||||||
beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly.
|
beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly.
|
||||||
rows--;
|
rows--;
|
||||||
remove_cylinder(current, index.row());
|
remove_cylinder(current, index.row());
|
||||||
|
|
Loading…
Add table
Reference in a new issue