1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 19:55:53 +01:00
GPXSee/src/GUI/graphitem.h

97 lines
2.1 KiB
C
Raw Normal View History

#ifndef GRAPHITEM_H
#define GRAPHITEM_H
2016-09-19 00:56:10 +02:00
#include <QGraphicsObject>
#include <QPen>
2017-11-26 18:54:03 +01:00
#include "data/graph.h"
#include "units.h"
#include "graphicsscene.h"
class GraphItem : public QObject, public GraphicsItem
{
2016-09-19 00:56:10 +02:00
Q_OBJECT
public:
struct SegmentTime
{
SegmentTime() : time(NAN) {}
SegmentTime(const QDateTime &date, qreal time)
: date(date), time(time) {}
QDateTime date;
qreal time;
};
GraphItem(const Graph &graph, GraphType type, int width,
const QColor &color, Qt::PenStyle style, QGraphicsItem *parent = 0);
2018-03-08 00:57:09 +01:00
virtual ~GraphItem() {}
2016-09-19 00:56:10 +02:00
virtual ToolTip info() const = 0;
QPainterPath shape() const {return _shape;}
QRectF boundingRect() const {return _shape.boundingRect();}
2016-09-19 00:56:10 +02:00
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget);
GraphType graphType() const {return _type;}
const QRectF &bounds() const {return _bounds;}
2019-02-11 23:28:08 +01:00
qreal max() const;
qreal min() const;
qreal avg() const;
2017-10-04 23:15:39 +02:00
void setScale(qreal sx, qreal sy);
2016-09-25 18:08:39 +02:00
void setGraphType(GraphType type);
2016-08-19 19:48:44 +02:00
void setColor(const QColor &color);
2016-12-06 01:48:26 +01:00
void setWidth(int width);
void setUnits(Units units) {_units = units;}
2022-09-25 02:15:24 +02:00
void updateStyle();
GraphItem *secondaryGraph() const {return _secondaryGraph;}
void setSecondaryGraph(GraphItem *graph) {_secondaryGraph = graph;}
qreal yAtX(qreal x) const;
qreal distanceAtTime(qreal time) const;
qreal timeAtDistance(qreal distance) const;
SegmentTime date(qreal x);
2016-09-19 00:56:10 +02:00
2017-10-04 23:15:39 +02:00
void redraw();
2016-09-19 00:56:10 +02:00
signals:
void selected(bool);
2016-09-19 00:56:10 +02:00
public slots:
void hover(bool hover);
2016-09-19 00:56:10 +02:00
protected:
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void mousePressEvent(QGraphicsSceneMouseEvent *event);
Units _units;
private:
2019-02-11 23:28:08 +01:00
const GraphSegment *segment(qreal x, GraphType type) const;
void updatePath();
void updateShape();
void updateBounds();
2022-09-25 02:15:24 +02:00
void updateColor();
const QColor &color() const;
Graph _graph;
2022-09-25 02:15:24 +02:00
QColor _color;
2016-09-19 23:35:04 +02:00
GraphType _type;
2022-09-25 02:15:24 +02:00
qreal _sx, _sy;
QPainterPath _path;
QPainterPath _shape;
QRectF _bounds;
QPen _pen;
2017-05-22 18:42:23 +02:00
bool _time;
GraphItem *_secondaryGraph;
};
#endif // GRAPHITEM_H