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 "declarativeseries_p.h" |
31 | #include <QtCore/QMetaMethod> |
32 | |
33 | QT_BEGIN_NAMESPACE_DATAVISUALIZATION |
34 | |
35 | static void setSeriesGradient(QAbstract3DSeries *series, const ColorGradient &gradient, |
36 | GradientType type) |
37 | { |
38 | QLinearGradient newGradient; |
39 | QGradientStops stops; |
40 | QList<ColorGradientStop *> qmlstops = gradient.m_stops; |
41 | |
42 | // Get sorted gradient stops |
43 | for (int i = 0; i < qmlstops.size(); i++) { |
44 | int j = 0; |
45 | while (j < stops.size() && stops.at(i: j).first < qmlstops[i]->position()) |
46 | j++; |
47 | stops.insert(i: j, t: QGradientStop(qmlstops.at(i)->position(), qmlstops.at(i)->color())); |
48 | } |
49 | |
50 | newGradient.setStops(stops); |
51 | switch (type) { |
52 | case GradientTypeBase: |
53 | series->setBaseGradient(newGradient); |
54 | break; |
55 | case GradientTypeSingle: |
56 | series->setSingleHighlightGradient(newGradient); |
57 | break; |
58 | case GradientTypeMulti: |
59 | series->setMultiHighlightGradient(newGradient); |
60 | break; |
61 | default: // Never goes here |
62 | break; |
63 | } |
64 | } |
65 | |
66 | static void connectSeriesGradient(QAbstract3DSeries *series, ColorGradient *newGradient, |
67 | GradientType type, ColorGradient **memberGradient) |
68 | { |
69 | // connect new / disconnect old |
70 | if (newGradient != *memberGradient) { |
71 | if (*memberGradient) |
72 | QObject::disconnect(sender: *memberGradient, signal: 0, receiver: series, member: 0); |
73 | |
74 | *memberGradient = newGradient; |
75 | |
76 | int updatedIndex = newGradient->metaObject()->indexOfSignal(signal: "updated()" ); |
77 | QMetaMethod updateFunction = newGradient->metaObject()->method(index: updatedIndex); |
78 | int handleIndex = -1; |
79 | switch (type) { |
80 | case GradientTypeBase: |
81 | handleIndex = series->metaObject()->indexOfSlot(slot: "handleBaseGradientUpdate()" ); |
82 | break; |
83 | case GradientTypeSingle: |
84 | handleIndex = series->metaObject()->indexOfSlot(slot: "handleSingleHighlightGradientUpdate()" ); |
85 | break; |
86 | case GradientTypeMulti: |
87 | handleIndex = series->metaObject()->indexOfSlot(slot: "handleMultiHighlightGradientUpdate()" ); |
88 | break; |
89 | default: // Never goes here |
90 | break; |
91 | } |
92 | QMetaMethod handleFunction = series->metaObject()->method(index: handleIndex); |
93 | |
94 | if (*memberGradient) |
95 | QObject::connect(sender: *memberGradient, signal: updateFunction, receiver: series, method: handleFunction); |
96 | } |
97 | |
98 | if (*memberGradient) |
99 | setSeriesGradient(series, gradient: **memberGradient, type); |
100 | } |
101 | |
102 | DeclarativeBar3DSeries::DeclarativeBar3DSeries(QObject *parent) |
103 | : QBar3DSeries(parent), |
104 | m_baseGradient(0), |
105 | m_singleHighlightGradient(0), |
106 | m_multiHighlightGradient(0) |
107 | { |
108 | QObject::connect(sender: this, signal: &QBar3DSeries::selectedBarChanged, receiver: this, |
109 | slot: &DeclarativeBar3DSeries::selectedBarChanged); |
110 | } |
111 | |
112 | DeclarativeBar3DSeries::~DeclarativeBar3DSeries() |
113 | { |
114 | } |
115 | |
116 | QQmlListProperty<QObject> DeclarativeBar3DSeries::seriesChildren() |
117 | { |
118 | return QQmlListProperty<QObject>(this, this, &DeclarativeBar3DSeries::appendSeriesChildren |
119 | , 0, 0, 0); |
120 | } |
121 | |
122 | void DeclarativeBar3DSeries::appendSeriesChildren(QQmlListProperty<QObject> *list, QObject *element) |
123 | { |
124 | QBarDataProxy *proxy = qobject_cast<QBarDataProxy *>(object: element); |
125 | if (proxy) |
126 | reinterpret_cast<DeclarativeBar3DSeries *>(list->data)->setDataProxy(proxy); |
127 | } |
128 | |
129 | void DeclarativeBar3DSeries::setSelectedBar(const QPointF &position) |
130 | { |
131 | QBar3DSeries::setSelectedBar(position.toPoint()); |
132 | } |
133 | |
134 | QPointF DeclarativeBar3DSeries::selectedBar() const |
135 | { |
136 | return QPointF(QBar3DSeries::selectedBar()); |
137 | } |
138 | |
139 | QPointF DeclarativeBar3DSeries::invalidSelectionPosition() const |
140 | { |
141 | return QPointF(QBar3DSeries::invalidSelectionPosition()); |
142 | } |
143 | |
144 | void DeclarativeBar3DSeries::setBaseGradient(ColorGradient *gradient) |
145 | { |
146 | connectSeriesGradient(series: this, newGradient: gradient, type: GradientTypeBase, memberGradient: &m_baseGradient); |
147 | } |
148 | |
149 | ColorGradient *DeclarativeBar3DSeries::baseGradient() const |
150 | { |
151 | return m_baseGradient; |
152 | } |
153 | |
154 | void DeclarativeBar3DSeries::setSingleHighlightGradient(ColorGradient *gradient) |
155 | { |
156 | connectSeriesGradient(series: this, newGradient: gradient, type: GradientTypeSingle, memberGradient: &m_singleHighlightGradient); |
157 | } |
158 | |
159 | ColorGradient *DeclarativeBar3DSeries::singleHighlightGradient() const |
160 | { |
161 | return m_singleHighlightGradient; |
162 | } |
163 | |
164 | void DeclarativeBar3DSeries::setMultiHighlightGradient(ColorGradient *gradient) |
165 | { |
166 | connectSeriesGradient(series: this, newGradient: gradient, type: GradientTypeMulti, memberGradient: &m_multiHighlightGradient); |
167 | } |
168 | |
169 | ColorGradient *DeclarativeBar3DSeries::multiHighlightGradient() const |
170 | { |
171 | return m_multiHighlightGradient; |
172 | } |
173 | |
174 | void DeclarativeBar3DSeries::handleBaseGradientUpdate() |
175 | { |
176 | if (m_baseGradient) |
177 | setSeriesGradient(series: this, gradient: *m_baseGradient, type: GradientTypeBase); |
178 | } |
179 | |
180 | void DeclarativeBar3DSeries::handleSingleHighlightGradientUpdate() |
181 | { |
182 | if (m_singleHighlightGradient) |
183 | setSeriesGradient(series: this, gradient: *m_singleHighlightGradient, type: GradientTypeSingle); |
184 | } |
185 | |
186 | void DeclarativeBar3DSeries::handleMultiHighlightGradientUpdate() |
187 | { |
188 | if (m_multiHighlightGradient) |
189 | setSeriesGradient(series: this, gradient: *m_multiHighlightGradient, type: GradientTypeMulti); |
190 | } |
191 | |
192 | DeclarativeScatter3DSeries::DeclarativeScatter3DSeries(QObject *parent) |
193 | : QScatter3DSeries(parent), |
194 | m_baseGradient(0), |
195 | m_singleHighlightGradient(0), |
196 | m_multiHighlightGradient(0) |
197 | { |
198 | } |
199 | |
200 | DeclarativeScatter3DSeries::~DeclarativeScatter3DSeries() |
201 | { |
202 | } |
203 | |
204 | QQmlListProperty<QObject> DeclarativeScatter3DSeries::seriesChildren() |
205 | { |
206 | return QQmlListProperty<QObject>(this, this, &DeclarativeScatter3DSeries::appendSeriesChildren |
207 | , 0, 0, 0); |
208 | } |
209 | |
210 | void DeclarativeScatter3DSeries::appendSeriesChildren(QQmlListProperty<QObject> *list, |
211 | QObject *element) |
212 | { |
213 | QScatterDataProxy *proxy = qobject_cast<QScatterDataProxy *>(object: element); |
214 | if (proxy) |
215 | reinterpret_cast<DeclarativeScatter3DSeries *>(list->data)->setDataProxy(proxy); |
216 | } |
217 | |
218 | void DeclarativeScatter3DSeries::setBaseGradient(ColorGradient *gradient) |
219 | { |
220 | connectSeriesGradient(series: this, newGradient: gradient, type: GradientTypeBase, memberGradient: &m_baseGradient); |
221 | } |
222 | |
223 | ColorGradient *DeclarativeScatter3DSeries::baseGradient() const |
224 | { |
225 | return m_baseGradient; |
226 | } |
227 | |
228 | void DeclarativeScatter3DSeries::setSingleHighlightGradient(ColorGradient *gradient) |
229 | { |
230 | connectSeriesGradient(series: this, newGradient: gradient, type: GradientTypeSingle, memberGradient: &m_singleHighlightGradient); |
231 | } |
232 | |
233 | ColorGradient *DeclarativeScatter3DSeries::singleHighlightGradient() const |
234 | { |
235 | return m_singleHighlightGradient; |
236 | } |
237 | |
238 | void DeclarativeScatter3DSeries::setMultiHighlightGradient(ColorGradient *gradient) |
239 | { |
240 | connectSeriesGradient(series: this, newGradient: gradient, type: GradientTypeMulti, memberGradient: &m_multiHighlightGradient); |
241 | } |
242 | |
243 | ColorGradient *DeclarativeScatter3DSeries::multiHighlightGradient() const |
244 | { |
245 | return m_multiHighlightGradient; |
246 | } |
247 | |
248 | int DeclarativeScatter3DSeries::invalidSelectionIndex() const |
249 | { |
250 | return QScatter3DSeries::invalidSelectionIndex(); |
251 | } |
252 | |
253 | void DeclarativeScatter3DSeries::handleBaseGradientUpdate() |
254 | { |
255 | if (m_baseGradient) |
256 | setSeriesGradient(series: this, gradient: *m_baseGradient, type: GradientTypeBase); |
257 | } |
258 | |
259 | void DeclarativeScatter3DSeries::handleSingleHighlightGradientUpdate() |
260 | { |
261 | if (m_singleHighlightGradient) |
262 | setSeriesGradient(series: this, gradient: *m_singleHighlightGradient, type: GradientTypeSingle); |
263 | } |
264 | |
265 | void DeclarativeScatter3DSeries::handleMultiHighlightGradientUpdate() |
266 | { |
267 | if (m_multiHighlightGradient) |
268 | setSeriesGradient(series: this, gradient: *m_multiHighlightGradient, type: GradientTypeMulti); |
269 | } |
270 | |
271 | DeclarativeSurface3DSeries::DeclarativeSurface3DSeries(QObject *parent) |
272 | : QSurface3DSeries(parent), |
273 | m_baseGradient(0), |
274 | m_singleHighlightGradient(0), |
275 | m_multiHighlightGradient(0) |
276 | { |
277 | QObject::connect(sender: this, signal: &QSurface3DSeries::selectedPointChanged, receiver: this, |
278 | slot: &DeclarativeSurface3DSeries::selectedPointChanged); |
279 | } |
280 | |
281 | DeclarativeSurface3DSeries::~DeclarativeSurface3DSeries() |
282 | { |
283 | } |
284 | |
285 | void DeclarativeSurface3DSeries::setSelectedPoint(const QPointF &position) |
286 | { |
287 | QSurface3DSeries::setSelectedPoint(position.toPoint()); |
288 | } |
289 | |
290 | QPointF DeclarativeSurface3DSeries::selectedPoint() const |
291 | { |
292 | return QPointF(QSurface3DSeries::selectedPoint()); |
293 | } |
294 | |
295 | QPointF DeclarativeSurface3DSeries::invalidSelectionPosition() const |
296 | { |
297 | return QPointF(QSurface3DSeries::invalidSelectionPosition()); |
298 | } |
299 | |
300 | QQmlListProperty<QObject> DeclarativeSurface3DSeries::seriesChildren() |
301 | { |
302 | return QQmlListProperty<QObject>(this, this, &DeclarativeSurface3DSeries::appendSeriesChildren |
303 | , 0, 0, 0); |
304 | } |
305 | |
306 | void DeclarativeSurface3DSeries::appendSeriesChildren(QQmlListProperty<QObject> *list, |
307 | QObject *element) |
308 | { |
309 | QSurfaceDataProxy *proxy = qobject_cast<QSurfaceDataProxy *>(object: element); |
310 | if (proxy) |
311 | reinterpret_cast<DeclarativeSurface3DSeries *>(list->data)->setDataProxy(proxy); |
312 | } |
313 | |
314 | void DeclarativeSurface3DSeries::setBaseGradient(ColorGradient *gradient) |
315 | { |
316 | connectSeriesGradient(series: this, newGradient: gradient, type: GradientTypeBase, memberGradient: &m_baseGradient); |
317 | } |
318 | |
319 | ColorGradient *DeclarativeSurface3DSeries::baseGradient() const |
320 | { |
321 | return m_baseGradient; |
322 | } |
323 | |
324 | void DeclarativeSurface3DSeries::setSingleHighlightGradient(ColorGradient *gradient) |
325 | { |
326 | connectSeriesGradient(series: this, newGradient: gradient, type: GradientTypeSingle, memberGradient: &m_singleHighlightGradient); |
327 | } |
328 | |
329 | ColorGradient *DeclarativeSurface3DSeries::singleHighlightGradient() const |
330 | { |
331 | return m_singleHighlightGradient; |
332 | } |
333 | |
334 | void DeclarativeSurface3DSeries::setMultiHighlightGradient(ColorGradient *gradient) |
335 | { |
336 | connectSeriesGradient(series: this, newGradient: gradient, type: GradientTypeMulti, memberGradient: &m_multiHighlightGradient); |
337 | } |
338 | |
339 | ColorGradient *DeclarativeSurface3DSeries::multiHighlightGradient() const |
340 | { |
341 | return m_multiHighlightGradient; |
342 | } |
343 | |
344 | void DeclarativeSurface3DSeries::handleBaseGradientUpdate() |
345 | { |
346 | if (m_baseGradient) |
347 | setSeriesGradient(series: this, gradient: *m_baseGradient, type: GradientTypeBase); |
348 | } |
349 | |
350 | void DeclarativeSurface3DSeries::handleSingleHighlightGradientUpdate() |
351 | { |
352 | if (m_singleHighlightGradient) |
353 | setSeriesGradient(series: this, gradient: *m_singleHighlightGradient, type: GradientTypeSingle); |
354 | } |
355 | |
356 | void DeclarativeSurface3DSeries::handleMultiHighlightGradientUpdate() |
357 | { |
358 | if (m_multiHighlightGradient) |
359 | setSeriesGradient(series: this, gradient: *m_multiHighlightGradient, type: GradientTypeMulti); |
360 | } |
361 | |
362 | QT_END_NAMESPACE_DATAVISUALIZATION |
363 | |