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 Q3DSCATTERCONTROLLER_p_H |
15 | #define Q3DSCATTERCONTROLLER_p_H |
16 | |
17 | #include <private/graphsglobal_p.h> |
18 | #include <private/abstract3dcontroller_p.h> |
19 | |
20 | QT_BEGIN_NAMESPACE |
21 | |
22 | class QScatterDataProxy; |
23 | class QScatter3DSeries; |
24 | |
25 | struct Scatter3DChangeBitField { |
26 | bool selectedItemChanged : 1; |
27 | bool itemChanged : 1; |
28 | |
29 | Scatter3DChangeBitField() : |
30 | selectedItemChanged(true), |
31 | itemChanged(false) |
32 | { |
33 | } |
34 | }; |
35 | |
36 | class Q_GRAPHS_EXPORT Scatter3DController : public Abstract3DController |
37 | { |
38 | Q_OBJECT |
39 | |
40 | public: |
41 | struct ChangeItem { |
42 | QScatter3DSeries *series; |
43 | int index; |
44 | }; |
45 | private: |
46 | Scatter3DChangeBitField m_changeTracker; |
47 | QList<ChangeItem> m_changedItems; |
48 | |
49 | // Rendering |
50 | int m_selectedItem; |
51 | QScatter3DSeries *m_selectedItemSeries; // Points to the series for which the bar is selected |
52 | // in single series selection cases. |
53 | |
54 | struct InsertRemoveRecord { |
55 | bool m_isInsert; |
56 | int m_startIndex; |
57 | int m_count; |
58 | QAbstract3DSeries *m_series; |
59 | |
60 | InsertRemoveRecord() : |
61 | m_isInsert(false), |
62 | m_startIndex(0), |
63 | m_count(0), |
64 | m_series(0) |
65 | {} |
66 | |
67 | InsertRemoveRecord(bool isInsert, int startIndex, int count, QAbstract3DSeries *series) : |
68 | m_isInsert(isInsert), |
69 | m_startIndex(startIndex), |
70 | m_count(count), |
71 | m_series(series) |
72 | {} |
73 | }; |
74 | |
75 | QList<InsertRemoveRecord> m_insertRemoveRecords; |
76 | bool m_recordInsertsAndRemoves; |
77 | |
78 | public: |
79 | explicit Scatter3DController(QRect rect, Q3DScene *scene = 0); |
80 | ~Scatter3DController(); |
81 | |
82 | // Change selection mode |
83 | void setSelectionMode(QAbstract3DGraph::SelectionFlags mode) override; |
84 | |
85 | inline QScatter3DSeries *selectedSeries() const { return m_selectedItemSeries; } |
86 | |
87 | void setSelectedItem(int index, QScatter3DSeries *series); |
88 | static inline int invalidSelectionIndex() { return -1; } |
89 | void clearSelection() override; |
90 | |
91 | void addSeries(QAbstract3DSeries *series) override; |
92 | void removeSeries(QAbstract3DSeries *series) override; |
93 | virtual QList<QScatter3DSeries *> scatterSeriesList(); |
94 | |
95 | inline bool hasSelectedItemChanged() const { return m_changeTracker.selectedItemChanged; } |
96 | inline void setSelectedItemChanged(bool changed) { m_changeTracker.selectedItemChanged = changed; } |
97 | inline bool hasItemChanged() const { return m_changeTracker.itemChanged; } |
98 | inline void setItemChanged(bool changed) { m_changeTracker.itemChanged = changed; } |
99 | |
100 | void clearChangedItems(); |
101 | |
102 | void handleAxisAutoAdjustRangeChangedInOrientation( |
103 | QAbstract3DAxis::AxisOrientation orientation, bool autoAdjust) override; |
104 | void handleAxisRangeChangedBySender(QObject *sender) override; |
105 | void adjustAxisRanges() override; |
106 | inline bool hasChangedSeriesList() const { return !m_changedSeriesList.empty(); } |
107 | inline bool isSeriesVisualsDirty() const { return m_isSeriesVisualsDirty; } |
108 | inline void setSeriesVisualsDirty() { m_isSeriesVisualsDirty = true; } |
109 | inline bool isDataDirty() const { return m_isDataDirty; } |
110 | |
111 | public Q_SLOTS: |
112 | void handleArrayReset(); |
113 | void handleItemsAdded(int startIndex, int count); |
114 | void handleItemsChanged(int startIndex, int count); |
115 | void handleItemsRemoved(int startIndex, int count); |
116 | void handleItemsInserted(int startIndex, int count); |
117 | |
118 | Q_SIGNALS: |
119 | void selectedSeriesChanged(QScatter3DSeries *series); |
120 | |
121 | protected: |
122 | void startRecordingRemovesAndInserts() override; |
123 | |
124 | private: |
125 | |
126 | friend class QQuickGraphsScatter; |
127 | Q_DISABLE_COPY(Scatter3DController) |
128 | }; |
129 | |
130 | QT_END_NAMESPACE |
131 | |
132 | #endif |
133 | |