1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Data Visualization module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 or (at your option) any later version |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | |
30 | #include "declarativebars_p.h" |
31 | #include <QtCore/QMutexLocker> |
32 | |
33 | QT_BEGIN_NAMESPACE_DATAVISUALIZATION |
34 | |
35 | DeclarativeBars::DeclarativeBars(QQuickItem *parent) |
36 | : AbstractDeclarative(parent), |
37 | m_barsController(0) |
38 | { |
39 | setAcceptedMouseButtons(Qt::AllButtons); |
40 | |
41 | // Create the shared component on the main GUI thread. |
42 | m_barsController = new Bars3DController(boundingRect().toRect(), new Declarative3DScene); |
43 | AbstractDeclarative::setSharedController(m_barsController); |
44 | |
45 | QObject::connect(sender: m_barsController, signal: &Bars3DController::primarySeriesChanged, |
46 | receiver: this, slot: &DeclarativeBars::primarySeriesChanged); |
47 | QObject::connect(sender: m_barsController, signal: &Bars3DController::selectedSeriesChanged, |
48 | receiver: this, slot: &DeclarativeBars::selectedSeriesChanged); |
49 | } |
50 | |
51 | DeclarativeBars::~DeclarativeBars() |
52 | { |
53 | QMutexLocker locker(m_nodeMutex.data()); |
54 | const QMutexLocker locker2(mutex()); |
55 | delete m_barsController; |
56 | } |
57 | |
58 | QCategory3DAxis *DeclarativeBars::rowAxis() const |
59 | { |
60 | return static_cast<QCategory3DAxis *>(m_barsController->axisZ()); |
61 | } |
62 | |
63 | void DeclarativeBars::setRowAxis(QCategory3DAxis *axis) |
64 | { |
65 | m_barsController->setAxisZ(axis); |
66 | } |
67 | |
68 | QValue3DAxis *DeclarativeBars::valueAxis() const |
69 | { |
70 | return static_cast<QValue3DAxis *>(m_barsController->axisY()); |
71 | } |
72 | |
73 | void DeclarativeBars::setValueAxis(QValue3DAxis *axis) |
74 | { |
75 | m_barsController->setAxisY(axis); |
76 | } |
77 | |
78 | QCategory3DAxis *DeclarativeBars::columnAxis() const |
79 | { |
80 | return static_cast<QCategory3DAxis *>(m_barsController->axisX()); |
81 | } |
82 | |
83 | void DeclarativeBars::setColumnAxis(QCategory3DAxis *axis) |
84 | { |
85 | m_barsController->setAxisX(axis); |
86 | } |
87 | |
88 | void DeclarativeBars::setMultiSeriesUniform(bool uniform) |
89 | { |
90 | if (uniform != isMultiSeriesUniform()) { |
91 | m_barsController->setMultiSeriesScaling(uniform); |
92 | emit multiSeriesUniformChanged(uniform); |
93 | } |
94 | } |
95 | |
96 | bool DeclarativeBars::isMultiSeriesUniform() const |
97 | { |
98 | return m_barsController->multiSeriesScaling(); |
99 | } |
100 | |
101 | void DeclarativeBars::setBarThickness(float thicknessRatio) |
102 | { |
103 | if (thicknessRatio != barThickness()) { |
104 | m_barsController->setBarSpecs(thicknessRatio: GLfloat(thicknessRatio), spacing: barSpacing(), |
105 | relative: isBarSpacingRelative()); |
106 | emit barThicknessChanged(thicknessRatio); |
107 | } |
108 | } |
109 | |
110 | float DeclarativeBars::barThickness() const |
111 | { |
112 | return m_barsController->barThickness(); |
113 | } |
114 | |
115 | void DeclarativeBars::setBarSpacing(QSizeF spacing) |
116 | { |
117 | if (spacing != barSpacing()) { |
118 | m_barsController->setBarSpecs(thicknessRatio: GLfloat(barThickness()), spacing, relative: isBarSpacingRelative()); |
119 | emit barSpacingChanged(spacing); |
120 | } |
121 | } |
122 | |
123 | QSizeF DeclarativeBars::barSpacing() const |
124 | { |
125 | return m_barsController->barSpacing(); |
126 | } |
127 | |
128 | void DeclarativeBars::setBarSpacingRelative(bool relative) |
129 | { |
130 | if (relative != isBarSpacingRelative()) { |
131 | m_barsController->setBarSpecs(thicknessRatio: GLfloat(barThickness()), spacing: barSpacing(), relative); |
132 | emit barSpacingRelativeChanged(relative); |
133 | } |
134 | } |
135 | |
136 | bool DeclarativeBars::isBarSpacingRelative() const |
137 | { |
138 | return m_barsController->isBarSpecRelative(); |
139 | } |
140 | |
141 | QBar3DSeries *DeclarativeBars::selectedSeries() const |
142 | { |
143 | return m_barsController->selectedSeries(); |
144 | } |
145 | |
146 | void DeclarativeBars::setFloorLevel(float level) |
147 | { |
148 | if (level != floorLevel()) { |
149 | m_barsController->setFloorLevel(level); |
150 | emit floorLevelChanged(level); |
151 | } |
152 | } |
153 | |
154 | float DeclarativeBars::floorLevel() const |
155 | { |
156 | return m_barsController->floorLevel(); |
157 | } |
158 | |
159 | QQmlListProperty<QBar3DSeries> DeclarativeBars::seriesList() |
160 | { |
161 | return QQmlListProperty<QBar3DSeries>(this, this, |
162 | &DeclarativeBars::appendSeriesFunc, |
163 | &DeclarativeBars::countSeriesFunc, |
164 | &DeclarativeBars::atSeriesFunc, |
165 | &DeclarativeBars::clearSeriesFunc); |
166 | } |
167 | |
168 | void DeclarativeBars::appendSeriesFunc(QQmlListProperty<QBar3DSeries> *list, QBar3DSeries *series) |
169 | { |
170 | reinterpret_cast<DeclarativeBars *>(list->data)->addSeries(series); |
171 | } |
172 | |
173 | int DeclarativeBars::countSeriesFunc(QQmlListProperty<QBar3DSeries> *list) |
174 | { |
175 | return reinterpret_cast<DeclarativeBars *>(list->data)->m_barsController->barSeriesList().size(); |
176 | } |
177 | |
178 | QBar3DSeries *DeclarativeBars::atSeriesFunc(QQmlListProperty<QBar3DSeries> *list, int index) |
179 | { |
180 | return reinterpret_cast<DeclarativeBars *>(list->data)->m_barsController->barSeriesList().at(i: index); |
181 | } |
182 | |
183 | void DeclarativeBars::clearSeriesFunc(QQmlListProperty<QBar3DSeries> *list) |
184 | { |
185 | DeclarativeBars *declBars = reinterpret_cast<DeclarativeBars *>(list->data); |
186 | QList<QBar3DSeries *> realList = declBars->m_barsController->barSeriesList(); |
187 | int count = realList.size(); |
188 | for (int i = 0; i < count; i++) |
189 | declBars->removeSeries(series: realList.at(i)); |
190 | } |
191 | |
192 | void DeclarativeBars::addSeries(QBar3DSeries *series) |
193 | { |
194 | m_barsController->addSeries(series); |
195 | } |
196 | |
197 | void DeclarativeBars::removeSeries(QBar3DSeries *series) |
198 | { |
199 | m_barsController->removeSeries(series); |
200 | series->setParent(this); // Reparent as removing will leave series parentless |
201 | } |
202 | |
203 | void DeclarativeBars::insertSeries(int index, QBar3DSeries *series) |
204 | { |
205 | m_barsController->insertSeries(index, series); |
206 | } |
207 | |
208 | void DeclarativeBars::setPrimarySeries(QBar3DSeries *series) |
209 | { |
210 | m_barsController->setPrimarySeries(series); |
211 | } |
212 | |
213 | QBar3DSeries *DeclarativeBars::primarySeries() const |
214 | { |
215 | return m_barsController->primarySeries(); |
216 | } |
217 | |
218 | void DeclarativeBars::handleAxisXChanged(QAbstract3DAxis *axis) |
219 | { |
220 | emit columnAxisChanged(axis: static_cast<QCategory3DAxis *>(axis)); |
221 | } |
222 | |
223 | void DeclarativeBars::handleAxisYChanged(QAbstract3DAxis *axis) |
224 | { |
225 | emit valueAxisChanged(axis: static_cast<QValue3DAxis *>(axis)); |
226 | } |
227 | |
228 | void DeclarativeBars::handleAxisZChanged(QAbstract3DAxis *axis) |
229 | { |
230 | emit rowAxisChanged(axis: static_cast<QCategory3DAxis *>(axis)); |
231 | } |
232 | |
233 | QT_END_NAMESPACE_DATAVISUALIZATION |
234 | |