1// Copyright (C) 2024 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QTGRAPHS_Q3DGRAPHSWIDGETITEM_H
5#define QTGRAPHS_Q3DGRAPHSWIDGETITEM_H
6
7#include <QtCore/qlocale.h>
8#include <QtGraphs/q3dscene.h>
9#include <QtGraphs/qgraphs3dnamespace.h>
10#include <QtGraphs/qgraphstheme.h>
11#include <QtGraphsWidgets/qgraphswidgetsglobal.h>
12#include <QtQuick/qquickitemgrabresult.h>
13#include <QtQuickWidgets/qquickwidget.h>
14
15QT_BEGIN_NAMESPACE
16
17class QCustom3DItem;
18class QAbstract3DAxis;
19class QAbstract3DSeries;
20class QQuickGraphsItem;
21class QQuickItemGrabResult;
22class QQuickWheelEvent;
23class Q3DGraphsWidgetItemPrivate;
24
25class Q_GRAPHSWIDGETS_EXPORT Q3DGraphsWidgetItem : public QObject
26{
27 Q_OBJECT
28 Q_CLASSINFO("RegisterEnumClassesUnscoped", "false")
29 Q_PROPERTY(QGraphsTheme *activeTheme READ activeTheme WRITE setActiveTheme NOTIFY activeThemeChanged)
30 Q_PROPERTY(QtGraphs3D::SelectionFlags selectionMode READ selectionMode WRITE setSelectionMode
31 NOTIFY selectionModeChanged)
32 Q_PROPERTY(QtGraphs3D::ShadowQuality shadowQuality READ shadowQuality WRITE setShadowQuality
33 NOTIFY shadowQualityChanged)
34 Q_PROPERTY(QtGraphs3D::TransparencyTechnique transparencyTechnique READ transparencyTechnique
35 WRITE setTransparencyTechnique NOTIFY transparencyTechniqueChanged REVISION(6, 9))
36 Q_PROPERTY(Q3DScene *scene READ scene CONSTANT)
37 Q_PROPERTY(bool measureFps READ measureFps WRITE setMeasureFps NOTIFY measureFpsChanged)
38 Q_PROPERTY(int currentFps READ currentFps NOTIFY currentFpsChanged)
39 Q_PROPERTY(bool orthoProjection READ isOrthoProjection WRITE setOrthoProjection NOTIFY
40 orthoProjectionChanged)
41 Q_PROPERTY(
42 QtGraphs3D::ElementType selectedElement READ selectedElement NOTIFY selectedElementChanged)
43 Q_PROPERTY(qreal aspectRatio READ aspectRatio WRITE setAspectRatio NOTIFY aspectRatioChanged)
44 Q_PROPERTY(QtGraphs3D::OptimizationHint optimizationHint READ optimizationHint WRITE
45 setOptimizationHint NOTIFY optimizationHintChanged)
46 Q_PROPERTY(bool polar READ isPolar WRITE setPolar NOTIFY polarChanged)
47 Q_PROPERTY(float labelMargin READ labelMargin WRITE setLabelMargin NOTIFY labelMarginChanged)
48 Q_PROPERTY(float radialLabelOffset READ radialLabelOffset WRITE setRadialLabelOffset NOTIFY
49 radialLabelOffsetChanged)
50 Q_PROPERTY(qreal horizontalAspectRatio READ horizontalAspectRatio WRITE setHorizontalAspectRatio
51 NOTIFY horizontalAspectRatioChanged)
52 Q_PROPERTY(QLocale locale READ locale WRITE setLocale NOTIFY localeChanged)
53 Q_PROPERTY(
54 QVector3D queriedGraphPosition READ queriedGraphPosition NOTIFY queriedGraphPositionChanged)
55 Q_PROPERTY(qreal margin READ margin WRITE setMargin NOTIFY marginChanged)
56 Q_PROPERTY(QtGraphs3D::CameraPreset cameraPreset READ cameraPreset WRITE setCameraPreset NOTIFY
57 cameraPresetChanged)
58 Q_PROPERTY(float cameraXRotation READ cameraXRotation WRITE setCameraXRotation NOTIFY
59 cameraXRotationChanged)
60 Q_PROPERTY(float cameraYRotation READ cameraYRotation WRITE setCameraYRotation NOTIFY
61 cameraYRotationChanged)
62 Q_PROPERTY(float cameraZoomLevel READ cameraZoomLevel WRITE setCameraZoomLevel NOTIFY
63 cameraZoomLevelChanged)
64 Q_PROPERTY(float minCameraZoomLevel READ minCameraZoomLevel WRITE setMinCameraZoomLevel NOTIFY
65 minCameraZoomLevelChanged)
66 Q_PROPERTY(float maxCameraZoomLevel READ maxCameraZoomLevel WRITE setMaxCameraZoomLevel NOTIFY
67 maxCameraZoomLevelChanged)
68 Q_PROPERTY(bool wrapCameraXRotation READ wrapCameraXRotation WRITE setWrapCameraXRotation NOTIFY
69 wrapCameraXRotationChanged)
70 Q_PROPERTY(bool wrapCameraYRotation READ wrapCameraYRotation WRITE setWrapCameraYRotation NOTIFY
71 wrapCameraYRotationChanged)
72 Q_PROPERTY(float minCameraXRotation READ minCameraXRotation WRITE setMinCameraXRotation NOTIFY
73 minCameraXRotationChanged)
74 Q_PROPERTY(float maxCameraXRotation READ maxCameraXRotation WRITE setMaxCameraXRotation NOTIFY
75 maxCameraXRotationChanged)
76 Q_PROPERTY(float minCameraYRotation READ minCameraYRotation WRITE setMinCameraYRotation NOTIFY
77 minCameraYRotationChanged)
78 Q_PROPERTY(float maxCameraYRotation READ maxCameraYRotation WRITE setMaxCameraYRotation NOTIFY
79 maxCameraYRotationChanged)
80 Q_PROPERTY(QVector3D cameraTargetPosition READ cameraTargetPosition WRITE
81 setCameraTargetPosition NOTIFY cameraTargetPositionChanged)
82 Q_PROPERTY(int msaaSamples READ msaaSamples WRITE setMsaaSamples NOTIFY msaaSamplesChanged)
83 Q_PROPERTY(bool rotationEnabled READ isRotationEnabled WRITE setRotationEnabled NOTIFY
84 rotationEnabledChanged)
85 Q_PROPERTY(bool zoomAtTargetEnabled READ isZoomAtTargetEnabled WRITE setZoomAtTargetEnabled NOTIFY
86 zoomAtTargetEnabledChanged)
87 Q_PROPERTY(bool selectionEnabled READ isSelectionEnabled WRITE setSelectionEnabled NOTIFY
88 selectionEnabledChanged)
89 Q_PROPERTY(bool zoomEnabled READ isZoomEnabled WRITE setZoomEnabled NOTIFY
90 zoomEnabledChanged)
91
92 Q_PROPERTY(QColor lightColor READ lightColor WRITE setLightColor NOTIFY lightColorChanged)
93 Q_PROPERTY(float ambientLightStrength READ ambientLightStrength WRITE setAmbientLightStrength
94 NOTIFY ambientLightStrengthChanged)
95 Q_PROPERTY(
96 float lightStrength READ lightStrength WRITE setLightStrength NOTIFY lightStrengthChanged)
97 Q_PROPERTY(float shadowStrength READ shadowStrength WRITE setShadowStrength NOTIFY
98 shadowStrengthChanged)
99 Q_PROPERTY(QtGraphs3D::GridLineType gridLineType READ gridLineType WRITE setGridLineType NOTIFY
100 gridLineTypeChanged FINAL)
101
102public:
103 void addTheme(QGraphsTheme *theme);
104 void releaseTheme(QGraphsTheme *theme);
105 QGraphsTheme *activeTheme() const;
106 void setActiveTheme(QGraphsTheme *activeTheme);
107 QList<QGraphsTheme *> themes() const;
108
109 void setTransparencyTechnique(QtGraphs3D::TransparencyTechnique technique);
110 QtGraphs3D::TransparencyTechnique transparencyTechnique() const;
111
112 QtGraphs3D::ShadowQuality shadowQuality() const;
113 void setShadowQuality(const QtGraphs3D::ShadowQuality &shadowQuality);
114
115 QtGraphs3D::SelectionFlags selectionMode() const;
116 void setSelectionMode(const QtGraphs3D::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 QtGraphs3D::ElementType selectedElement() const;
128
129 void setAspectRatio(qreal ratio);
130 qreal aspectRatio() const;
131
132 void setOptimizationHint(QtGraphs3D::OptimizationHint hint);
133 QtGraphs3D::OptimizationHint optimizationHint() const;
134
135 void setPolar(bool enable);
136 bool isPolar() const;
137
138 void setLabelMargin(float margin);
139 float labelMargin() const;
140
141 void setRadialLabelOffset(float offset);
142 float radialLabelOffset() const;
143
144 void setHorizontalAspectRatio(qreal ratio);
145 qreal horizontalAspectRatio() const;
146
147 void setLocale(const QLocale &locale);
148 QLocale locale() const;
149
150 QVector3D queriedGraphPosition() const;
151
152 void setMargin(qreal margin);
153 qreal margin() const;
154
155 void clearSelection();
156
157 bool hasSeries(QAbstract3DSeries *series) const;
158
159 qsizetype addCustomItem(QCustom3DItem *item);
160 void removeCustomItems();
161 void removeCustomItem(QCustom3DItem *item);
162 void removeCustomItemAt(QVector3D position);
163 void releaseCustomItem(QCustom3DItem *item);
164 QList<QCustom3DItem *> customItems() const;
165
166 int selectedLabelIndex() const;
167 QAbstract3DAxis *selectedAxis() const;
168
169 qsizetype selectedCustomItemIndex() const;
170 QCustom3DItem *selectedCustomItem() const;
171
172 QSharedPointer<QQuickItemGrabResult> renderToImage(QSize imageSize = QSize()) const;
173
174 QtGraphs3D::CameraPreset cameraPreset() const;
175 void setCameraPreset(QtGraphs3D::CameraPreset preset);
176
177 float cameraXRotation() const;
178 void setCameraXRotation(float rotation);
179 float cameraYRotation() const;
180 void setCameraYRotation(float rotation);
181
182 float minCameraXRotation() const;
183 void setMinCameraXRotation(float rotation);
184 float maxCameraXRotation() const;
185 void setMaxCameraXRotation(float rotation);
186
187 float minCameraYRotation() const;
188 void setMinCameraYRotation(float rotation);
189 float maxCameraYRotation() const;
190 void setMaxCameraYRotation(float rotation);
191
192 void setZoomAtTargetEnabled(bool enable);
193 bool isZoomAtTargetEnabled() const;
194 void setZoomEnabled(bool enable);
195 bool isZoomEnabled() const;
196 void setSelectionEnabled(bool enable);
197 bool isSelectionEnabled() const;
198 void setRotationEnabled(bool enable);
199 bool isRotationEnabled() const;
200
201 void setDefaultInputHandler();
202 void unsetDefaultInputHandler();
203 void unsetDefaultTapHandler();
204 void unsetDefaultDragHandler();
205 void unsetDefaultWheelHandler();
206 void unsetDefaultPinchHandler();
207 void setDragButton(Qt::MouseButtons button);
208
209 float cameraZoomLevel() const;
210 void setCameraZoomLevel(float level);
211
212 float minCameraZoomLevel() const;
213 void setMinCameraZoomLevel(float level);
214
215 float maxCameraZoomLevel() const;
216 void setMaxCameraZoomLevel(float level);
217
218 QVector3D cameraTargetPosition() const;
219 void setCameraTargetPosition(QVector3D target);
220
221 bool wrapCameraXRotation() const;
222 void setWrapCameraXRotation(bool wrap);
223
224 bool wrapCameraYRotation() const;
225 void setWrapCameraYRotation(bool wrap);
226
227 void setCameraPosition(float horizontal, float vertical, float zoom = 100.0f);
228
229 int msaaSamples() const;
230 void setMsaaSamples(int samples);
231
232 void doPicking(QPoint point);
233 void doRayPicking(QVector3D origin, QVector3D direction);
234
235 float ambientLightStrength() const;
236 void setAmbientLightStrength(float newAmbientLightStrength);
237 float lightStrength() const;
238 void setLightStrength(float newLightStrength);
239 float shadowStrength() const;
240 void setShadowStrength(float newShadowStrength);
241 QColor lightColor() const;
242 void setLightColor(QColor newLightColor);
243 QtGraphs3D::GridLineType gridLineType() const;
244 void setGridLineType(const QtGraphs3D::GridLineType &gridLineType);
245
246 void setWidget(QQuickWidget *widget);
247 QQuickWidget *widget() const;
248
249 ~Q3DGraphsWidgetItem() override;
250
251protected:
252 Q3DGraphsWidgetItem(Q3DGraphsWidgetItemPrivate &dd, QObject *parent, const QString &graph);
253
254 bool event(QEvent *event) override;
255 bool eventFilter(QObject *obj, QEvent *event) override;
256
257Q_SIGNALS:
258 void activeThemeChanged(QGraphsTheme *activeTheme);
259 void shadowQualityChanged(QtGraphs3D::ShadowQuality quality);
260 Q_REVISION(6, 9) void transparencyTechniqueChanged(QtGraphs3D::TransparencyTechnique technique);
261 void selectionModeChanged(const QtGraphs3D::SelectionFlags selectionMode);
262 void selectedElementChanged(QtGraphs3D::ElementType type);
263 void measureFpsChanged(bool enabled);
264 void currentFpsChanged(int fps);
265 void orthoProjectionChanged(bool enabled);
266 void aspectRatioChanged(qreal ratio);
267 void optimizationHintChanged(QtGraphs3D::OptimizationHint hint);
268 void polarChanged(bool enabled);
269 void labelMarginChanged(float margin);
270 void radialLabelOffsetChanged(float offset);
271 void horizontalAspectRatioChanged(qreal ratio);
272 void localeChanged(const QLocale &locale);
273 void queriedGraphPositionChanged(QVector3D data);
274 void marginChanged(qreal margin);
275 void cameraPresetChanged(QtGraphs3D::CameraPreset preset);
276 void cameraXRotationChanged(float rotation);
277 void cameraYRotationChanged(float rotation);
278 void cameraZoomLevelChanged(float zoomLevel);
279 void cameraTargetPositionChanged(QVector3D target);
280 void minCameraZoomLevelChanged(float zoomLevel);
281 void maxCameraZoomLevelChanged(float zoomLevel);
282 void minCameraXRotationChanged(float rotation);
283 void minCameraYRotationChanged(float rotation);
284 void maxCameraXRotationChanged(float rotation);
285 void maxCameraYRotationChanged(float rotation);
286 void wrapCameraXRotationChanged(bool wrap);
287 void wrapCameraYRotationChanged(bool wrap);
288 void msaaSamplesChanged(int samples);
289
290 void tapped(QEventPoint eventPoint, Qt::MouseButton button);
291 void doubleTapped(QEventPoint eventPoint, Qt::MouseButton button);
292 void longPressed();
293 void dragged(QVector2D delta);
294 void wheel(QWheelEvent *event);
295 void pinch(qreal delta);
296 void mouseMove(QPoint mousePos);
297
298 void zoomEnabledChanged(bool enable);
299 void zoomAtTargetEnabledChanged(bool enable);
300 void rotationEnabledChanged(bool enable);
301 void selectionEnabledChanged(bool enable);
302
303 void ambientLightStrengthChanged();
304 void lightStrengthChanged();
305 void shadowStrengthChanged();
306 void lightColorChanged();
307 void gridLineTypeChanged();
308
309private:
310 Q_DISABLE_COPY_MOVE(Q3DGraphsWidgetItem)
311 Q_DECLARE_PRIVATE(Q3DGraphsWidgetItem)
312};
313
314QT_END_NAMESPACE
315
316#endif
317

source code of qtgraphs/src/graphs3d/widget/q3dgraphswidgetitem.h