mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
3025e0630d
commit
fbd74c26d6
2 changed files with 15 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue