From 250653a67f11517acd52fd0e933de03452d96031 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 27 Feb 2014 14:59:41 -0300 Subject: New profile: DiveRuler compiles / not working yet. This patch removes the GC macros and change the calling to use the DiveCartesianAxis. Signed-off-by: Tomaz Canabrava Signed-off-by: Dirk Hohndel --- qt-ui/profile/ruleritem.cpp | 58 +++++++++++++++++++++++++++++---------------- qt-ui/profile/ruleritem.h | 14 +++++++---- 2 files changed, 47 insertions(+), 25 deletions(-) (limited to 'qt-ui') diff --git a/qt-ui/profile/ruleritem.cpp b/qt-ui/profile/ruleritem.cpp index b7b3a8229..e3362adea 100644 --- a/qt-ui/profile/ruleritem.cpp +++ b/qt-ui/profile/ruleritem.cpp @@ -4,10 +4,12 @@ #include #include +#include + #include "profile.h" #include "display.h" -RulerNodeItem2::RulerNodeItem2(QGraphicsItem *parent) : QGraphicsEllipseItem(parent), entry(NULL) , ruler(NULL) +RulerNodeItem2::RulerNodeItem2() : entry(NULL) , ruler(NULL) { setRect(QRect(QPoint(-8,8),QPoint(8,-8))); setBrush(QColor(0xff, 0, 0, 127)); @@ -24,23 +26,22 @@ void RulerNodeItem2::setRuler(RulerItem2 *r) void RulerNodeItem2::recalculate() { - // Port that away from the SCALEGC - //struct plot_info *pi = &gc.pi; - //struct plot_data *data = pi->entry+(pi->nr-1); - //uint16_t count = 0; -// if (x() < 0) { -// setPos(0, y()); -// } else if (x() > SCALEXGC(data->sec)) { -// setPos(SCALEXGC(data->sec), y()); -// } else { -// data = pi->entry; -// count=0; -// while (SCALEXGC(data->sec) < x() && count < pi->nr) { -// data = pi->entry+count; -// count++; -// } -// setPos(SCALEGC(data->sec, data->depth)); -// entry=data; + struct plot_data *data = pInfo->entry+(pInfo->nr-1); + uint16_t count = 0; + if (x() < 0) { + setPos(0, y()); + } else if (x() > timeAxis->posAtValue(data->sec)) { + setPos(timeAxis->posAtValue(data->sec), y()); + } 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; + } } QVariant RulerNodeItem2::itemChange(GraphicsItemChange change, const QVariant &value) @@ -56,9 +57,16 @@ QVariant RulerNodeItem2::itemChange(GraphicsItemChange change, const QVariant &v return QGraphicsEllipseItem::itemChange(change, value); } -RulerItem2::RulerItem2(QGraphicsItem *parent, RulerNodeItem2 *sourceNode, RulerNodeItem2 *destNode) : QGraphicsObject(parent), source(sourceNode), dest(destNode) +RulerItem2::RulerItem2(): + pInfo(NULL), + timeAxis(NULL), + depthAxis(NULL), + source(new RulerNodeItem2()), + dest(new RulerNodeItem2()) { - recalculate(); + + source->setRuler(this); + dest->setRuler(this); } void RulerItem2::recalculate() @@ -68,7 +76,7 @@ void RulerItem2::recalculate() QFont font; QFontMetrics fm(font); - if (source == NULL || dest == NULL) + if (timeAxis == NULL || depthAxis == NULL || pInfo == NULL) return; prepareGeometryChange(); @@ -159,3 +167,11 @@ QPainterPath RulerItem2::shape() const path.lineTo(startPoint); return path; } + +void RulerItem2::setPlotInfo(plot_info* info) +{ + pInfo = info; + dest->pInfo = info; + source->pInfo = info; + recalculate(); +} diff --git a/qt-ui/profile/ruleritem.h b/qt-ui/profile/ruleritem.h index 68d6c3180..29b79231d 100644 --- a/qt-ui/profile/ruleritem.h +++ b/qt-ui/profile/ruleritem.h @@ -4,6 +4,7 @@ #include #include #include +#include "divecartesianaxis.h" struct plot_data; class RulerItem2; @@ -13,7 +14,7 @@ class RulerNodeItem2 : public QObject, public QGraphicsEllipseItem Q_OBJECT friend class RulerItem2; public: - explicit RulerNodeItem2(QGraphicsItem* parent); + explicit RulerNodeItem2(); void setRuler(RulerItem2 *r); void recalculate(); @@ -21,19 +22,21 @@ protected: QVariant itemChange(GraphicsItemChange change, const QVariant & value ); private: + struct plot_info *pInfo; struct plot_data *entry; RulerItem2* ruler; + DiveCartesianAxis *timeAxis; + DiveCartesianAxis *depthAxis; }; class RulerItem2 : public QGraphicsObject { Q_OBJECT public: - explicit RulerItem2(QGraphicsItem* parent, - RulerNodeItem2 *sourceMarker, - RulerNodeItem2 *destMarker); + explicit RulerItem2(); void recalculate(); + void setPlotInfo(struct plot_info *pInfo); RulerNodeItem2* sourceNode() const; RulerNodeItem2* destNode() const; void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget * widget = 0); @@ -41,10 +44,13 @@ public: QPainterPath shape() const; private: + struct plot_info *pInfo; QPointF startPoint, endPoint; RulerNodeItem2 *source, *dest; QString text; int height; int paint_direction; + DiveCartesianAxis *timeAxis; + DiveCartesianAxis *depthAxis; }; #endif \ No newline at end of file -- cgit v1.2.3-70-g09d2