2016-08-16 00:27:54 +02:00
|
|
|
#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"
|
2017-09-24 19:54:13 +02:00
|
|
|
#include "units.h"
|
2019-10-15 23:59:15 +02:00
|
|
|
#include "graphicsscene.h"
|
2016-08-16 00:27:54 +02:00
|
|
|
|
2019-10-15 23:59:15 +02:00
|
|
|
class GraphItem : public QObject, public GraphicsItem
|
2016-08-16 00:27:54 +02:00
|
|
|
{
|
2016-09-19 00:56:10 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2016-08-16 00:27:54 +02:00
|
|
|
public:
|
2020-03-25 23:08:26 +01:00
|
|
|
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
|
|
|
|
2021-08-04 08:57:42 +02:00
|
|
|
virtual ToolTip info() const = 0;
|
2019-10-13 20:20:32 +02:00
|
|
|
|
2017-09-24 19:54:13 +02:00
|
|
|
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);
|
2016-08-16 00:27:54 +02:00
|
|
|
|
2021-01-17 16:02:37 +01:00
|
|
|
GraphType graphType() const {return _type;}
|
2016-10-12 20:38:18 +02:00
|
|
|
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);
|
2019-10-13 20:20:32 +02:00
|
|
|
void setUnits(Units units) {_units = units;}
|
2022-09-25 02:15:24 +02:00
|
|
|
void updateStyle();
|
2016-08-16 00:27:54 +02:00
|
|
|
|
2020-03-25 23:08:26 +01:00
|
|
|
GraphItem *secondaryGraph() const {return _secondaryGraph;}
|
|
|
|
void setSecondaryGraph(GraphItem *graph) {_secondaryGraph = graph;}
|
|
|
|
|
2021-01-17 16:02:37 +01:00
|
|
|
qreal yAtX(qreal x) const;
|
|
|
|
qreal distanceAtTime(qreal time) const;
|
|
|
|
qreal timeAtDistance(qreal distance) const;
|
2016-09-19 00:56:10 +02:00
|
|
|
|
2017-10-04 23:15:39 +02:00
|
|
|
void redraw();
|
2017-09-24 19:54:13 +02:00
|
|
|
|
2016-09-19 00:56:10 +02:00
|
|
|
signals:
|
2017-09-24 19:54:13 +02:00
|
|
|
void selected(bool);
|
2016-09-19 00:56:10 +02:00
|
|
|
|
|
|
|
public slots:
|
2017-09-24 19:54:13 +02:00
|
|
|
void hover(bool hover);
|
2016-09-19 00:56:10 +02:00
|
|
|
|
2019-10-13 20:20:32 +02:00
|
|
|
protected:
|
2017-09-24 19:54:13 +02:00
|
|
|
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
|
|
|
|
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
|
2019-10-13 20:20:32 +02:00
|
|
|
void mousePressEvent(QGraphicsSceneMouseEvent *event);
|
2017-09-24 19:54:13 +02:00
|
|
|
|
2019-10-15 23:59:15 +02:00
|
|
|
Units _units;
|
|
|
|
|
2019-10-13 20:20:32 +02:00
|
|
|
private:
|
2019-02-11 23:28:08 +01:00
|
|
|
const GraphSegment *segment(qreal x, GraphType type) const;
|
2016-10-12 20:38:18 +02:00
|
|
|
void updatePath();
|
2017-09-24 19:54:13 +02:00
|
|
|
void updateShape();
|
2016-10-12 20:38:18 +02:00
|
|
|
void updateBounds();
|
2022-09-25 02:15:24 +02:00
|
|
|
void updateColor();
|
|
|
|
const QColor &color() const;
|
2016-10-12 20:38:18 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2016-10-12 20:38:18 +02:00
|
|
|
QPainterPath _path;
|
2017-09-24 19:54:13 +02:00
|
|
|
QPainterPath _shape;
|
2016-10-12 20:38:18 +02:00
|
|
|
QRectF _bounds;
|
2019-08-25 10:54:25 +02:00
|
|
|
QPen _pen;
|
2017-05-22 18:42:23 +02:00
|
|
|
bool _time;
|
2020-03-25 23:08:26 +01:00
|
|
|
|
|
|
|
GraphItem *_secondaryGraph;
|
2016-08-16 00:27:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GRAPHITEM_H
|