@@ -1,639 +1,639 | |||
|
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 part of QtCommercial chart API. |
|
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 QBarSeries, QGroupedBarSeries, 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 BarSeries, GroupedBarSeries, 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 | \property QBarSet::color |
|
80 | 80 | The fill (brush) color of the bar set. |
|
81 | 81 | */ |
|
82 | 82 | /*! |
|
83 | 83 | \qmlproperty color BarSet::color |
|
84 | 84 | The fill (brush) color of the bar set. |
|
85 | 85 | */ |
|
86 | 86 | |
|
87 | 87 | /*! |
|
88 | 88 | \property QBarSet::borderColor |
|
89 | 89 | The line (pen) color of the bar set. |
|
90 | 90 | */ |
|
91 | 91 | /*! |
|
92 | 92 | \qmlproperty color BarSet::borderColor |
|
93 | 93 | The line (pen) color of the bar set. |
|
94 | 94 | */ |
|
95 | 95 | |
|
96 | 96 | /*! |
|
97 | 97 | \property QBarSet::labelColor |
|
98 | 98 | The text (label) color of the bar set. |
|
99 | 99 | */ |
|
100 | 100 | /*! |
|
101 | 101 | \qmlproperty color BarSet::labelColor |
|
102 | 102 | The text (label) color of the bar set. |
|
103 | 103 | */ |
|
104 | 104 | |
|
105 | 105 | /*! |
|
106 | 106 | \fn void QBarSet::clicked(int index) |
|
107 | 107 | |
|
108 | 108 | The signal is emitted if the user clicks with a mouse on top of barset. |
|
109 | 109 | Clicked bar inside set is indexed by \a index |
|
110 | 110 | */ |
|
111 | 111 | |
|
112 | 112 | /*! |
|
113 | 113 | \fn void QBarSet::hovered(bool status) |
|
114 | 114 | |
|
115 | 115 | The signal is emitted if mouse is hovered on top of barset. |
|
116 | 116 | Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset. |
|
117 | 117 | */ |
|
118 | 118 | |
|
119 | 119 | |
|
120 | 120 | /*! |
|
121 | 121 | \fn void QBarSet::labelChanged() |
|
122 | 122 | This signal is emitted when the label of the barSet has changed. |
|
123 | 123 | \sa label |
|
124 | 124 | */ |
|
125 | 125 | |
|
126 | 126 | /*! |
|
127 | 127 | \fn void QBarSet::penChanged() |
|
128 | 128 | This signal is emitted when the pen of the barSet has changed. |
|
129 | 129 | \sa pen |
|
130 | 130 | */ |
|
131 | 131 | |
|
132 | 132 | /*! |
|
133 | 133 | \fn void QBarSet::brushChanged() |
|
134 | 134 | This signal is emitted when the brush of the barSet has changed. |
|
135 | 135 | \sa brush |
|
136 | 136 | */ |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | \fn void QBarSet::labelBrushChanged() |
|
140 | 140 | This signal is emitted when the brush of the barSet's label has changed. |
|
141 | 141 | \sa labelBrush |
|
142 | 142 | */ |
|
143 | 143 | |
|
144 | 144 | /*! |
|
145 | 145 | \fn void QBarSet::labelFontChanged() |
|
146 | 146 | This signal is emitted when the font of the barSet's label has changed. |
|
147 | 147 | \sa labelBrush |
|
148 | 148 | */ |
|
149 | 149 | |
|
150 | 150 | /*! |
|
151 | 151 | \fn void QBarSet::colorChanged(QColor) |
|
152 | 152 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
153 | 153 | */ |
|
154 | 154 | /*! |
|
155 | 155 | \qmlsignal BarSet::onColorChanged(color color) |
|
156 | 156 | This signal is emitted when the fill (brush) color of the set has changed to \a color. |
|
157 | 157 | */ |
|
158 | 158 | |
|
159 | 159 | /*! |
|
160 | 160 | \fn void QBarSet::borderColorChanged(QColor) |
|
161 | 161 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
162 | 162 | */ |
|
163 | 163 | /*! |
|
164 | 164 | \qmlsignal BarSet::onBorderColorChanged(color color) |
|
165 | 165 | This signal is emitted when the line (pen) color of the set has changed to \a color. |
|
166 | 166 | */ |
|
167 | 167 | |
|
168 | 168 | /*! |
|
169 | 169 | \fn void QBarSet::labelColorChanged(QColor) |
|
170 | 170 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
171 | 171 | */ |
|
172 | 172 | /*! |
|
173 | 173 | \qmlsignal BarSet::onLabelColorChanged(color color) |
|
174 | 174 | This signal is emitted when the text (label) color of the set has changed to \a color. |
|
175 | 175 | */ |
|
176 | 176 | |
|
177 | 177 | /*! |
|
178 | 178 | \fn void QBarSet::valuesAdded(int index, int count) |
|
179 | 179 | This signal is emitted when new values have been added to the set. |
|
180 | 180 | Parameter \a index indicates the position of the first inserted value. |
|
181 | 181 | Parameter \a count is the number of iserted values. |
|
182 | 182 | \sa append(), insert() |
|
183 | 183 | */ |
|
184 | 184 | /*! |
|
185 | 185 | \qmlsignal BarSet::onValuesAdded(int index, int count) |
|
186 | 186 | This signal is emitted when new values have been added to the set. |
|
187 | 187 | Parameter \a index indicates the position of the first inserted value. |
|
188 | 188 | Parameter \a count is the number of iserted values. |
|
189 | 189 | */ |
|
190 | 190 | |
|
191 | 191 | /*! |
|
192 | 192 | \fn void QBarSet::valuesRemoved(int index, int count) |
|
193 | 193 | This signal is emitted values have been removed from the set. |
|
194 | 194 | Parameter \a index indicates the position of the first removed value. |
|
195 | 195 | Parameter \a count is the number of removed values. |
|
196 | 196 | \sa remove() |
|
197 | 197 | */ |
|
198 | 198 | /*! |
|
199 | 199 | \qmlsignal BarSet::onValuesRemoved(int index, int count) |
|
200 | 200 | This signal is emitted values have been removed from the set. |
|
201 | 201 | Parameter \a index indicates the position of the first removed value. |
|
202 | 202 | Parameter \a count is the number of removed values. |
|
203 | 203 | */ |
|
204 | 204 | |
|
205 | 205 | /*! |
|
206 | 206 | \fn void QBarSet::valueChanged(int index) |
|
207 | 207 | This signal is emitted values the value in the set has been modified. |
|
208 | 208 | Parameter \a index indicates the position of the modified value. |
|
209 | 209 | \sa at() |
|
210 | 210 | */ |
|
211 | 211 | /*! |
|
212 | 212 | \qmlsignal BarSet::onValueChanged(int index) |
|
213 | 213 | This signal is emitted values the value in the set has been modified. |
|
214 | 214 | Parameter \a index indicates the position of the modified value. |
|
215 | 215 | */ |
|
216 | 216 | |
|
217 | 217 | /*! |
|
218 | 218 | Constructs QBarSet with a label of \a label and with parent of \a parent |
|
219 | 219 | */ |
|
220 | 220 | QBarSet::QBarSet(const QString label, QObject *parent) |
|
221 | 221 | : QObject(parent) |
|
222 | 222 | ,d_ptr(new QBarSetPrivate(label,this)) |
|
223 | 223 | { |
|
224 | 224 | } |
|
225 | 225 | |
|
226 | 226 | /*! |
|
227 | 227 | Destroys the barset |
|
228 | 228 | */ |
|
229 | 229 | QBarSet::~QBarSet() |
|
230 | 230 | { |
|
231 | 231 | // NOTE: d_ptr destroyed by QObject |
|
232 | 232 | } |
|
233 | 233 | |
|
234 | 234 | /*! |
|
235 | 235 | Sets new \a label for set. |
|
236 | 236 | */ |
|
237 | 237 | void QBarSet::setLabel(const QString label) |
|
238 | 238 | { |
|
239 | 239 | d_ptr->m_label = label; |
|
240 | 240 | emit labelChanged(); |
|
241 | 241 | } |
|
242 | 242 | |
|
243 | 243 | /*! |
|
244 | 244 | Returns label of the set. |
|
245 | 245 | */ |
|
246 | 246 | QString QBarSet::label() const |
|
247 | 247 | { |
|
248 | 248 | return d_ptr->m_label; |
|
249 | 249 | } |
|
250 | 250 | |
|
251 | 251 | /*! |
|
252 | 252 | Appends a point to set. Parameter \a value x coordinate defines the |
|
253 | 253 | position in x-axis and y coordinate defines the height of bar. |
|
254 | 254 | Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries) |
|
255 | 255 | the x values are used or ignored. |
|
256 | 256 | */ |
|
257 | 257 | void QBarSet::append(const QPointF value) |
|
258 | 258 | { |
|
259 | 259 | int index = d_ptr->m_values.count(); |
|
260 | 260 | d_ptr->append(value); |
|
261 | 261 | emit valuesAdded(index, 1); |
|
262 | 262 | } |
|
263 | 263 | |
|
264 | 264 | /*! |
|
265 | 265 | Appends a list of \a values to set. Works like append with single point. |
|
266 | 266 | \sa append() |
|
267 | 267 | */ |
|
268 | void QBarSet::append(const QList<QPointF> values) | |
|
268 | void QBarSet::append(const QList<QPointF> &values) | |
|
269 | 269 | { |
|
270 | 270 | int index = d_ptr->m_values.count(); |
|
271 | 271 | d_ptr->append(values); |
|
272 | 272 | emit valuesAdded(index, values.count()); |
|
273 | 273 | } |
|
274 | 274 | |
|
275 | 275 | /*! |
|
276 | 276 | Appends new value \a value to the end of set. Internally the value is converted to QPointF, |
|
277 | 277 | with x coordinate being the index of appended value and y coordinate is the value. |
|
278 | 278 | */ |
|
279 | 279 | void QBarSet::append(const qreal value) |
|
280 | 280 | { |
|
281 | 281 | // Convert to QPointF and use other append(QPointF) method. |
|
282 | 282 | append(QPointF(d_ptr->m_values.count(), value)); |
|
283 | 283 | } |
|
284 | 284 | |
|
285 | 285 | /*! |
|
286 | 286 | Appends a list of reals to set. Works like append with single real value. The \a values in list |
|
287 | 287 | are converted to QPointF, where x coordinate is the index of point and y coordinate is the value. |
|
288 | 288 | \sa append() |
|
289 | 289 | */ |
|
290 | void QBarSet::append(const QList<qreal> values) | |
|
290 | void QBarSet::append(const QList<qreal> &values) | |
|
291 | 291 | { |
|
292 | 292 | int index = d_ptr->m_values.count(); |
|
293 | 293 | d_ptr->append(values); |
|
294 | 294 | emit valuesAdded(index, values.count()); |
|
295 | 295 | } |
|
296 | 296 | |
|
297 | 297 | /*! |
|
298 | 298 | Convinience operator. Same as append, with real \a value. |
|
299 | 299 | \sa append() |
|
300 | 300 | */ |
|
301 | 301 | QBarSet& QBarSet::operator << (const qreal &value) |
|
302 | 302 | { |
|
303 | 303 | append(value); |
|
304 | 304 | return *this; |
|
305 | 305 | } |
|
306 | 306 | |
|
307 | 307 | /*! |
|
308 | 308 | Convinience operator. Same as append, with QPointF \a value. |
|
309 | 309 | \sa append() |
|
310 | 310 | */ |
|
311 | 311 | QBarSet& QBarSet::operator << (const QPointF &value) |
|
312 | 312 | { |
|
313 | 313 | append(value); |
|
314 | 314 | return *this; |
|
315 | 315 | } |
|
316 | 316 | |
|
317 | 317 | /*! |
|
318 | 318 | Inserts new \a value on the \a index position. |
|
319 | 319 | The value that is currently at this postion is moved to postion index + 1 |
|
320 | 320 | \sa remove() |
|
321 | 321 | */ |
|
322 | 322 | void QBarSet::insert(const int index, const qreal value) |
|
323 | 323 | { |
|
324 | 324 | d_ptr->insert(index, value); |
|
325 | 325 | emit valuesAdded(index,1); |
|
326 | 326 | } |
|
327 | 327 | |
|
328 | 328 | /*! |
|
329 | 329 | Inserts new \a value on the \a index position. |
|
330 | 330 | The value that is currently at this postion is moved to postion index + 1 |
|
331 | 331 | \sa remove() |
|
332 | 332 | */ |
|
333 | 333 | void QBarSet::insert(const int index, const QPointF value) |
|
334 | 334 | { |
|
335 | 335 | d_ptr->insert(index,value); |
|
336 | 336 | emit valuesAdded(index,1); |
|
337 | 337 | } |
|
338 | 338 | |
|
339 | 339 | /*! |
|
340 | 340 | Removes \a count number of values from the set starting at \a index. |
|
341 | 341 | Returns true if remove operation was succesfull. |
|
342 | 342 | \sa insert() |
|
343 | 343 | */ |
|
344 | 344 | bool QBarSet::remove(const int index, const int count) |
|
345 | 345 | { |
|
346 | 346 | bool success = d_ptr->remove(index,count); |
|
347 | 347 | if (success) { |
|
348 | 348 | emit valuesRemoved(index,count); |
|
349 | 349 | } |
|
350 | 350 | return success; |
|
351 | 351 | } |
|
352 | 352 | |
|
353 | 353 | /*! |
|
354 | 354 | Sets a new value \a value to set, indexed by \a index |
|
355 | 355 | */ |
|
356 | 356 | void QBarSet::replace(const int index, const qreal value) |
|
357 | 357 | { |
|
358 | 358 | d_ptr->replace(index,value); |
|
359 | 359 | emit valueChanged(index); |
|
360 | 360 | } |
|
361 | 361 | |
|
362 | 362 | /*! |
|
363 | 363 | Sets a new value \a value to set, indexed by \a index |
|
364 | 364 | */ |
|
365 | 365 | void QBarSet::replace(const int index, const QPointF value) |
|
366 | 366 | { |
|
367 | 367 | d_ptr->replace(index,value); |
|
368 | 368 | emit valueChanged(index); |
|
369 | 369 | } |
|
370 | 370 | |
|
371 | 371 | /*! |
|
372 | 372 | Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF. |
|
373 | 373 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value |
|
374 | 374 | of the QPointF (if appended with QPointF append). |
|
375 | 375 | If the index is out of bounds QPointF(0, 0.0) is returned. |
|
376 | 376 | */ |
|
377 | 377 | QPointF QBarSet::at(const int index) const |
|
378 | 378 | { |
|
379 | 379 | if (index < 0 || index >= d_ptr->m_values.count()) { |
|
380 | 380 | return QPointF(index, 0.0); |
|
381 | 381 | } |
|
382 | 382 | |
|
383 | 383 | return d_ptr->m_values.at(index); |
|
384 | 384 | } |
|
385 | 385 | |
|
386 | 386 | /*! |
|
387 | 387 | Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF. |
|
388 | 388 | The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value |
|
389 | 389 | of the QPointF (if appended with QPointF append). |
|
390 | 390 | */ |
|
391 | 391 | QPointF QBarSet::operator [](const int index) const |
|
392 | 392 | { |
|
393 | 393 | return d_ptr->m_values.at(index); |
|
394 | 394 | } |
|
395 | 395 | |
|
396 | 396 | /*! |
|
397 | 397 | Returns count of values in set. |
|
398 | 398 | */ |
|
399 | 399 | int QBarSet::count() const |
|
400 | 400 | { |
|
401 | 401 | return d_ptr->m_values.count(); |
|
402 | 402 | } |
|
403 | 403 | |
|
404 | 404 | /*! |
|
405 | 405 | Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation. |
|
406 | 406 | */ |
|
407 | 407 | qreal QBarSet::sum() const |
|
408 | 408 | { |
|
409 | 409 | qreal total(0); |
|
410 | 410 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
411 | 411 | //total += d_ptr->m_values.at(i); |
|
412 | 412 | total += d_ptr->m_values.at(i).y(); |
|
413 | 413 | } |
|
414 | 414 | return total; |
|
415 | 415 | } |
|
416 | 416 | |
|
417 | 417 | /*! |
|
418 | 418 | Sets pen for set. Bars of this set are drawn using \a pen |
|
419 | 419 | */ |
|
420 | 420 | void QBarSet::setPen(const QPen &pen) |
|
421 | 421 | { |
|
422 | 422 | if(d_ptr->m_pen!=pen){ |
|
423 | 423 | d_ptr->m_pen = pen; |
|
424 | 424 | emit d_ptr->updatedBars(); |
|
425 | 425 | emit penChanged(); |
|
426 | 426 | } |
|
427 | 427 | } |
|
428 | 428 | |
|
429 | 429 | /*! |
|
430 | 430 | Returns pen of the set. |
|
431 | 431 | */ |
|
432 | 432 | QPen QBarSet::pen() const |
|
433 | 433 | { |
|
434 | 434 | return d_ptr->m_pen; |
|
435 | 435 | } |
|
436 | 436 | |
|
437 | 437 | /*! |
|
438 | 438 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
439 | 439 | */ |
|
440 | 440 | void QBarSet::setBrush(const QBrush &brush) |
|
441 | 441 | { |
|
442 | 442 | if(d_ptr->m_brush!=brush){ |
|
443 | 443 | d_ptr->m_brush = brush; |
|
444 | 444 | emit d_ptr->updatedBars(); |
|
445 | 445 | emit brushChanged(); |
|
446 | 446 | } |
|
447 | 447 | } |
|
448 | 448 | |
|
449 | 449 | /*! |
|
450 | 450 | Returns brush of the set. |
|
451 | 451 | */ |
|
452 | 452 | QBrush QBarSet::brush() const |
|
453 | 453 | { |
|
454 | 454 | return d_ptr->m_brush; |
|
455 | 455 | } |
|
456 | 456 | |
|
457 | 457 | /*! |
|
458 | 458 | Sets \a brush of the values that are drawn on top of this barset |
|
459 | 459 | */ |
|
460 | 460 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
461 | 461 | { |
|
462 | 462 | if(d_ptr->m_labelBrush!=brush){ |
|
463 | 463 | d_ptr->m_labelBrush = brush; |
|
464 | 464 | emit d_ptr->updatedBars(); |
|
465 | 465 | emit labelBrushChanged(); |
|
466 | 466 | } |
|
467 | 467 | } |
|
468 | 468 | |
|
469 | 469 | /*! |
|
470 | 470 | Returns brush of the values that are drawn on top of this barset |
|
471 | 471 | */ |
|
472 | 472 | QBrush QBarSet::labelBrush() const |
|
473 | 473 | { |
|
474 | 474 | return d_ptr->m_labelBrush; |
|
475 | 475 | } |
|
476 | 476 | |
|
477 | 477 | /*! |
|
478 | 478 | Sets the \a font for values that are drawn on top of this barset |
|
479 | 479 | */ |
|
480 | 480 | void QBarSet::setLabelFont(const QFont &font) |
|
481 | 481 | { |
|
482 | 482 | if(d_ptr->m_labelFont!=font) { |
|
483 | 483 | d_ptr->m_labelFont = font; |
|
484 | 484 | emit d_ptr->updatedBars(); |
|
485 | 485 | emit labelFontChanged(); |
|
486 | 486 | } |
|
487 | 487 | |
|
488 | 488 | } |
|
489 | 489 | |
|
490 | 490 | /*! |
|
491 | 491 | Returns the pen for values that are drawn on top of this barset |
|
492 | 492 | */ |
|
493 | 493 | QFont QBarSet::labelFont() const |
|
494 | 494 | { |
|
495 | 495 | return d_ptr->m_labelFont; |
|
496 | 496 | } |
|
497 | 497 | |
|
498 | 498 | /*! |
|
499 | 499 | Returns the color of the brush of barset. |
|
500 | 500 | */ |
|
501 | 501 | QColor QBarSet::color() |
|
502 | 502 | { |
|
503 | 503 | return brush().color(); |
|
504 | 504 | } |
|
505 | 505 | |
|
506 | 506 | /*! |
|
507 | 507 | Sets the \a color of brush for this barset |
|
508 | 508 | */ |
|
509 | 509 | void QBarSet::setColor(QColor color) |
|
510 | 510 | { |
|
511 | 511 | QBrush b = brush(); |
|
512 | 512 | if (b.color() != color) { |
|
513 | 513 | b.setColor(color); |
|
514 | 514 | setBrush(b); |
|
515 | 515 | emit colorChanged(color); |
|
516 | 516 | } |
|
517 | 517 | } |
|
518 | 518 | |
|
519 | 519 | /*! |
|
520 | 520 | Returns the color of pen of this barset |
|
521 | 521 | */ |
|
522 | 522 | QColor QBarSet::borderColor() |
|
523 | 523 | { |
|
524 | 524 | return pen().color(); |
|
525 | 525 | } |
|
526 | 526 | |
|
527 | 527 | /*! |
|
528 | 528 | Sets the color of pen for this barset |
|
529 | 529 | */ |
|
530 | 530 | void QBarSet::setBorderColor(QColor color) |
|
531 | 531 | { |
|
532 | 532 | QPen p = pen(); |
|
533 | 533 | if (p.color() != color) { |
|
534 | 534 | p.setColor(color); |
|
535 | 535 | setPen(p); |
|
536 | 536 | emit borderColorChanged(color); |
|
537 | 537 | } |
|
538 | 538 | } |
|
539 | 539 | |
|
540 | 540 | /*! |
|
541 | 541 | Returns the color of labels of this barset |
|
542 | 542 | */ |
|
543 | 543 | QColor QBarSet::labelColor() |
|
544 | 544 | { |
|
545 | 545 | return labelBrush().color(); |
|
546 | 546 | } |
|
547 | 547 | |
|
548 | 548 | /*! |
|
549 | 549 | Sets the color of labels for this barset |
|
550 | 550 | */ |
|
551 | 551 | void QBarSet::setLabelColor(QColor color) |
|
552 | 552 | { |
|
553 | 553 | QBrush b = labelBrush(); |
|
554 | 554 | if (b.color() != color) { |
|
555 | 555 | b.setColor(color); |
|
556 | 556 | setLabelBrush(b); |
|
557 | 557 | emit labelColorChanged(color); |
|
558 | 558 | } |
|
559 | 559 | } |
|
560 | 560 | |
|
561 | 561 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
562 | 562 | |
|
563 | 563 | QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent), |
|
564 | 564 | q_ptr(parent), |
|
565 | 565 | m_label(label) |
|
566 | 566 | { |
|
567 | 567 | } |
|
568 | 568 | |
|
569 | 569 | QBarSetPrivate::~QBarSetPrivate() |
|
570 | 570 | { |
|
571 | 571 | } |
|
572 | 572 | |
|
573 | 573 | void QBarSetPrivate::append(QPointF value) |
|
574 | 574 | { |
|
575 | 575 | m_values.append(value); |
|
576 | 576 | emit restructuredBars(); |
|
577 | 577 | } |
|
578 | 578 | |
|
579 | 579 | void QBarSetPrivate::append(QList<QPointF> values) |
|
580 | 580 | { |
|
581 | 581 | for (int i=0; i<values.count(); i++) { |
|
582 | 582 | m_values.append(values.at(i)); |
|
583 | 583 | } |
|
584 | 584 | emit restructuredBars(); |
|
585 | 585 | } |
|
586 | 586 | |
|
587 | 587 | void QBarSetPrivate::append(QList<qreal> values) |
|
588 | 588 | { |
|
589 | 589 | int index = m_values.count(); |
|
590 | 590 | for (int i=0; i<values.count(); i++) { |
|
591 | 591 | m_values.append(QPointF(index,values.at(i))); |
|
592 | 592 | index++; |
|
593 | 593 | } |
|
594 | 594 | emit restructuredBars(); |
|
595 | 595 | } |
|
596 | 596 | |
|
597 | 597 | void QBarSetPrivate::insert(const int index, const qreal value) |
|
598 | 598 | { |
|
599 | 599 | m_values.insert(index, QPointF(index, value)); |
|
600 | 600 | emit restructuredBars(); |
|
601 | 601 | } |
|
602 | 602 | |
|
603 | 603 | void QBarSetPrivate::insert(const int index, const QPointF value) |
|
604 | 604 | { |
|
605 | 605 | m_values.insert(index, value); |
|
606 | 606 | emit restructuredBars(); |
|
607 | 607 | } |
|
608 | 608 | |
|
609 | 609 | bool QBarSetPrivate::remove(const int index, const int count) |
|
610 | 610 | { |
|
611 | 611 | if ((index + count) > m_values.count()) { |
|
612 | 612 | // cant remove more values than there are |
|
613 | 613 | return false; |
|
614 | 614 | } |
|
615 | 615 | int c = count; |
|
616 | 616 | while (c > 0) { |
|
617 | 617 | m_values.removeAt(index); |
|
618 | 618 | c--; |
|
619 | 619 | } |
|
620 | 620 | emit restructuredBars(); |
|
621 | 621 | return true; |
|
622 | 622 | } |
|
623 | 623 | |
|
624 | 624 | void QBarSetPrivate::replace(const int index, const qreal value) |
|
625 | 625 | { |
|
626 | 626 | m_values.replace(index,QPointF(index,value)); |
|
627 | 627 | emit updatedBars(); |
|
628 | 628 | } |
|
629 | 629 | |
|
630 | 630 | void QBarSetPrivate::replace(const int index, const QPointF value) |
|
631 | 631 | { |
|
632 | 632 | m_values.replace(index,value); |
|
633 | 633 | emit updatedBars(); |
|
634 | 634 | } |
|
635 | 635 | |
|
636 | 636 | #include "moc_qbarset.cpp" |
|
637 | 637 | #include "moc_qbarset_p.cpp" |
|
638 | 638 | |
|
639 | 639 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,117 +1,117 | |||
|
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 | #ifndef QBARSET_H |
|
22 | 22 | #define QBARSET_H |
|
23 | 23 | |
|
24 | 24 | #include <qchartglobal.h> |
|
25 | 25 | #include <QPen> |
|
26 | 26 | #include <QBrush> |
|
27 | 27 | #include <QFont> |
|
28 | 28 | |
|
29 | 29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | 30 | class QBarSetPrivate; |
|
31 | 31 | |
|
32 | 32 | class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject |
|
33 | 33 | { |
|
34 | 34 | Q_OBJECT |
|
35 | 35 | Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged) |
|
36 | 36 | Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged) |
|
37 | 37 | Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged) |
|
38 | 38 | Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged) |
|
39 | 39 | Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged) |
|
40 | 40 | Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) |
|
41 | 41 | Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged) |
|
42 | 42 | Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged) |
|
43 | 43 | |
|
44 | 44 | public: |
|
45 | 45 | explicit QBarSet(const QString label, QObject *parent = 0); |
|
46 | 46 | virtual ~QBarSet(); |
|
47 | 47 | |
|
48 | 48 | void setLabel(const QString label); |
|
49 | 49 | QString label() const; |
|
50 | 50 | |
|
51 | 51 | void append(const QPointF value); |
|
52 | void append(const QList<QPointF> values); | |
|
52 | void append(const QList<QPointF> &values); | |
|
53 | 53 | void append(const qreal value); |
|
54 | void append(const QList<qreal> values); | |
|
54 | void append(const QList<qreal> &values); | |
|
55 | 55 | |
|
56 | 56 | QBarSet& operator << (const qreal &value); |
|
57 | 57 | QBarSet& operator << (const QPointF &value); |
|
58 | 58 | |
|
59 | 59 | void insert(const int index, const qreal value); |
|
60 | 60 | void insert(const int index, const QPointF value); |
|
61 | 61 | bool remove(const int index, const int count = 1); |
|
62 | 62 | void replace(const int index, const qreal value); |
|
63 | 63 | void replace(const int index, const QPointF value); |
|
64 | 64 | QPointF at(const int index) const; |
|
65 | 65 | QPointF operator [] (const int index) const; |
|
66 | 66 | int count() const; |
|
67 | 67 | qreal sum() const; |
|
68 | 68 | |
|
69 | 69 | void setPen(const QPen &pen); |
|
70 | 70 | QPen pen() const; |
|
71 | 71 | |
|
72 | 72 | void setBrush(const QBrush &brush); |
|
73 | 73 | QBrush brush() const; |
|
74 | 74 | |
|
75 | 75 | void setLabelBrush(const QBrush &brush); |
|
76 | 76 | QBrush labelBrush() const; |
|
77 | 77 | |
|
78 | 78 | void setLabelFont(const QFont &font); |
|
79 | 79 | QFont labelFont() const; |
|
80 | 80 | |
|
81 | 81 | QColor color(); |
|
82 | 82 | void setColor(QColor color); |
|
83 | 83 | |
|
84 | 84 | QColor borderColor(); |
|
85 | 85 | void setBorderColor(QColor color); |
|
86 | 86 | |
|
87 | 87 | QColor labelColor(); |
|
88 | 88 | void setLabelColor(QColor color); |
|
89 | 89 | |
|
90 | 90 | Q_SIGNALS: |
|
91 | 91 | void clicked(int index); |
|
92 | 92 | void hovered(bool status); |
|
93 | 93 | void penChanged(); |
|
94 | 94 | void brushChanged(); |
|
95 | 95 | void labelChanged(); |
|
96 | 96 | void labelBrushChanged(); |
|
97 | 97 | void labelFontChanged(); |
|
98 | 98 | void colorChanged(QColor color); |
|
99 | 99 | void borderColorChanged(QColor color); |
|
100 | 100 | void labelColorChanged(QColor color); |
|
101 | 101 | |
|
102 | 102 | void valuesAdded(int index, int count); |
|
103 | 103 | void valuesRemoved(int index, int count); |
|
104 | 104 | void valueChanged(int index); |
|
105 | 105 | |
|
106 | 106 | private: |
|
107 | 107 | QScopedPointer<QBarSetPrivate> d_ptr; |
|
108 | 108 | Q_DISABLE_COPY(QBarSet) |
|
109 | 109 | friend class QBarSeries; |
|
110 | 110 | friend class BarLegendMarker; |
|
111 | 111 | friend class BarChartItem; |
|
112 | 112 | friend class QBarSeriesPrivate; |
|
113 | 113 | }; |
|
114 | 114 | |
|
115 | 115 | QTCOMMERCIALCHART_END_NAMESPACE |
|
116 | 116 | |
|
117 | 117 | #endif // QBARSET_H |
General Comments 0
You need to be logged in to leave comments.
Login now