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 <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-02-27 14:59:41 -03:00 committed by Dirk Hohndel
parent 52fe9101c8
commit 250653a67f
2 changed files with 47 additions and 25 deletions

View file

@ -4,10 +4,12 @@
#include <QPainter>
#include <QGraphicsScene>
#include <stdint.h>
#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();
}

View file

@ -4,6 +4,7 @@
#include <QObject>
#include <QGraphicsEllipseItem>
#include <QGraphicsObject>
#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