summaryrefslogtreecommitdiffstats
path: root/profile-widget
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2019-07-06 11:49:29 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2019-11-09 19:19:04 +0100
commitfbd74c26d6652543cbc7331734e304dbf2ef5113 (patch)
treed473a2807097f8e1c04e07d33e94dd7fd067fe38 /profile-widget
parent3025e0630de2b9ced3d0aadd1513cb0e1c93b159 (diff)
downloadsubsurface-fbd74c26d6652543cbc7331734e304dbf2ef5113.tar.gz
Profile: Change RulerItem2 to use index instead of pointer
To make the pressure data dynamic (size of the arrays depending on the cylinders in the dive), it has to be separated from the standard plot_data structure. To enable this, use indexes instead of pointers to plot_data elements. This commit converts the RulerItem2 to use an index. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget')
-rw-r--r--profile-widget/ruleritem.cpp29
-rw-r--r--profile-widget/ruleritem.h2
2 files changed, 15 insertions, 16 deletions
diff --git a/profile-widget/ruleritem.cpp b/profile-widget/ruleritem.cpp
index 3e61790ad..aecbab85b 100644
--- a/profile-widget/ruleritem.cpp
+++ b/profile-widget/ruleritem.cpp
@@ -12,7 +12,7 @@
#include "core/profile.h"
RulerNodeItem2::RulerNodeItem2() :
- entry(NULL),
+ idx(-1),
ruler(NULL),
timeAxis(NULL),
depthAxis(NULL)
@@ -29,7 +29,7 @@ RulerNodeItem2::RulerNodeItem2() :
void RulerNodeItem2::setPlotInfo(const plot_info &info)
{
pInfo = info;
- entry = pInfo.entry;
+ idx = 0;
}
void RulerNodeItem2::setRuler(RulerItem2 *r)
@@ -39,21 +39,20 @@ void RulerNodeItem2::setRuler(RulerItem2 *r)
void RulerNodeItem2::recalculate()
{
- struct plot_data *data = pInfo.entry + (pInfo.nr - 1);
- uint16_t count = 0;
+ if (pInfo.nr <= 0)
+ return;
+
+ const struct plot_data &last = pInfo.entry[pInfo.nr - 1];
if (x() < 0) {
setPos(0, y());
- } else if (x() > timeAxis->posAtValue(data->sec)) {
- setPos(timeAxis->posAtValue(data->sec), depthAxis->posAtValue(data->depth));
+ } else if (x() > timeAxis->posAtValue(last.sec)) {
+ setPos(timeAxis->posAtValue(last.sec), depthAxis->posAtValue(last.depth));
} else {
- data = pInfo.entry;
- count = 0;
- while (timeAxis->posAtValue(data->sec) < x() && count < pInfo.nr) {
- data = pInfo.entry + count;
- count++;
- }
- setPos(timeAxis->posAtValue(data->sec), depthAxis->posAtValue(data->depth));
- entry = data;
+ idx = 0;
+ while (idx < pInfo.nr && timeAxis->posAtValue(pInfo.entry[idx].sec) < x())
+ ++idx;
+ const struct plot_data &data = pInfo.entry[idx];
+ setPos(timeAxis->posAtValue(data.sec), depthAxis->posAtValue(data.depth));
}
}
@@ -117,7 +116,7 @@ void RulerItem2::recalculate()
}
QLineF line(startPoint, endPoint);
setLine(line);
- compare_samples(source->entry, dest->entry, buffer, 500, 1);
+ compare_samples(&pInfo.entry[source->idx], &pInfo.entry[dest->idx], buffer, 500, 1);
text = QString(buffer);
// draw text
diff --git a/profile-widget/ruleritem.h b/profile-widget/ruleritem.h
index 2c7c5b3ea..dd028fc1f 100644
--- a/profile-widget/ruleritem.h
+++ b/profile-widget/ruleritem.h
@@ -25,7 +25,7 @@ protected:
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
private:
struct plot_info pInfo;
- struct plot_data *entry;
+ int idx;
RulerItem2 *ruler;
DiveCartesianAxis *timeAxis;
DiveCartesianAxis *depthAxis;