1 | // Copyright (C) 2023 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #ifndef QABSTRACT3DGRAPH_H |
5 | #define QABSTRACT3DGRAPH_H |
6 | |
7 | #include <QtGraphs/qgraphsglobal.h> |
8 | #include <QtGraphs/q3dtheme.h> |
9 | #include <QtGraphs/q3dscene.h> |
10 | #include <QtGraphs/qabstract3dinputhandler.h> |
11 | #include <QtCore/qlocale.h> |
12 | #include <QtQuickWidgets/qquickwidget.h> |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | class QCustom3DItem; |
17 | class QAbstract3DAxis; |
18 | class QAbstract3DSeries; |
19 | class QQuickGraphsItem; |
20 | |
21 | class Q_GRAPHS_EXPORT QAbstract3DGraph : public QQuickWidget |
22 | { |
23 | Q_OBJECT |
24 | Q_FLAGS(SelectionFlag SelectionFlags) |
25 | Q_FLAGS(OptimizationHint OptimizationHints) |
26 | Q_PROPERTY(QAbstract3DInputHandler* activeInputHandler READ activeInputHandler WRITE setActiveInputHandler NOTIFY activeInputHandlerChanged) |
27 | Q_PROPERTY(Q3DTheme* activeTheme READ activeTheme WRITE setActiveTheme NOTIFY activeThemeChanged) |
28 | Q_PROPERTY(QAbstract3DGraph::SelectionFlags selectionMode READ selectionMode WRITE setSelectionMode NOTIFY selectionModeChanged) |
29 | Q_PROPERTY(QAbstract3DGraph::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality NOTIFY shadowQualityChanged) |
30 | Q_PROPERTY(Q3DScene* scene READ scene CONSTANT) |
31 | Q_PROPERTY(bool measureFps READ measureFps WRITE setMeasureFps NOTIFY measureFpsChanged) |
32 | Q_PROPERTY(int currentFps READ currentFps NOTIFY currentFpsChanged) |
33 | Q_PROPERTY(bool orthoProjection READ isOrthoProjection WRITE setOrthoProjection NOTIFY orthoProjectionChanged) |
34 | Q_PROPERTY(QAbstract3DGraph::ElementType selectedElement READ selectedElement NOTIFY selectedElementChanged) |
35 | Q_PROPERTY(qreal aspectRatio READ aspectRatio WRITE setAspectRatio NOTIFY aspectRatioChanged) |
36 | Q_PROPERTY(QAbstract3DGraph::OptimizationHints optimizationHints READ optimizationHints WRITE setOptimizationHints NOTIFY optimizationHintsChanged) |
37 | Q_PROPERTY(bool polar READ isPolar WRITE setPolar NOTIFY polarChanged) |
38 | Q_PROPERTY(float radialLabelOffset READ radialLabelOffset WRITE setRadialLabelOffset NOTIFY radialLabelOffsetChanged) |
39 | Q_PROPERTY(qreal horizontalAspectRatio READ horizontalAspectRatio WRITE setHorizontalAspectRatio NOTIFY horizontalAspectRatioChanged) |
40 | Q_PROPERTY(bool reflection READ isReflection WRITE setReflection NOTIFY reflectionChanged) |
41 | Q_PROPERTY(qreal reflectivity READ reflectivity WRITE setReflectivity NOTIFY reflectivityChanged) |
42 | Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged) |
43 | Q_PROPERTY(QVector3D queriedGraphPosition READ queriedGraphPosition NOTIFY queriedGraphPositionChanged) |
44 | Q_PROPERTY(qreal margin READ margin WRITE setMargin NOTIFY marginChanged) |
45 | |
46 | QML_NAMED_ELEMENT(AbstractGraph3D) |
47 | QML_UNCREATABLE("Trying to create uncreatable: AbstractGraph3D." ) |
48 | |
49 | public: |
50 | enum SelectionFlag { |
51 | SelectionNone = 0, |
52 | SelectionItem = 1, |
53 | SelectionRow = 2, |
54 | SelectionItemAndRow = SelectionItem | SelectionRow, |
55 | SelectionColumn = 4, |
56 | SelectionItemAndColumn = SelectionItem | SelectionColumn, |
57 | SelectionRowAndColumn = SelectionRow | SelectionColumn, |
58 | SelectionItemRowAndColumn = SelectionItem | SelectionRow | SelectionColumn, |
59 | SelectionSlice = 8, |
60 | SelectionMultiSeries = 16 |
61 | }; |
62 | Q_ENUM(SelectionFlag) |
63 | Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag) |
64 | |
65 | enum ShadowQuality { |
66 | ShadowQualityNone = 0, |
67 | ShadowQualityLow, |
68 | ShadowQualityMedium, |
69 | ShadowQualityHigh, |
70 | ShadowQualitySoftLow, |
71 | ShadowQualitySoftMedium, |
72 | ShadowQualitySoftHigh |
73 | }; |
74 | Q_ENUM(ShadowQuality) |
75 | |
76 | enum ElementType { |
77 | ElementNone = 0, |
78 | ElementSeries, |
79 | ElementAxisXLabel, |
80 | ElementAxisYLabel, |
81 | ElementAxisZLabel, |
82 | ElementCustomItem |
83 | }; |
84 | Q_ENUM(ElementType) |
85 | |
86 | enum OptimizationHint { |
87 | OptimizationDefault = 0, |
88 | OptimizationStatic = 1, |
89 | OptimizationLegacy |
90 | }; |
91 | Q_ENUM(OptimizationHint) |
92 | Q_DECLARE_FLAGS(OptimizationHints, OptimizationHint) |
93 | |
94 | enum RenderingMode { |
95 | RenderDirectToBackground = 0, |
96 | RenderIndirect |
97 | }; |
98 | Q_ENUM(RenderingMode) |
99 | |
100 | void addInputHandler(QAbstract3DInputHandler *inputHandler); |
101 | void releaseInputHandler(QAbstract3DInputHandler *inputHandler); |
102 | void setActiveInputHandler(QAbstract3DInputHandler *inputHandler); |
103 | QAbstract3DInputHandler *activeInputHandler() const; |
104 | QList<QAbstract3DInputHandler *> inputHandlers() const; |
105 | |
106 | void addTheme(Q3DTheme *theme); |
107 | void releaseTheme(Q3DTheme *theme); |
108 | Q3DTheme *activeTheme() const; |
109 | void setActiveTheme(Q3DTheme *activeTheme); |
110 | QList<Q3DTheme *> themes() const; |
111 | |
112 | QAbstract3DGraph::ShadowQuality shadowQuality() const; |
113 | void setShadowQuality(const QAbstract3DGraph::ShadowQuality &shadowQuality); |
114 | |
115 | QAbstract3DGraph::SelectionFlags selectionMode() const; |
116 | void setSelectionMode(const QAbstract3DGraph::SelectionFlags &selectionMode); |
117 | |
118 | Q3DScene *scene() const; |
119 | |
120 | void setMeasureFps(bool enable); |
121 | bool measureFps() const; |
122 | int currentFps() const; |
123 | |
124 | void setOrthoProjection(bool enable); |
125 | bool isOrthoProjection() const; |
126 | |
127 | QAbstract3DGraph::ElementType selectedElement() const; |
128 | |
129 | void setAspectRatio(qreal ratio); |
130 | qreal aspectRatio() const; |
131 | |
132 | void setOptimizationHints(QAbstract3DGraph::OptimizationHints hints); |
133 | QAbstract3DGraph::OptimizationHints optimizationHints() const; |
134 | |
135 | void setPolar(bool enable); |
136 | bool isPolar() const; |
137 | |
138 | void setRadialLabelOffset(float offset); |
139 | float radialLabelOffset() const; |
140 | |
141 | void setHorizontalAspectRatio(qreal ratio); |
142 | qreal horizontalAspectRatio() const; |
143 | |
144 | void setReflection(bool enable); |
145 | bool isReflection() const; |
146 | |
147 | void setReflectivity(qreal reflectivity); |
148 | qreal reflectivity() const; |
149 | |
150 | void setLocale(const QLocale &locale); |
151 | QLocale locale() const; |
152 | |
153 | QVector3D queriedGraphPosition() const; |
154 | |
155 | void setMargin(qreal margin); |
156 | qreal margin() const; |
157 | |
158 | void clearSelection(); |
159 | |
160 | bool hasSeries(QAbstract3DSeries *series) const; |
161 | |
162 | int addCustomItem(QCustom3DItem *item); |
163 | void removeCustomItems(); |
164 | void removeCustomItem(QCustom3DItem *item); |
165 | void removeCustomItemAt(const QVector3D &position); |
166 | void releaseCustomItem(QCustom3DItem *item); |
167 | QList<QCustom3DItem *> customItems() const; |
168 | |
169 | int selectedLabelIndex() const; |
170 | QAbstract3DAxis *selectedAxis() const; |
171 | |
172 | int selectedCustomItemIndex() const; |
173 | QCustom3DItem *selectedCustomItem() const; |
174 | |
175 | QImage renderToImage(int msaaSamples = 0, const QSize &imageSize = QSize()); |
176 | |
177 | virtual ~QAbstract3DGraph(); |
178 | |
179 | protected: |
180 | QAbstract3DGraph(); |
181 | |
182 | bool event(QEvent *event) override; |
183 | void resizeEvent(QResizeEvent *event) override; |
184 | |
185 | void mouseDoubleClickEvent(QMouseEvent *event) override; |
186 | void mousePressEvent(QMouseEvent *event) override; |
187 | void mouseReleaseEvent(QMouseEvent *event) override; |
188 | void mouseMoveEvent(QMouseEvent *event) override; |
189 | #if QT_CONFIG(wheelevent) |
190 | void wheelEvent(QWheelEvent *event) override; |
191 | #endif |
192 | |
193 | Q_SIGNALS: |
194 | void activeInputHandlerChanged(QAbstract3DInputHandler *inputHandler); |
195 | void activeThemeChanged(Q3DTheme *activeTheme); |
196 | void shadowQualityChanged(QAbstract3DGraph::ShadowQuality quality); |
197 | void selectionModeChanged(const QAbstract3DGraph::SelectionFlags selectionMode); |
198 | void selectedElementChanged(QAbstract3DGraph::ElementType type); |
199 | void measureFpsChanged(bool enabled); |
200 | void currentFpsChanged(int fps); |
201 | void orthoProjectionChanged(bool enabled); |
202 | void aspectRatioChanged(qreal ratio); |
203 | void optimizationHintsChanged(QAbstract3DGraph::OptimizationHints hints); |
204 | void polarChanged(bool enabled); |
205 | void radialLabelOffsetChanged(float offset); |
206 | void horizontalAspectRatioChanged(qreal ratio); |
207 | void reflectionChanged(bool enabled); |
208 | void reflectivityChanged(qreal reflectivity); |
209 | void localeChanged(const QLocale &locale); |
210 | void queriedGraphPositionChanged(const QVector3D &data); |
211 | void marginChanged(qreal margin); |
212 | private: |
213 | Q_DISABLE_COPY(QAbstract3DGraph) |
214 | QScopedPointer<QQuickGraphsItem> m_graphsItem; |
215 | |
216 | friend class Q3DBars; |
217 | friend class Q3DScatter; |
218 | friend class Q3DSurface; |
219 | }; |
220 | Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstract3DGraph::SelectionFlags) |
221 | Q_DECLARE_OPERATORS_FOR_FLAGS(QAbstract3DGraph::OptimizationHints) |
222 | |
223 | QT_END_NAMESPACE |
224 | |
225 | #endif |
226 | |