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