aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Stefan Fuchs <sfuchs@gmx.de>2017-10-11 21:29:47 +0200
committerGravatar Robert C. Helling <helling@atdotde.de>2017-10-16 17:14:17 +0200
commit24bd5a8dcebec886b8fbbf077fabfb2106dc7dcd (patch)
tree35c03fc280dab0a09ccb2f59939f0a1d93595aaf
parent73d2ab8099ce08ab20f119a126334463ffd41b1e (diff)
downloadsubsurface-24bd5a8dcebec886b8fbbf077fabfb2106dc7dcd.tar.gz
Planner: Autom. move first datapoint gas to first gaslist position
In the planner it is best practise to start the dive with the first gas in the gaslist. Otherwise one would get a gaschange event at the very beginning of a dive. This change implements the following feature: Automatically move a gas to position 0 in the gaslist if the user selects this gas for the first dive data point. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
-rw-r--r--qt-models/cylindermodel.cpp21
-rw-r--r--qt-models/cylindermodel.h1
-rw-r--r--qt-models/diveplannermodel.cpp3
3 files changed, 25 insertions, 0 deletions
diff --git a/qt-models/cylindermodel.cpp b/qt-models/cylindermodel.cpp
index 6408342bc..ca5e74cff 100644
--- a/qt-models/cylindermodel.cpp
+++ b/qt-models/cylindermodel.cpp
@@ -581,6 +581,27 @@ void CylindersModel::remove(const QModelIndex &index)
dataChanged(index, index);
}
+void CylindersModel::moveAtFirst(int cylid)
+{
+ int mapping[MAX_CYLINDERS];
+ cylinder_t temp_cyl;
+
+ beginMoveRows(QModelIndex(), cylid, cylid, QModelIndex(), 0);
+ memmove(&temp_cyl, &displayed_dive.cylinder[cylid], sizeof(temp_cyl));
+ for (int i = cylid - 1; i >= 0; i--) {
+ memmove(&displayed_dive.cylinder[i + 1], &displayed_dive.cylinder[i], sizeof(temp_cyl));
+ mapping[i] = i + 1;
+ }
+ memmove(&displayed_dive.cylinder[0], &temp_cyl, sizeof(temp_cyl));
+ mapping[cylid] = 0;
+ for (int i = cylid + 1; i < MAX_CYLINDERS; i++)
+ mapping[i] = i;
+ changed = true;
+ endMoveRows();
+ cylinder_renumber(&displayed_dive, mapping);
+ DivePlannerPointsModel::instance()->cylinderRenumber(mapping);
+}
+
void CylindersModel::updateDecoDepths(pressure_t olddecopo2)
{
pressure_t decopo2;
diff --git a/qt-models/cylindermodel.h b/qt-models/cylindermodel.h
index d77cd84dd..502780a6d 100644
--- a/qt-models/cylindermodel.h
+++ b/qt-models/cylindermodel.h
@@ -40,6 +40,7 @@ public:
void copyFromDive(struct dive *d);
void updateDecoDepths(pressure_t olddecopo2);
void updateTrashIcon();
+ void moveAtFirst(int cylid);
cylinder_t *cylinderAt(const QModelIndex &index);
bool changed;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp
index 5fc692a38..cd237f950 100644
--- a/qt-models/diveplannermodel.cpp
+++ b/qt-models/diveplannermodel.cpp
@@ -337,6 +337,9 @@ bool DivePlannerPointsModel::setData(const QModelIndex &index, const QVariant &v
case GAS:
if (value.toInt() >= 0 && value.toInt() < MAX_CYLINDERS)
p.cylinderid = value.toInt();
+ /* Did we change the start (dp 0) cylinder to another cylinderid than 0? */
+ if (value.toInt() != 0 && index.row() == 0)
+ CylindersModel::instance()->moveAtFirst(value.toInt());
CylindersModel::instance()->updateTrashIcon();
break;
}