@@ -1,639 +1,638 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "qbarset.h" |
|
22 | 22 | #include "qbarset_p.h" |
|
23 | 23 | |
|
24 | 24 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
25 | 25 | |
|
26 | 26 | /*! |
|
27 | 27 | \class QBarSet |
|
28 | 28 | \brief Building block for different bar charts |
|
29 | 29 | |
|
30 | 30 | QBarSet represents one set of bars. Set of bars contains one data value for each category. |
|
31 | 31 | First value of set is assumed to belong to first category, second to second category and so on. |
|
32 | 32 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
33 | 33 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
34 | 34 | |
|
35 | 35 | \mainclass |
|
36 | 36 | |
|
37 | 37 | \sa QAbstractBarSeries, QBarSeries, QStackedBarSeries, QPercentBarSeries |
|
38 | 38 | */ |
|
39 | 39 | /*! |
|
40 | 40 | \qmlclass BarSet QBarSet |
|
41 | 41 | |
|
42 | 42 | BarSet represents one set of bars. Set of bars contains one data value for each category. |
|
43 | 43 | First value of set is assumed to belong to first category, second to second category and so on. |
|
44 | 44 | If set has fewer values than there are categories, then the missing values are assumed to be |
|
45 | 45 | at the end of set. For missing values in middle of a set, numerical value of zero is used. |
|
46 | 46 | \sa AbstractBarSeries, BarSeries, StackedBarSeries, PercentBarSeries |
|
47 | 47 | */ |
|
48 | 48 | |
|
49 | 49 | /*! |
|
50 | 50 | \property QBarSet::label |
|
51 | 51 | Defines the label of the barSet. |
|
52 | 52 | */ |
|
53 | 53 | /*! |
|
54 | 54 | \qmlproperty string BarSet::label |
|
55 | 55 | Defines the label of the barSet. |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \property QBarSet::pen |
|
60 | 60 | \brief Defines the pen used by the barSet. |
|
61 | 61 | */ |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | \property QBarSet::brush |
|
65 | 65 | \brief Defines the brush used by the barSet. |
|
66 | 66 | */ |
|
67 | 67 | |
|
68 | 68 | /*! |
|
69 | 69 | \property QBarSet::labelBrush |
|
70 | 70 | \brief Defines the brush used by the barSet's label. |
|
71 | 71 | */ |
|
72 | 72 | |
|
73 | 73 | /*! |
|
74 | 74 | \property QBarSet::labelFont |
|
75 | 75 | \brief Defines the font used by the barSet's label. |
|
76 | 76 | */ |
|
77 | 77 | |
|
78 | 78 | /*! |
|
79 | 79 | \qmlproperty Font BarSet::labelFont |
|
80 | 80 | Defines the font used by the barSet's label. |
|
81 | 81 | |
|
82 | 82 | See the \l {Font} {QML Font Element} for detailed documentation. |
|
83 | 83 | */ |
|
84 | 84 | |
|
85 | 85 | /*! |
|
86 | 86 | \property QBarSet::color |
|
87 | 87 | The fill (brush) color of the bar set. |
|
88 | 88 | */ |
|
89 | 89 | /*! |
|
90 | 90 | \qmlproperty color BarSet::color |
|
91 | 91 | The fill (brush) color of the bar set. |
|
92 | 92 | */ |
|
93 | 93 | |
|
94 | 94 | /*! |
|
95 | 95 | \property QBarSet::borderColor |
|
96 | 96 | The line (pen) color of the bar set. |
|
97 | 97 | */ |
|
98 | 98 | /*! |
|
99 | 99 | \qmlproperty color BarSet::borderColor |
|
100 | 100 | The line (pen) color of the bar set. |
|
101 | 101 | */ |
|
102 | 102 | |
|
103 | 103 | /*! |
|
104 | 104 | \property QBarSet::labelColor |
|
105 | 105 | The text (label) color of the bar set. |
|
106 | 106 | */ |
|
107 | 107 | /*! |
|
108 | 108 | \qmlproperty color BarSet::labelColor |
|
109 | 109 | The text (label) color of the bar set. |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \fn void QBarSet::clicked(int index) |
|
114 | 114 | |
|
115 | 115 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
116 | 116 | Clicked bar inside set is indexed by \a index |
|
117 | 117 | */ |
|
118 | 118 | |
|
119 | 119 | /*! |
|
120 | 120 | \fn void QBarSet::hovered(bool status) |
|
121 | 121 | |
|
122 | 122 | The signal is emitted if mouse is hovered on top of barset. |
|
123 | 123 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
124 | 124 | */ |
|
125 | 125 | |
|
126 | 126 | |
|
127 | 127 | /*! |
|
128 | 128 | \fn void QBarSet::labelChanged() |
|
129 | 129 | This signal is emitted when the label of the barSet has changed. |
|
130 | 130 | \sa label |
|
131 | 131 | */ |
|
132 | 132 | /*! |
|
133 | 133 | \qmlsignal BarSet::onLabelChanged() |
|
134 | 134 | This signal is emitted when the label of the barSet has changed. |
|
135 | 135 | */ |
|
136 | 136 | |
|
137 | 137 | /*! |
|
138 | 138 | \fn void QBarSet::penChanged() |
|
139 | 139 | This signal is emitted when the pen of the barSet has changed. |
|
140 | 140 | \sa pen |
|
141 | 141 | */ |
|
142 | 142 | |
|
143 | 143 | /*! |
|
144 | 144 | \fn void QBarSet::brushChanged() |
|
145 | 145 | This signal is emitted when the brush of the barSet has changed. |
|
146 | 146 | \sa brush |
|
147 | 147 | */ |
|
148 | 148 | |
|
149 | 149 | /*! |
|
150 | 150 | \fn void QBarSet::labelBrushChanged() |
|
151 | 151 | This signal is emitted when the brush of the barSet's label has changed. |
|
152 | 152 | \sa labelBrush |
|
153 | 153 | */ |
|
154 | 154 | |
|
155 | 155 | /*! |
|
156 | 156 | \fn void QBarSet::labelFontChanged() |
|
157 | 157 | This signal is emitted when the font of the barSet's label has changed. |
|
158 | 158 | \sa labelBrush |
|
159 | 159 | */ |
|
160 | 160 | |
|
161 | 161 | /*! |
|
162 | 162 | \fn void QBarSet::colorChanged(QColor) |
|
163 | 163 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
164 | 164 | */ |
|
165 | 165 | /*! |
|
166 | 166 | \qmlsignal BarSet::onColorChanged(color color) |
|
167 | 167 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
168 | 168 | */ |
|
169 | 169 | |
|
170 | 170 | /*! |
|
171 | 171 | \fn void QBarSet::borderColorChanged(QColor) |
|
172 | 172 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
173 | 173 | */ |
|
174 | 174 | /*! |
|
175 | 175 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
176 | 176 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
177 | 177 | */ |
|
178 | 178 | |
|
179 | 179 | /*! |
|
180 | 180 | \fn void QBarSet::labelColorChanged(QColor) |
|
181 | 181 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
182 | 182 | */ |
|
183 | 183 | /*! |
|
184 | 184 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
185 | 185 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
186 | 186 | */ |
|
187 | 187 | |
|
188 | 188 | /*! |
|
189 | 189 | \fn void QBarSet::valuesAdded(int index, int count) |
|
190 | 190 | This signal is emitted when new values have been added to the set. |
|
191 | 191 | Parameter \a index indicates the position of the first inserted value. |
|
192 | 192 | Parameter \a count is the number of iserted values. |
|
193 | 193 | \sa append(), insert() |
|
194 | 194 | */ |
|
195 | 195 | /*! |
|
196 | 196 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
197 | 197 | This signal is emitted when new values have been added to the set. |
|
198 | 198 | Parameter \a index indicates the position of the first inserted value. |
|
199 | 199 | Parameter \a count is the number of iserted values. |
|
200 | 200 | */ |
|
201 | 201 | |
|
202 | 202 | /*! |
|
203 | 203 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
204 | 204 | This signal is emitted values have been removed from the set. |
|
205 | 205 | Parameter \a index indicates the position of the first removed value. |
|
206 | 206 | Parameter \a count is the number of removed values. |
|
207 | 207 | \sa remove() |
|
208 | 208 | */ |
|
209 | 209 | /*! |
|
210 | 210 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
211 | 211 | This signal is emitted values have been removed from the set. |
|
212 | 212 | Parameter \a index indicates the position of the first removed value. |
|
213 | 213 | Parameter \a count is the number of removed values. |
|
214 | 214 | */ |
|
215 | 215 | |
|
216 | 216 | /*! |
|
217 | 217 | \fn void QBarSet::valueChanged(int index) |
|
218 | 218 | This signal is emitted values the value in the set has been modified. |
|
219 | 219 | Parameter \a index indicates the position of the modified value. |
|
220 | 220 | \sa at() |
|
221 | 221 | */ |
|
222 | 222 | /*! |
|
223 | 223 | \qmlsignal BarSet::onValueChanged(int index) |
|
224 | 224 | This signal is emitted values the value in the set has been modified. |
|
225 | 225 | Parameter \a index indicates the position of the modified value. |
|
226 | 226 | */ |
|
227 | 227 | |
|
228 | 228 | /*! |
|
229 | 229 | \qmlproperty int BarSet::count |
|
230 | 230 | The count of values on the barset |
|
231 | 231 | */ |
|
232 | 232 | |
|
233 | 233 | /*! |
|
234 | 234 | \qmlproperty QVariantList BarSet::values |
|
235 | 235 | The values of the barset. You can set either a list of reals or a list of points as values. If you set a list of |
|
236 | 236 | reals as values, the values are automatically completed to points by using the index of a value as it's |
|
237 | 237 | x-coordinate. For example: |
|
238 | 238 | \code |
|
239 | 239 | myBarSet1.values = [0, 5, 1, 5]; |
|
240 | 240 | myBarSet2.values = [Qt.point(0, 1), Qt.point(1, 5), Qt.point(2.2, 4.3)]; |
|
241 | 241 | \endcode |
|
242 | 242 | */ |
|
243 | 243 | |
|
244 | 244 | /*! |
|
245 | 245 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
246 | 246 | */ |
|
247 | 247 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
248 | 248 | : QObject(parent) |
|
249 | 249 | ,d_ptr(new QBarSetPrivate(label,this)) |
|
250 | 250 | { |
|
251 | 251 | } |
|
252 | 252 | |
|
253 | 253 | /*! |
|
254 | 254 | Destroys the barset |
|
255 | 255 | */ |
|
256 | 256 | QBarSet::~QBarSet() |
|
257 | 257 | { |
|
258 | 258 | // NOTE: d_ptr destroyed by QObject |
|
259 | 259 | } |
|
260 | 260 | |
|
261 | 261 | /*! |
|
262 | 262 | Sets new \a label for set. |
|
263 | 263 | */ |
|
264 | 264 | void QBarSet::setLabel(const QString label) |
|
265 | 265 | { |
|
266 | 266 | d_ptr->m_label = label; |
|
267 | 267 | emit labelChanged(); |
|
268 | 268 | } |
|
269 | 269 | |
|
270 | 270 | /*! |
|
271 | 271 | Returns label of the set. |
|
272 | 272 | */ |
|
273 | 273 | QString QBarSet::label() const |
|
274 | 274 | { |
|
275 | 275 | return d_ptr->m_label; |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | /*! |
|
279 | 279 | Appends new value \a value to the end of set. |
|
280 | 280 | */ |
|
281 | 281 | void QBarSet::append(const qreal value) |
|
282 | 282 | { |
|
283 | 283 | // Convert to QPointF |
|
284 | 284 | int index = d_ptr->m_values.count(); |
|
285 | 285 | d_ptr->append(QPointF(d_ptr->m_values.count(), value)); |
|
286 | 286 | emit valuesAdded(index, 1); |
|
287 | 287 | } |
|
288 | 288 | |
|
289 | 289 | /*! |
|
290 | 290 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
291 | 291 | are appended to end of barset |
|
292 | 292 | \sa append() |
|
293 | 293 | */ |
|
294 | 294 | void QBarSet::append(const QList<qreal> &values) |
|
295 | 295 | { |
|
296 | 296 | int index = d_ptr->m_values.count(); |
|
297 | 297 | d_ptr->append(values); |
|
298 | 298 | emit valuesAdded(index, values.count()); |
|
299 | 299 | } |
|
300 | 300 | |
|
301 | 301 | /*! |
|
302 | 302 | Convinience operator. Same as append, with real \a value. |
|
303 | 303 | \sa append() |
|
304 | 304 | */ |
|
305 | 305 | QBarSet& QBarSet::operator << (const qreal &value) |
|
306 | 306 | { |
|
307 | 307 | append(value); |
|
308 | 308 | return *this; |
|
309 | 309 | } |
|
310 | 310 | |
|
311 | 311 | /*! |
|
312 | 312 | Inserts new \a value on the \a index position. |
|
313 | 313 | The value that is currently at this postion is moved to postion index + 1 |
|
314 | 314 | \sa remove() |
|
315 | 315 | */ |
|
316 | 316 | void QBarSet::insert(const int index, const qreal value) |
|
317 | 317 | { |
|
318 | 318 | d_ptr->insert(index, value); |
|
319 | 319 | emit valuesAdded(index,1); |
|
320 | 320 | } |
|
321 | 321 | |
|
322 | 322 | /*! |
|
323 | 323 | Removes \a count number of values from the set starting at \a index. |
|
324 | 324 | \sa insert() |
|
325 | 325 | */ |
|
326 | 326 | void QBarSet::remove(const int index, const int count) |
|
327 | 327 | { |
|
328 | 328 | int removedCount = d_ptr->remove(index,count); |
|
329 | 329 | if (removedCount > 0) { |
|
330 | 330 | emit valuesRemoved(index,removedCount); |
|
331 | 331 | } |
|
332 | 332 | return; |
|
333 | 333 | } |
|
334 | 334 | |
|
335 | 335 | /*! |
|
336 | 336 | Sets a new value \a value to set, indexed by \a index |
|
337 | 337 | */ |
|
338 | 338 | void QBarSet::replace(const int index, const qreal value) |
|
339 | 339 | { |
|
340 | 340 | if (index >= 0 && index < d_ptr->m_values.count()) { |
|
341 | 341 | d_ptr->replace(index,value); |
|
342 | 342 | emit valueChanged(index); |
|
343 | 343 | } |
|
344 | 344 | } |
|
345 | 345 | |
|
346 | 346 | |
|
347 | 347 | /*! |
|
348 | 348 | Returns value of set indexed by \a index. |
|
349 | 349 | If the index is out of bounds 0.0 is returned. |
|
350 | 350 | */ |
|
351 | 351 | qreal QBarSet::at(const int index) const |
|
352 | 352 | { |
|
353 | 353 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
354 | 354 | return 0; |
|
355 | 355 | } |
|
356 | 356 | |
|
357 | 357 | return d_ptr->m_values.at(index).y(); |
|
358 | 358 | } |
|
359 | 359 | |
|
360 | 360 | /*! |
|
361 | 361 | Returns value of set indexed by \a index. |
|
362 | 362 | If the index is out of bounds 0.0 is returned. |
|
363 | 363 | */ |
|
364 | 364 | qreal QBarSet::operator [](const int index) const |
|
365 | 365 | { |
|
366 | 366 | return at(index); |
|
367 | 367 | } |
|
368 | 368 | |
|
369 | 369 | /*! |
|
370 | 370 | Returns count of values in set. |
|
371 | 371 | */ |
|
372 | 372 | int QBarSet::count() const |
|
373 | 373 | { |
|
374 | 374 | return d_ptr->m_values.count(); |
|
375 | 375 | } |
|
376 | 376 | |
|
377 | 377 | /*! |
|
378 | 378 | Returns sum of all values in barset. |
|
379 | 379 | */ |
|
380 | 380 | qreal QBarSet::sum() const |
|
381 | 381 | { |
|
382 | 382 | qreal total(0); |
|
383 | 383 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
384 | 384 | total += d_ptr->m_values.at(i).y(); |
|
385 | 385 | } |
|
386 | 386 | return total; |
|
387 | 387 | } |
|
388 | 388 | |
|
389 | 389 | /*! |
|
390 | 390 | Sets pen for set. Bars of this set are drawn using \a pen |
|
391 | 391 | */ |
|
392 | 392 | void QBarSet::setPen(const QPen &pen) |
|
393 | 393 | { |
|
394 | 394 | if(d_ptr->m_pen!=pen){ |
|
395 | 395 | d_ptr->m_pen = pen; |
|
396 | 396 | emit d_ptr->updatedBars(); |
|
397 | 397 | emit penChanged(); |
|
398 | 398 | } |
|
399 | 399 | } |
|
400 | 400 | |
|
401 | 401 | /*! |
|
402 | 402 | Returns pen of the set. |
|
403 | 403 | */ |
|
404 | 404 | QPen QBarSet::pen() const |
|
405 | 405 | { |
|
406 | 406 | return d_ptr->m_pen; |
|
407 | 407 | } |
|
408 | 408 | |
|
409 | 409 | /*! |
|
410 | 410 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
411 | 411 | */ |
|
412 | 412 | void QBarSet::setBrush(const QBrush &brush) |
|
413 | 413 | { |
|
414 | 414 | if(d_ptr->m_brush!=brush){ |
|
415 | 415 | d_ptr->m_brush = brush; |
|
416 | 416 | emit d_ptr->updatedBars(); |
|
417 | 417 | emit brushChanged(); |
|
418 | 418 | } |
|
419 | 419 | } |
|
420 | 420 | |
|
421 | 421 | /*! |
|
422 | 422 | Returns brush of the set. |
|
423 | 423 | */ |
|
424 | 424 | QBrush QBarSet::brush() const |
|
425 | 425 | { |
|
426 | 426 | return d_ptr->m_brush; |
|
427 | 427 | } |
|
428 | 428 | |
|
429 | 429 | /*! |
|
430 | 430 | Sets \a brush of the values that are drawn on top of this barset |
|
431 | 431 | */ |
|
432 | 432 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
433 | 433 | { |
|
434 | 434 | if(d_ptr->m_labelBrush!=brush){ |
|
435 | 435 | d_ptr->m_labelBrush = brush; |
|
436 | 436 | emit d_ptr->updatedBars(); |
|
437 | 437 | emit labelBrushChanged(); |
|
438 | 438 | } |
|
439 | 439 | } |
|
440 | 440 | |
|
441 | 441 | /*! |
|
442 | 442 | Returns brush of the values that are drawn on top of this barset |
|
443 | 443 | */ |
|
444 | 444 | QBrush QBarSet::labelBrush() const |
|
445 | 445 | { |
|
446 | 446 | return d_ptr->m_labelBrush; |
|
447 | 447 | } |
|
448 | 448 | |
|
449 | 449 | /*! |
|
450 | 450 | Sets the \a font for values that are drawn on top of this barset |
|
451 | 451 | */ |
|
452 | 452 | void QBarSet::setLabelFont(const QFont &font) |
|
453 | 453 | { |
|
454 | 454 | if(d_ptr->m_labelFont!=font) { |
|
455 | 455 | d_ptr->m_labelFont = font; |
|
456 | 456 | emit d_ptr->updatedBars(); |
|
457 | 457 | emit labelFontChanged(); |
|
458 | 458 | } |
|
459 | 459 | |
|
460 | 460 | } |
|
461 | 461 | |
|
462 | 462 | /*! |
|
463 | 463 | Returns the pen for values that are drawn on top of this barset |
|
464 | 464 | */ |
|
465 | 465 | QFont QBarSet::labelFont() const |
|
466 | 466 | { |
|
467 | 467 | return d_ptr->m_labelFont; |
|
468 | 468 | } |
|
469 | 469 | |
|
470 | 470 | /*! |
|
471 | 471 | Returns the color of the brush of barset. |
|
472 | 472 | */ |
|
473 | 473 | QColor QBarSet::color() |
|
474 | 474 | { |
|
475 | 475 | return brush().color(); |
|
476 | 476 | } |
|
477 | 477 | |
|
478 | 478 | /*! |
|
479 | 479 | Sets the \a color of brush for this barset |
|
480 | 480 | */ |
|
481 | 481 | void QBarSet::setColor(QColor color) |
|
482 | 482 | { |
|
483 | 483 | QBrush b = brush(); |
|
484 | 484 | if (b.color() != color) { |
|
485 | 485 | b.setColor(color); |
|
486 | 486 | setBrush(b); |
|
487 | 487 | emit colorChanged(color); |
|
488 | 488 | } |
|
489 | 489 | } |
|
490 | 490 | |
|
491 | 491 | /*! |
|
492 | 492 | Returns the color of pen of this barset |
|
493 | 493 | */ |
|
494 | 494 | QColor QBarSet::borderColor() |
|
495 | 495 | { |
|
496 | 496 | return pen().color(); |
|
497 | 497 | } |
|
498 | 498 | |
|
499 | 499 | /*! |
|
500 | 500 | Sets the color of pen for this barset |
|
501 | 501 | */ |
|
502 | 502 | void QBarSet::setBorderColor(QColor color) |
|
503 | 503 | { |
|
504 | 504 | QPen p = pen(); |
|
505 | 505 | if (p.color() != color) { |
|
506 | 506 | p.setColor(color); |
|
507 | 507 | setPen(p); |
|
508 | 508 | emit borderColorChanged(color); |
|
509 | 509 | } |
|
510 | 510 | } |
|
511 | 511 | |
|
512 | 512 | /*! |
|
513 | 513 | Returns the color of labels of this barset |
|
514 | 514 | */ |
|
515 | 515 | QColor QBarSet::labelColor() |
|
516 | 516 | { |
|
517 | 517 | return labelBrush().color(); |
|
518 | 518 | } |
|
519 | 519 | |
|
520 | 520 | /*! |
|
521 | 521 | Sets the color of labels for this barset |
|
522 | 522 | */ |
|
523 | 523 | void QBarSet::setLabelColor(QColor color) |
|
524 | { | |
|
525 | QBrush defaultBrush; | |
|
524 | { | |
|
526 | 525 |
|
|
527 |
if (b == |
|
|
526 | if (b == QBrush()) | |
|
528 | 527 | b.setStyle(Qt::SolidPattern); |
|
529 | 528 | |
|
530 | 529 | if (b.color() != color) { |
|
531 | 530 | b.setColor(color); |
|
532 | 531 | setLabelBrush(b); |
|
533 | 532 | emit labelColorChanged(color); |
|
534 | 533 | } |
|
535 | 534 | } |
|
536 | 535 | |
|
537 | 536 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
538 | 537 | |
|
539 | 538 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
540 | 539 | q_ptr(parent), |
|
541 | 540 | m_label(label) |
|
542 | 541 | { |
|
543 | 542 | } |
|
544 | 543 | |
|
545 | 544 | QBarSetPrivate::~QBarSetPrivate() |
|
546 | 545 | { |
|
547 | 546 | } |
|
548 | 547 | |
|
549 | 548 | void QBarSetPrivate::append(QPointF value) |
|
550 | 549 | { |
|
551 | 550 | m_values.append(value); |
|
552 | 551 | emit restructuredBars(); |
|
553 | 552 | } |
|
554 | 553 | |
|
555 | 554 | void QBarSetPrivate::append(QList<QPointF> values) |
|
556 | 555 | { |
|
557 | 556 | for (int i=0; i<values.count(); i++) { |
|
558 | 557 | m_values.append(values.at(i)); |
|
559 | 558 | } |
|
560 | 559 | emit restructuredBars(); |
|
561 | 560 | } |
|
562 | 561 | |
|
563 | 562 | void QBarSetPrivate::append(QList<qreal> values) |
|
564 | 563 | { |
|
565 | 564 | int index = m_values.count(); |
|
566 | 565 | for (int i=0; i<values.count(); i++) { |
|
567 | 566 | m_values.append(QPointF(index,values.at(i))); |
|
568 | 567 | index++; |
|
569 | 568 | } |
|
570 | 569 | emit restructuredBars(); |
|
571 | 570 | } |
|
572 | 571 | |
|
573 | 572 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
574 | 573 | { |
|
575 | 574 | m_values.insert(index, QPointF(index, value)); |
|
576 | 575 | emit restructuredBars(); |
|
577 | 576 | } |
|
578 | 577 | |
|
579 | 578 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
580 | 579 | { |
|
581 | 580 | m_values.insert(index, value); |
|
582 | 581 | emit restructuredBars(); |
|
583 | 582 | } |
|
584 | 583 | |
|
585 | 584 | int QBarSetPrivate::remove(const int index, const int count) |
|
586 | 585 | { |
|
587 | 586 | int removeCount = count; |
|
588 | 587 | |
|
589 | 588 | if ((index <0) || (m_values.count() == 0)) { |
|
590 | 589 | // Invalid index or not values in list, remove nothing. |
|
591 | 590 | return 0; |
|
592 | 591 | } else if ((index + count) > m_values.count()) { |
|
593 | 592 | // Trying to remove more items than list has. Limit amount to be removed. |
|
594 | 593 | removeCount = m_values.count() - index; |
|
595 | 594 | } |
|
596 | 595 | |
|
597 | 596 | int c = 0; |
|
598 | 597 | while (c < removeCount) { |
|
599 | 598 | m_values.removeAt(index); |
|
600 | 599 | c++; |
|
601 | 600 | } |
|
602 | 601 | emit restructuredBars(); |
|
603 | 602 | return removeCount; |
|
604 | 603 | } |
|
605 | 604 | |
|
606 | 605 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
607 | 606 | { |
|
608 | 607 | m_values.replace(index,QPointF(index,value)); |
|
609 | 608 | emit updatedBars(); |
|
610 | 609 | } |
|
611 | 610 | |
|
612 | 611 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
613 | 612 | { |
|
614 | 613 | m_values.replace(index,value); |
|
615 | 614 | emit updatedBars(); |
|
616 | 615 | } |
|
617 | 616 | |
|
618 | 617 | qreal QBarSetPrivate::pos(const int index) |
|
619 | 618 | { |
|
620 | 619 | if (index < 0 || index >= m_values.count()) { |
|
621 | 620 | return 0; |
|
622 | 621 | } |
|
623 | 622 | |
|
624 | 623 | return m_values.at(index).x(); |
|
625 | 624 | } |
|
626 | 625 | |
|
627 | 626 | qreal QBarSetPrivate::value(const int index) |
|
628 | 627 | { |
|
629 | 628 | if (index < 0 || index >= m_values.count()) { |
|
630 | 629 | return 0; |
|
631 | 630 | } |
|
632 | 631 | |
|
633 | 632 | return m_values.at(index).y(); |
|
634 | 633 | } |
|
635 | 634 | |
|
636 | 635 | #include "moc_qbarset.cpp" |
|
637 | 636 | #include "moc_qbarset_p.cpp" |
|
638 | 637 | |
|
639 | 638 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,393 +1,393 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "charttheme_p.h" |
|
22 | 22 | #include "qchart.h" |
|
23 | 23 | #include "qchart_p.h" |
|
24 | 24 | #include "qchartview.h" |
|
25 | 25 | #include "qlegend.h" |
|
26 | 26 | #include "qabstractaxis.h" |
|
27 | 27 | #include <QTime> |
|
28 | 28 | |
|
29 | 29 | //series |
|
30 | 30 | #include "qbarset.h" |
|
31 | 31 | #include "qabstractbarseries.h" |
|
32 | 32 | #include "qstackedbarseries.h" |
|
33 | 33 | #include "qpercentbarseries.h" |
|
34 | 34 | #include "qlineseries.h" |
|
35 | 35 | #include "qareaseries.h" |
|
36 | 36 | #include "qscatterseries.h" |
|
37 | 37 | #include "qpieseries.h" |
|
38 | 38 | #include "qpieslice.h" |
|
39 | 39 | #include "qpieslice_p.h" |
|
40 | 40 | #include "qsplineseries.h" |
|
41 | 41 | |
|
42 | 42 | //items |
|
43 | 43 | #include "chartaxis_p.h" |
|
44 | 44 | #include "abstractbarchartitem_p.h" |
|
45 | 45 | #include "stackedbarchartitem_p.h" |
|
46 | 46 | #include "percentbarchartitem_p.h" |
|
47 | 47 | #include "linechartitem_p.h" |
|
48 | 48 | #include "areachartitem_p.h" |
|
49 | 49 | #include "scatterchartitem_p.h" |
|
50 | 50 | #include "piechartitem_p.h" |
|
51 | 51 | #include "splinechartitem_p.h" |
|
52 | 52 | |
|
53 | 53 | //themes |
|
54 | 54 | #include "chartthemesystem_p.h" |
|
55 | 55 | #include "chartthemelight_p.h" |
|
56 | 56 | #include "chartthemebluecerulean_p.h" |
|
57 | 57 | #include "chartthemedark_p.h" |
|
58 | 58 | #include "chartthemebrownsand_p.h" |
|
59 | 59 | #include "chartthemebluencs_p.h" |
|
60 | 60 | #include "chartthemehighcontrast_p.h" |
|
61 | 61 | #include "chartthemeblueicy_p.h" |
|
62 | 62 | |
|
63 | 63 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
64 | 64 | |
|
65 | 65 | ChartTheme::ChartTheme(QChart::ChartTheme id) : |
|
66 | 66 | m_masterFont(QFont("arial", 14)), |
|
67 | 67 | m_labelFont(QFont("arial", 10)), |
|
68 | 68 | m_labelBrush(QColor(QRgb(0x000000))), |
|
69 | 69 | m_axisLinePen(QPen(QRgb(0x000000))), |
|
70 | 70 | m_backgroundShadesPen(Qt::NoPen), |
|
71 | 71 | m_backgroundShadesBrush(Qt::NoBrush), |
|
72 | 72 | m_backgroundShades(BackgroundShadesNone), |
|
73 | 73 | m_backgroundDropShadowEnabled(false), |
|
74 | 74 | m_gridLinePen(QPen(QRgb(0x000000))), |
|
75 | 75 | m_force(false) |
|
76 | 76 | { |
|
77 | 77 | m_id = id; |
|
78 | 78 | qsrand(QTime(0,0,0).secsTo(QTime::currentTime())); |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | |
|
82 | 82 | ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme) |
|
83 | 83 | { |
|
84 | 84 | switch(theme) { |
|
85 | 85 | case QChart::ChartThemeLight: |
|
86 | 86 | return new ChartThemeLight(); |
|
87 | 87 | case QChart::ChartThemeBlueCerulean: |
|
88 | 88 | return new ChartThemeBlueCerulean(); |
|
89 | 89 | case QChart::ChartThemeDark: |
|
90 | 90 | return new ChartThemeDark(); |
|
91 | 91 | case QChart::ChartThemeBrownSand: |
|
92 | 92 | return new ChartThemeBrownSand(); |
|
93 | 93 | case QChart::ChartThemeBlueNcs: |
|
94 | 94 | return new ChartThemeBlueNcs(); |
|
95 | 95 | case QChart::ChartThemeHighContrast: |
|
96 | 96 | return new ChartThemeHighContrast(); |
|
97 | 97 | case QChart::ChartThemeBlueIcy: |
|
98 | 98 | return new ChartThemeBlueIcy(); |
|
99 | 99 | default: |
|
100 | 100 | return new ChartThemeSystem(); |
|
101 | 101 | } |
|
102 | 102 | } |
|
103 | 103 | |
|
104 | 104 | void ChartTheme::decorate(QChart *chart) |
|
105 | 105 | { |
|
106 | 106 | QBrush brush; |
|
107 | 107 | |
|
108 |
if(brush == chart->backgroundBrush() |
|
|
108 | if(m_force || brush == chart->backgroundBrush()) | |
|
109 | 109 | chart->setBackgroundBrush(m_chartBackgroundGradient); |
|
110 | 110 | chart->setTitleFont(m_masterFont); |
|
111 | 111 | chart->setTitleBrush(m_labelBrush); |
|
112 | 112 | chart->setDropShadowEnabled(m_backgroundDropShadowEnabled); |
|
113 | 113 | } |
|
114 | 114 | |
|
115 | 115 | void ChartTheme::decorate(QLegend *legend) |
|
116 | 116 | { |
|
117 | 117 | QPen pen; |
|
118 | 118 | QBrush brush; |
|
119 | 119 | QFont font; |
|
120 | 120 | |
|
121 |
if (pen == legend->pen() |
|
|
121 | if (m_force || pen == legend->pen()) | |
|
122 | 122 | legend->setPen(m_axisLinePen); |
|
123 | 123 | |
|
124 |
if (brush == legend->brush() |
|
|
124 | if (m_force || brush == legend->brush()) | |
|
125 | 125 | legend->setBrush(m_chartBackgroundGradient); |
|
126 | 126 | |
|
127 |
if (font == legend->font() |
|
|
127 | if (m_force || font == legend->font()) | |
|
128 | 128 | legend->setFont(m_labelFont); |
|
129 | 129 | |
|
130 |
if (brush == legend->labelBrush() |
|
|
130 | if (m_force || brush == legend->labelBrush()) | |
|
131 | 131 | legend->setLabelBrush(m_labelBrush); |
|
132 | 132 | } |
|
133 | 133 | |
|
134 | 134 | void ChartTheme::decorate(QAreaSeries *series, int index) |
|
135 | 135 | { |
|
136 | 136 | QPen pen; |
|
137 | 137 | QBrush brush; |
|
138 | 138 | |
|
139 |
if (pen == series->pen() |
|
|
139 | if (m_force || pen == series->pen()){ | |
|
140 | 140 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
141 | 141 | pen.setWidthF(2); |
|
142 | 142 | series->setPen(pen); |
|
143 | 143 | } |
|
144 | 144 | |
|
145 |
if (brush == series->brush() |
|
|
145 | if (m_force || brush == series->brush()) { | |
|
146 | 146 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
147 | 147 | series->setBrush(brush); |
|
148 | 148 | } |
|
149 | 149 | } |
|
150 | 150 | |
|
151 | 151 | |
|
152 | 152 | void ChartTheme::decorate(QLineSeries *series,int index) |
|
153 | 153 | { |
|
154 | 154 | QPen pen; |
|
155 |
if(pen == series->pen() |
|
|
155 | if(m_force || pen == series->pen()){ | |
|
156 | 156 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
157 | 157 | pen.setWidthF(2); |
|
158 | 158 | series->setPen(pen); |
|
159 | 159 | } |
|
160 | 160 | } |
|
161 | 161 | |
|
162 | 162 | void ChartTheme::decorate(QAbstractBarSeries *series, int index) |
|
163 | 163 | { |
|
164 | 164 | QBrush brush; |
|
165 | 165 | QPen pen; |
|
166 | 166 | QList<QBarSet *> sets = series->barSets(); |
|
167 | 167 | |
|
168 | 168 | qreal takeAtPos = 0.5; |
|
169 | 169 | qreal step = 0.2; |
|
170 | 170 | if (sets.count() > 1 ) { |
|
171 | 171 | step = 1.0 / (qreal) sets.count(); |
|
172 | 172 | if (sets.count() % m_seriesGradients.count()) |
|
173 | 173 | step *= m_seriesGradients.count(); |
|
174 | 174 | else |
|
175 | 175 | step *= (m_seriesGradients.count() - 1); |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | for (int i(0); i < sets.count(); i++) { |
|
179 | 179 | int colorIndex = (index + i) % m_seriesGradients.count(); |
|
180 | 180 | if (i > 0 && i % m_seriesGradients.count() == 0) { |
|
181 | 181 | // There is no dedicated base color for each sets, generate more colors |
|
182 | 182 | takeAtPos += step; |
|
183 | 183 | if (takeAtPos == 1.0) |
|
184 | 184 | takeAtPos += step; |
|
185 | 185 | takeAtPos -= (int) takeAtPos; |
|
186 | 186 | } |
|
187 |
if (brush == sets.at(i)->brush() |
|
|
187 | if (m_force || brush == sets.at(i)->brush()) | |
|
188 | 188 | sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos)); |
|
189 | 189 | |
|
190 | 190 | // Pick label color from the opposite end of the gradient. |
|
191 | 191 | // 0.3 as a boundary seems to work well. |
|
192 |
if (brush == sets.at(i)->labelBrush() |
|
|
192 | if (m_force || brush == sets.at(i)->labelBrush()) { | |
|
193 | 193 | if (takeAtPos < 0.3) |
|
194 | 194 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1)); |
|
195 | 195 | else |
|
196 | 196 | sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0)); |
|
197 | 197 | } |
|
198 | 198 | |
|
199 |
if (pen == sets.at(i)->pen() |
|
|
199 | if (m_force || pen == sets.at(i)->pen()) { | |
|
200 | 200 | QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
201 | 201 | sets.at(i)->setPen(c); |
|
202 | 202 | } |
|
203 | 203 | } |
|
204 | 204 | } |
|
205 | 205 | |
|
206 | 206 | void ChartTheme::decorate(QScatterSeries *series, int index) |
|
207 | 207 | { |
|
208 | 208 | QPen pen; |
|
209 | 209 | QBrush brush; |
|
210 | 210 | |
|
211 |
if (pen == series->pen() |
|
|
211 | if (m_force || pen == series->pen()) { | |
|
212 | 212 | pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0)); |
|
213 | 213 | pen.setWidthF(2); |
|
214 | 214 | series->setPen(pen); |
|
215 | 215 | } |
|
216 | 216 | |
|
217 |
if (brush == series->brush() |
|
|
217 | if (m_force || brush == series->brush()) { | |
|
218 | 218 | QBrush brush(m_seriesColors.at(index % m_seriesColors.size())); |
|
219 | 219 | series->setBrush(brush); |
|
220 | 220 | } |
|
221 | 221 | } |
|
222 | 222 | |
|
223 | 223 | void ChartTheme::decorate(QPieSeries *series, int index) |
|
224 | 224 | { |
|
225 | 225 | |
|
226 | 226 | for (int i(0); i < series->slices().count(); i++) { |
|
227 | 227 | |
|
228 | 228 | QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0); |
|
229 | 229 | |
|
230 | 230 | // Get color for a slice from a gradient linearly, beginning from the start of the gradient |
|
231 | 231 | qreal pos = (qreal) (i + 1) / (qreal) series->count(); |
|
232 | 232 | QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos); |
|
233 | 233 | |
|
234 | 234 | QPieSlice *s = series->slices().at(i); |
|
235 | 235 | QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s); |
|
236 | 236 | |
|
237 |
if (d->m_data.m_slicePen.isThemed() |
|
|
237 | if (m_force || d->m_data.m_slicePen.isThemed()) | |
|
238 | 238 | d->setPen(penColor, true); |
|
239 | 239 | |
|
240 |
if (d->m_data.m_sliceBrush.isThemed() |
|
|
240 | if (m_force || d->m_data.m_sliceBrush.isThemed()) | |
|
241 | 241 | d->setBrush(brushColor, true); |
|
242 | 242 | |
|
243 |
if (d->m_data.m_labelBrush.isThemed() |
|
|
243 | if (m_force || d->m_data.m_labelBrush.isThemed()) | |
|
244 | 244 | d->setLabelBrush(m_labelBrush.color(), true); |
|
245 | 245 | |
|
246 |
if (d->m_data.m_labelFont.isThemed() |
|
|
246 | if (m_force || d->m_data.m_labelFont.isThemed()) | |
|
247 | 247 | d->setLabelFont(m_labelFont, true); |
|
248 | 248 | } |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | void ChartTheme::decorate(QSplineSeries *series, int index) |
|
252 | 252 | { |
|
253 | 253 | QPen pen; |
|
254 |
if(pen == series->pen() |
|
|
254 | if(m_force || pen == series->pen()){ | |
|
255 | 255 | pen.setColor(m_seriesColors.at(index%m_seriesColors.size())); |
|
256 | 256 | pen.setWidthF(2); |
|
257 | 257 | series->setPen(pen); |
|
258 | 258 | } |
|
259 | 259 | } |
|
260 | 260 | |
|
261 | 261 | void ChartTheme::decorate(QAbstractAxis *axis) |
|
262 | 262 | { |
|
263 | 263 | QPen pen; |
|
264 | 264 | QBrush brush; |
|
265 | 265 | QFont font; |
|
266 | 266 | |
|
267 | 267 | bool axisX = axis->orientation()== Qt::Horizontal; |
|
268 | 268 | |
|
269 | 269 | if (axis->isArrowVisible()) { |
|
270 | 270 | |
|
271 |
if(brush == axis->labelsBrush() |
|
|
271 | if(m_force || brush == axis->labelsBrush()){ | |
|
272 | 272 | axis->setLabelsBrush(m_labelBrush); |
|
273 | 273 | } |
|
274 |
if(pen == axis->labelsPen() |
|
|
274 | if(m_force || pen == axis->labelsPen()){ | |
|
275 | 275 | axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons |
|
276 | 276 | } |
|
277 | 277 | |
|
278 | 278 | |
|
279 |
if (axis->shadesVisible() |
|
|
279 | if (m_force || axis->shadesVisible()) { | |
|
280 | 280 | |
|
281 |
if(brush == axis->shadesBrush() |
|
|
281 | if(m_force || brush == axis->shadesBrush()){ | |
|
282 | 282 | axis->setShadesBrush(m_backgroundShadesBrush); |
|
283 | 283 | } |
|
284 | 284 | |
|
285 |
if(pen == axis->shadesPen() |
|
|
285 | if(m_force || pen == axis->shadesPen()){ | |
|
286 | 286 | axis->setShadesPen(m_backgroundShadesPen); |
|
287 | 287 | } |
|
288 | 288 | |
|
289 | 289 | if( m_force && (m_backgroundShades == BackgroundShadesBoth |
|
290 | 290 | || (m_backgroundShades == BackgroundShadesVertical && axisX) |
|
291 | 291 | || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){ |
|
292 | 292 | axis->setShadesVisible(true); |
|
293 | 293 | |
|
294 | 294 | } |
|
295 | 295 | } |
|
296 | 296 | |
|
297 |
if(pen == axis->axisPen() |
|
|
297 | if(m_force || pen == axis->axisPen()){ | |
|
298 | 298 | axis->setAxisPen(m_axisLinePen); |
|
299 | 299 | } |
|
300 | 300 | |
|
301 |
if(pen == axis->gridLinePen() |
|
|
301 | if(m_force || pen == axis->gridLinePen()){ | |
|
302 | 302 | axis->setGridLinePen(m_gridLinePen); |
|
303 | 303 | } |
|
304 | 304 | |
|
305 |
if(font == axis->labelsFont() |
|
|
305 | if(m_force || font == axis->labelsFont()){ | |
|
306 | 306 | axis->setLabelsFont(m_labelFont); |
|
307 | 307 | } |
|
308 | 308 | } |
|
309 | 309 | } |
|
310 | 310 | |
|
311 | 311 | void ChartTheme::generateSeriesGradients() |
|
312 | 312 | { |
|
313 | 313 | // Generate gradients in HSV color space |
|
314 | 314 | foreach (const QColor& color, m_seriesColors) { |
|
315 | 315 | QLinearGradient g; |
|
316 | 316 | qreal h = color.hsvHueF(); |
|
317 | 317 | qreal s = color.hsvSaturationF(); |
|
318 | 318 | |
|
319 | 319 | // TODO: tune the algorithm to give nice results with most base colors defined in |
|
320 | 320 | // most themes. The rest of the gradients we can define manually in theme specific |
|
321 | 321 | // implementation. |
|
322 | 322 | QColor start = color; |
|
323 | 323 | start.setHsvF(h, 0.0, 1.0); |
|
324 | 324 | g.setColorAt(0.0, start); |
|
325 | 325 | |
|
326 | 326 | g.setColorAt(0.5, color); |
|
327 | 327 | |
|
328 | 328 | QColor end = color; |
|
329 | 329 | end.setHsvF(h, s, 0.25); |
|
330 | 330 | g.setColorAt(1.0, end); |
|
331 | 331 | |
|
332 | 332 | m_seriesGradients << g; |
|
333 | 333 | } |
|
334 | 334 | } |
|
335 | 335 | |
|
336 | 336 | |
|
337 | 337 | QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos) |
|
338 | 338 | { |
|
339 | 339 | Q_ASSERT(pos >= 0.0 && pos <= 1.0); |
|
340 | 340 | qreal r = start.redF() + ((end.redF() - start.redF()) * pos); |
|
341 | 341 | qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos); |
|
342 | 342 | qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos); |
|
343 | 343 | QColor c; |
|
344 | 344 | c.setRgbF(r, g, b); |
|
345 | 345 | return c; |
|
346 | 346 | } |
|
347 | 347 | |
|
348 | 348 | QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos) |
|
349 | 349 | { |
|
350 | 350 | Q_ASSERT(pos >= 0 && pos <= 1.0); |
|
351 | 351 | |
|
352 | 352 | QGradientStops stops = gradient.stops(); |
|
353 | 353 | int count = stops.count(); |
|
354 | 354 | |
|
355 | 355 | // find previous stop relative to position |
|
356 | 356 | QGradientStop prev = stops.first(); |
|
357 | 357 | for (int i = 0; i < count; i++) { |
|
358 | 358 | QGradientStop stop = stops.at(i); |
|
359 | 359 | if (pos > stop.first) |
|
360 | 360 | prev = stop; |
|
361 | 361 | |
|
362 | 362 | // given position is actually a stop position? |
|
363 | 363 | if (pos == stop.first) { |
|
364 | 364 | //qDebug() << "stop color" << pos; |
|
365 | 365 | return stop.second; |
|
366 | 366 | } |
|
367 | 367 | } |
|
368 | 368 | |
|
369 | 369 | // find next stop relative to position |
|
370 | 370 | QGradientStop next = stops.last(); |
|
371 | 371 | for (int i = count - 1; i >= 0; i--) { |
|
372 | 372 | QGradientStop stop = stops.at(i); |
|
373 | 373 | if (pos < stop.first) |
|
374 | 374 | next = stop; |
|
375 | 375 | } |
|
376 | 376 | |
|
377 | 377 | //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first; |
|
378 | 378 | |
|
379 | 379 | qreal range = next.first - prev.first; |
|
380 | 380 | qreal posDelta = pos - prev.first; |
|
381 | 381 | qreal relativePos = posDelta / range; |
|
382 | 382 | |
|
383 | 383 | //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos; |
|
384 | 384 | |
|
385 | 385 | return colorAt(prev.second, next.second, relativePos); |
|
386 | 386 | } |
|
387 | 387 | |
|
388 | 388 | void ChartTheme::setForced(bool enabled) |
|
389 | 389 | { |
|
390 | m_force=enabled; | |
|
390 | m_force = enabled; | |
|
391 | 391 | } |
|
392 | 392 | |
|
393 | 393 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now