1 | // Copyright (C) 2023 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | // |
5 | // W A R N I N G |
6 | // ------------- |
7 | // |
8 | // This file is not part of the QtGraphs API. It exists purely as an |
9 | // implementation detail. This header file may change from version to |
10 | // version without notice, or even be removed. |
11 | // |
12 | // We mean it. |
13 | |
14 | #ifndef QQUICKGRAPHSSURFACE_P_H |
15 | #define QQUICKGRAPHSSURFACE_P_H |
16 | |
17 | #include "qquickgraphsitem_p.h" |
18 | #include "qsurface3dseries.h" |
19 | |
20 | #include <private/graphsglobal_p.h> |
21 | #include <private/surface3dcontroller_p.h> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | class QValue3DAxis; |
26 | class QSurface3DSeries; |
27 | class Surface3DController; |
28 | class SurfaceSelectionInstancing; |
29 | class Q3DSurface; |
30 | |
31 | class QQuickGraphsSurface : public QQuickGraphsItem |
32 | { |
33 | Q_OBJECT |
34 | Q_PROPERTY(QValue3DAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged) |
35 | Q_PROPERTY(QValue3DAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged) |
36 | Q_PROPERTY(QValue3DAxis *axisZ READ axisZ WRITE setAxisZ NOTIFY axisZChanged) |
37 | Q_PROPERTY(QSurface3DSeries *selectedSeries READ selectedSeries NOTIFY selectedSeriesChanged) |
38 | Q_PROPERTY(QQmlListProperty<QSurface3DSeries> seriesList READ seriesList CONSTANT) |
39 | Q_PROPERTY(bool flipHorizontalGrid READ flipHorizontalGrid WRITE setFlipHorizontalGrid NOTIFY flipHorizontalGridChanged) |
40 | Q_CLASSINFO("DefaultProperty" , "seriesList" ) |
41 | |
42 | QML_NAMED_ELEMENT(Surface3D) |
43 | |
44 | public: |
45 | explicit QQuickGraphsSurface(QQuickItem *parent = 0); |
46 | ~QQuickGraphsSurface(); |
47 | |
48 | QValue3DAxis *axisX() const; |
49 | void setAxisX(QValue3DAxis *axis); |
50 | QValue3DAxis *axisY() const; |
51 | void setAxisY(QValue3DAxis *axis); |
52 | QValue3DAxis *axisZ() const; |
53 | void setAxisZ(QValue3DAxis *axis); |
54 | |
55 | QQmlListProperty<QSurface3DSeries> seriesList(); |
56 | static void appendSeriesFunc(QQmlListProperty<QSurface3DSeries> *list, QSurface3DSeries *series); |
57 | static qsizetype countSeriesFunc(QQmlListProperty<QSurface3DSeries> *list); |
58 | static QSurface3DSeries *atSeriesFunc(QQmlListProperty<QSurface3DSeries> *list, qsizetype index); |
59 | static void clearSeriesFunc(QQmlListProperty<QSurface3DSeries> *list); |
60 | Q_INVOKABLE void addSeries(QSurface3DSeries *series); |
61 | Q_INVOKABLE void removeSeries(QSurface3DSeries *series); |
62 | |
63 | QSurface3DSeries *selectedSeries() const; |
64 | void setFlipHorizontalGrid(bool flip); |
65 | bool flipHorizontalGrid() const; |
66 | |
67 | protected: |
68 | void componentComplete() override; |
69 | void synchData() override; |
70 | void updateGraph() override; |
71 | void updateSliceGraph() override; |
72 | bool handleMousePressedEvent(QMouseEvent *event) override; |
73 | void updateSingleHighlightColor() override; |
74 | void updateLightStrength() override; |
75 | void handleThemeTypeChange() override; |
76 | bool handleTouchEvent(QTouchEvent *event) override; |
77 | bool doPicking(const QPointF &position) override; |
78 | |
79 | void createSliceView() override; |
80 | |
81 | public Q_SLOTS: |
82 | void handleAxisXChanged(QAbstract3DAxis *axis) override; |
83 | void handleAxisYChanged(QAbstract3DAxis *axis) override; |
84 | void handleAxisZChanged(QAbstract3DAxis *axis) override; |
85 | |
86 | void handleFlatShadingEnabledChanged(); |
87 | void handleWireframeColorChanged(); |
88 | void handleFlipHorizontalGridChanged(bool flip); |
89 | |
90 | Q_SIGNALS: |
91 | void axisXChanged(QValue3DAxis *axis); |
92 | void axisYChanged(QValue3DAxis *axis); |
93 | void axisZChanged(QValue3DAxis *axis); |
94 | void selectedSeriesChanged(QSurface3DSeries *series); |
95 | void flipHorizontalGridChanged(bool flip); |
96 | |
97 | private: |
98 | struct SurfaceVertex { |
99 | QVector3D position; |
100 | QVector2D uv; |
101 | QPoint coord; |
102 | }; |
103 | |
104 | struct SurfaceModel { |
105 | QQuick3DModel *model; |
106 | QQuick3DModel *gridModel; |
107 | QQuick3DModel *sliceModel; |
108 | QQuick3DModel *sliceGridModel; |
109 | QVector<SurfaceVertex> vertices; |
110 | QVector<SurfaceVertex> coarceVertices; |
111 | QVector<quint32> indices; |
112 | QVector<quint32> gridIndices; |
113 | QSurface3DSeries *series; |
114 | QQuick3DTexture *texture; |
115 | QQuick3DTexture *heightTexture; |
116 | QQuick3DCustomMaterial *texturedMaterial; |
117 | QQuick3DCustomMaterial *customMaterial; |
118 | int columnCount; |
119 | int rowCount; |
120 | SurfaceVertex selectedVertex; |
121 | bool picked = false; |
122 | QVector3D boundsMin; |
123 | QVector3D boundsMax; |
124 | QVector2D rangeMin; |
125 | QVector2D rangeMax; |
126 | }; |
127 | |
128 | QVector3D getNormalizedVertex(const QSurfaceDataItem &data, bool polar, bool flipXZ); |
129 | void createSmoothIndices(SurfaceModel *model, int x, int y, int endX, int endY); |
130 | void createCoarseVertices(SurfaceModel *model, int x, int y, int endX, int endY); |
131 | void createGridlineIndices(SurfaceModel *model, int x, int y, int endX, int endY); |
132 | void handleChangedSeries(); |
133 | void updateModel(SurfaceModel *model); |
134 | void updateMaterial(SurfaceModel *model); |
135 | void updateSelectedPoint(); |
136 | void addModel(QSurface3DSeries *series); |
137 | void addSliceModel(SurfaceModel *model); |
138 | |
139 | QVector<SurfaceModel *> m_model; |
140 | Surface3DController *m_surfaceController; |
141 | QQuick3DModel *m_selectionPointer = nullptr; |
142 | SurfaceSelectionInstancing *m_instancing = nullptr; |
143 | QQuick3DModel *m_sliceSelectionPointer = nullptr; |
144 | SurfaceSelectionInstancing *m_sliceInstancing = nullptr; |
145 | |
146 | bool m_isIndexDirty = true; |
147 | |
148 | friend class Q3DSurface; |
149 | }; |
150 | |
151 | QT_END_NAMESPACE |
152 | |
153 | #endif // QQUICKGRAPHSSURFACE_P_H |
154 | |