##// END OF EJS Templates
minor doc update
sauimone -
r1299:60e2b55c1831
parent child
Show More
@@ -1,575 +1,591
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarseries.h"
21 #include "qbarseries.h"
22 #include "qbarseries_p.h"
22 #include "qbarseries_p.h"
23 #include "qbarset.h"
23 #include "qbarset.h"
24 #include "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "legendmarker_p.h"
26 #include "legendmarker_p.h"
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartanimator_p.h"
29 #include "chartanimator_p.h"
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \class QBarSeries
34 \class QBarSeries
35 \brief part of QtCommercial chart API.
35 \brief part of QtCommercial chart API.
36 \mainclass
36 \mainclass
37
37
38 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
38 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
39 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
39 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
40 and y-value is the height of the bar. The category names are ignored with this series and x-axis
40 and y-value is the height of the bar. The category names are ignored with this series and x-axis
41 shows the x-values.
41 shows the x-values.
42
42
43 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
43 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
44 \image examples_barchart.png
44 \image examples_barchart.png
45
45
46 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
46 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
47 */
47 */
48
48
49 /*!
49 /*!
50 \fn void QBarSeries::clicked(QBarSet *barset, QString category)
50 \fn void QBarSeries::clicked(QBarSet *barset, QString category)
51
51
52 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category
52 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset of category \a category
53 contained by the series.
53 contained by the series.
54 */
54 */
55
55
56 /*!
56 /*!
57 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
57 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
58
58
59 The signal is emitted if mouse is hovered on top of series.
59 The signal is emitted if mouse is hovered on top of series.
60 Parameter \a barset is the pointer of barset, where hover happened.
60 Parameter \a barset is the pointer of barset, where hover happened.
61 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
61 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
62 */
62 */
63
63
64 /*!
64 /*!
65 Constructs empty QBarSeries.
65 Constructs empty QBarSeries.
66 QBarSeries is QObject which is a child of a \a parent.
66 QBarSeries is QObject which is a child of a \a parent.
67 */
67 */
68 QBarSeries::QBarSeries(QObject *parent) :
68 QBarSeries::QBarSeries(QObject *parent) :
69 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
69 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
70 {
70 {
71 }
71 }
72
72
73 /*!
73 /*!
74 Destructs barseries and owned barsets.
74 Destructs barseries and owned barsets.
75 */
75 */
76 QBarSeries::~QBarSeries()
76 QBarSeries::~QBarSeries()
77 {
77 {
78 Q_D(QBarSeries);
78 Q_D(QBarSeries);
79 if(d->m_dataset){
79 if(d->m_dataset){
80 d->m_dataset->removeSeries(this);
80 d->m_dataset->removeSeries(this);
81 }
81 }
82 }
82 }
83
83
84 /*!
84 /*!
85 \internal
85 \internal
86 */
86 */
87 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
87 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
88 QAbstractSeries(d,parent)
88 QAbstractSeries(d,parent)
89 {
89 {
90 }
90 }
91
91
92 /*!
92 /*!
93 Returns the type of series. Derived classes override this.
93 Returns the type of series. Derived classes override this.
94 */
94 */
95 QAbstractSeries::SeriesType QBarSeries::type() const
95 QAbstractSeries::SeriesType QBarSeries::type() const
96 {
96 {
97 return QAbstractSeries::SeriesTypeBar;
97 return QAbstractSeries::SeriesTypeBar;
98 }
98 }
99
99
100 /*!
100 /*!
101 Sets the \a categories, which are used to to group the data.
101 Sets the \a categories, which are used to to group the data.
102 */
102 */
103 void QBarSeries::setCategories(QBarCategories categories)
103 void QBarSeries::setCategories(QBarCategories categories)
104 {
104 {
105 Q_D(QBarSeries);
105 Q_D(QBarSeries);
106 d->setCategories(categories);
106 d->setCategories(categories);
107 emit d->categoriesUpdated();
107 emit d->categoriesUpdated();
108 }
108 }
109
109
110 /*!
111 Sets the margin around bars. Parameter \a margin is from 0 to 1 and represents
112 percentage of margin compared to bars
113 */
110 void QBarSeries::setBarMargin(qreal margin)
114 void QBarSeries::setBarMargin(qreal margin)
111 {
115 {
112 Q_D(QBarSeries);
116 Q_D(QBarSeries);
113 d->setBarMargin(margin);
117 d->setBarMargin(margin);
114 }
118 }
115
119
120 /*!
121 Returns the margin around bars
122 */
116 qreal QBarSeries::barMargin() const
123 qreal QBarSeries::barMargin() const
117 {
124 {
118 Q_D(const QBarSeries);
125 Q_D(const QBarSeries);
119 return d->barMargin();
126 return d->barMargin();
120 }
127 }
121
128
122 /*!
129 /*!
123 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
130 Adds a set of bars to series. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
124 Returns true, if appending succeeded.
131 Returns true, if appending succeeded.
125
132
126 */
133 */
127 bool QBarSeries::append(QBarSet *set)
134 bool QBarSeries::append(QBarSet *set)
128 {
135 {
129 Q_D(QBarSeries);
136 Q_D(QBarSeries);
130 return d->append(set);
137 return d->append(set);
131 }
138 }
132
139
133 /*!
140 /*!
134 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
141 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
135 Returns true, if set was removed.
142 Returns true, if set was removed.
136 */
143 */
137 bool QBarSeries::remove(QBarSet *set)
144 bool QBarSeries::remove(QBarSet *set)
138 {
145 {
139 Q_D(QBarSeries);
146 Q_D(QBarSeries);
140 return d->remove(set);
147 return d->remove(set);
141 }
148 }
142
149
143 /*!
150 /*!
144 Adds a list of barsets to series. Takes ownership of \a sets.
151 Adds a list of barsets to series. Takes ownership of \a sets.
145 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
152 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
146 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
153 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
147 and function returns false.
154 and function returns false.
148 */
155 */
149 bool QBarSeries::append(QList<QBarSet* > sets)
156 bool QBarSeries::append(QList<QBarSet* > sets)
150 {
157 {
151 Q_D(QBarSeries);
158 Q_D(QBarSeries);
152 return d->append(sets);
159 return d->append(sets);
153 }
160 }
154
161
155 /*!
162 /*!
156 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
163 Removes a list of barsets from series. Releases ownership of \a sets. Doesn't delete \a sets.
157 */
164 */
158 bool QBarSeries::remove(QList<QBarSet* > sets)
165 bool QBarSeries::remove(QList<QBarSet* > sets)
159 {
166 {
160 Q_D(QBarSeries);
167 Q_D(QBarSeries);
161 return d->remove(sets);
168 return d->remove(sets);
162 }
169 }
163
170
164 void QBarSeries::clear()
171 void QBarSeries::clear()
165 {
172 {
166 Q_D(QBarSeries);
173 Q_D(QBarSeries);
167 d->m_barSets.clear();
174 d->m_barSets.clear();
168 d->m_categories.clear();
175 d->m_categories.clear();
169 }
176 }
170
177
171 /*!
178 /*!
172 Returns number of sets in series.
179 Returns number of sets in series.
173 */
180 */
174 int QBarSeries::barsetCount() const
181 int QBarSeries::barsetCount() const
175 {
182 {
176 Q_D(const QBarSeries);
183 Q_D(const QBarSeries);
177 return d->m_barSets.count();
184 return d->m_barSets.count();
178 }
185 }
179
186
180 /*!
187 /*!
181 Returns number of categories in series
188 Returns number of categories in series
182 */
189 */
183 int QBarSeries::categoryCount() const
190 int QBarSeries::categoryCount() const
184 {
191 {
185 Q_D(const QBarSeries);
192 Q_D(const QBarSeries);
186 return d->categoryCount();
193 return d->categoryCount();
187 }
194 }
188
195
189 /*!
196 /*!
190 Returns a list of sets in series. Keeps ownership of sets.
197 Returns a list of sets in series. Keeps ownership of sets.
191 */
198 */
192 QList<QBarSet*> QBarSeries::barSets() const
199 QList<QBarSet*> QBarSeries::barSets() const
193 {
200 {
194 Q_D(const QBarSeries);
201 Q_D(const QBarSeries);
195 return d->m_barSets;
202 return d->m_barSets;
196 }
203 }
197
204
198 /*!
205 /*!
199 Returns the bar categories of the series.
206 Returns the bar categories of the series.
200 */
207 */
201 QBarCategories QBarSeries::categories() const
208 QBarCategories QBarSeries::categories() const
202 {
209 {
203 Q_D(const QBarSeries);
210 Q_D(const QBarSeries);
204 return d->categories();
211 return d->categories();
205 }
212 }
206
213
214 /*!
215 Sets the visibility of series to \a visible
216 */
207 void QBarSeries::setVisible(bool visible)
217 void QBarSeries::setVisible(bool visible)
208 {
218 {
209 Q_D(QBarSeries);
219 Q_D(QBarSeries);
210 d->setVisible(visible);
220 d->setVisible(visible);
211 }
221 }
212
222
223 /*!
224 Returns the visibility of series
225 */
213 bool QBarSeries::isVisible() const
226 bool QBarSeries::isVisible() const
214 {
227 {
215 Q_D(const QBarSeries);
228 Q_D(const QBarSeries);
216 return d->isVisible();
229 return d->isVisible();
217 }
230 }
218
231
219 /*!
232 /*!
220 Sets the visibility of labels in series to \a visible
233 Sets the visibility of labels in series to \a visible
221 */
234 */
222 void QBarSeries::setLabelsVisible(bool visible)
235 void QBarSeries::setLabelsVisible(bool visible)
223 {
236 {
224 Q_D(QBarSeries);
237 Q_D(QBarSeries);
225 if (d->m_labelsVisible != visible) {
238 if (d->m_labelsVisible != visible) {
226 d->m_labelsVisible = visible;
239 d->m_labelsVisible = visible;
227 emit d->updatedBars();
240 emit d->updatedBars();
228 }
241 }
229 }
242 }
230
243
244 /*!
245 Returns the visibility of labels
246 */
231 bool QBarSeries::isLabelsVisible() const
247 bool QBarSeries::isLabelsVisible() const
232 {
248 {
233 Q_D(const QBarSeries);
249 Q_D(const QBarSeries);
234 return d->m_labelsVisible;
250 return d->m_labelsVisible;
235 }
251 }
236
252
237 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
253 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
238
254
239 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
255 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
240 QAbstractSeriesPrivate(q),
256 QAbstractSeriesPrivate(q),
241 m_barMargin(0.5), // Default value is 50% of category width
257 m_barMargin(0.5), // Default value is 50% of category width
242 m_labelsVisible(false),
258 m_labelsVisible(false),
243 m_visible(true)
259 m_visible(true)
244 {
260 {
245 }
261 }
246
262
247 void QBarSeriesPrivate::setCategories(QBarCategories categories)
263 void QBarSeriesPrivate::setCategories(QBarCategories categories)
248 {
264 {
249 m_categories = categories;
265 m_categories = categories;
250 }
266 }
251
267
252 void QBarSeriesPrivate::insertCategory(int index, const QString category)
268 void QBarSeriesPrivate::insertCategory(int index, const QString category)
253 {
269 {
254 m_categories.insert(index, category);
270 m_categories.insert(index, category);
255 emit categoriesUpdated();
271 emit categoriesUpdated();
256 }
272 }
257
273
258 void QBarSeriesPrivate::removeCategory(int index)
274 void QBarSeriesPrivate::removeCategory(int index)
259 {
275 {
260 m_categories.removeAt(index);
276 m_categories.removeAt(index);
261 emit categoriesUpdated();
277 emit categoriesUpdated();
262 }
278 }
263
279
264 int QBarSeriesPrivate::categoryCount() const
280 int QBarSeriesPrivate::categoryCount() const
265 {
281 {
266 if (m_categories.count() > 0) {
282 if (m_categories.count() > 0) {
267 return m_categories.count();
283 return m_categories.count();
268 }
284 }
269
285
270 // No categories defined. return count of longest set.
286 // No categories defined. return count of longest set.
271 int count = 0;
287 int count = 0;
272 for (int i=0; i<m_barSets.count(); i++) {
288 for (int i=0; i<m_barSets.count(); i++) {
273 if (m_barSets.at(i)->count() > count) {
289 if (m_barSets.at(i)->count() > count) {
274 count = m_barSets.at(i)->count();
290 count = m_barSets.at(i)->count();
275 }
291 }
276 }
292 }
277
293
278 return count;
294 return count;
279 }
295 }
280
296
281 QBarCategories QBarSeriesPrivate::categories() const
297 QBarCategories QBarSeriesPrivate::categories() const
282 {
298 {
283 if (m_categories.count() > 0) {
299 if (m_categories.count() > 0) {
284 return m_categories;
300 return m_categories;
285 }
301 }
286
302
287 // No categories defined. retun list of indices.
303 // No categories defined. retun list of indices.
288 QBarCategories categories;
304 QBarCategories categories;
289
305
290 int count = categoryCount();
306 int count = categoryCount();
291 for (int i = 0; i < count; i++) {
307 for (int i = 0; i < count; i++) {
292 categories.append(QString::number(i));
308 categories.append(QString::number(i));
293 }
309 }
294 return categories;
310 return categories;
295 }
311 }
296
312
297 void QBarSeriesPrivate::setBarMargin(qreal margin)
313 void QBarSeriesPrivate::setBarMargin(qreal margin)
298 {
314 {
299 if (margin > 1.0) {
315 if (margin > 1.0) {
300 margin = 1.0;
316 margin = 1.0;
301 } else if (margin < 0.0) {
317 } else if (margin < 0.0) {
302 margin = 0.0;
318 margin = 0.0;
303 }
319 }
304
320
305 m_barMargin = margin;
321 m_barMargin = margin;
306 emit updatedBars();
322 emit updatedBars();
307 }
323 }
308
324
309 qreal QBarSeriesPrivate::barMargin() const
325 qreal QBarSeriesPrivate::barMargin() const
310 {
326 {
311 return m_barMargin;
327 return m_barMargin;
312 }
328 }
313
329
314 QBarSet* QBarSeriesPrivate::barsetAt(int index)
330 QBarSet* QBarSeriesPrivate::barsetAt(int index)
315 {
331 {
316 return m_barSets.at(index);
332 return m_barSets.at(index);
317 }
333 }
318
334
319 void QBarSeriesPrivate::setVisible(bool visible)
335 void QBarSeriesPrivate::setVisible(bool visible)
320 {
336 {
321 if (m_visible != visible) {
337 if (m_visible != visible) {
322 m_visible = visible;
338 m_visible = visible;
323 emit updatedBars();
339 emit updatedBars();
324 }
340 }
325 }
341 }
326
342
327 bool QBarSeriesPrivate::isVisible() const
343 bool QBarSeriesPrivate::isVisible() const
328 {
344 {
329 return m_visible;
345 return m_visible;
330 }
346 }
331
347
332 QString QBarSeriesPrivate::categoryName(int category)
348 QString QBarSeriesPrivate::categoryName(int category)
333 {
349 {
334 if ((category >= 0) && (category < m_categories.count())) {
350 if ((category >= 0) && (category < m_categories.count())) {
335 return m_categories.at(category);
351 return m_categories.at(category);
336 }
352 }
337
353
338 return QString::number(category);
354 return QString::number(category);
339 }
355 }
340
356
341 qreal QBarSeriesPrivate::min()
357 qreal QBarSeriesPrivate::min()
342 {
358 {
343 if (m_barSets.count() <= 0) {
359 if (m_barSets.count() <= 0) {
344 return 0;
360 return 0;
345 }
361 }
346 qreal min = INT_MAX;
362 qreal min = INT_MAX;
347
363
348 for (int i = 0; i < m_barSets.count(); i++) {
364 for (int i = 0; i < m_barSets.count(); i++) {
349 int categoryCount = m_barSets.at(i)->count();
365 int categoryCount = m_barSets.at(i)->count();
350 for (int j = 0; j < categoryCount; j++) {
366 for (int j = 0; j < categoryCount; j++) {
351 qreal temp = m_barSets.at(i)->at(j).y();
367 qreal temp = m_barSets.at(i)->at(j).y();
352 if (temp < min)
368 if (temp < min)
353 min = temp;
369 min = temp;
354 }
370 }
355 }
371 }
356 return min;
372 return min;
357 }
373 }
358
374
359 qreal QBarSeriesPrivate::max()
375 qreal QBarSeriesPrivate::max()
360 {
376 {
361 if (m_barSets.count() <= 0) {
377 if (m_barSets.count() <= 0) {
362 return 0;
378 return 0;
363 }
379 }
364 qreal max = INT_MIN;
380 qreal max = INT_MIN;
365
381
366 for (int i = 0; i < m_barSets.count(); i++) {
382 for (int i = 0; i < m_barSets.count(); i++) {
367 int categoryCount = m_barSets.at(i)->count();
383 int categoryCount = m_barSets.at(i)->count();
368 for (int j = 0; j < categoryCount; j++) {
384 for (int j = 0; j < categoryCount; j++) {
369 qreal temp = m_barSets.at(i)->at(j).y();
385 qreal temp = m_barSets.at(i)->at(j).y();
370 if (temp > max)
386 if (temp > max)
371 max = temp;
387 max = temp;
372 }
388 }
373 }
389 }
374
390
375 return max;
391 return max;
376 }
392 }
377
393
378 qreal QBarSeriesPrivate::valueAt(int set, int category)
394 qreal QBarSeriesPrivate::valueAt(int set, int category)
379 {
395 {
380 if ((set < 0) || (set >= m_barSets.count())) {
396 if ((set < 0) || (set >= m_barSets.count())) {
381 // No set, no value.
397 // No set, no value.
382 return 0;
398 return 0;
383 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
399 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
384 // No category, no value.
400 // No category, no value.
385 return 0;
401 return 0;
386 }
402 }
387
403
388 return m_barSets.at(set)->at(category).y();
404 return m_barSets.at(set)->at(category).y();
389 }
405 }
390
406
391 qreal QBarSeriesPrivate::percentageAt(int set, int category)
407 qreal QBarSeriesPrivate::percentageAt(int set, int category)
392 {
408 {
393 if ((set < 0) || (set >= m_barSets.count())) {
409 if ((set < 0) || (set >= m_barSets.count())) {
394 // No set, no value.
410 // No set, no value.
395 return 0;
411 return 0;
396 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
412 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
397 // No category, no value.
413 // No category, no value.
398 return 0;
414 return 0;
399 }
415 }
400
416
401 qreal value = m_barSets.at(set)->at(category).y();
417 qreal value = m_barSets.at(set)->at(category).y();
402 qreal sum = categorySum(category);
418 qreal sum = categorySum(category);
403 if ( qFuzzyIsNull(sum) ) {
419 if ( qFuzzyIsNull(sum) ) {
404 return 0;
420 return 0;
405 }
421 }
406
422
407 return value / sum;
423 return value / sum;
408 }
424 }
409
425
410 qreal QBarSeriesPrivate::categorySum(int category)
426 qreal QBarSeriesPrivate::categorySum(int category)
411 {
427 {
412 qreal sum(0);
428 qreal sum(0);
413 int count = m_barSets.count(); // Count sets
429 int count = m_barSets.count(); // Count sets
414 for (int set = 0; set < count; set++) {
430 for (int set = 0; set < count; set++) {
415 if (category < m_barSets.at(set)->count())
431 if (category < m_barSets.at(set)->count())
416 sum += m_barSets.at(set)->at(category).y();
432 sum += m_barSets.at(set)->at(category).y();
417 }
433 }
418 return sum;
434 return sum;
419 }
435 }
420
436
421 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
437 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
422 {
438 {
423 qreal sum(0);
439 qreal sum(0);
424 int count = m_barSets.count(); // Count sets
440 int count = m_barSets.count(); // Count sets
425 for (int set = 0; set < count; set++) {
441 for (int set = 0; set < count; set++) {
426 if (category < m_barSets.at(set)->count())
442 if (category < m_barSets.at(set)->count())
427 sum += qAbs(m_barSets.at(set)->at(category).y());
443 sum += qAbs(m_barSets.at(set)->at(category).y());
428 }
444 }
429 return sum;
445 return sum;
430 }
446 }
431
447
432 qreal QBarSeriesPrivate::maxCategorySum()
448 qreal QBarSeriesPrivate::maxCategorySum()
433 {
449 {
434 qreal max = INT_MIN;
450 qreal max = INT_MIN;
435 int count = categoryCount();
451 int count = categoryCount();
436 for (int i = 0; i < count; i++) {
452 for (int i = 0; i < count; i++) {
437 qreal sum = categorySum(i);
453 qreal sum = categorySum(i);
438 if (sum > max)
454 if (sum > max)
439 max = sum;
455 max = sum;
440 }
456 }
441 return max;
457 return max;
442 }
458 }
443
459
444 void QBarSeriesPrivate::barsetChanged()
460 void QBarSeriesPrivate::barsetChanged()
445 {
461 {
446 emit updatedBars();
462 emit updatedBars();
447 }
463 }
448
464
449 void QBarSeriesPrivate::scaleDomain(Domain& domain)
465 void QBarSeriesPrivate::scaleDomain(Domain& domain)
450 {
466 {
451 qreal minX(domain.minX());
467 qreal minX(domain.minX());
452 qreal minY(domain.minY());
468 qreal minY(domain.minY());
453 qreal maxX(domain.maxX());
469 qreal maxX(domain.maxX());
454 qreal maxY(domain.maxY());
470 qreal maxY(domain.maxY());
455 int tickXCount(domain.tickXCount());
471 int tickXCount(domain.tickXCount());
456 int tickYCount(domain.tickYCount());
472 int tickYCount(domain.tickYCount());
457
473
458 qreal x = categoryCount();
474 qreal x = categoryCount();
459 qreal y = max();
475 qreal y = max();
460 minX = qMin(minX, x) - 0.5;
476 minX = qMin(minX, x) - 0.5;
461 minY = qMin(minY, y);
477 minY = qMin(minY, y);
462 maxX = qMax(maxX, x) - 0.5;
478 maxX = qMax(maxX, x) - 0.5;
463 maxY = qMax(maxY, y);
479 maxY = qMax(maxY, y);
464 tickXCount = x+1;
480 tickXCount = x+1;
465
481
466 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
482 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
467 }
483 }
468
484
469 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
485 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
470 {
486 {
471 Q_Q(QBarSeries);
487 Q_Q(QBarSeries);
472
488
473 BarChartItem* bar = new BarChartItem(q,presenter);
489 BarChartItem* bar = new BarChartItem(q,presenter);
474 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
490 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
475 presenter->animator()->addAnimation(bar);
491 presenter->animator()->addAnimation(bar);
476 }
492 }
477 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
493 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
478 return bar;
494 return bar;
479
495
480 }
496 }
481
497
482 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
498 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
483 {
499 {
484 Q_Q(QBarSeries);
500 Q_Q(QBarSeries);
485 QList<LegendMarker*> markers;
501 QList<LegendMarker*> markers;
486 foreach(QBarSet* set, q->barSets()) {
502 foreach(QBarSet* set, q->barSets()) {
487 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
503 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
488 markers << marker;
504 markers << marker;
489 }
505 }
490
506
491 return markers;
507 return markers;
492 }
508 }
493
509
494 bool QBarSeriesPrivate::append(QBarSet *set)
510 bool QBarSeriesPrivate::append(QBarSet *set)
495 {
511 {
496 Q_Q(QBarSeries);
512 Q_Q(QBarSeries);
497 if ((m_barSets.contains(set)) || (set == 0)) {
513 if ((m_barSets.contains(set)) || (set == 0)) {
498 // Fail if set is already in list or set is null.
514 // Fail if set is already in list or set is null.
499 return false;
515 return false;
500 }
516 }
501 m_barSets.append(set);
517 m_barSets.append(set);
502 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
518 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
503 if (m_dataset) {
519 if (m_dataset) {
504 m_dataset->updateSeries(q); // this notifies legend
520 m_dataset->updateSeries(q); // this notifies legend
505 }
521 }
506 emit restructuredBars(); // this notifies barchartitem
522 emit restructuredBars(); // this notifies barchartitem
507 return true;
523 return true;
508 }
524 }
509
525
510 bool QBarSeriesPrivate::remove(QBarSet *set)
526 bool QBarSeriesPrivate::remove(QBarSet *set)
511 {
527 {
512 Q_Q(QBarSeries);
528 Q_Q(QBarSeries);
513 if (!m_barSets.contains(set)) {
529 if (!m_barSets.contains(set)) {
514 // Fail if set is not in list
530 // Fail if set is not in list
515 return false;
531 return false;
516 }
532 }
517 m_barSets.removeOne(set);
533 m_barSets.removeOne(set);
518 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
534 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
519 if (m_dataset) {
535 if (m_dataset) {
520 m_dataset->updateSeries(q); // this notifies legend
536 m_dataset->updateSeries(q); // this notifies legend
521 }
537 }
522 emit restructuredBars(); // this notifies barchartitem
538 emit restructuredBars(); // this notifies barchartitem
523 return true;
539 return true;
524 }
540 }
525
541
526 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
542 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
527 {
543 {
528 Q_Q(QBarSeries);
544 Q_Q(QBarSeries);
529 foreach (QBarSet* set, sets) {
545 foreach (QBarSet* set, sets) {
530 if ((set == 0) || (m_barSets.contains(set))) {
546 if ((set == 0) || (m_barSets.contains(set))) {
531 // Fail if any of the sets is null or is already appended.
547 // Fail if any of the sets is null or is already appended.
532 return false;
548 return false;
533 }
549 }
534 if (sets.count(set) != 1) {
550 if (sets.count(set) != 1) {
535 // Also fail if same set is more than once in given list.
551 // Also fail if same set is more than once in given list.
536 return false;
552 return false;
537 }
553 }
538 }
554 }
539
555
540 foreach (QBarSet* set, sets) {
556 foreach (QBarSet* set, sets) {
541 m_barSets.append(set);
557 m_barSets.append(set);
542 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
558 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
543 }
559 }
544 if (m_dataset) {
560 if (m_dataset) {
545 m_dataset->updateSeries(q); // this notifies legend
561 m_dataset->updateSeries(q); // this notifies legend
546 }
562 }
547 emit restructuredBars(); // this notifies barchartitem
563 emit restructuredBars(); // this notifies barchartitem
548 return true;
564 return true;
549 }
565 }
550
566
551 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
567 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
552 {
568 {
553 Q_Q(QBarSeries);
569 Q_Q(QBarSeries);
554 bool setsRemoved = false;
570 bool setsRemoved = false;
555 foreach (QBarSet* set, sets) {
571 foreach (QBarSet* set, sets) {
556 if (m_barSets.contains(set)) {
572 if (m_barSets.contains(set)) {
557 m_barSets.removeOne(set);
573 m_barSets.removeOne(set);
558 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
574 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(barsetChanged()));
559 setsRemoved = true;
575 setsRemoved = true;
560 }
576 }
561 }
577 }
562
578
563 if (setsRemoved) {
579 if (setsRemoved) {
564 if (m_dataset) {
580 if (m_dataset) {
565 m_dataset->updateSeries(q); // this notifies legend
581 m_dataset->updateSeries(q); // this notifies legend
566 }
582 }
567 emit restructuredBars(); // this notifies barchartitem
583 emit restructuredBars(); // this notifies barchartitem
568 }
584 }
569 return setsRemoved;
585 return setsRemoved;
570 }
586 }
571
587
572 #include "moc_qbarseries.cpp"
588 #include "moc_qbarseries.cpp"
573 #include "moc_qbarseries_p.cpp"
589 #include "moc_qbarseries_p.cpp"
574
590
575 QTCOMMERCIALCHART_END_NAMESPACE
591 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now