1 | // Copyright (C) 2023 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 QtGraphs 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 | #ifndef QQUICKGRAPHSSCATTER_P_H |
13 | #define QQUICKGRAPHSSCATTER_P_H |
14 | |
15 | #include "qscatter3dseries.h" |
16 | #include "qquickgraphsitem_p.h" |
17 | #include "scatter3dcontroller_p.h" |
18 | #include "scatterinstancing_p.h" |
19 | |
20 | #include <private/graphsglobal_p.h> |
21 | #include <private/qqmldelegatemodel_p.h> |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | class Q3DScatter; |
26 | |
27 | class QQuickGraphsScatter : public QQuickGraphsItem |
28 | { |
29 | Q_OBJECT |
30 | Q_PROPERTY(QValue3DAxis *axisX READ axisX WRITE setAxisX NOTIFY axisXChanged) |
31 | Q_PROPERTY(QValue3DAxis *axisY READ axisY WRITE setAxisY NOTIFY axisYChanged) |
32 | Q_PROPERTY(QValue3DAxis *axisZ READ axisZ WRITE setAxisZ NOTIFY axisZChanged) |
33 | Q_PROPERTY(QScatter3DSeries *selectedSeries READ selectedSeries NOTIFY selectedSeriesChanged) |
34 | Q_PROPERTY(QQmlListProperty<QScatter3DSeries> seriesList READ seriesList CONSTANT) |
35 | Q_CLASSINFO("DefaultProperty" , "seriesList" ) |
36 | |
37 | QML_NAMED_ELEMENT(Scatter3D) |
38 | |
39 | public: |
40 | explicit QQuickGraphsScatter(QQuickItem *parent = 0); |
41 | ~QQuickGraphsScatter(); |
42 | |
43 | QValue3DAxis *axisX() const; |
44 | void setAxisX(QValue3DAxis *axis); |
45 | QValue3DAxis *axisY() const; |
46 | void setAxisY(QValue3DAxis *axis); |
47 | QValue3DAxis *axisZ() const; |
48 | void setAxisZ(QValue3DAxis *axis); |
49 | |
50 | QQmlListProperty<QScatter3DSeries> seriesList(); |
51 | static void appendSeriesFunc(QQmlListProperty<QScatter3DSeries> *list, QScatter3DSeries *series); |
52 | static qsizetype countSeriesFunc(QQmlListProperty<QScatter3DSeries> *list); |
53 | static QScatter3DSeries *atSeriesFunc(QQmlListProperty<QScatter3DSeries> *list, qsizetype index); |
54 | static void clearSeriesFunc(QQmlListProperty<QScatter3DSeries> *list); |
55 | Q_INVOKABLE void addSeries(QScatter3DSeries *series); |
56 | Q_INVOKABLE void removeSeries(QScatter3DSeries *series); |
57 | |
58 | QScatter3DSeries *selectedSeries() const; |
59 | void setSelectedItem(int index, QScatter3DSeries *series); |
60 | static inline int invalidSelectionIndex() { return -1; } |
61 | |
62 | public Q_SLOTS: |
63 | void handleAxisXChanged(QAbstract3DAxis *axis) override; |
64 | void handleAxisYChanged(QAbstract3DAxis *axis) override; |
65 | void handleAxisZChanged(QAbstract3DAxis *axis) override; |
66 | void handleSeriesMeshChanged(); |
67 | void handleMeshSmoothChanged(bool enable); |
68 | |
69 | Q_SIGNALS: |
70 | void axisXChanged(QValue3DAxis *axis); |
71 | void axisYChanged(QValue3DAxis *axis); |
72 | void axisZChanged(QValue3DAxis *axis); |
73 | void selectedSeriesChanged(QScatter3DSeries *series); |
74 | |
75 | protected: |
76 | void calculateSceneScalingFactors() override; |
77 | bool handleMousePressedEvent(QMouseEvent *event) override; |
78 | void componentComplete() override; |
79 | bool handleTouchEvent(QTouchEvent *event) override; |
80 | bool doPicking(const QPointF &position) override; |
81 | void updateShadowQuality(QAbstract3DGraph::ShadowQuality quality) override; |
82 | |
83 | private: |
84 | |
85 | struct ScatterModel { |
86 | QList <QQuick3DModel *> dataItems; |
87 | QQuick3DTexture *seriesTexture; |
88 | QQuick3DTexture *highlightTexture; |
89 | QScatter3DSeries *series; |
90 | |
91 | // For Static optimization |
92 | ScatterInstancing *instancing = nullptr; |
93 | QQuick3DModel *instancingRootItem = nullptr; |
94 | QQuick3DModel *selectionIndicator = nullptr; |
95 | |
96 | }; |
97 | |
98 | Scatter3DController *m_scatterController; |
99 | float m_maxItemSize = 0.0f; |
100 | |
101 | const float m_defaultMinSize = 0.01f; |
102 | const float m_defaultMaxSize = 0.1f; |
103 | const float m_itemScaler = 3.0f; |
104 | float m_pointScale = 0; |
105 | |
106 | const float m_indicatorScaleAdjustment = 1.1f; |
107 | const float m_rangeGradientYHelper = 0.5f; |
108 | |
109 | float m_scaleX = 1.0f; |
110 | float m_scaleY = 1.0f; |
111 | float m_scaleZ = 1.0f; |
112 | |
113 | float m_requestedMargin = -1.0f; |
114 | float m_vBackgroundMargin = 0.1f; |
115 | float m_hBackgroundMargin = 0.1f; |
116 | |
117 | bool m_polarGraph = false; |
118 | |
119 | bool m_selectionActive = false; |
120 | float m_selectedGradientPos = 0.0f; |
121 | int m_selectedItem; |
122 | QScatter3DSeries *m_selectedItemSeries; // Points to the series for which the bar is selected |
123 | // in single series selection cases. |
124 | QQuick3DModel *m_selected = nullptr; |
125 | QQuick3DModel *m_previousSelected = nullptr; |
126 | |
127 | QList<ScatterModel *> m_scatterGraphs; |
128 | |
129 | void connectSeries(QScatter3DSeries *series); |
130 | void disconnectSeries(QScatter3DSeries *series); |
131 | qsizetype getItemIndex(QQuick3DModel *item); |
132 | // void clearSelection(); |
133 | QVector3D selectedItemPosition(); |
134 | |
135 | bool m_smooth = false; |
136 | |
137 | float m_dotSizedScale = 1.0f; |
138 | |
139 | void updateInstancedCustomMaterial(ScatterModel *graphModel, bool isHighlight = false, |
140 | QQuick3DTexture *seriesTexture = nullptr, |
141 | QQuick3DTexture *highlightTexture = nullptr); |
142 | |
143 | void updateItemMaterial(QQuick3DModel *item, bool useGradient, bool rangeGradient, |
144 | const QString &materialName); |
145 | void updatePointItemMaterial(QQuick3DModel *item, |
146 | const QString &materialName, const QString &objectName); |
147 | void updateInstancedPointItemMaterial(QQuick3DModel *item, |
148 | const QString &materialName, const QString &objectName); |
149 | void updateCustomMaterial(QQuick3DModel *item, QQuick3DTexture *texture); |
150 | void updatePrincipledMaterial(QQuick3DModel *model, const QColor &color, |
151 | bool useGradient, QQuick3DTexture *texture = nullptr); |
152 | |
153 | QQuick3DTexture *createTexture(); |
154 | QQuick3DModel *createDataItemModel(QAbstract3DSeries::Mesh meshType); |
155 | QQuick3DNode *createSeriesRoot(); |
156 | QQuick3DModel *createDataItem(QAbstract3DSeries *series); |
157 | void removeDataItems(ScatterModel *graphModel); |
158 | void fixMeshFileName(QString &fileName, QAbstract3DSeries::Mesh meshType); |
159 | QString getMeshFileName(QAbstract3DSeries::Mesh meshType); |
160 | |
161 | void deleteDataItem(QQuick3DModel *item); |
162 | void removeDataItems(QList<QQuick3DModel *> &items, qsizetype count); |
163 | void recreateDataItems(); |
164 | void recreateDataItems(const QList<ScatterModel *> &); |
165 | void addPointsToScatterModel(ScatterModel *graphModel, qsizetype count); |
166 | int sizeDifference(qsizetype size1, qsizetype size2); |
167 | void handleSeriesChanged(QList<QAbstract3DSeries *> changedSeries); |
168 | |
169 | QColor m_selectedSeriesColor; |
170 | |
171 | bool isDotPositionInAxisRange(const QVector3D &dotPos); |
172 | |
173 | QQmlComponent *createRepeaterDelegate(QAbstract3DSeries::Mesh MeshType); |
174 | float calculatePointScaleSize(); |
175 | void updatePointScaleSize(); |
176 | |
177 | void generatePointsForScatterModel(ScatterModel *series); |
178 | void updateScatterGraphItemPositions(ScatterModel *graphModel); |
179 | void updateScatterGraphItemVisuals(ScatterModel *graphModel); |
180 | |
181 | QQuick3DModel *selected() const; |
182 | void setSelected(QQuick3DModel *newSelected); |
183 | void setSelected(QQuick3DModel *root, qsizetype index); |
184 | void clearSelectionModel(); |
185 | void clearAllSelectionInstanced(); |
186 | |
187 | void updateGraph() override; |
188 | void synchData() override; |
189 | |
190 | private slots: |
191 | void cameraRotationChanged(); |
192 | |
193 | friend class Q3DScatter; |
194 | }; |
195 | |
196 | QT_END_NAMESPACE |
197 | #endif // QQUICKGRAPHSSCATTER_P_H |
198 | |