1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Data Visualization module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#ifndef QABSTRACT3DGRAPH_H
31#define QABSTRACT3DGRAPH_H
32
33#include <QtDataVisualization/qdatavisualizationglobal.h>
34#include <QtDataVisualization/q3dtheme.h>
35#include <QtDataVisualization/q3dscene.h>
36#include <QtDataVisualization/qabstract3dinputhandler.h>
37#include <QtGui/QWindow>
38#include <QtGui/QOpenGLFunctions>
39#include <QtCore/QLocale>
40
41QT_BEGIN_NAMESPACE_DATAVISUALIZATION
42
43class QAbstract3DGraphPrivate;
44class QCustom3DItem;
45class QAbstract3DAxis;
46
47class QT_DATAVISUALIZATION_EXPORT QAbstract3DGraph : public QWindow, protected QOpenGLFunctions
48{
49 Q_OBJECT
50 Q_ENUMS(ShadowQuality)
51 Q_ENUMS(ElementType)
52 Q_FLAGS(SelectionFlag SelectionFlags)
53 Q_FLAGS(OptimizationHint OptimizationHints)
54 Q_PROPERTY(QAbstract3DInputHandler* activeInputHandler READ activeInputHandler WRITE setActiveInputHandler NOTIFY activeInputHandlerChanged)
55 Q_PROPERTY(Q3DTheme* activeTheme READ activeTheme WRITE setActiveTheme NOTIFY activeThemeChanged)
56 Q_PROPERTY(SelectionFlags selectionMode READ selectionMode WRITE setSelectionMode NOTIFY selectionModeChanged)
57 Q_PROPERTY(ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality NOTIFY shadowQualityChanged)
58 Q_PROPERTY(Q3DScene* scene READ scene)
59 Q_PROPERTY(bool measureFps READ measureFps WRITE setMeasureFps NOTIFY measureFpsChanged)
60 Q_PROPERTY(qreal currentFps READ currentFps NOTIFY currentFpsChanged)
61 Q_PROPERTY(bool orthoProjection READ isOrthoProjection WRITE setOrthoProjection NOTIFY orthoProjectionChanged)
62 Q_PROPERTY(ElementType selectedElement READ selectedElement NOTIFY selectedElementChanged)
63 Q_PROPERTY(qreal aspectRatio READ aspectRatio WRITE setAspectRatio NOTIFY aspectRatioChanged)
64 Q_PROPERTY(OptimizationHints optimizationHints READ optimizationHints WRITE setOptimizationHints NOTIFY optimizationHintsChanged)
65 Q_PROPERTY(bool polar READ isPolar WRITE setPolar NOTIFY polarChanged)
66 Q_PROPERTY(float radialLabelOffset READ radialLabelOffset WRITE setRadialLabelOffset NOTIFY radialLabelOffsetChanged)
67 Q_PROPERTY(qreal horizontalAspectRatio READ horizontalAspectRatio WRITE setHorizontalAspectRatio NOTIFY horizontalAspectRatioChanged)
68 Q_PROPERTY(bool reflection READ isReflection WRITE setReflection NOTIFY reflectionChanged)
69 Q_PROPERTY(qreal reflectivity READ reflectivity WRITE setReflectivity NOTIFY reflectivityChanged)
70 Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged)
71 Q_PROPERTY(QVector3D queriedGraphPosition READ queriedGraphPosition NOTIFY queriedGraphPositionChanged)
72 Q_PROPERTY(qreal margin READ margin WRITE setMargin NOTIFY marginChanged)
73
74protected:
75 explicit QAbstract3DGraph(QAbstract3DGraphPrivate *d, const QSurfaceFormat *format,
76 QWindow *parent = nullptr);
77
78public:
79 enum SelectionFlag {
80 SelectionNone = 0,
81 SelectionItem = 1,
82 SelectionRow = 2,
83 SelectionItemAndRow = SelectionItem | SelectionRow,
84 SelectionColumn = 4,
85 SelectionItemAndColumn = SelectionItem | SelectionColumn,
86 SelectionRowAndColumn = SelectionRow | SelectionColumn,
87 SelectionItemRowAndColumn = SelectionItem | SelectionRow | SelectionColumn,
88 SelectionSlice = 8,
89 SelectionMultiSeries = 16
90 };
91 Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag)
92
93 enum ShadowQuality {
94 ShadowQualityNone = 0,
95 ShadowQualityLow,
96 ShadowQualityMedium,
97 ShadowQualityHigh,
98 ShadowQualitySoftLow,
99 ShadowQualitySoftMedium,
100 ShadowQualitySoftHigh
101 };
102
103 enum ElementType {
104 ElementNone = 0,
105 ElementSeries,
106 ElementAxisXLabel,
107 ElementAxisYLabel,
108 ElementAxisZLabel,
109 ElementCustomItem
110 };
111
112 enum OptimizationHint {
113 OptimizationDefault = 0,
114 OptimizationStatic = 1
115 };
116 Q_DECLARE_FLAGS(OptimizationHints, OptimizationHint)
117
118public:
119 virtual ~QAbstract3DGraph();
120
121 void addInputHandler(QAbstract3DInputHandler *inputHandler);
122 void releaseInputHandler(QAbstract3DInputHandler *inputHandler);
123 void setActiveInputHandler(QAbstract3DInputHandler *inputHandler);
124 QAbstract3DInputHandler *activeInputHandler() const;
125 QList<QAbstract3DInputHandler *> inputHandlers() const;
126
127 void addTheme(Q3DTheme *theme);
128 void releaseTheme(Q3DTheme *theme);
129 void setActiveTheme(Q3DTheme *theme);
130 Q3DTheme *activeTheme() const;
131 QList<Q3DTheme *> themes() const;
132
133 void setSelectionMode(SelectionFlags mode);
134 SelectionFlags selectionMode() const;
135
136 void setShadowQuality(ShadowQuality quality);
137 ShadowQuality shadowQuality() const;
138 virtual bool shadowsSupported() const;
139
140 Q3DScene *scene() const;
141
142 void clearSelection();
143
144 int addCustomItem(QCustom3DItem *item);
145 void removeCustomItems();
146 void removeCustomItem(QCustom3DItem *item);
147 void removeCustomItemAt(const QVector3D &position);
148 void releaseCustomItem(QCustom3DItem *item);
149 QList<QCustom3DItem *> customItems() const;
150
151 int selectedLabelIndex() const;
152 QAbstract3DAxis *selectedAxis() const;
153
154 int selectedCustomItemIndex() const;
155 QCustom3DItem *selectedCustomItem() const;
156
157 QImage renderToImage(int msaaSamples = 0, const QSize &imageSize = QSize());
158
159 void setMeasureFps(bool enable);
160 bool measureFps() const;
161 qreal currentFps() const;
162
163 void setOrthoProjection(bool enable);
164 bool isOrthoProjection() const;
165
166 ElementType selectedElement() const;
167
168 void setAspectRatio(qreal ratio);
169 qreal aspectRatio() const;
170
171 void setOptimizationHints(OptimizationHints hints);
172 OptimizationHints optimizationHints() const;
173
174 void setPolar(bool enable);
175 bool isPolar() const;
176
177 void setRadialLabelOffset(float offset);
178 float radialLabelOffset() const;
179
180 void setHorizontalAspectRatio(qreal ratio);
181 qreal horizontalAspectRatio() const;
182
183 void setReflection(bool enable);
184 bool isReflection() const;
185
186 void setReflectivity(qreal reflectivity);
187 qreal reflectivity() const;
188
189 void setLocale(const QLocale &locale);
190 QLocale locale() const;
191
192 QVector3D queriedGraphPosition() const;
193
194 void setMargin(qreal margin);
195 qreal margin() const;
196
197 bool hasContext() const;
198
199protected:
200 bool event(QEvent *event);
201 void resizeEvent(QResizeEvent *event);
202 void exposeEvent(QExposeEvent *event);
203
204 void mouseDoubleClickEvent(QMouseEvent *event);
205 void touchEvent(QTouchEvent *event);
206 void mousePressEvent(QMouseEvent *event);
207 void mouseReleaseEvent(QMouseEvent *event);
208 void mouseMoveEvent(QMouseEvent *event);
209#if QT_CONFIG(wheelevent)
210 void wheelEvent(QWheelEvent *event);
211#endif
212
213Q_SIGNALS:
214 void activeInputHandlerChanged(QAbstract3DInputHandler *inputHandler);
215 void activeThemeChanged(Q3DTheme *theme);
216 void selectionModeChanged(QAbstract3DGraph::SelectionFlags mode);
217 void shadowQualityChanged(QAbstract3DGraph::ShadowQuality quality);
218 void selectedElementChanged(QAbstract3DGraph::ElementType type);
219 void measureFpsChanged(bool enabled);
220 void currentFpsChanged(qreal fps);
221 void orthoProjectionChanged(bool enabled);
222 void aspectRatioChanged(qreal ratio);
223 void optimizationHintsChanged(QAbstract3DGraph::OptimizationHints hints);
224 void polarChanged(bool enabled);
225 void radialLabelOffsetChanged(float offset);
226 void horizontalAspectRatioChanged(qreal ratio);
227 void reflectionChanged(bool enabled);
228 void reflectivityChanged(qreal reflectivity);
229 void localeChanged(const QLocale &locale);
230 void queriedGraphPositionChanged(const QVector3D &data);
231 void marginChanged(qreal margin);
232
233private:
234 Q_DISABLE_COPY(QAbstract3DGraph)
235 QScopedPointer<QAbstract3DGraphPrivate> d_ptr;
236
237 friend class Q3DBars;
238 friend class Q3DScatter;
239 friend class Q3DSurface;
240};
241Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstract3DGraph::SelectionFlags)
242Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstract3DGraph::OptimizationHints)
243
244QT_END_NAMESPACE_DATAVISUALIZATION
245
246#endif
247

source code of qtdatavis3d/src/datavisualization/engine/qabstract3dgraph.h