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 Q3DBARSCONTROLLER_p_H
15#define Q3DBARSCONTROLLER_p_H
16
17#include "axishelper_p.h"
18#include <private/graphsglobal_p.h>
19#include <private/abstract3dcontroller_p.h>
20#include <QtQuick3D/private/qquick3drepeater_p.h>
21
22QT_BEGIN_NAMESPACE
23
24class QBarDataProxy;
25class QBar3DSeries;
26class QQuick3DModel;
27
28struct Bars3DChangeBitField {
29 bool multiSeriesScalingChanged : 1;
30 bool barSpecsChanged : 1;
31 bool selectedBarChanged : 1;
32 bool rowsChanged : 1;
33 bool itemChanged : 1;
34 bool floorLevelChanged : 1;
35 bool barSeriesMarginChanged : 1;
36
37 Bars3DChangeBitField() :
38 multiSeriesScalingChanged(true),
39 barSpecsChanged(true),
40 selectedBarChanged(true),
41 rowsChanged(false),
42 itemChanged(false),
43 floorLevelChanged(false),
44 barSeriesMarginChanged(false)
45 {
46 }
47};
48
49class Q_GRAPHS_EXPORT Bars3DController : public Abstract3DController
50{
51 Q_OBJECT
52
53public:
54 struct ChangeItem {
55 QBar3DSeries *series;
56 QPoint point;
57 };
58 struct ChangeRow {
59 QBar3DSeries *series;
60 int row;
61 };
62
63private:
64 Bars3DChangeBitField m_changeTracker;
65 QList<ChangeItem> m_changedItems;
66 QList<ChangeRow> m_changedRows;
67
68 // Interaction
69 QPoint m_selectedBar; // Points to row & column in data window.
70 QBar3DSeries *m_selectedBarSeries; // Points to the series for which the bar is selected in
71 // single series selection cases.
72 QBar3DSeries *m_primarySeries; // Category axis labels are taken from the primary series
73
74 // Look'n'feel
75 bool m_isMultiSeriesUniform;
76 bool m_isBarSpecRelative;
77 float m_barThicknessRatio;
78 QSizeF m_barSpacing;
79 float m_floorLevel;
80 QSizeF m_barSeriesMargin;
81
82public:
83 explicit Bars3DController(QRect rect, Q3DScene *scene = 0);
84 ~Bars3DController();
85
86 void setMultiSeriesScaling(bool uniform);
87 bool multiSeriesScaling() const;
88
89 // bar thickness, spacing between bars, and is spacing relative to thickness or absolute
90 // y -component sets the thickness/spacing of z -direction
91 // With relative 0.0f means side-to-side, 1.0f = one thickness in between
92 void setBarSpecs(float thicknessRatio = 1.0f,
93 const QSizeF &spacing = QSizeF(1.0, 1.0),
94 bool relative = true);
95 void setBarSeriesMargin(const QSizeF &margin);
96 QSizeF barSeriesMargin();
97
98 float barThickness();
99 QSizeF barSpacing();
100 bool isBarSpecRelative();
101 void setFloorLevel(float level);
102 float floorLevel() const;
103
104 inline QBar3DSeries *selectedSeries() const { return m_selectedBarSeries; }
105
106 void setSelectionMode(QAbstract3DGraph::SelectionFlags mode) override;
107 void setSelectedBar(const QPoint &position, QBar3DSeries *series, bool enterSlice);
108 void clearSelection() override;
109
110 void handleAxisAutoAdjustRangeChangedInOrientation(
111 QAbstract3DAxis::AxisOrientation orientation, bool autoAdjust) override;
112 void handleSeriesVisibilityChangedBySender(QObject *sender) override;
113
114 static QPoint invalidSelectionPosition();
115
116 void setAxisX(QAbstract3DAxis *axis) override;
117 void setAxisZ(QAbstract3DAxis *axis) override;
118
119 virtual void setPrimarySeries(QBar3DSeries *series);
120 virtual QBar3DSeries *primarySeries() const;
121 void addSeries(QAbstract3DSeries *series) override;
122 void removeSeries(QAbstract3DSeries *series) override;
123 void insertSeries(int index, QAbstract3DSeries *series) override;
124 virtual QList<QBar3DSeries *> barSeriesList();
125
126 void handleAxisRangeChangedBySender(QObject *sender) override;
127 void adjustAxisRanges() override;
128
129 bool hasChangedSeriesList() { return !m_changedSeriesList.isEmpty(); }
130 bool isSeriesVisualsDirty() const { return m_isSeriesVisualsDirty; }
131 void setSeriesVisualsDirty(bool dirty) { m_isSeriesVisualsDirty = dirty; }
132 bool isDataDirty() const { return m_isDataDirty; }
133 void setDataDirty(bool dirty) { m_isDataDirty = dirty; }
134
135public Q_SLOTS:
136 void handleArrayReset();
137 void handleRowsAdded(int startIndex, int count);
138 void handleRowsChanged(int startIndex, int count);
139 void handleRowsRemoved(int startIndex, int count);
140 void handleRowsInserted(int startIndex, int count);
141 void handleItemChanged(int rowIndex, int columnIndex);
142 void handleDataRowLabelsChanged();
143 void handleDataColumnLabelsChanged();
144 void handleRowColorsChanged();
145
146Q_SIGNALS:
147 void primarySeriesChanged(QBar3DSeries *series);
148 void selectedSeriesChanged(QBar3DSeries *series);
149
150protected:
151 QAbstract3DAxis *createDefaultAxis(QAbstract3DAxis::AxisOrientation orientation) override;
152 QSizeF m_cachedBarThickness;
153 QSizeF m_cachedBarSpacing;
154
155 void updateBarSpecs(float thicknessRatio, const QSizeF &spacing, bool relative);
156
157private:
158 void adjustSelectionPosition(QPoint &pos, const QBar3DSeries *series);
159
160 Q_DISABLE_COPY(Bars3DController)
161 friend class QQuickGraphsItem;
162 friend class QQuickGraphsBars;
163};
164
165QT_END_NAMESPACE
166
167#endif
168

source code of qtgraphs/src/graphs/engine/bars3dcontroller_p.h