summaryrefslogtreecommitdiffstats
path: root/profile-widget/diveprofileitem.cpp
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-08-04 18:44:57 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-11-09 19:19:04 +0100
commit7c9f46acd202121e67557bb634961ef17a9f6c1f (patch)
treef21b6ff42a930cc97c31db9f20c03f1613e70291 /profile-widget/diveprofileitem.cpp
parentcd4f66014f7b5269dff9e088c9d7d38241c03156 (diff)
downloadsubsurface-7c9f46acd202121e67557bb634961ef17a9f6c1f.tar.gz
Core: remove MAX_CYLINDERS restriction
Instead of using fixed size arrays, use a new cylinder_table structure. The code copies the weightsystem code, but is significantly more complex because cylinders are such an integral part of the core. Two functions to access the cylinders were added: get_cylinder() and get_or_create_cylinder() The former does a simple array access and supposes that the cylinder exists. The latter is used by the parser(s) and if a cylinder with the given id does not exist, cylinders up to that id are generated. One point will make C programmers cringe: the cylinder structure is passed by value. This is due to the way the table-macros work. A refactoring of the table macros is planned. It has to be noted that the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit architecture, so passing on the stack is probably not even significantly slower than passing as reference. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget/diveprofileitem.cpp')
-rw-r--r--profile-widget/diveprofileitem.cpp26
1 files changed, 13 insertions, 13 deletions
diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp
index bc74f7f40..3d0ba2e7a 100644
--- a/profile-widget/diveprofileitem.cpp
+++ b/profile-widget/diveprofileitem.cpp
@@ -659,17 +659,17 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo
if (!shouldCalculateStuff(topLeft, bottomRight))
return;
- std::vector<int> plotted_cyl(MAX_CYLINDERS, false);
- std::vector<int> last_plotted(MAX_CYLINDERS, 0);
- std::vector<QPolygonF> poly(MAX_CYLINDERS);
+ const struct plot_info *pInfo = &dataModel->data();
+ std::vector<int> plotted_cyl(pInfo->nr_cylinders, false);
+ std::vector<int> last_plotted(pInfo->nr_cylinders, 0);
+ std::vector<QPolygonF> poly(pInfo->nr_cylinders);
QPolygonF boundingPoly;
polygons.clear();
- const struct plot_info *pInfo = &dataModel->data();
for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
const struct plot_data *entry = pInfo->entry + i;
- for (int cyl = 0; cyl < MAX_CYLINDERS; cyl++) {
+ for (int cyl = 0; cyl < pInfo->nr_cylinders; cyl++) {
int mbar = get_plot_pressure(pInfo, i, cyl);
int time = entry->sec;
@@ -698,7 +698,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo
}
}
- for (int cyl = 0; cyl < MAX_CYLINDERS; cyl++) {
+ for (int cyl = 0; cyl < pInfo->nr_cylinders; cyl++) {
if (!plotted_cyl[cyl])
continue;
polygons.append(poly[cyl]);
@@ -708,9 +708,9 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo
qDeleteAll(texts);
texts.clear();
- std::vector<int> seen_cyl(MAX_CYLINDERS, false);
- std::vector<int> last_pressure(MAX_CYLINDERS, 0);
- std::vector<int> last_time(MAX_CYLINDERS, 0);
+ std::vector<int> seen_cyl(pInfo->nr_cylinders, false);
+ std::vector<int> last_pressure(pInfo->nr_cylinders, 0);
+ std::vector<int> last_time(pInfo->nr_cylinders, 0);
// These are offset values used to print the gas lables and pressures on a
// dive profile at appropriate Y-coordinates. We alternate aligning the
@@ -721,7 +721,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo
// pressures.
QFlags<Qt::AlignmentFlag> alignVar = Qt::AlignTop;
- std::vector<QFlags<Qt::AlignmentFlag>> align(MAX_CYLINDERS);
+ std::vector<QFlags<Qt::AlignmentFlag>> align(pInfo->nr_cylinders);
double axisRange = (vAxis->maximum() - vAxis->minimum())/1000; // Convert axis pressure range to bar
double axisLog = log10(log10(axisRange));
@@ -729,7 +729,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo
for (int i = 0, count = dataModel->rowCount(); i < count; i++) {
const struct plot_data *entry = pInfo->entry + i;
- for (int cyl = 0; cyl < MAX_CYLINDERS; cyl++) {
+ for (int cyl = 0; cyl < pInfo->nr_cylinders; cyl++) {
int mbar = get_plot_pressure(pInfo, i, cyl);
if (!mbar)
@@ -748,7 +748,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo
label_y_offset = -7 * axisLog;
}
plotPressureValue(mbar, entry->sec, alignVar, value_y_offset);
- plotGasValue(mbar, entry->sec, displayed_dive.cylinder[cyl].gasmix, alignVar, label_y_offset);
+ plotGasValue(mbar, entry->sec, displayed_dive.cylinders.cylinders[cyl].gasmix, alignVar, label_y_offset);
seen_cyl[cyl] = true;
/* Alternate alignment as we see cylinder use.. */
@@ -761,7 +761,7 @@ void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QMo
}
// For each cylinder, on right hand side of profile, write cylinder pressure
- for (int cyl = 0; cyl < MAX_CYLINDERS; cyl++) {
+ for (int cyl = 0; cyl < pInfo->nr_cylinders; cyl++) {
if (last_time[cyl]) {
double value_y_offset = -0.5;
plotPressureValue(last_pressure[cyl], last_time[cyl], align[cyl] | Qt::AlignLeft, value_y_offset);