1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4// W A R N I N G
5// -------------
6//
7// This file is not part of the Qt Chart API. It exists purely as an
8// implementation detail. This header file may change from version to
9// version without notice, or even be removed.
10//
11// We mean it.
12
13#ifndef GLWIDGET_H
14#define GLWIDGET_H
15
16#ifndef QT_NO_OPENGL
17
18#include <QtOpenGLWidgets/QOpenGLWidget>
19#include <QtWidgets/QGraphicsView>
20#include <QtGui/QOpenGLFunctions>
21#include <QtOpenGL/QOpenGLVertexArrayObject>
22#include <QtOpenGL/QOpenGLBuffer>
23#include <QtOpenGL/QOpenGLFramebufferObject>
24#include <QtCore/QHash>
25#include <QtCharts/QAbstractSeries>
26#include <QtCharts/QXYSeries>
27#include <QtCharts/QChart>
28#include <QtCore/private/qglobal_p.h>
29
30QT_FORWARD_DECLARE_CLASS(QOpenGLShaderProgram)
31
32QT_BEGIN_NAMESPACE
33
34class GLXYSeriesDataManager;
35
36class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
37{
38 Q_OBJECT
39
40public:
41 GLWidget(GLXYSeriesDataManager *xyDataManager, QChart *chart, QGraphicsView *parent = 0);
42 ~GLWidget();
43
44 bool needsReset() const;
45
46public Q_SLOTS:
47 void cleanup();
48 void cleanXYSeriesResources(const QXYSeries *series);
49
50protected:
51 void initializeGL() override;
52 void paintGL() override;
53 void resizeGL(int width, int height) override;
54 void mouseDoubleClickEvent(QMouseEvent *event) override;
55 void mouseMoveEvent(QMouseEvent *event) override;
56 void mousePressEvent(QMouseEvent *event) override;
57 void mouseReleaseEvent(QMouseEvent *event) override;
58
59private:
60 QXYSeries *findSeriesAtEvent(QMouseEvent *event);
61 void render(bool selection);
62 void recreateSelectionFbo();
63 QXYSeries *chartSeries(const QXYSeries *cSeries);
64
65 QOpenGLShaderProgram *m_program;
66 int m_shaderAttribLoc;
67 int m_colorUniformLoc;
68 int m_minUniformLoc;
69 int m_deltaUniformLoc;
70 int m_pointSizeUniformLoc;
71 int m_matrixUniformLoc;
72 QOpenGLVertexArrayObject m_vao;
73
74 QHash<const QAbstractSeries *, QOpenGLBuffer *> m_seriesBufferMap;
75 GLXYSeriesDataManager *m_xyDataManager;
76 bool m_antiAlias;
77 QGraphicsView *m_view;
78 QOpenGLFramebufferObject *m_selectionFbo;
79 QSize m_fboSize;
80 QList<const QXYSeries *> m_selectionList;
81 QChart *m_chart;
82 bool m_recreateSelectionFbo;
83 bool m_selectionRenderNeeded;
84 QPoint m_mousePressPos;
85 bool m_mousePressed;
86 QXYSeries *m_lastPressSeries;
87 QXYSeries *m_lastHoverSeries;
88};
89
90QT_END_NAMESPACE
91#endif
92#endif
93

source code of qtcharts/src/charts/glwidget_p.h