mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
profile: only keep pointer to plot_info in ruler objects
Now this one was strange: The ruler items keep a copy of the plot_info struct. However, only a shallow copy is made (the actual plot data is not copied). This means that the data is only valid as long as the source plot_info is valid. But if that is guaranteed, we simply can keep a pointer instead of the full object. I wonder if it wouldn't be better still to keep a pointer to the profile and query that for the plot info? Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
f9b9582a64
commit
ed83f6ce32
2 changed files with 14 additions and 14 deletions
|
@ -8,12 +8,12 @@
|
||||||
#include "core/profile.h"
|
#include "core/profile.h"
|
||||||
|
|
||||||
RulerNodeItem2::RulerNodeItem2() :
|
RulerNodeItem2::RulerNodeItem2() :
|
||||||
|
pInfo(NULL),
|
||||||
idx(-1),
|
idx(-1),
|
||||||
ruler(NULL),
|
ruler(NULL),
|
||||||
timeAxis(NULL),
|
timeAxis(NULL),
|
||||||
depthAxis(NULL)
|
depthAxis(NULL)
|
||||||
{
|
{
|
||||||
init_plot_info(&pInfo);
|
|
||||||
setRect(-8, -8, 16, 16);
|
setRect(-8, -8, 16, 16);
|
||||||
setBrush(QColor(0xff, 0, 0, 127));
|
setBrush(QColor(0xff, 0, 0, 127));
|
||||||
setPen(QColor(Qt::red));
|
setPen(QColor(Qt::red));
|
||||||
|
@ -24,7 +24,7 @@ RulerNodeItem2::RulerNodeItem2() :
|
||||||
|
|
||||||
void RulerNodeItem2::setPlotInfo(const plot_info &info)
|
void RulerNodeItem2::setPlotInfo(const plot_info &info)
|
||||||
{
|
{
|
||||||
pInfo = info;
|
pInfo = &info;
|
||||||
idx = 0;
|
idx = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,19 +35,19 @@ void RulerNodeItem2::setRuler(RulerItem2 *r)
|
||||||
|
|
||||||
void RulerNodeItem2::recalculate()
|
void RulerNodeItem2::recalculate()
|
||||||
{
|
{
|
||||||
if (pInfo.nr <= 0)
|
if (!pInfo || pInfo->nr <= 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const struct plot_data &last = pInfo.entry[pInfo.nr - 1];
|
const struct plot_data &last = pInfo->entry[pInfo->nr - 1];
|
||||||
if (x() < 0) {
|
if (x() < 0) {
|
||||||
setPos(0, y());
|
setPos(0, y());
|
||||||
} else if (x() > timeAxis->posAtValue(last.sec)) {
|
} else if (x() > timeAxis->posAtValue(last.sec)) {
|
||||||
setPos(timeAxis->posAtValue(last.sec), depthAxis->posAtValue(last.depth));
|
setPos(timeAxis->posAtValue(last.sec), depthAxis->posAtValue(last.depth));
|
||||||
} else {
|
} else {
|
||||||
idx = 0;
|
idx = 0;
|
||||||
while (idx < pInfo.nr && timeAxis->posAtValue(pInfo.entry[idx].sec) < x())
|
while (idx < pInfo->nr && timeAxis->posAtValue(pInfo->entry[idx].sec) < x())
|
||||||
++idx;
|
++idx;
|
||||||
const struct plot_data &data = pInfo.entry[idx];
|
const struct plot_data &data = pInfo->entry[idx];
|
||||||
setPos(timeAxis->posAtValue(data.sec), depthAxis->posAtValue(data.depth));
|
setPos(timeAxis->posAtValue(data.sec), depthAxis->posAtValue(data.depth));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,14 +62,14 @@ void RulerNodeItem2::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
|
||||||
ruler->recalculate();
|
ruler->recalculate();
|
||||||
}
|
}
|
||||||
|
|
||||||
RulerItem2::RulerItem2() : source(new RulerNodeItem2()),
|
RulerItem2::RulerItem2() : pInfo(NULL),
|
||||||
|
source(new RulerNodeItem2()),
|
||||||
dest(new RulerNodeItem2()),
|
dest(new RulerNodeItem2()),
|
||||||
timeAxis(NULL),
|
timeAxis(NULL),
|
||||||
depthAxis(NULL),
|
depthAxis(NULL),
|
||||||
textItemBack(new QGraphicsRectItem(this)),
|
textItemBack(new QGraphicsRectItem(this)),
|
||||||
textItem(new QGraphicsSimpleTextItem(this))
|
textItem(new QGraphicsSimpleTextItem(this))
|
||||||
{
|
{
|
||||||
memset(&pInfo, 0, sizeof(pInfo));
|
|
||||||
source->setRuler(this);
|
source->setRuler(this);
|
||||||
dest->setRuler(this);
|
dest->setRuler(this);
|
||||||
textItem->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
textItem->setFlag(QGraphicsItem::ItemIgnoresTransformations);
|
||||||
|
@ -98,7 +98,7 @@ void RulerItem2::recalculate()
|
||||||
QFont font;
|
QFont font;
|
||||||
QFontMetrics fm(font);
|
QFontMetrics fm(font);
|
||||||
|
|
||||||
if (timeAxis == NULL || depthAxis == NULL || pInfo.nr == 0)
|
if (timeAxis == NULL || depthAxis == NULL || !pInfo || pInfo->nr == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
|
@ -112,7 +112,7 @@ void RulerItem2::recalculate()
|
||||||
}
|
}
|
||||||
QLineF line(startPoint, endPoint);
|
QLineF line(startPoint, endPoint);
|
||||||
setLine(line);
|
setLine(line);
|
||||||
compare_samples(dive, &pInfo, source->idx, dest->idx, buffer, 500, 1);
|
compare_samples(dive, pInfo, source->idx, dest->idx, buffer, 500, 1);
|
||||||
text = QString(buffer);
|
text = QString(buffer);
|
||||||
|
|
||||||
// draw text
|
// draw text
|
||||||
|
@ -150,7 +150,7 @@ RulerNodeItem2 *RulerItem2::destNode() const
|
||||||
void RulerItem2::setPlotInfo(const struct dive *d, const plot_info &info)
|
void RulerItem2::setPlotInfo(const struct dive *d, const plot_info &info)
|
||||||
{
|
{
|
||||||
dive = d;
|
dive = d;
|
||||||
pInfo = info;
|
pInfo = &info;
|
||||||
dest->setPlotInfo(info);
|
dest->setPlotInfo(info);
|
||||||
source->setPlotInfo(info);
|
source->setPlotInfo(info);
|
||||||
dest->recalculate();
|
dest->recalculate();
|
||||||
|
|
|
@ -6,9 +6,9 @@
|
||||||
#include <QGraphicsEllipseItem>
|
#include <QGraphicsEllipseItem>
|
||||||
#include <QGraphicsObject>
|
#include <QGraphicsObject>
|
||||||
#include "profile-widget/divecartesianaxis.h"
|
#include "profile-widget/divecartesianaxis.h"
|
||||||
#include "core/profile.h"
|
|
||||||
|
|
||||||
struct plot_data;
|
struct plot_data;
|
||||||
|
struct plot_info;
|
||||||
class RulerItem2;
|
class RulerItem2;
|
||||||
|
|
||||||
class RulerNodeItem2 : public QObject, public QGraphicsEllipseItem {
|
class RulerNodeItem2 : public QObject, public QGraphicsEllipseItem {
|
||||||
|
@ -23,7 +23,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
|
||||||
struct plot_info pInfo;
|
const struct plot_info *pInfo;
|
||||||
int idx;
|
int idx;
|
||||||
RulerItem2 *ruler;
|
RulerItem2 *ruler;
|
||||||
DiveCartesianAxis *timeAxis;
|
DiveCartesianAxis *timeAxis;
|
||||||
|
@ -48,7 +48,7 @@ slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const struct dive *dive;
|
const struct dive *dive;
|
||||||
struct plot_info pInfo;
|
const struct plot_info *pInfo;
|
||||||
QPointF startPoint, endPoint;
|
QPointF startPoint, endPoint;
|
||||||
RulerNodeItem2 *source, *dest;
|
RulerNodeItem2 *source, *dest;
|
||||||
QString text;
|
QString text;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue