@@ -1,718 +1,719 | |||
|
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 "qbarseries.h" |
|
22 | 22 | #include "qbarseries_p.h" |
|
23 | 23 | #include "qbarset.h" |
|
24 | 24 | #include "qbarset_p.h" |
|
25 | 25 | #include "domain_p.h" |
|
26 | 26 | #include "legendmarker_p.h" |
|
27 | 27 | #include "chartdataset_p.h" |
|
28 | 28 | #include "charttheme_p.h" |
|
29 | 29 | #include "chartanimator_p.h" |
|
30 | 30 | |
|
31 | 31 | #include <QAbstractItemModel> |
|
32 | 32 | #include <QModelIndex> |
|
33 | 33 | |
|
34 | 34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
35 | 35 | |
|
36 | 36 | /*! |
|
37 | 37 | \class QBarSeries |
|
38 | 38 | \brief part of QtCommercial chart API. |
|
39 | 39 | \mainclass |
|
40 | 40 | |
|
41 | 41 | QBarSeries represents a series of data shown as bars. One QBarSeries can contain multiple |
|
42 | 42 | QBarSet data sets. QBarSeries groups the data from sets to categories, which are defined |
|
43 | 43 | by QStringList. |
|
44 | 44 | |
|
45 | 45 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
46 | 46 | \image examples_barchart.png |
|
47 | 47 | |
|
48 | 48 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
49 | 49 | */ |
|
50 | 50 | |
|
51 | 51 | /*! |
|
52 | 52 | \fn void QBarSeries::clicked(QBarSet *barset, QString category) |
|
53 | 53 | |
|
54 | 54 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category |
|
55 | 55 | contained by the series. |
|
56 | 56 | */ |
|
57 | 57 | |
|
58 | 58 | /*! |
|
59 | 59 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
60 | 60 | |
|
61 | 61 | The signal is emitted if mouse is hovered on top of series. |
|
62 | 62 | Parameter \a barset is the pointer of barset, where hover happened. |
|
63 | 63 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
64 | 64 | */ |
|
65 | 65 | |
|
66 | 66 | /*! |
|
67 | 67 | Constructs empty QBarSeries. Parameter \a categories defines the categories for chart. |
|
68 | 68 | QBarSeries is QObject which is a child of a \a parent. |
|
69 | 69 | */ |
|
70 | 70 | QBarSeries::QBarSeries(/*QBarCategories categories,*/ QObject *parent) : |
|
71 | 71 | QAbstractSeries(*new QBarSeriesPrivate(/*categories,*/ this),parent) |
|
72 | 72 | { |
|
73 | 73 | } |
|
74 | 74 | |
|
75 | 75 | /*! |
|
76 | 76 | Destructs barseries and owned barsets. |
|
77 | 77 | */ |
|
78 | 78 | QBarSeries::~QBarSeries() |
|
79 | 79 | { |
|
80 | 80 | // NOTE: d_ptr destroyed by QObject |
|
81 | 81 | } |
|
82 | 82 | |
|
83 | 83 | /*! |
|
84 | 84 | \internal |
|
85 | 85 | */ |
|
86 | 86 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
87 | 87 | QAbstractSeries(d,parent) |
|
88 | 88 | { |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | 91 | /*! |
|
92 | 92 | Returns the type of series. Derived classes override this. |
|
93 | 93 | */ |
|
94 | 94 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
95 | 95 | { |
|
96 | 96 | return QAbstractSeries::SeriesTypeBar; |
|
97 | 97 | } |
|
98 | 98 | |
|
99 | 99 | void QBarSeries::setCategories(QBarCategories categories) |
|
100 | 100 | { |
|
101 | 101 | Q_D(QBarSeries); |
|
102 | 102 | d->setCategories(categories); |
|
103 | 103 | emit d->categoriesUpdated(); |
|
104 | 104 | } |
|
105 | 105 | |
|
106 | 106 | /*! |
|
107 | 107 | Adds a set of bars to series. Takes ownership of \a set. |
|
108 | 108 | */ |
|
109 | 109 | bool QBarSeries::appendBarSet(QBarSet *set) |
|
110 | 110 | { |
|
111 | 111 | Q_D(QBarSeries); |
|
112 | 112 | if ((d->m_barSets.contains(set)) || (set == 0)) { |
|
113 | 113 | // Fail if set is already in list or set is null. |
|
114 | 114 | return false; |
|
115 | 115 | } |
|
116 | 116 | d->m_barSets.append(set); |
|
117 | 117 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
118 | 118 | emit d->restructuredBars(); |
|
119 | 119 | return true; |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
124 | 124 | */ |
|
125 | 125 | bool QBarSeries::removeBarSet(QBarSet *set) |
|
126 | 126 | { |
|
127 | 127 | Q_D(QBarSeries); |
|
128 | 128 | if (!d->m_barSets.contains(set)) { |
|
129 | 129 | // Fail if set is not in list |
|
130 | 130 | return false; |
|
131 | 131 | } |
|
132 | 132 | d->m_barSets.removeOne(set); |
|
133 | 133 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
134 | 134 | emit d->restructuredBars(); |
|
135 | 135 | return true; |
|
136 | 136 | } |
|
137 | 137 | |
|
138 | 138 | /*! |
|
139 | 139 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
140 | 140 | */ |
|
141 | 141 | bool QBarSeries::appendBarSets(QList<QBarSet* > sets) |
|
142 | 142 | { |
|
143 | 143 | Q_D(QBarSeries); |
|
144 | 144 | foreach (QBarSet* set, sets) { |
|
145 | 145 | if ((set == 0) || (d->m_barSets.contains(set))) { |
|
146 | 146 | // Fail if any of the sets is null or is already appended. |
|
147 | 147 | return false; |
|
148 | 148 | } |
|
149 | 149 | if (sets.count(set) != 1) { |
|
150 | 150 | // Also fail if same set is more than once in given list. |
|
151 | 151 | return false; |
|
152 | 152 | } |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | 155 | foreach (QBarSet* set, sets) { |
|
156 | 156 | d->m_barSets.append(set); |
|
157 | 157 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
158 | 158 | } |
|
159 | 159 | emit d->restructuredBars(); |
|
160 | 160 | return true; |
|
161 | 161 | } |
|
162 | 162 | |
|
163 | 163 | /*! |
|
164 | 164 | Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets. |
|
165 | 165 | */ |
|
166 | 166 | bool QBarSeries::removeBarSets(QList<QBarSet* > sets) |
|
167 | 167 | { |
|
168 | 168 | Q_D(QBarSeries); |
|
169 | 169 | |
|
170 | 170 | bool setsRemoved = false; |
|
171 | 171 | foreach (QBarSet* set, sets) { |
|
172 | 172 | if (d->m_barSets.contains(set)) { |
|
173 | 173 | d->m_barSets.removeOne(set); |
|
174 | 174 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), d, SLOT(barsetChanged())); |
|
175 | 175 | setsRemoved = true; |
|
176 | 176 | } |
|
177 | 177 | } |
|
178 | 178 | |
|
179 | 179 | if (setsRemoved) { |
|
180 | 180 | emit d->restructuredBars(); |
|
181 | 181 | } |
|
182 | 182 | return setsRemoved; |
|
183 | 183 | } |
|
184 | 184 | |
|
185 | 185 | /*! |
|
186 | 186 | Returns number of sets in series. |
|
187 | 187 | */ |
|
188 | 188 | int QBarSeries::barsetCount() const |
|
189 | 189 | { |
|
190 | 190 | Q_D(const QBarSeries); |
|
191 | 191 | return d->m_barSets.count(); |
|
192 | 192 | } |
|
193 | 193 | |
|
194 | 194 | /*! |
|
195 | 195 | Returns number of categories in series |
|
196 | 196 | */ |
|
197 | 197 | int QBarSeries::categoryCount() const |
|
198 | 198 | { |
|
199 | 199 | Q_D(const QBarSeries); |
|
200 | 200 | return d->m_categories.count(); |
|
201 | 201 | } |
|
202 | 202 | |
|
203 | 203 | /*! |
|
204 | 204 | Returns a list of sets in series. Keeps ownership of sets. |
|
205 | 205 | */ |
|
206 | 206 | QList<QBarSet*> QBarSeries::barSets() const |
|
207 | 207 | { |
|
208 | 208 | Q_D(const QBarSeries); |
|
209 | 209 | return d->m_barSets; |
|
210 | 210 | } |
|
211 | 211 | |
|
212 | 212 | /*! |
|
213 | 213 | \fn bool QBarSeries::setModel(QAbstractItemModel *model) |
|
214 | 214 | Sets the \a model to be used as a data source |
|
215 | 215 | */ |
|
216 |
void QBarSeries::setModel(QAbstractItemModel |
|
|
216 | void QBarSeries::setModel(QAbstractItemModel *model) | |
|
217 | 217 | { |
|
218 | Q_UNUSED(model); | |
|
218 | 219 | // Q_D(QBarSeries); |
|
219 | 220 | // d->setModel(model); |
|
220 | 221 | } |
|
221 | 222 | |
|
222 | 223 | /*! |
|
223 | 224 | \fn bool QBarSeries::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
224 | 225 | Sets column/row specified by \a categories to be used as a list of bar series categories. |
|
225 | 226 | Parameter \a bottomBoundry indicates the column/row where the first bar set is located in the model. |
|
226 | 227 | Parameter \a topBoundry indicates the column/row where the last bar set is located in the model. |
|
227 | 228 | All the columns/rows inbetween those two values are also used as data for bar sets. |
|
228 | 229 | The \a orientation parameter specifies whether the data is in columns or in rows. |
|
229 | 230 | */ |
|
230 | 231 | //void QBarSeries::setModelMapping(int categories, int bottomBoundary, int topBoundary, Qt::Orientation orientation) |
|
231 | 232 | //{ |
|
232 | 233 | // Q_D(QBarSeries); |
|
233 | 234 | // d->setModelMapping(categories,bottomBoundary,topBoundary,orientation); |
|
234 | 235 | //} |
|
235 | 236 | |
|
236 | 237 | //void QBarSeries::setModelMappingRange(int first, int count) |
|
237 | 238 | //{ |
|
238 | 239 | // Q_D(QBarSeries); |
|
239 | 240 | // d->setModelMappingRange(first, count); |
|
240 | 241 | //} |
|
241 | 242 | |
|
242 | 243 | /*! |
|
243 | 244 | Returns the bar categories of the series. |
|
244 | 245 | */ |
|
245 | 246 | QBarCategories QBarSeries::categories() const |
|
246 | 247 | { |
|
247 | 248 | Q_D(const QBarSeries); |
|
248 | 249 | return d->m_categories; |
|
249 | 250 | } |
|
250 | 251 | |
|
251 | 252 | /*! |
|
252 | 253 | Sets the visibility of labels in series to \a visible |
|
253 | 254 | */ |
|
254 | 255 | void QBarSeries::setLabelsVisible(bool visible) |
|
255 | 256 | { |
|
256 | 257 | foreach (QBarSet* s, barSets()) { |
|
257 | 258 | s->setLabelsVisible(visible); |
|
258 | 259 | } |
|
259 | 260 | } |
|
260 | 261 | |
|
261 | 262 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
262 | 263 | |
|
263 | 264 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : |
|
264 | 265 | QAbstractSeriesPrivate(q), |
|
265 | 266 | m_barMargin(0.05), // Default value is 5% of category width |
|
266 | 267 | m_mapCategories(-1), |
|
267 | 268 | m_mapBarBottom(-1), |
|
268 | 269 | m_mapBarTop(-1) |
|
269 | 270 | { |
|
270 | 271 | } |
|
271 | 272 | |
|
272 | 273 | void QBarSeriesPrivate::setCategories(QBarCategories categories) |
|
273 | 274 | { |
|
274 | 275 | m_categories = categories; |
|
275 | 276 | } |
|
276 | 277 | |
|
277 | 278 | void QBarSeriesPrivate::setBarMargin(qreal margin) |
|
278 | 279 | { |
|
279 | 280 | if (margin > 1.0) { |
|
280 | 281 | margin = 1.0; |
|
281 | 282 | } else if (margin < 0.0) { |
|
282 | 283 | margin = 0.0; |
|
283 | 284 | } |
|
284 | 285 | |
|
285 | 286 | m_barMargin = margin; |
|
286 | 287 | emit updatedBars(); |
|
287 | 288 | } |
|
288 | 289 | |
|
289 | 290 | qreal QBarSeriesPrivate::barMargin() |
|
290 | 291 | { |
|
291 | 292 | return m_barMargin; |
|
292 | 293 | } |
|
293 | 294 | |
|
294 | 295 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
295 | 296 | { |
|
296 | 297 | return m_barSets.at(index); |
|
297 | 298 | } |
|
298 | 299 | |
|
299 | 300 | QString QBarSeriesPrivate::categoryName(int category) |
|
300 | 301 | { |
|
301 | 302 | return m_categories.at(category); |
|
302 | 303 | } |
|
303 | 304 | |
|
304 | 305 | qreal QBarSeriesPrivate::min() |
|
305 | 306 | { |
|
306 | 307 | if (m_barSets.count() <= 0) { |
|
307 | 308 | return 0; |
|
308 | 309 | } |
|
309 | 310 | qreal min = INT_MAX; |
|
310 | 311 | |
|
311 | 312 | for (int i = 0; i < m_barSets.count(); i++) { |
|
312 | 313 | int categoryCount = m_barSets.at(i)->count(); |
|
313 | 314 | for (int j = 0; j < categoryCount; j++) { |
|
314 | 315 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
315 | 316 | if (temp < min) |
|
316 | 317 | min = temp; |
|
317 | 318 | } |
|
318 | 319 | } |
|
319 | 320 | return min; |
|
320 | 321 | } |
|
321 | 322 | |
|
322 | 323 | qreal QBarSeriesPrivate::max() |
|
323 | 324 | { |
|
324 | 325 | if (m_barSets.count() <= 0) { |
|
325 | 326 | return 0; |
|
326 | 327 | } |
|
327 | 328 | qreal max = INT_MIN; |
|
328 | 329 | |
|
329 | 330 | for (int i = 0; i < m_barSets.count(); i++) { |
|
330 | 331 | int categoryCount = m_barSets.at(i)->count(); |
|
331 | 332 | for (int j = 0; j < categoryCount; j++) { |
|
332 | 333 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
333 | 334 | if (temp > max) |
|
334 | 335 | max = temp; |
|
335 | 336 | } |
|
336 | 337 | } |
|
337 | 338 | |
|
338 | 339 | return max; |
|
339 | 340 | } |
|
340 | 341 | |
|
341 | 342 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
342 | 343 | { |
|
343 | 344 | if ((set < 0) || (set >= m_barSets.count())) { |
|
344 | 345 | // No set, no value. |
|
345 | 346 | return 0; |
|
346 | 347 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
347 | 348 | // No category, no value. |
|
348 | 349 | return 0; |
|
349 | 350 | } |
|
350 | 351 | |
|
351 | 352 | return m_barSets.at(set)->at(category).y(); |
|
352 | 353 | } |
|
353 | 354 | |
|
354 | 355 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
355 | 356 | { |
|
356 | 357 | if ((set < 0) || (set >= m_barSets.count())) { |
|
357 | 358 | // No set, no value. |
|
358 | 359 | return 0; |
|
359 | 360 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
360 | 361 | // No category, no value. |
|
361 | 362 | return 0; |
|
362 | 363 | } |
|
363 | 364 | |
|
364 | 365 | qreal value = m_barSets.at(set)->at(category).y(); |
|
365 | 366 | qreal sum = categorySum(category); |
|
366 | 367 | if ( qFuzzyIsNull(sum) ) { |
|
367 | 368 | return 0; |
|
368 | 369 | } |
|
369 | 370 | |
|
370 | 371 | return value / sum; |
|
371 | 372 | } |
|
372 | 373 | |
|
373 | 374 | qreal QBarSeriesPrivate::categorySum(int category) |
|
374 | 375 | { |
|
375 | 376 | qreal sum(0); |
|
376 | 377 | int count = m_barSets.count(); // Count sets |
|
377 | 378 | for (int set = 0; set < count; set++) { |
|
378 | 379 | if (category < m_barSets.at(set)->count()) |
|
379 | 380 | sum += m_barSets.at(set)->at(category).y(); |
|
380 | 381 | } |
|
381 | 382 | return sum; |
|
382 | 383 | } |
|
383 | 384 | |
|
384 | 385 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
385 | 386 | { |
|
386 | 387 | qreal sum(0); |
|
387 | 388 | int count = m_barSets.count(); // Count sets |
|
388 | 389 | for (int set = 0; set < count; set++) { |
|
389 | 390 | if (category < m_barSets.at(set)->count()) |
|
390 | 391 | sum += qAbs(m_barSets.at(set)->at(category).y()); |
|
391 | 392 | } |
|
392 | 393 | return sum; |
|
393 | 394 | } |
|
394 | 395 | |
|
395 | 396 | qreal QBarSeriesPrivate::maxCategorySum() |
|
396 | 397 | { |
|
397 | 398 | qreal max = INT_MIN; |
|
398 | 399 | int count = m_categories.count(); |
|
399 | 400 | for (int i = 0; i < count; i++) { |
|
400 | 401 | qreal sum = categorySum(i); |
|
401 | 402 | if (sum > max) |
|
402 | 403 | max = sum; |
|
403 | 404 | } |
|
404 | 405 | return max; |
|
405 | 406 | } |
|
406 | 407 | |
|
407 | 408 | //void QBarSeriesPrivate::setModel(QAbstractItemModel *model) |
|
408 | 409 | //{ |
|
409 | 410 | // // disconnect signals from old model |
|
410 | 411 | // if(m_model) |
|
411 | 412 | // { |
|
412 | 413 | // disconnect(m_model, 0, this, 0); |
|
413 | 414 | // m_mapCategories = -1; |
|
414 | 415 | // m_mapBarBottom = -1; |
|
415 | 416 | // m_mapBarTop = -1; |
|
416 | 417 | // m_mapOrientation = Qt::Vertical; |
|
417 | 418 | // } |
|
418 | 419 | |
|
419 | 420 | // // set new model |
|
420 | 421 | // if(model) |
|
421 | 422 | // { |
|
422 | 423 | // m_model = model; |
|
423 | 424 | // } |
|
424 | 425 | // else |
|
425 | 426 | // { |
|
426 | 427 | // m_model = 0; |
|
427 | 428 | // } |
|
428 | 429 | //} |
|
429 | 430 | |
|
430 | 431 | //void QBarSeriesPrivate::setModelMapping(int categories, int bottomBoundry, int topBoundry, Qt::Orientation orientation) |
|
431 | 432 | //{ |
|
432 | 433 | // Q_Q(QBarSeries); |
|
433 | 434 | |
|
434 | 435 | // if (m_model == 0) |
|
435 | 436 | // return; |
|
436 | 437 | |
|
437 | 438 | // m_mapCategories = categories; |
|
438 | 439 | // m_mapBarBottom = bottomBoundry; |
|
439 | 440 | // m_mapBarTop = topBoundry; |
|
440 | 441 | // m_mapOrientation = orientation; |
|
441 | 442 | |
|
442 | 443 | // // connect the signals |
|
443 | 444 | // connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
444 | 445 | // if (m_mapOrientation == Qt::Vertical) { |
|
445 | 446 | // connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
446 | 447 | // connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
447 | 448 | // } else { |
|
448 | 449 | // connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
449 | 450 | // connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
450 | 451 | // } |
|
451 | 452 | |
|
452 | 453 | // // create the initial bars |
|
453 | 454 | // m_categories.clear(); |
|
454 | 455 | // if (m_mapOrientation == Qt::Vertical) { |
|
455 | 456 | // int rowCount = 0; |
|
456 | 457 | // if(m_mapCount == -1) |
|
457 | 458 | // rowCount = m_model->rowCount() - m_mapFirst; |
|
458 | 459 | // else |
|
459 | 460 | // rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); |
|
460 | 461 | // for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { |
|
461 | 462 | // m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
462 | 463 | // } |
|
463 | 464 | |
|
464 | 465 | // for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
465 | 466 | // QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); |
|
466 | 467 | // for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) |
|
467 | 468 | // *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
468 | 469 | // q->appendBarSet(barSet); |
|
469 | 470 | // } |
|
470 | 471 | // } else { |
|
471 | 472 | // int columnCount = 0; |
|
472 | 473 | // if(m_mapCount == -1) |
|
473 | 474 | // columnCount = m_model->columnCount() - m_mapFirst; |
|
474 | 475 | // else |
|
475 | 476 | // columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); |
|
476 | 477 | // for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { |
|
477 | 478 | // m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
478 | 479 | // } |
|
479 | 480 | |
|
480 | 481 | // for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
481 | 482 | // QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); |
|
482 | 483 | // for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) |
|
483 | 484 | // *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
484 | 485 | // q->appendBarSet(barSet); |
|
485 | 486 | // } |
|
486 | 487 | // } |
|
487 | 488 | //} |
|
488 | 489 | |
|
489 | 490 | //void QBarSeriesPrivate::setModelMappingRange(int first, int count) |
|
490 | 491 | //{ |
|
491 | 492 | // m_mapFirst = first; |
|
492 | 493 | // m_mapCount = count; |
|
493 | 494 | //} |
|
494 | 495 | |
|
495 | 496 | //void QBarSeriesPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight) |
|
496 | 497 | //{ |
|
497 | 498 | // for (int row = topLeft.row(); row <= bottomRight.row(); row++) { |
|
498 | 499 | // for (int column = topLeft.column(); column <= bottomRight.column(); column++) { |
|
499 | 500 | // if (m_mapOrientation == Qt::Vertical) |
|
500 | 501 | // { |
|
501 | 502 | // // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
502 | 503 | // if ( row >= m_mapFirst && (m_mapCount == - 1 || row < m_mapFirst + m_mapCount)) { |
|
503 | 504 | // if (column >= m_mapBarBottom && column <= m_mapBarTop) |
|
504 | 505 | // barsetAt(column - m_mapBarBottom)->replace(row - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
505 | 506 | // // if (column == m_mapCategories);// TODO: |
|
506 | 507 | // } |
|
507 | 508 | // } |
|
508 | 509 | // else |
|
509 | 510 | // { |
|
510 | 511 | // // model update is relevant to BarSeries if the change was made to the part of the model that was mapped to BarSeries |
|
511 | 512 | // if (column >= m_mapFirst && (m_mapCount == - 1 || column < m_mapFirst + m_mapCount)) { |
|
512 | 513 | // if (row >= m_mapBarBottom && row <= m_mapBarTop) |
|
513 | 514 | // barsetAt(row - m_mapBarBottom)->replace(column - m_mapFirst, m_model->data(topLeft, Qt::DisplayRole).toDouble()); |
|
514 | 515 | // // if (row == m_mapCategories);// TODO: |
|
515 | 516 | // } |
|
516 | 517 | // } |
|
517 | 518 | // } |
|
518 | 519 | // } |
|
519 | 520 | //} |
|
520 | 521 | |
|
521 | 522 | void QBarSeriesPrivate::modelDataAdded(QModelIndex parent, int start, int end) |
|
522 | 523 | { |
|
523 | 524 | Q_UNUSED(parent); |
|
524 | 525 | Q_UNUSED(start); |
|
525 | 526 | Q_UNUSED(end); |
|
526 | 527 | // initializeDataFromModel(); |
|
527 | 528 | // // series uses model as a data sourceupda |
|
528 | 529 | // int addedCount = end - start + 1; |
|
529 | 530 | // if (m_mapCount != -1 && start >= m_mapFirst + m_mapCount) { |
|
530 | 531 | // return; |
|
531 | 532 | // } else { |
|
532 | 533 | |
|
533 | 534 | // for (int bar = m_mapBarBottom; bar <= m_mapBarTop; bar++) { |
|
534 | 535 | // QBarSet *barSet = barsetAt(bar - m_mapBarBottom); |
|
535 | 536 | // // adding items to unlimited map |
|
536 | 537 | // if (m_mapCount == -1 && start >= m_mapFirst) { |
|
537 | 538 | // for (int i = start; i <= end; i++) { |
|
538 | 539 | // if (bar == m_mapBarBottom) |
|
539 | 540 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
540 | 541 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
541 | 542 | // } |
|
542 | 543 | // } else if (m_mapCount == - 1 && start < m_mapFirst) { |
|
543 | 544 | // // not all newly added items |
|
544 | 545 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { |
|
545 | 546 | // if (bar == m_mapBarBottom) |
|
546 | 547 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
547 | 548 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
548 | 549 | // } |
|
549 | 550 | // } |
|
550 | 551 | |
|
551 | 552 | // // adding items to limited map |
|
552 | 553 | // else if (start >= m_mapFirst) { |
|
553 | 554 | // // remove the items that will no longer fit into the map |
|
554 | 555 | // // int toRemove = addedCount - (count - points().size()); |
|
555 | 556 | // for (int i = start; i <= end; i++) { |
|
556 | 557 | // if (bar == m_mapBarBottom) |
|
557 | 558 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
558 | 559 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
559 | 560 | // } |
|
560 | 561 | // if (m_barSets.size() > m_mapCount) |
|
561 | 562 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { |
|
562 | 563 | // if (bar == m_mapBarBottom) |
|
563 | 564 | // removeCategory(i); |
|
564 | 565 | // barSet->remove(i); |
|
565 | 566 | // } |
|
566 | 567 | // } else { |
|
567 | 568 | // // |
|
568 | 569 | // for (int i = m_mapFirst; i < m_mapFirst + addedCount; i++) { |
|
569 | 570 | // if (bar == m_mapBarBottom) |
|
570 | 571 | // insertCategory(i - m_mapFirst, m_model->data(m_model->index(i, m_mapCategories), Qt::DisplayRole).toString()); |
|
571 | 572 | // barSet->insert(i - m_mapFirst, m_model->data(m_model->index(i, bar), Qt::DisplayRole).toDouble()); |
|
572 | 573 | // } |
|
573 | 574 | // if (m_barSets.size() > m_mapCount) |
|
574 | 575 | // for (int i = m_barSets.size() - 1; i >= m_mapCount; i--) { |
|
575 | 576 | // if (bar == m_mapBarBottom) |
|
576 | 577 | // removeCategory(i); |
|
577 | 578 | // barSet->remove(i); |
|
578 | 579 | // } |
|
579 | 580 | // } |
|
580 | 581 | // } |
|
581 | 582 | // emit restructuredBars(); |
|
582 | 583 | // emit barsetChanged(); |
|
583 | 584 | // emit categoriesUpdated(); |
|
584 | 585 | // } |
|
585 | 586 | } |
|
586 | 587 | |
|
587 | 588 | void QBarSeriesPrivate::modelDataRemoved(QModelIndex parent, int start, int end) |
|
588 | 589 | { |
|
589 | 590 | Q_UNUSED(parent); |
|
590 | 591 | Q_UNUSED(start); |
|
591 | 592 | Q_UNUSED(end); |
|
592 | 593 | // initializeDataFromModel(); |
|
593 | 594 | } |
|
594 | 595 | |
|
595 | 596 | //void QBarSeriesPrivate::initializeDataFromModel() |
|
596 | 597 | //{ |
|
597 | 598 | // Q_Q(QBarSeries); |
|
598 | 599 | |
|
599 | 600 | // if (m_model == 0) |
|
600 | 601 | // return; |
|
601 | 602 | |
|
602 | 603 | // // connect the signals |
|
603 | 604 | //// connect(m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(modelUpdated(QModelIndex,QModelIndex))); |
|
604 | 605 | //// if (m_mapOrientation == Qt::Vertical) { |
|
605 | 606 | //// connect(m_model,SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
606 | 607 | //// connect(m_model,SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
607 | 608 | //// } else { |
|
608 | 609 | //// connect(m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), this, SLOT(modelDataAdded(QModelIndex,int,int))); |
|
609 | 610 | //// connect(m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), this, SLOT(modelDataRemoved(QModelIndex,int,int))); |
|
610 | 611 | //// } |
|
611 | 612 | |
|
612 | 613 | // // create the initial bars |
|
613 | 614 | // m_categories.clear(); |
|
614 | 615 | // m_barSets.clear(); |
|
615 | 616 | //// emit restructuredBars(); |
|
616 | 617 | // if (m_mapOrientation == Qt::Vertical) { |
|
617 | 618 | // int rowCount = 0; |
|
618 | 619 | // if(m_mapCount == -1) |
|
619 | 620 | // rowCount = m_model->rowCount() - m_mapFirst; |
|
620 | 621 | // else |
|
621 | 622 | // rowCount = qMin(m_mapCount, m_model->rowCount() - m_mapFirst); |
|
622 | 623 | // for (int k = m_mapFirst; k < m_mapFirst + rowCount; k++) { |
|
623 | 624 | // m_categories << m_model->data(m_model->index(k, m_mapCategories), Qt::DisplayRole).toString(); |
|
624 | 625 | // } |
|
625 | 626 | |
|
626 | 627 | // for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
627 | 628 | // QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Horizontal, Qt::DisplayRole).toString()); |
|
628 | 629 | // for(int m = m_mapFirst; m < m_mapFirst + rowCount; m++) |
|
629 | 630 | // *barSet << m_model->data(m_model->index(m, i), Qt::DisplayRole).toDouble(); |
|
630 | 631 | // q->appendBarSet(barSet); |
|
631 | 632 | // } |
|
632 | 633 | // } else { |
|
633 | 634 | // int columnCount = 0; |
|
634 | 635 | // if(m_mapCount == -1) |
|
635 | 636 | // columnCount = m_model->columnCount() - m_mapFirst; |
|
636 | 637 | // else |
|
637 | 638 | // columnCount = qMin(m_mapCount, m_model->columnCount() - m_mapFirst); |
|
638 | 639 | // for (int k = m_mapFirst; k < m_mapFirst + columnCount; k++) { |
|
639 | 640 | // m_categories << m_model->data(m_model->index(m_mapCategories, k), Qt::DisplayRole).toString(); |
|
640 | 641 | // } |
|
641 | 642 | |
|
642 | 643 | // for (int i = m_mapBarBottom; i <= m_mapBarTop; i++) { |
|
643 | 644 | // QBarSet* barSet = new QBarSet(m_model->headerData(i, Qt::Vertical, Qt::DisplayRole).toString()); |
|
644 | 645 | // for(int m = m_mapFirst; m < m_mapFirst + columnCount; m++) |
|
645 | 646 | // *barSet << m_model->data(m_model->index(i, m), Qt::DisplayRole).toDouble(); |
|
646 | 647 | // q->appendBarSet(barSet); |
|
647 | 648 | // } |
|
648 | 649 | // } |
|
649 | 650 | // emit restructuredBars(); |
|
650 | 651 | //// emit updatedBars(); |
|
651 | 652 | //} |
|
652 | 653 | |
|
653 | 654 | void QBarSeriesPrivate::insertCategory(int index, const QString category) |
|
654 | 655 | { |
|
655 | 656 | m_categories.insert(index, category); |
|
656 | 657 | emit categoriesUpdated(); |
|
657 | 658 | } |
|
658 | 659 | |
|
659 | 660 | void QBarSeriesPrivate::removeCategory(int index) |
|
660 | 661 | { |
|
661 | 662 | m_categories.removeAt(index); |
|
662 | 663 | emit categoriesUpdated(); |
|
663 | 664 | } |
|
664 | 665 | |
|
665 | 666 | void QBarSeriesPrivate::barsetChanged() |
|
666 | 667 | { |
|
667 | 668 | emit updatedBars(); |
|
668 | 669 | } |
|
669 | 670 | |
|
670 | 671 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
671 | 672 | { |
|
672 | 673 | qreal minX(domain.minX()); |
|
673 | 674 | qreal minY(domain.minY()); |
|
674 | 675 | qreal maxX(domain.maxX()); |
|
675 | 676 | qreal maxY(domain.maxY()); |
|
676 | 677 | int tickXCount(domain.tickXCount()); |
|
677 | 678 | int tickYCount(domain.tickYCount()); |
|
678 | 679 | |
|
679 | 680 | qreal x = m_categories.count(); |
|
680 | 681 | qreal y = max(); |
|
681 | 682 | minX = qMin(minX, x); |
|
682 | 683 | minY = qMin(minY, y); |
|
683 | 684 | maxX = qMax(maxX, x); |
|
684 | 685 | maxY = qMax(maxY, y); |
|
685 | 686 | tickXCount = x+1; |
|
686 | 687 | |
|
687 | 688 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
688 | 689 | } |
|
689 | 690 | |
|
690 | 691 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
691 | 692 | { |
|
692 | 693 | Q_Q(QBarSeries); |
|
693 | 694 | |
|
694 | 695 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
695 | 696 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
696 | 697 | presenter->animator()->addAnimation(bar); |
|
697 | 698 | } |
|
698 | 699 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
699 | 700 | return bar; |
|
700 | 701 | |
|
701 | 702 | } |
|
702 | 703 | |
|
703 | 704 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
704 | 705 | { |
|
705 | 706 | Q_Q(QBarSeries); |
|
706 | 707 | QList<LegendMarker*> markers; |
|
707 | 708 | foreach(QBarSet* set, q->barSets()) { |
|
708 | 709 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
709 | 710 | markers << marker; |
|
710 | 711 | } |
|
711 | 712 | |
|
712 | 713 | return markers; |
|
713 | 714 | } |
|
714 | 715 | |
|
715 | 716 | #include "moc_qbarseries.cpp" |
|
716 | 717 | #include "moc_qbarseries_p.cpp" |
|
717 | 718 | |
|
718 | 719 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,339 +1,340 | |||
|
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, QStackedBarSeries, QPercentBarSeries |
|
38 | 38 | */ |
|
39 | 39 | |
|
40 | 40 | /*! |
|
41 | 41 | \fn void QBarSet::clicked(QString category) |
|
42 | 42 | \brief signals that set has been clicked |
|
43 | 43 | Parameter \a category describes on which category was clicked |
|
44 | 44 | */ |
|
45 | 45 | |
|
46 | 46 | /*! |
|
47 | 47 | \fn void QBarSet::hovered(bool status) |
|
48 | 48 | \brief signals that mouse has hovered over the set. If \a status is true, then mouse was entered. If \a status is false, then mouse was left. |
|
49 | 49 | |
|
50 | 50 | The signal is emitted if mouse is hovered on top of set |
|
51 | 51 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
52 | 52 | */ |
|
53 | 53 | |
|
54 | 54 | /*! |
|
55 | 55 | Constructs QBarSet with a name of \a name and with parent of \a parent |
|
56 | 56 | */ |
|
57 | 57 | QBarSet::QBarSet(const QString name, QObject *parent) |
|
58 | 58 | : QObject(parent) |
|
59 | 59 | ,d_ptr(new QBarSetPrivate(name,this)) |
|
60 | 60 | { |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | 63 | /*! |
|
64 | 64 | Destroys the barset |
|
65 | 65 | */ |
|
66 | 66 | QBarSet::~QBarSet() |
|
67 | 67 | { |
|
68 | 68 | // NOTE: d_ptr destroyed by QObject |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | /*! |
|
72 | 72 | Sets new \a name for set. |
|
73 | 73 | */ |
|
74 | 74 | void QBarSet::setName(const QString name) |
|
75 | 75 | { |
|
76 | 76 | d_ptr->m_name = name; |
|
77 | 77 | } |
|
78 | 78 | |
|
79 | 79 | /*! |
|
80 | 80 | Returns name of the set. |
|
81 | 81 | */ |
|
82 | 82 | QString QBarSet::name() const |
|
83 | 83 | { |
|
84 | 84 | return d_ptr->m_name; |
|
85 | 85 | } |
|
86 | 86 | |
|
87 | 87 | void QBarSet::append(const QPointF value) |
|
88 | 88 | { |
|
89 | 89 | d_ptr->m_values.append(value); |
|
90 | 90 | emit d_ptr->restructuredBars(); |
|
91 | 91 | } |
|
92 | 92 | |
|
93 | 93 | |
|
94 | 94 | void QBarSet::append(const QList<QPointF> values) |
|
95 | 95 | { |
|
96 | 96 | for (int i=0; i<values.count(); i++) { |
|
97 | 97 | d_ptr->m_values.append(values.at(i)); |
|
98 | 98 | } |
|
99 | 99 | emit d_ptr->restructuredBars(); |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | /*! |
|
103 | 103 | Appends new value \a value to the end of set. |
|
104 | 104 | */ |
|
105 | 105 | void QBarSet::append(const qreal value) |
|
106 | 106 | { |
|
107 | 107 | append(QPointF(d_ptr->m_values.count(), value)); |
|
108 | 108 | // d_ptr->m_values.append(value); |
|
109 | 109 | } |
|
110 | 110 | |
|
111 | 111 | |
|
112 | 112 | void QBarSet::append(const QList<qreal> values) |
|
113 | 113 | { |
|
114 | 114 | int index = d_ptr->m_values.count(); |
|
115 | 115 | for (int i=0; i<values.count(); i++) { |
|
116 | 116 | d_ptr->m_values.append(QPointF(index,values.at(i))); |
|
117 | 117 | index++; |
|
118 | 118 | } |
|
119 | 119 | emit d_ptr->restructuredBars(); |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | /*! |
|
123 | 123 | Appends new value \a value to the end of set. |
|
124 | 124 | */ |
|
125 | 125 | QBarSet& QBarSet::operator << (const qreal &value) |
|
126 | 126 | { |
|
127 | 127 | append(value); |
|
128 | 128 | return *this; |
|
129 | 129 | } |
|
130 | 130 | |
|
131 | 131 | QBarSet& QBarSet::operator << (const QPointF &value) |
|
132 | 132 | { |
|
133 | 133 | append(value); |
|
134 | 134 | return *this; |
|
135 | 135 | } |
|
136 | 136 | |
|
137 | 137 | /*! |
|
138 | 138 | Inserts new \a value on the \a index position. |
|
139 | 139 | The value that is currently at this postion is moved to postion index + 1 |
|
140 | 140 | \sa remove() |
|
141 | 141 | */ |
|
142 | 142 | void QBarSet::insert(const int index, const qreal value) |
|
143 | 143 | { |
|
144 | 144 | d_ptr->m_values.insert(index, QPointF(index, value)); |
|
145 | 145 | // emit d_ptr->updatedBars(); |
|
146 | 146 | } |
|
147 | 147 | |
|
148 | 148 | /*! |
|
149 | 149 | Removes the value specified by \a index |
|
150 | 150 | \sa insert() |
|
151 | 151 | */ |
|
152 | 152 | void QBarSet::remove(const int index) |
|
153 | 153 | { |
|
154 | 154 | d_ptr->m_values.removeAt(index); |
|
155 | 155 | // emit d_ptr->updatedBars(); |
|
156 | 156 | } |
|
157 | 157 | |
|
158 | 158 | /*! |
|
159 | 159 | Sets a new value \a value to set, indexed by \a index |
|
160 | 160 | */ |
|
161 | 161 | void QBarSet::replace(const int index, const qreal value) |
|
162 | 162 | { |
|
163 | 163 | d_ptr->m_values.replace(index,QPointF(index,value)); |
|
164 | 164 | emit d_ptr->updatedBars(); |
|
165 | 165 | } |
|
166 | 166 | |
|
167 | 167 | /*! |
|
168 | 168 | Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF |
|
169 | 169 | */ |
|
170 | 170 | QPointF QBarSet::at(const int index) const |
|
171 | 171 | { |
|
172 | if (index < 0 || index >= d_ptr->m_values.count()) | |
|
173 | return 0.0; | |
|
172 | if (index < 0 || index >= d_ptr->m_values.count()) { | |
|
173 | return QPointF(index, 0.0); | |
|
174 | } | |
|
174 | 175 | |
|
175 | 176 | return d_ptr->m_values.at(index); |
|
176 | 177 | } |
|
177 | 178 | |
|
178 | 179 | /*! |
|
179 | 180 | Returns value of set indexed by \a index |
|
180 | 181 | */ |
|
181 | 182 | QPointF QBarSet::operator [](const int index) const |
|
182 | 183 | { |
|
183 | 184 | return d_ptr->m_values.at(index); |
|
184 | 185 | } |
|
185 | 186 | |
|
186 | 187 | /*! |
|
187 | 188 | Returns count of values in set. |
|
188 | 189 | */ |
|
189 | 190 | int QBarSet::count() const |
|
190 | 191 | { |
|
191 | 192 | return d_ptr->m_values.count(); |
|
192 | 193 | } |
|
193 | 194 | |
|
194 | 195 | /*! |
|
195 | 196 | Returns sum of all values in barset. |
|
196 | 197 | */ |
|
197 | 198 | qreal QBarSet::sum() const |
|
198 | 199 | { |
|
199 | 200 | qreal total(0); |
|
200 | 201 | for (int i=0; i < d_ptr->m_values.count(); i++) { |
|
201 | 202 | //total += d_ptr->m_values.at(i); |
|
202 | 203 | total += d_ptr->m_values.at(i).y(); |
|
203 | 204 | } |
|
204 | 205 | return total; |
|
205 | 206 | } |
|
206 | 207 | |
|
207 | 208 | /*! |
|
208 | 209 | Sets pen for set. Bars of this set are drawn using \a pen |
|
209 | 210 | */ |
|
210 | 211 | void QBarSet::setPen(const QPen &pen) |
|
211 | 212 | { |
|
212 | 213 | if(d_ptr->m_pen!=pen){ |
|
213 | 214 | d_ptr->m_pen = pen; |
|
214 | 215 | emit d_ptr->updatedBars(); |
|
215 | 216 | } |
|
216 | 217 | } |
|
217 | 218 | |
|
218 | 219 | /*! |
|
219 | 220 | Returns pen of the set. |
|
220 | 221 | */ |
|
221 | 222 | QPen QBarSet::pen() const |
|
222 | 223 | { |
|
223 | 224 | return d_ptr->m_pen; |
|
224 | 225 | } |
|
225 | 226 | |
|
226 | 227 | /*! |
|
227 | 228 | Sets brush for the set. Bars of this set are drawn using \a brush |
|
228 | 229 | */ |
|
229 | 230 | void QBarSet::setBrush(const QBrush &brush) |
|
230 | 231 | { |
|
231 | 232 | if(d_ptr->m_brush!=brush){ |
|
232 | 233 | d_ptr->m_brush = brush; |
|
233 | 234 | emit d_ptr->updatedBars(); |
|
234 | 235 | } |
|
235 | 236 | } |
|
236 | 237 | |
|
237 | 238 | /*! |
|
238 | 239 | Returns brush of the set. |
|
239 | 240 | */ |
|
240 | 241 | QBrush QBarSet::brush() const |
|
241 | 242 | { |
|
242 | 243 | return d_ptr->m_brush; |
|
243 | 244 | } |
|
244 | 245 | |
|
245 | 246 | /*! |
|
246 | 247 | Sets \a pen of the values that are drawn on top of this barset |
|
247 | 248 | */ |
|
248 | 249 | void QBarSet::setLabelPen(const QPen &pen) |
|
249 | 250 | { |
|
250 | 251 | if(d_ptr->m_labelPen!=pen){ |
|
251 | 252 | d_ptr->m_labelPen = pen; |
|
252 | 253 | emit d_ptr->updatedBars(); |
|
253 | 254 | } |
|
254 | 255 | } |
|
255 | 256 | |
|
256 | 257 | /*! |
|
257 | 258 | Returns pen of the values that are drawn on top of this barset |
|
258 | 259 | */ |
|
259 | 260 | QPen QBarSet::labelPen() const |
|
260 | 261 | { |
|
261 | 262 | return d_ptr->m_labelPen; |
|
262 | 263 | } |
|
263 | 264 | |
|
264 | 265 | /*! |
|
265 | 266 | Sets \a brush of the values that are drawn on top of this barset |
|
266 | 267 | */ |
|
267 | 268 | void QBarSet::setLabelBrush(const QBrush &brush) |
|
268 | 269 | { |
|
269 | 270 | if(d_ptr->m_labelBrush!=brush){ |
|
270 | 271 | d_ptr->m_labelBrush = brush; |
|
271 | 272 | emit d_ptr->updatedBars(); |
|
272 | 273 | } |
|
273 | 274 | } |
|
274 | 275 | |
|
275 | 276 | /*! |
|
276 | 277 | Returns brush of the values that are drawn on top of this barset |
|
277 | 278 | */ |
|
278 | 279 | QBrush QBarSet::labelBrush() const |
|
279 | 280 | { |
|
280 | 281 | return d_ptr->m_labelBrush; |
|
281 | 282 | } |
|
282 | 283 | |
|
283 | 284 | /*! |
|
284 | 285 | Sets the \a font for values that are drawn on top of this barset |
|
285 | 286 | */ |
|
286 | 287 | void QBarSet::setLabelFont(const QFont &font) |
|
287 | 288 | { |
|
288 | 289 | if(d_ptr->m_labelFont!=font) { |
|
289 | 290 | d_ptr->m_labelFont = font; |
|
290 | 291 | emit d_ptr->updatedBars(); |
|
291 | 292 | } |
|
292 | 293 | |
|
293 | 294 | } |
|
294 | 295 | |
|
295 | 296 | /*! |
|
296 | 297 | Returns the pen for values that are drawn on top of this set |
|
297 | 298 | */ |
|
298 | 299 | QFont QBarSet::labelFont() const |
|
299 | 300 | { |
|
300 | 301 | return d_ptr->m_labelFont; |
|
301 | 302 | } |
|
302 | 303 | |
|
303 | 304 | /*! |
|
304 | 305 | Sets visibility of bar labels. If \a visible is true, labels are drawn on top of barsets. |
|
305 | 306 | */ |
|
306 | 307 | |
|
307 | 308 | void QBarSet::setLabelsVisible(bool visible) |
|
308 | 309 | { |
|
309 | 310 | if(d_ptr->m_labelsVisible!=visible) { |
|
310 | 311 | d_ptr->m_labelsVisible = visible; |
|
311 | 312 | emit d_ptr->labelsVisibleChanged(visible); |
|
312 | 313 | } |
|
313 | 314 | } |
|
314 | 315 | |
|
315 | 316 | /*! |
|
316 | 317 | Returns the visibility of values |
|
317 | 318 | */ |
|
318 | 319 | bool QBarSet::labelsVisible() const |
|
319 | 320 | { |
|
320 | 321 | return d_ptr->m_labelsVisible; |
|
321 | 322 | } |
|
322 | 323 | |
|
323 | 324 | //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
324 | 325 | |
|
325 | 326 | QBarSetPrivate::QBarSetPrivate(const QString name, QBarSet *parent) : QObject(parent), |
|
326 | 327 | q_ptr(parent), |
|
327 | 328 | m_name(name), |
|
328 | 329 | m_labelsVisible(false) |
|
329 | 330 | { |
|
330 | 331 | } |
|
331 | 332 | |
|
332 | 333 | QBarSetPrivate::~QBarSetPrivate() |
|
333 | 334 | { |
|
334 | 335 | } |
|
335 | 336 | |
|
336 | 337 | #include "moc_qbarset.cpp" |
|
337 | 338 | #include "moc_qbarset_p.cpp" |
|
338 | 339 | |
|
339 | 340 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now