-
Notifications
You must be signed in to change notification settings - Fork 9
/
zoomablechartview.h
56 lines (43 loc) · 1.33 KB
/
zoomablechartview.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#ifndef CHARTVIEW_H
#define CHARTVIEW_H
#include <QtCharts/QChartView>
#include <QtWidgets/QRubberBand>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QT_CHARTS_USE_NAMESPACE
#endif
//![1]
class ZoomableChartView : public QChartView
//![1]
{
public:
enum ZoomMode {
Pan,
RectangleZoom,
VerticalZoom,
HorizontalZoom
};
ZoomableChartView(QWidget *parent = 0);
ZoomableChartView(QChart *chart, QWidget *parent = nullptr);
void zoomX(qreal factor, qreal xcenter);
void zoomX(qreal factor);
void zoomY(qreal factor, qreal ycenter);
void zoomY(qreal factor);
//![2]
ZoomMode zoomMode() const;
void setZoomMode(const ZoomMode &zoomMode);
protected:
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
void wheelEvent(QWheelEvent *event);
//![2]
private:
bool m_isTouching = false;
QPointF m_lastMousePos;
ZoomMode m_zoomMode = RectangleZoom;
static bool isAxisTypeZoomableWithMouse(const QAbstractAxis::AxisType type);
QPointF getSeriesCoordFromChartCoord(const QPointF & mousePos, QAbstractSeries *series) const;
QPointF getChartCoordFromSeriesCoord(const QPointF & seriesPos, QAbstractSeries *series) const;
};
#endif