1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-07 07:13:21 +02:00
GPXSee/src/graph.h

90 lines
1.8 KiB
C
Raw Normal View History

2015-10-05 01:43:48 +02:00
#ifndef GRAPH_H
#define GRAPH_H
#include <QGraphicsView>
2015-10-13 23:49:15 +02:00
#include <QGraphicsScene>
2015-10-05 01:43:48 +02:00
#include <QVector>
#include <QList>
#include <QPointF>
#include "axisitem.h"
#include "colorshop.h"
2015-11-26 00:21:11 +01:00
#define THIN_SPACE QString::fromUtf8("\xE2\x80\x89")
2015-10-12 01:12:12 +02:00
class SliderItem;
2015-10-17 01:33:02 +02:00
class SliderInfoItem;
2015-10-12 01:12:12 +02:00
class InfoItem;
2015-10-13 23:49:15 +02:00
class Scene : public QGraphicsScene
{
Q_OBJECT
public:
Scene(QObject *parent = 0) : QGraphicsScene(parent) {}
void mousePressEvent(QGraphicsSceneMouseEvent *e);
signals:
void mouseClicked(const QPointF &pos);
};
2015-10-05 01:43:48 +02:00
class Graph : public QGraphicsView
{
Q_OBJECT
public:
Graph(QWidget *parent = 0);
~Graph();
void loadData(const QVector<QPointF> &data);
2015-10-12 01:12:12 +02:00
void setXLabel(const QString &label);
void setYLabel(const QString &label);
void setXUnits(const QString &units);
void setYUnits(const QString &units);
2015-10-05 01:43:48 +02:00
void setXScale(qreal scale) {_xScale = scale;}
void setYScale(qreal scale) {_yScale = scale;}
2015-10-17 01:33:02 +02:00
void setPrecision(int p) {_precision = p;}
2015-10-05 01:43:48 +02:00
void plot(QPainter *painter, const QRectF &target);
void clear();
qreal sliderPosition() const;
void setSliderPosition(qreal pos);
2015-10-12 01:12:12 +02:00
void addInfo(const QString &key, const QString &value);
2015-10-05 01:43:48 +02:00
signals:
void sliderPositionChanged(qreal);
protected:
void resizeEvent(QResizeEvent *);
2015-10-12 01:12:12 +02:00
qreal _xScale, _yScale;
QString _xUnits, _yUnits;
QString _xLabel, _yLabel;
2015-10-17 01:33:02 +02:00
int _precision;
2015-10-12 01:12:12 +02:00
2015-10-05 01:43:48 +02:00
private slots:
void emitSliderPositionChanged(const QPointF &pos);
2015-10-13 23:49:15 +02:00
void newSliderPosition(const QPointF &pos);
2015-10-05 01:43:48 +02:00
private:
2015-10-12 01:12:12 +02:00
void createXLabel();
void createYLabel();
2015-10-05 01:43:48 +02:00
void updateBounds(const QPointF &point);
void resize(const QSizeF &size);
2015-10-13 23:49:15 +02:00
Scene *_scene;
2015-10-17 01:33:02 +02:00
2015-10-05 01:43:48 +02:00
AxisItem *_xAxis, *_yAxis;
SliderItem *_slider;
2015-10-17 01:33:02 +02:00
SliderInfoItem *_sliderInfo;
2015-10-12 01:12:12 +02:00
InfoItem *_info;
2015-10-17 01:33:02 +02:00
QList<QGraphicsPathItem*> _graphs;
2015-10-12 01:12:12 +02:00
qreal _xMin, _xMax, _yMin, _yMax;
2015-10-05 01:43:48 +02:00
ColorShop _colorShop;
};
#endif // GRAPH_H