summaryrefslogtreecommitdiffstats
path: root/profile-widget
diff options
context:
space:
mode:
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;