##// END OF EJS Templates
updated documentation for barseries
sauimone -
r1493:32c9b390e951
parent child
Show More
@@ -1,670 +1,680
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 \qmlclass BarSeries QBarSeries
49 \qmlclass BarSeries QBarSeries
50
50
51 \beginfloatleft
51 \beginfloatleft
52 \image demos_qmlchart6.png
52 \image demos_qmlchart6.png
53 \endfloat
53 \endfloat
54 \clearfloat
54 \clearfloat
55
55
56 The following QML shows how to create a simple bar chart:
56 The following QML shows how to create a simple bar chart:
57 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
57 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
58 */
58 */
59
59
60 /*!
60 /*!
61 \property QBarSeries::barWidth
61 \property QBarSeries::barWidth
62 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
62 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
63 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
63 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
64 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
64 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
65 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
65 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
66 \sa QGroupedBarSeries
66 \sa QGroupedBarSeries
67 */
67 */
68 /*!
68 /*!
69 \qmlproperty real BarSeries::barWidth
69 \qmlproperty real BarSeries::barWidth
70 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
70 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
71 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
71 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
72 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
72 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
73 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
73 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
74 */
74 */
75
75
76 /*!
76 /*!
77 \property QBarSeries::count
77 \property QBarSeries::count
78 Holds the number of sets in series.
78 Holds the number of sets in series.
79 */
79 */
80 /*!
80 /*!
81 \qmlproperty int BarSeries::count
81 \qmlproperty int BarSeries::count
82 Holds the number of sets in series.
82 Holds the number of sets in series.
83 */
83 */
84
84
85 /*!
85 /*!
86 \property QBarSeries::labelsVisible
86 \property QBarSeries::labelsVisible
87 Defines the visibility of the labels in series
87 Defines the visibility of the labels in series
88 */
88 */
89 /*!
89 /*!
90 \qmlproperty bool BarSeries::labelsVisible
90 \qmlproperty bool BarSeries::labelsVisible
91 Defines the visibility of the labels in series
91 Defines the visibility of the labels in series
92 */
92 */
93
93
94 /*!
94 /*!
95 \fn void QBarSeries::clicked(QBarSet *barset, int index)
95 \fn void QBarSeries::clicked(QBarSet *barset, int index)
96
96
97 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
97 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
98 Clicked bar inside set is indexed by \a index
98 Clicked bar inside set is indexed by \a index
99 */
99 */
100 /*!
100 /*!
101 \qmlsignal BarSeries::onClicked(BarSet barset, int index)
101 \qmlsignal BarSeries::onClicked(BarSet barset, int index)
102
102
103 The signal is emitted if the user clicks with a mouse on top of BarSet.
103 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 Clicked bar inside set is indexed by \a index
104 Clicked bar inside set is indexed by \a index
105 */
105 */
106
106
107 /*!
107 /*!
108 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
108 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
109
109
110 The signal is emitted if mouse is hovered on top of series.
110 The signal is emitted if mouse is hovered on top of series.
111 Parameter \a barset is the pointer of barset, where hover happened.
111 Parameter \a barset is the pointer of barset, where hover happened.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
113 */
113 */
114 /*!
114 /*!
115 \qmlsignal BarSeries::onHovered(BarSet barset, bool status)
115 \qmlsignal BarSeries::onHovered(BarSet barset, bool status)
116
116
117 The signal is emitted if mouse is hovered on top of series.
117 The signal is emitted if mouse is hovered on top of series.
118 Parameter \a barset is the pointer of barset, where hover happened.
118 Parameter \a barset is the pointer of barset, where hover happened.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 */
120 */
121
121
122 /*!
122 /*!
123 \fn void QBarSeries::countChanged()
123 \fn void QBarSeries::countChanged()
124 This signal is emitted when barset count has been changed, for example by append or remove.
124 This signal is emitted when barset count has been changed, for example by append or remove.
125 */
125 */
126 /*!
126 /*!
127 \qmlsignal BarSeries::countChanged()
127 \qmlsignal BarSeries::countChanged()
128 This signal is emitted when barset count has been changed, for example by append or remove.
128 This signal is emitted when barset count has been changed, for example by append or remove.
129 */
129 */
130
130
131 /*!
131 /*!
132 \fn void QBarSeries::labelsVisibleChanged()
132 \fn void QBarSeries::labelsVisibleChanged()
133 This signal is emitted when labels visibility have changed.
133 This signal is emitted when labels visibility have changed.
134 \sa isLabelsVisible(), setLabelsVisible()
134 \sa isLabelsVisible(), setLabelsVisible()
135 */
135 */
136
136
137 /*!
137 /*!
138 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
138 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 This signal is emitted when \a sets have been added to the series.
139 This signal is emitted when \a sets have been added to the series.
140 \sa append(), insert()
140 \sa append(), insert()
141 */
141 */
142
142
143 /*!
143 /*!
144 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
144 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
145 This signal is emitted when \a sets have been removed from the series.
145 This signal is emitted when \a sets have been removed from the series.
146 \sa remove()
146 \sa remove()
147 */
147 */
148
148
149 /*!
149 /*!
150 Constructs empty QBarSeries.
150 Constructs empty QBarSeries.
151 QBarSeries is QObject which is a child of a \a parent.
151 QBarSeries is QObject which is a child of a \a parent.
152 */
152 */
153 QBarSeries::QBarSeries(QObject *parent) :
153 QBarSeries::QBarSeries(QObject *parent) :
154 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
154 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
155 {
155 {
156 }
156 }
157
157
158 /*!
158 /*!
159 Destructs barseries and owned barsets.
159 Destructs barseries and owned barsets.
160 */
160 */
161 QBarSeries::~QBarSeries()
161 QBarSeries::~QBarSeries()
162 {
162 {
163 Q_D(QBarSeries);
163 Q_D(QBarSeries);
164 if(d->m_dataset){
164 if(d->m_dataset){
165 d->m_dataset->removeSeries(this);
165 d->m_dataset->removeSeries(this);
166 }
166 }
167 }
167 }
168
168
169 /*!
169 /*!
170 \internal
170 \internal
171 */
171 */
172 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
172 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
173 QAbstractSeries(d,parent)
173 QAbstractSeries(d,parent)
174 {
174 {
175 }
175 }
176
176
177 /*!
177 /*!
178 Returns the type of series. Derived classes override this.
178 Returns the type of series. Derived classes override this.
179 */
179 */
180 QAbstractSeries::SeriesType QBarSeries::type() const
180 QAbstractSeries::SeriesType QBarSeries::type() const
181 {
181 {
182 return QAbstractSeries::SeriesTypeBar;
182 return QAbstractSeries::SeriesTypeBar;
183 }
183 }
184
184
185 /*!
186 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
187 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
188 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
189 Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar.
190 */
185 void QBarSeries::setBarWidth(qreal width)
191 void QBarSeries::setBarWidth(qreal width)
186 {
192 {
187 Q_D(QBarSeries);
193 Q_D(QBarSeries);
188 d->setBarWidth(width);
194 d->setBarWidth(width);
189 }
195 }
190
196
197 /*!
198 Returns the width of the bars of the series.
199 \sa setBarWidth()
200 */
191 qreal QBarSeries::barWidth() const
201 qreal QBarSeries::barWidth() const
192 {
202 {
193 Q_D(const QBarSeries);
203 Q_D(const QBarSeries);
194 return d->barWidth();
204 return d->barWidth();
195 }
205 }
196
206
197 /*!
207 /*!
198 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.
208 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.
199 Returns true, if appending succeeded.
209 Returns true, if appending succeeded.
200 */
210 */
201 bool QBarSeries::append(QBarSet *set)
211 bool QBarSeries::append(QBarSet *set)
202 {
212 {
203 Q_D(QBarSeries);
213 Q_D(QBarSeries);
204 bool success = d->append(set);
214 bool success = d->append(set);
205 if (success) {
215 if (success) {
206 QList<QBarSet*> sets;
216 QList<QBarSet*> sets;
207 sets.append(set);
217 sets.append(set);
208 emit barsetsAdded(sets);
218 emit barsetsAdded(sets);
209 emit countChanged();
219 emit countChanged();
210 }
220 }
211 return success;
221 return success;
212 }
222 }
213
223
214 /*!
224 /*!
215 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
225 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
216 Returns true, if set was removed.
226 Returns true, if set was removed.
217 */
227 */
218 bool QBarSeries::remove(QBarSet *set)
228 bool QBarSeries::remove(QBarSet *set)
219 {
229 {
220 Q_D(QBarSeries);
230 Q_D(QBarSeries);
221 bool success = d->remove(set);
231 bool success = d->remove(set);
222 if (success) {
232 if (success) {
223 QList<QBarSet*> sets;
233 QList<QBarSet*> sets;
224 sets.append(set);
234 sets.append(set);
225 emit barsetsRemoved(sets);
235 emit barsetsRemoved(sets);
226 emit countChanged();
236 emit countChanged();
227 }
237 }
228 return success;
238 return success;
229 }
239 }
230
240
231 /*!
241 /*!
232 Adds a list of barsets to series. Takes ownership of \a sets.
242 Adds a list of barsets to series. Takes ownership of \a sets.
233 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
243 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
234 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
244 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
235 and function returns false.
245 and function returns false.
236 */
246 */
237 bool QBarSeries::append(QList<QBarSet* > sets)
247 bool QBarSeries::append(QList<QBarSet* > sets)
238 {
248 {
239 Q_D(QBarSeries);
249 Q_D(QBarSeries);
240 bool success = d->append(sets);
250 bool success = d->append(sets);
241 if (success) {
251 if (success) {
242 emit barsetsAdded(sets);
252 emit barsetsAdded(sets);
243 emit countChanged();
253 emit countChanged();
244 }
254 }
245 return success;
255 return success;
246 }
256 }
247
257
248 /*!
258 /*!
249 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
259 Insert a set of bars to series at \a index postion. Takes ownership of \a set. If the set is null or is already in series, it won't be appended.
250 Returns true, if inserting succeeded.
260 Returns true, if inserting succeeded.
251
261
252 */
262 */
253 bool QBarSeries::insert(int index, QBarSet *set)
263 bool QBarSeries::insert(int index, QBarSet *set)
254 {
264 {
255 Q_D(QBarSeries);
265 Q_D(QBarSeries);
256 bool success = d->insert(index, set);
266 bool success = d->insert(index, set);
257 if (success) {
267 if (success) {
258 QList<QBarSet*> sets;
268 QList<QBarSet*> sets;
259 sets.append(set);
269 sets.append(set);
260 emit barsetsAdded(sets);
270 emit barsetsAdded(sets);
261 emit countChanged();
271 emit countChanged();
262 }
272 }
263 return success;
273 return success;
264 }
274 }
265
275
266 /*!
276 /*!
267 Removes all of the bar sets from the series
277 Removes all of the bar sets from the series
268 */
278 */
269 void QBarSeries::clear()
279 void QBarSeries::clear()
270 {
280 {
271 Q_D(QBarSeries);
281 Q_D(QBarSeries);
272 QList<QBarSet *> sets = barSets();
282 QList<QBarSet *> sets = barSets();
273 bool success = d->remove(sets);
283 bool success = d->remove(sets);
274 if (success) {
284 if (success) {
275 emit barsetsRemoved(sets);
285 emit barsetsRemoved(sets);
276 emit countChanged();
286 emit countChanged();
277 }
287 }
278 }
288 }
279
289
280 /*!
290 /*!
281 Returns number of sets in series.
291 Returns number of sets in series.
282 */
292 */
283 int QBarSeries::count() const
293 int QBarSeries::count() const
284 {
294 {
285 Q_D(const QBarSeries);
295 Q_D(const QBarSeries);
286 return d->m_barSets.count();
296 return d->m_barSets.count();
287 }
297 }
288
298
289 /*!
299 /*!
290 Returns a list of sets in series. Keeps ownership of sets.
300 Returns a list of sets in series. Keeps ownership of sets.
291 */
301 */
292 QList<QBarSet*> QBarSeries::barSets() const
302 QList<QBarSet*> QBarSeries::barSets() const
293 {
303 {
294 Q_D(const QBarSeries);
304 Q_D(const QBarSeries);
295 return d->m_barSets;
305 return d->m_barSets;
296 }
306 }
297
307
298 /*!
308 /*!
299 Sets the visibility of labels in series to \a visible
309 Sets the visibility of labels in series to \a visible
300 */
310 */
301 void QBarSeries::setLabelsVisible(bool visible)
311 void QBarSeries::setLabelsVisible(bool visible)
302 {
312 {
303 Q_D(QBarSeries);
313 Q_D(QBarSeries);
304 if (d->m_labelsVisible != visible) {
314 if (d->m_labelsVisible != visible) {
305 d->setLabelsVisible(visible);
315 d->setLabelsVisible(visible);
306 emit labelsVisibleChanged();
316 emit labelsVisibleChanged();
307 }
317 }
308 }
318 }
309
319
310 /*!
320 /*!
311 Returns the visibility of labels
321 Returns the visibility of labels
312 */
322 */
313 bool QBarSeries::isLabelsVisible() const
323 bool QBarSeries::isLabelsVisible() const
314 {
324 {
315 Q_D(const QBarSeries);
325 Q_D(const QBarSeries);
316 return d->m_labelsVisible;
326 return d->m_labelsVisible;
317 }
327 }
318
328
319 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
329 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
320
330
321 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
331 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
322 QAbstractSeriesPrivate(q),
332 QAbstractSeriesPrivate(q),
323 m_barWidth(0.5), // Default value is 50% of category width
333 m_barWidth(0.5), // Default value is 50% of category width
324 m_labelsVisible(false),
334 m_labelsVisible(false),
325 m_visible(true)
335 m_visible(true)
326 {
336 {
327 }
337 }
328
338
329 int QBarSeriesPrivate::categoryCount() const
339 int QBarSeriesPrivate::categoryCount() const
330 {
340 {
331 // No categories defined. return count of longest set.
341 // No categories defined. return count of longest set.
332 int count = 0;
342 int count = 0;
333 for (int i=0; i<m_barSets.count(); i++) {
343 for (int i=0; i<m_barSets.count(); i++) {
334 if (m_barSets.at(i)->count() > count) {
344 if (m_barSets.at(i)->count() > count) {
335 count = m_barSets.at(i)->count();
345 count = m_barSets.at(i)->count();
336 }
346 }
337 }
347 }
338
348
339 return count;
349 return count;
340 }
350 }
341
351
342 void QBarSeriesPrivate::setBarWidth(qreal width)
352 void QBarSeriesPrivate::setBarWidth(qreal width)
343 {
353 {
344 if (width < 0.0) {
354 if (width < 0.0) {
345 width = 0.0;
355 width = 0.0;
346 }
356 }
347 m_barWidth = width;
357 m_barWidth = width;
348 emit updatedBars();
358 emit updatedBars();
349 }
359 }
350
360
351 qreal QBarSeriesPrivate::barWidth() const
361 qreal QBarSeriesPrivate::barWidth() const
352 {
362 {
353 return m_barWidth;
363 return m_barWidth;
354 }
364 }
355
365
356 QBarSet* QBarSeriesPrivate::barsetAt(int index)
366 QBarSet* QBarSeriesPrivate::barsetAt(int index)
357 {
367 {
358 return m_barSets.at(index);
368 return m_barSets.at(index);
359 }
369 }
360
370
361 void QBarSeriesPrivate::setVisible(bool visible)
371 void QBarSeriesPrivate::setVisible(bool visible)
362 {
372 {
363 m_visible = visible;
373 m_visible = visible;
364 emit updatedBars();
374 emit updatedBars();
365 }
375 }
366
376
367 void QBarSeriesPrivate::setLabelsVisible(bool visible)
377 void QBarSeriesPrivate::setLabelsVisible(bool visible)
368 {
378 {
369 m_labelsVisible = visible;
379 m_labelsVisible = visible;
370 emit labelsVisibleChanged(visible);
380 emit labelsVisibleChanged(visible);
371 }
381 }
372
382
373 qreal QBarSeriesPrivate::min()
383 qreal QBarSeriesPrivate::min()
374 {
384 {
375 if (m_barSets.count() <= 0) {
385 if (m_barSets.count() <= 0) {
376 return 0;
386 return 0;
377 }
387 }
378 qreal min = INT_MAX;
388 qreal min = INT_MAX;
379
389
380 for (int i = 0; i < m_barSets.count(); i++) {
390 for (int i = 0; i < m_barSets.count(); i++) {
381 int categoryCount = m_barSets.at(i)->count();
391 int categoryCount = m_barSets.at(i)->count();
382 for (int j = 0; j < categoryCount; j++) {
392 for (int j = 0; j < categoryCount; j++) {
383 qreal temp = m_barSets.at(i)->at(j).y();
393 qreal temp = m_barSets.at(i)->at(j).y();
384 if (temp < min)
394 if (temp < min)
385 min = temp;
395 min = temp;
386 }
396 }
387 }
397 }
388 return min;
398 return min;
389 }
399 }
390
400
391 qreal QBarSeriesPrivate::max()
401 qreal QBarSeriesPrivate::max()
392 {
402 {
393 if (m_barSets.count() <= 0) {
403 if (m_barSets.count() <= 0) {
394 return 0;
404 return 0;
395 }
405 }
396 qreal max = INT_MIN;
406 qreal max = INT_MIN;
397
407
398 for (int i = 0; i < m_barSets.count(); i++) {
408 for (int i = 0; i < m_barSets.count(); i++) {
399 int categoryCount = m_barSets.at(i)->count();
409 int categoryCount = m_barSets.at(i)->count();
400 for (int j = 0; j < categoryCount; j++) {
410 for (int j = 0; j < categoryCount; j++) {
401 qreal temp = m_barSets.at(i)->at(j).y();
411 qreal temp = m_barSets.at(i)->at(j).y();
402 if (temp > max)
412 if (temp > max)
403 max = temp;
413 max = temp;
404 }
414 }
405 }
415 }
406
416
407 return max;
417 return max;
408 }
418 }
409
419
410 qreal QBarSeriesPrivate::valueAt(int set, int category)
420 qreal QBarSeriesPrivate::valueAt(int set, int category)
411 {
421 {
412 if ((set < 0) || (set >= m_barSets.count())) {
422 if ((set < 0) || (set >= m_barSets.count())) {
413 // No set, no value.
423 // No set, no value.
414 return 0;
424 return 0;
415 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
425 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
416 // No category, no value.
426 // No category, no value.
417 return 0;
427 return 0;
418 }
428 }
419
429
420 return m_barSets.at(set)->at(category).y();
430 return m_barSets.at(set)->at(category).y();
421 }
431 }
422
432
423 qreal QBarSeriesPrivate::percentageAt(int set, int category)
433 qreal QBarSeriesPrivate::percentageAt(int set, int category)
424 {
434 {
425 if ((set < 0) || (set >= m_barSets.count())) {
435 if ((set < 0) || (set >= m_barSets.count())) {
426 // No set, no value.
436 // No set, no value.
427 return 0;
437 return 0;
428 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
438 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
429 // No category, no value.
439 // No category, no value.
430 return 0;
440 return 0;
431 }
441 }
432
442
433 qreal value = m_barSets.at(set)->at(category).y();
443 qreal value = m_barSets.at(set)->at(category).y();
434 qreal sum = categorySum(category);
444 qreal sum = categorySum(category);
435 if ( qFuzzyIsNull(sum) ) {
445 if ( qFuzzyIsNull(sum) ) {
436 return 0;
446 return 0;
437 }
447 }
438
448
439 return value / sum;
449 return value / sum;
440 }
450 }
441
451
442 qreal QBarSeriesPrivate::categorySum(int category)
452 qreal QBarSeriesPrivate::categorySum(int category)
443 {
453 {
444 qreal sum(0);
454 qreal sum(0);
445 int count = m_barSets.count(); // Count sets
455 int count = m_barSets.count(); // Count sets
446 for (int set = 0; set < count; set++) {
456 for (int set = 0; set < count; set++) {
447 if (category < m_barSets.at(set)->count())
457 if (category < m_barSets.at(set)->count())
448 sum += m_barSets.at(set)->at(category).y();
458 sum += m_barSets.at(set)->at(category).y();
449 }
459 }
450 return sum;
460 return sum;
451 }
461 }
452
462
453 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
463 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
454 {
464 {
455 qreal sum(0);
465 qreal sum(0);
456 int count = m_barSets.count(); // Count sets
466 int count = m_barSets.count(); // Count sets
457 for (int set = 0; set < count; set++) {
467 for (int set = 0; set < count; set++) {
458 if (category < m_barSets.at(set)->count())
468 if (category < m_barSets.at(set)->count())
459 sum += qAbs(m_barSets.at(set)->at(category).y());
469 sum += qAbs(m_barSets.at(set)->at(category).y());
460 }
470 }
461 return sum;
471 return sum;
462 }
472 }
463
473
464 qreal QBarSeriesPrivate::maxCategorySum()
474 qreal QBarSeriesPrivate::maxCategorySum()
465 {
475 {
466 qreal max = INT_MIN;
476 qreal max = INT_MIN;
467 int count = categoryCount();
477 int count = categoryCount();
468 for (int i = 0; i < count; i++) {
478 for (int i = 0; i < count; i++) {
469 qreal sum = categorySum(i);
479 qreal sum = categorySum(i);
470 if (sum > max)
480 if (sum > max)
471 max = sum;
481 max = sum;
472 }
482 }
473 return max;
483 return max;
474 }
484 }
475
485
476 qreal QBarSeriesPrivate::minX()
486 qreal QBarSeriesPrivate::minX()
477 {
487 {
478 if (m_barSets.count() <= 0) {
488 if (m_barSets.count() <= 0) {
479 return 0;
489 return 0;
480 }
490 }
481 qreal min = INT_MAX;
491 qreal min = INT_MAX;
482
492
483 for (int i = 0; i < m_barSets.count(); i++) {
493 for (int i = 0; i < m_barSets.count(); i++) {
484 int categoryCount = m_barSets.at(i)->count();
494 int categoryCount = m_barSets.at(i)->count();
485 for (int j = 0; j < categoryCount; j++) {
495 for (int j = 0; j < categoryCount; j++) {
486 qreal temp = m_barSets.at(i)->at(j).x();
496 qreal temp = m_barSets.at(i)->at(j).x();
487 if (temp < min)
497 if (temp < min)
488 min = temp;
498 min = temp;
489 }
499 }
490 }
500 }
491 return min;
501 return min;
492 }
502 }
493
503
494 qreal QBarSeriesPrivate::maxX()
504 qreal QBarSeriesPrivate::maxX()
495 {
505 {
496 if (m_barSets.count() <= 0) {
506 if (m_barSets.count() <= 0) {
497 return 0;
507 return 0;
498 }
508 }
499 qreal max = INT_MIN;
509 qreal max = INT_MIN;
500
510
501 for (int i = 0; i < m_barSets.count(); i++) {
511 for (int i = 0; i < m_barSets.count(); i++) {
502 int categoryCount = m_barSets.at(i)->count();
512 int categoryCount = m_barSets.at(i)->count();
503 for (int j = 0; j < categoryCount; j++) {
513 for (int j = 0; j < categoryCount; j++) {
504 qreal temp = m_barSets.at(i)->at(j).x();
514 qreal temp = m_barSets.at(i)->at(j).x();
505 if (temp > max)
515 if (temp > max)
506 max = temp;
516 max = temp;
507 }
517 }
508 }
518 }
509
519
510 return max;
520 return max;
511 }
521 }
512
522
513
523
514 void QBarSeriesPrivate::scaleDomain(Domain& domain)
524 void QBarSeriesPrivate::scaleDomain(Domain& domain)
515 {
525 {
516 qreal minX(domain.minX());
526 qreal minX(domain.minX());
517 qreal minY(domain.minY());
527 qreal minY(domain.minY());
518 qreal maxX(domain.maxX());
528 qreal maxX(domain.maxX());
519 qreal maxY(domain.maxY());
529 qreal maxY(domain.maxY());
520 int tickXCount(domain.tickXCount());
530 int tickXCount(domain.tickXCount());
521 int tickYCount(domain.tickYCount());
531 int tickYCount(domain.tickYCount());
522
532
523 qreal seriesMinX = this->minX();
533 qreal seriesMinX = this->minX();
524 qreal seriesMaxX = this->maxX();
534 qreal seriesMaxX = this->maxX();
525 qreal y = max();
535 qreal y = max();
526 minX = qMin(minX, seriesMinX - 0.5);
536 minX = qMin(minX, seriesMinX - 0.5);
527 minY = qMin(minY, y);
537 minY = qMin(minY, y);
528 maxX = qMax(maxX, seriesMaxX + 0.5);
538 maxX = qMax(maxX, seriesMaxX + 0.5);
529 maxY = qMax(maxY, y);
539 maxY = qMax(maxY, y);
530 tickXCount = categoryCount()+1;
540 tickXCount = categoryCount()+1;
531
541
532 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
542 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
533 }
543 }
534
544
535 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
545 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
536 {
546 {
537 Q_Q(QBarSeries);
547 Q_Q(QBarSeries);
538
548
539 BarChartItem* bar = new BarChartItem(q,presenter);
549 BarChartItem* bar = new BarChartItem(q,presenter);
540 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
550 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
541 presenter->animator()->addAnimation(bar);
551 presenter->animator()->addAnimation(bar);
542 }
552 }
543 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
553 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
544 return bar;
554 return bar;
545
555
546 }
556 }
547
557
548 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
558 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
549 {
559 {
550 Q_Q(QBarSeries);
560 Q_Q(QBarSeries);
551 QList<LegendMarker*> markers;
561 QList<LegendMarker*> markers;
552 foreach(QBarSet* set, q->barSets()) {
562 foreach(QBarSet* set, q->barSets()) {
553 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
563 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
554 markers << marker;
564 markers << marker;
555 }
565 }
556
566
557 return markers;
567 return markers;
558 }
568 }
559
569
560 bool QBarSeriesPrivate::append(QBarSet *set)
570 bool QBarSeriesPrivate::append(QBarSet *set)
561 {
571 {
562 Q_Q(QBarSeries);
572 Q_Q(QBarSeries);
563 if ((m_barSets.contains(set)) || (set == 0)) {
573 if ((m_barSets.contains(set)) || (set == 0)) {
564 // Fail if set is already in list or set is null.
574 // Fail if set is already in list or set is null.
565 return false;
575 return false;
566 }
576 }
567 m_barSets.append(set);
577 m_barSets.append(set);
568 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
578 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
569 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
579 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
570 emit restructuredBars(); // this notifies barchartitem
580 emit restructuredBars(); // this notifies barchartitem
571 if (m_dataset) {
581 if (m_dataset) {
572 m_dataset->updateSeries(q); // this notifies legend
582 m_dataset->updateSeries(q); // this notifies legend
573 }
583 }
574 return true;
584 return true;
575 }
585 }
576
586
577 bool QBarSeriesPrivate::remove(QBarSet *set)
587 bool QBarSeriesPrivate::remove(QBarSet *set)
578 {
588 {
579 Q_Q(QBarSeries);
589 Q_Q(QBarSeries);
580 if (!m_barSets.contains(set)) {
590 if (!m_barSets.contains(set)) {
581 // Fail if set is not in list
591 // Fail if set is not in list
582 return false;
592 return false;
583 }
593 }
584 m_barSets.removeOne(set);
594 m_barSets.removeOne(set);
585 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
595 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
586 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
596 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
587 emit restructuredBars(); // this notifies barchartitem
597 emit restructuredBars(); // this notifies barchartitem
588 if (m_dataset) {
598 if (m_dataset) {
589 m_dataset->updateSeries(q); // this notifies legend
599 m_dataset->updateSeries(q); // this notifies legend
590 }
600 }
591 return true;
601 return true;
592 }
602 }
593
603
594 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
604 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
595 {
605 {
596 Q_Q(QBarSeries);
606 Q_Q(QBarSeries);
597 foreach (QBarSet* set, sets) {
607 foreach (QBarSet* set, sets) {
598 if ((set == 0) || (m_barSets.contains(set))) {
608 if ((set == 0) || (m_barSets.contains(set))) {
599 // Fail if any of the sets is null or is already appended.
609 // Fail if any of the sets is null or is already appended.
600 return false;
610 return false;
601 }
611 }
602 if (sets.count(set) != 1) {
612 if (sets.count(set) != 1) {
603 // Also fail if same set is more than once in given list.
613 // Also fail if same set is more than once in given list.
604 return false;
614 return false;
605 }
615 }
606 }
616 }
607
617
608 foreach (QBarSet* set, sets) {
618 foreach (QBarSet* set, sets) {
609 m_barSets.append(set);
619 m_barSets.append(set);
610 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
620 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
611 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
621 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
612 }
622 }
613 emit restructuredBars(); // this notifies barchartitem
623 emit restructuredBars(); // this notifies barchartitem
614 if (m_dataset) {
624 if (m_dataset) {
615 m_dataset->updateSeries(q); // this notifies legend
625 m_dataset->updateSeries(q); // this notifies legend
616 }
626 }
617 return true;
627 return true;
618 }
628 }
619
629
620 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
630 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
621 {
631 {
622 Q_Q(QBarSeries);
632 Q_Q(QBarSeries);
623 if (sets.count() == 0) {
633 if (sets.count() == 0) {
624 return false;
634 return false;
625 }
635 }
626 foreach (QBarSet* set, sets) {
636 foreach (QBarSet* set, sets) {
627 if ((set == 0) || (!m_barSets.contains(set))) {
637 if ((set == 0) || (!m_barSets.contains(set))) {
628 // Fail if any of the sets is null or is not in series
638 // Fail if any of the sets is null or is not in series
629 return false;
639 return false;
630 }
640 }
631 if (sets.count(set) != 1) {
641 if (sets.count(set) != 1) {
632 // Also fail if same set is more than once in given list.
642 // Also fail if same set is more than once in given list.
633 return false;
643 return false;
634 }
644 }
635 }
645 }
636
646
637 foreach (QBarSet* set, sets) {
647 foreach (QBarSet* set, sets) {
638 m_barSets.removeOne(set);
648 m_barSets.removeOne(set);
639 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
649 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
640 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
650 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
641 }
651 }
642
652
643 emit restructuredBars(); // this notifies barchartitem
653 emit restructuredBars(); // this notifies barchartitem
644 if (m_dataset) {
654 if (m_dataset) {
645 m_dataset->updateSeries(q); // this notifies legend
655 m_dataset->updateSeries(q); // this notifies legend
646 }
656 }
647 return true;
657 return true;
648 }
658 }
649
659
650 bool QBarSeriesPrivate::insert(int index, QBarSet *set)
660 bool QBarSeriesPrivate::insert(int index, QBarSet *set)
651 {
661 {
652 Q_Q(QBarSeries);
662 Q_Q(QBarSeries);
653 if ((m_barSets.contains(set)) || (set == 0)) {
663 if ((m_barSets.contains(set)) || (set == 0)) {
654 // Fail if set is already in list or set is null.
664 // Fail if set is already in list or set is null.
655 return false;
665 return false;
656 }
666 }
657 m_barSets.insert(index, set);
667 m_barSets.insert(index, set);
658 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
668 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
659 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
669 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
660 emit restructuredBars(); // this notifies barchartitem
670 emit restructuredBars(); // this notifies barchartitem
661 if (m_dataset) {
671 if (m_dataset) {
662 m_dataset->updateSeries(q); // this notifies legend
672 m_dataset->updateSeries(q); // this notifies legend
663 }
673 }
664 return true;
674 return true;
665 }
675 }
666
676
667 #include "moc_qbarseries.cpp"
677 #include "moc_qbarseries.cpp"
668 #include "moc_qbarseries_p.cpp"
678 #include "moc_qbarseries_p.cpp"
669
679
670 QTCOMMERCIALCHART_END_NAMESPACE
680 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,621 +1,639
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 "qbarset.h"
21 #include "qbarset.h"
22 #include "qbarset_p.h"
22 #include "qbarset_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QBarSet
27 \class QBarSet
28 \brief part of QtCommercial chart API.
28 \brief part of QtCommercial chart API.
29
29
30 QBarSet represents one set of bars. Set of bars contains one data value for each category.
30 QBarSet represents one set of bars. Set of bars contains one data value for each category.
31 First value of set is assumed to belong to first category, second to second category and so on.
31 First value of set is assumed to belong to first category, second to second category and so on.
32 If set has fewer values than there are categories, then the missing values are assumed to be
32 If set has fewer values than there are categories, then the missing values are assumed to be
33 at the end of set. For missing values in middle of a set, numerical value of zero is used.
33 at the end of set. For missing values in middle of a set, numerical value of zero is used.
34
34
35 \mainclass
35 \mainclass
36
36
37 \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries
37 \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries
38 */
38 */
39 /*!
39 /*!
40 \qmlclass BarSet QBarSet
40 \qmlclass BarSet QBarSet
41
41
42 BarSet represents one set of bars. Set of bars contains one data value for each category.
42 BarSet represents one set of bars. Set of bars contains one data value for each category.
43 First value of set is assumed to belong to first category, second to second category and so on.
43 First value of set is assumed to belong to first category, second to second category and so on.
44 If set has fewer values than there are categories, then the missing values are assumed to be
44 If set has fewer values than there are categories, then the missing values are assumed to be
45 at the end of set. For missing values in middle of a set, numerical value of zero is used.
45 at the end of set. For missing values in middle of a set, numerical value of zero is used.
46 \sa BarSeries, GroupedBarSeries, StackedBarSeries, PercentBarSeries
46 \sa BarSeries, GroupedBarSeries, StackedBarSeries, PercentBarSeries
47 */
47 */
48
48
49 /*!
49 /*!
50 \property QBarSet::label
50 \property QBarSet::label
51 Defines the label of the barSet.
51 Defines the label of the barSet.
52 */
52 */
53 /*!
53 /*!
54 \qmlproperty string BarSet::label
54 \qmlproperty string BarSet::label
55 Defines the label of the barSet.
55 Defines the label of the barSet.
56 */
56 */
57
57
58 /*!
58 /*!
59 \property QBarSet::pen
59 \property QBarSet::pen
60 \brief Defines the pen used by the barSet.
60 \brief Defines the pen used by the barSet.
61 */
61 */
62
62
63 /*!
63 /*!
64 \property QBarSet::brush
64 \property QBarSet::brush
65 \brief Defines the brush used by the barSet.
65 \brief Defines the brush used by the barSet.
66 */
66 */
67
67
68 /*!
68 /*!
69 \property QBarSet::labelBrush
69 \property QBarSet::labelBrush
70 \brief Defines the brush used by the barSet's label.
70 \brief Defines the brush used by the barSet's label.
71 */
71 */
72
72
73 /*!
73 /*!
74 \property QBarSet::labelFont
74 \property QBarSet::labelFont
75 \brief Defines the font used by the barSet's label.
75 \brief Defines the font used by the barSet's label.
76 */
76 */
77
77
78 /*!
78 /*!
79 \property QBarSet::color
79 \property QBarSet::color
80 The fill (brush) color of the bar set.
80 The fill (brush) color of the bar set.
81 */
81 */
82 /*!
82 /*!
83 \qmlproperty color BarSet::color
83 \qmlproperty color BarSet::color
84 The fill (brush) color of the bar set.
84 The fill (brush) color of the bar set.
85 */
85 */
86
86
87 /*!
87 /*!
88 \property QBarSet::borderColor
88 \property QBarSet::borderColor
89 The line (pen) color of the bar set.
89 The line (pen) color of the bar set.
90 */
90 */
91 /*!
91 /*!
92 \qmlproperty color BarSet::borderColor
92 \qmlproperty color BarSet::borderColor
93 The line (pen) color of the bar set.
93 The line (pen) color of the bar set.
94 */
94 */
95
95
96 /*!
96 /*!
97 \property QBarSet::labelColor
97 \property QBarSet::labelColor
98 The text (label) color of the bar set.
98 The text (label) color of the bar set.
99 */
99 */
100 /*!
100 /*!
101 \qmlproperty color BarSet::labelColor
101 \qmlproperty color BarSet::labelColor
102 The text (label) color of the bar set.
102 The text (label) color of the bar set.
103 */
103 */
104
104
105 /*!
105 /*!
106 \fn void QBarSet::clicked(int index)
106 \fn void QBarSet::clicked(int index)
107
107
108 The signal is emitted if the user clicks with a mouse on top of barset.
108 The signal is emitted if the user clicks with a mouse on top of barset.
109 Clicked bar inside set is indexed by \a index
109 Clicked bar inside set is indexed by \a index
110 */
110 */
111
111
112 /*!
112 /*!
113 \fn void QBarSet::hovered(bool status)
113 \fn void QBarSet::hovered(bool status)
114
114
115 The signal is emitted if mouse is hovered on top of barset.
115 The signal is emitted if mouse is hovered on top of barset.
116 Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset.
116 Parameter \a status is true, if mouse entered on top of barset, false if mouse left from top of barset.
117 */
117 */
118
118
119
119
120 /*!
120 /*!
121 \fn void QBarSet::labelChanged()
121 \fn void QBarSet::labelChanged()
122 This signal is emitted when the label of the barSet has changed.
122 This signal is emitted when the label of the barSet has changed.
123 \sa label
123 \sa label
124 */
124 */
125
125
126 /*!
126 /*!
127 \fn void QBarSet::penChanged()
127 \fn void QBarSet::penChanged()
128 This signal is emitted when the pen of the barSet has changed.
128 This signal is emitted when the pen of the barSet has changed.
129 \sa pen
129 \sa pen
130 */
130 */
131
131
132 /*!
132 /*!
133 \fn void QBarSet::brushChanged()
133 \fn void QBarSet::brushChanged()
134 This signal is emitted when the brush of the barSet has changed.
134 This signal is emitted when the brush of the barSet has changed.
135 \sa brush
135 \sa brush
136 */
136 */
137
137
138 /*!
138 /*!
139 \fn void QBarSet::labelBrushChanged()
139 \fn void QBarSet::labelBrushChanged()
140 This signal is emitted when the brush of the barSet's label has changed.
140 This signal is emitted when the brush of the barSet's label has changed.
141 \sa labelBrush
141 \sa labelBrush
142 */
142 */
143
143
144 /*!
144 /*!
145 \fn void QBarSet::labelFontChanged()
145 \fn void QBarSet::labelFontChanged()
146 This signal is emitted when the font of the barSet's label has changed.
146 This signal is emitted when the font of the barSet's label has changed.
147 \sa labelBrush
147 \sa labelBrush
148 */
148 */
149
149
150 /*!
150 /*!
151 \fn void QBarSet::colorChanged(QColor)
151 \fn void QBarSet::colorChanged(QColor)
152 This signal is emitted when the fill (brush) color of the set has changed to \a color.
152 This signal is emitted when the fill (brush) color of the set has changed to \a color.
153 */
153 */
154 /*!
154 /*!
155 \qmlsignal BarSet::onColorChanged(color color)
155 \qmlsignal BarSet::onColorChanged(color color)
156 This signal is emitted when the fill (brush) color of the set has changed to \a color.
156 This signal is emitted when the fill (brush) color of the set has changed to \a color.
157 */
157 */
158
158
159 /*!
159 /*!
160 \fn void QBarSet::borderColorChanged(QColor)
160 \fn void QBarSet::borderColorChanged(QColor)
161 This signal is emitted when the line (pen) color of the set has changed to \a color.
161 This signal is emitted when the line (pen) color of the set has changed to \a color.
162 */
162 */
163 /*!
163 /*!
164 \qmlsignal BarSet::onBorderColorChanged(color color)
164 \qmlsignal BarSet::onBorderColorChanged(color color)
165 This signal is emitted when the line (pen) color of the set has changed to \a color.
165 This signal is emitted when the line (pen) color of the set has changed to \a color.
166 */
166 */
167
167
168 /*!
168 /*!
169 \fn void QBarSet::labelColorChanged(QColor)
169 \fn void QBarSet::labelColorChanged(QColor)
170 This signal is emitted when the text (label) color of the set has changed to \a color.
170 This signal is emitted when the text (label) color of the set has changed to \a color.
171 */
171 */
172 /*!
172 /*!
173 \qmlsignal BarSet::onLabelColorChanged(color color)
173 \qmlsignal BarSet::onLabelColorChanged(color color)
174 This signal is emitted when the text (label) color of the set has changed to \a color.
174 This signal is emitted when the text (label) color of the set has changed to \a color.
175 */
175 */
176
176
177 /*!
177 /*!
178 \fn void QBarSet::valuesAdded(int index, int count)
178 \fn void QBarSet::valuesAdded(int index, int count)
179 This signal is emitted when new values have been added to the set.
179 This signal is emitted when new values have been added to the set.
180 Parameter \a index indicates the position of the first inserted value.
180 Parameter \a index indicates the position of the first inserted value.
181 Parameter \a count is the number of iserted values.
181 Parameter \a count is the number of iserted values.
182 \sa append(), insert()
182 \sa append(), insert()
183 */
183 */
184 /*!
184 /*!
185 \qmlsignal BarSet::onValuesAdded(int index, int count)
185 \qmlsignal BarSet::onValuesAdded(int index, int count)
186 This signal is emitted when new values have been added to the set.
186 This signal is emitted when new values have been added to the set.
187 Parameter \a index indicates the position of the first inserted value.
187 Parameter \a index indicates the position of the first inserted value.
188 Parameter \a count is the number of iserted values.
188 Parameter \a count is the number of iserted values.
189 */
189 */
190
190
191 /*!
191 /*!
192 \fn void QBarSet::valuesRemoved(int index, int count)
192 \fn void QBarSet::valuesRemoved(int index, int count)
193 This signal is emitted values have been removed from the set.
193 This signal is emitted values have been removed from the set.
194 Parameter \a index indicates the position of the first removed value.
194 Parameter \a index indicates the position of the first removed value.
195 Parameter \a count is the number of removed values.
195 Parameter \a count is the number of removed values.
196 \sa remove()
196 \sa remove()
197 */
197 */
198 /*!
198 /*!
199 \qmlsignal BarSet::onValuesRemoved(int index, int count)
199 \qmlsignal BarSet::onValuesRemoved(int index, int count)
200 This signal is emitted values have been removed from the set.
200 This signal is emitted values have been removed from the set.
201 Parameter \a index indicates the position of the first removed value.
201 Parameter \a index indicates the position of the first removed value.
202 Parameter \a count is the number of removed values.
202 Parameter \a count is the number of removed values.
203 */
203 */
204
204
205 /*!
205 /*!
206 \fn void QBarSet::valueChanged(int index)
206 \fn void QBarSet::valueChanged(int index)
207 This signal is emitted values the value in the set has been modified.
207 This signal is emitted values the value in the set has been modified.
208 Parameter \a index indicates the position of the modified value.
208 Parameter \a index indicates the position of the modified value.
209 \sa at()
209 \sa at()
210 */
210 */
211 /*!
211 /*!
212 \qmlsignal BarSet::onValueChanged(int index)
212 \qmlsignal BarSet::onValueChanged(int index)
213 This signal is emitted values the value in the set has been modified.
213 This signal is emitted values the value in the set has been modified.
214 Parameter \a index indicates the position of the modified value.
214 Parameter \a index indicates the position of the modified value.
215 */
215 */
216
216
217 /*!
217 /*!
218 Constructs QBarSet with a label of \a label and with parent of \a parent
218 Constructs QBarSet with a label of \a label and with parent of \a parent
219 */
219 */
220 QBarSet::QBarSet(const QString label, QObject *parent)
220 QBarSet::QBarSet(const QString label, QObject *parent)
221 : QObject(parent)
221 : QObject(parent)
222 ,d_ptr(new QBarSetPrivate(label,this))
222 ,d_ptr(new QBarSetPrivate(label,this))
223 {
223 {
224 }
224 }
225
225
226 /*!
226 /*!
227 Destroys the barset
227 Destroys the barset
228 */
228 */
229 QBarSet::~QBarSet()
229 QBarSet::~QBarSet()
230 {
230 {
231 // NOTE: d_ptr destroyed by QObject
231 // NOTE: d_ptr destroyed by QObject
232 }
232 }
233
233
234 /*!
234 /*!
235 Sets new \a label for set.
235 Sets new \a label for set.
236 */
236 */
237 void QBarSet::setLabel(const QString label)
237 void QBarSet::setLabel(const QString label)
238 {
238 {
239 d_ptr->m_label = label;
239 d_ptr->m_label = label;
240 emit labelChanged();
240 emit labelChanged();
241 }
241 }
242
242
243 /*!
243 /*!
244 Returns label of the set.
244 Returns label of the set.
245 */
245 */
246 QString QBarSet::label() const
246 QString QBarSet::label() const
247 {
247 {
248 return d_ptr->m_label;
248 return d_ptr->m_label;
249 }
249 }
250
250
251 /*!
251 /*!
252 Appends a point to set. Parameter \a value x coordinate defines the
252 Appends a point to set. Parameter \a value x coordinate defines the
253 position in x-axis and y coordinate defines the height of bar.
253 position in x-axis and y coordinate defines the height of bar.
254 Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries)
254 Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries)
255 the x values are used or ignored.
255 the x values are used or ignored.
256 */
256 */
257 void QBarSet::append(const QPointF value)
257 void QBarSet::append(const QPointF value)
258 {
258 {
259 int index = d_ptr->m_values.count();
259 int index = d_ptr->m_values.count();
260 d_ptr->append(value);
260 d_ptr->append(value);
261 emit valuesAdded(index, 1);
261 emit valuesAdded(index, 1);
262 }
262 }
263
263
264 /*!
264 /*!
265 Appends a list of \a values to set. Works like append with single point.
265 Appends a list of \a values to set. Works like append with single point.
266 \sa append()
266 \sa append()
267 */
267 */
268 void QBarSet::append(const QList<QPointF> values)
268 void QBarSet::append(const QList<QPointF> values)
269 {
269 {
270 int index = d_ptr->m_values.count();
270 int index = d_ptr->m_values.count();
271 d_ptr->append(values);
271 d_ptr->append(values);
272 emit valuesAdded(index, values.count());
272 emit valuesAdded(index, values.count());
273 }
273 }
274
274
275 /*!
275 /*!
276 Appends new value \a value to the end of set. Internally the value is converted to QPointF,
276 Appends new value \a value to the end of set. Internally the value is converted to QPointF,
277 with x coordinate being the index of appended value and y coordinate is the value.
277 with x coordinate being the index of appended value and y coordinate is the value.
278 */
278 */
279 void QBarSet::append(const qreal value)
279 void QBarSet::append(const qreal value)
280 {
280 {
281 // Convert to QPointF and use other append(QPointF) method.
281 // Convert to QPointF and use other append(QPointF) method.
282 append(QPointF(d_ptr->m_values.count(), value));
282 append(QPointF(d_ptr->m_values.count(), value));
283 }
283 }
284
284
285 /*!
285 /*!
286 Appends a list of reals to set. Works like append with single real value. The \a values in list
286 Appends a list of reals to set. Works like append with single real value. The \a values in list
287 are converted to QPointF, where x coordinate is the index of point and y coordinate is the value.
287 are converted to QPointF, where x coordinate is the index of point and y coordinate is the value.
288 \sa append()
288 \sa append()
289 */
289 */
290 void QBarSet::append(const QList<qreal> values)
290 void QBarSet::append(const QList<qreal> values)
291 {
291 {
292 int index = d_ptr->m_values.count();
292 int index = d_ptr->m_values.count();
293 d_ptr->append(values);
293 d_ptr->append(values);
294 emit valuesAdded(index, values.count());
294 emit valuesAdded(index, values.count());
295 }
295 }
296
296
297 /*!
297 /*!
298 Convinience operator. Same as append, with real \a value.
298 Convinience operator. Same as append, with real \a value.
299 \sa append()
299 \sa append()
300 */
300 */
301 QBarSet& QBarSet::operator << (const qreal &value)
301 QBarSet& QBarSet::operator << (const qreal &value)
302 {
302 {
303 append(value);
303 append(value);
304 return *this;
304 return *this;
305 }
305 }
306
306
307 /*!
307 /*!
308 Convinience operator. Same as append, with QPointF \a value.
308 Convinience operator. Same as append, with QPointF \a value.
309 \sa append()
309 \sa append()
310 */
310 */
311 QBarSet& QBarSet::operator << (const QPointF &value)
311 QBarSet& QBarSet::operator << (const QPointF &value)
312 {
312 {
313 append(value);
313 append(value);
314 return *this;
314 return *this;
315 }
315 }
316
316
317 /*!
317 /*!
318 Inserts new \a value on the \a index position.
318 Inserts new \a value on the \a index position.
319 The value that is currently at this postion is moved to postion index + 1
319 The value that is currently at this postion is moved to postion index + 1
320 \sa remove()
320 \sa remove()
321 */
321 */
322 void QBarSet::insert(const int index, const qreal value)
322 void QBarSet::insert(const int index, const qreal value)
323 {
323 {
324 d_ptr->insert(index, value);
324 d_ptr->insert(index, value);
325 emit valuesAdded(index,1);
325 emit valuesAdded(index,1);
326 }
326 }
327
327
328 /*!
328 /*!
329 Inserts new \a value on the \a index position.
329 Inserts new \a value on the \a index position.
330 The value that is currently at this postion is moved to postion index + 1
330 The value that is currently at this postion is moved to postion index + 1
331 \sa remove()
331 \sa remove()
332 */
332 */
333 void QBarSet::insert(const int index, const QPointF value)
333 void QBarSet::insert(const int index, const QPointF value)
334 {
334 {
335 d_ptr->insert(index,value);
335 d_ptr->insert(index,value);
336 emit valuesAdded(index,1);
336 emit valuesAdded(index,1);
337 }
337 }
338
338
339 /*!
339 /*!
340 Removes \a count number of values from the set starting at \a index.
340 Removes \a count number of values from the set starting at \a index.
341 Returns true if remove operation was succesfull.
341 Returns true if remove operation was succesfull.
342 \sa insert()
342 \sa insert()
343 */
343 */
344 bool QBarSet::remove(const int index, const int count)
344 bool QBarSet::remove(const int index, const int count)
345 {
345 {
346 bool success = d_ptr->remove(index,count);
346 bool success = d_ptr->remove(index,count);
347 if (success) {
347 if (success) {
348 emit valuesRemoved(index,count);
348 emit valuesRemoved(index,count);
349 }
349 }
350 return success;
350 return success;
351 }
351 }
352
352
353 /*!
353 /*!
354 Sets a new value \a value to set, indexed by \a index
354 Sets a new value \a value to set, indexed by \a index
355 */
355 */
356 void QBarSet::replace(const int index, const qreal value)
356 void QBarSet::replace(const int index, const qreal value)
357 {
357 {
358 d_ptr->replace(index,value);
358 d_ptr->replace(index,value);
359 emit valueChanged(index);
359 emit valueChanged(index);
360 }
360 }
361
361
362 /*!
362 /*!
363 Sets a new value \a value to set, indexed by \a index
363 Sets a new value \a value to set, indexed by \a index
364 */
364 */
365 void QBarSet::replace(const int index, const QPointF value)
365 void QBarSet::replace(const int index, const QPointF value)
366 {
366 {
367 d_ptr->replace(index,value);
367 d_ptr->replace(index,value);
368 emit valueChanged(index);
368 emit valueChanged(index);
369 }
369 }
370
370
371 /*!
371 /*!
372 Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF.
372 Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF.
373 The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
373 The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
374 of the QPointF (if appended with QPointF append).
374 of the QPointF (if appended with QPointF append).
375 If the index is out of bounds QPointF(0, 0.0) is returned.
375 If the index is out of bounds QPointF(0, 0.0) is returned.
376 */
376 */
377 QPointF QBarSet::at(const int index) const
377 QPointF QBarSet::at(const int index) const
378 {
378 {
379 if (index < 0 || index >= d_ptr->m_values.count()) {
379 if (index < 0 || index >= d_ptr->m_values.count()) {
380 return QPointF(index, 0.0);
380 return QPointF(index, 0.0);
381 }
381 }
382
382
383 return d_ptr->m_values.at(index);
383 return d_ptr->m_values.at(index);
384 }
384 }
385
385
386 /*!
386 /*!
387 Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF.
387 Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF.
388 The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
388 The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
389 of the QPointF (if appended with QPointF append).
389 of the QPointF (if appended with QPointF append).
390 */
390 */
391 QPointF QBarSet::operator [](const int index) const
391 QPointF QBarSet::operator [](const int index) const
392 {
392 {
393 return d_ptr->m_values.at(index);
393 return d_ptr->m_values.at(index);
394 }
394 }
395
395
396 /*!
396 /*!
397 Returns count of values in set.
397 Returns count of values in set.
398 */
398 */
399 int QBarSet::count() const
399 int QBarSet::count() const
400 {
400 {
401 return d_ptr->m_values.count();
401 return d_ptr->m_values.count();
402 }
402 }
403
403
404 /*!
404 /*!
405 Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation.
405 Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation.
406 */
406 */
407 qreal QBarSet::sum() const
407 qreal QBarSet::sum() const
408 {
408 {
409 qreal total(0);
409 qreal total(0);
410 for (int i=0; i < d_ptr->m_values.count(); i++) {
410 for (int i=0; i < d_ptr->m_values.count(); i++) {
411 //total += d_ptr->m_values.at(i);
411 //total += d_ptr->m_values.at(i);
412 total += d_ptr->m_values.at(i).y();
412 total += d_ptr->m_values.at(i).y();
413 }
413 }
414 return total;
414 return total;
415 }
415 }
416
416
417 /*!
417 /*!
418 Sets pen for set. Bars of this set are drawn using \a pen
418 Sets pen for set. Bars of this set are drawn using \a pen
419 */
419 */
420 void QBarSet::setPen(const QPen &pen)
420 void QBarSet::setPen(const QPen &pen)
421 {
421 {
422 if(d_ptr->m_pen!=pen){
422 if(d_ptr->m_pen!=pen){
423 d_ptr->m_pen = pen;
423 d_ptr->m_pen = pen;
424 emit d_ptr->updatedBars();
424 emit d_ptr->updatedBars();
425 emit penChanged();
425 emit penChanged();
426 }
426 }
427 }
427 }
428
428
429 /*!
429 /*!
430 Returns pen of the set.
430 Returns pen of the set.
431 */
431 */
432 QPen QBarSet::pen() const
432 QPen QBarSet::pen() const
433 {
433 {
434 return d_ptr->m_pen;
434 return d_ptr->m_pen;
435 }
435 }
436
436
437 /*!
437 /*!
438 Sets brush for the set. Bars of this set are drawn using \a brush
438 Sets brush for the set. Bars of this set are drawn using \a brush
439 */
439 */
440 void QBarSet::setBrush(const QBrush &brush)
440 void QBarSet::setBrush(const QBrush &brush)
441 {
441 {
442 if(d_ptr->m_brush!=brush){
442 if(d_ptr->m_brush!=brush){
443 d_ptr->m_brush = brush;
443 d_ptr->m_brush = brush;
444 emit d_ptr->updatedBars();
444 emit d_ptr->updatedBars();
445 emit brushChanged();
445 emit brushChanged();
446 }
446 }
447 }
447 }
448
448
449 /*!
449 /*!
450 Returns brush of the set.
450 Returns brush of the set.
451 */
451 */
452 QBrush QBarSet::brush() const
452 QBrush QBarSet::brush() const
453 {
453 {
454 return d_ptr->m_brush;
454 return d_ptr->m_brush;
455 }
455 }
456
456
457 /*!
457 /*!
458 Sets \a brush of the values that are drawn on top of this barset
458 Sets \a brush of the values that are drawn on top of this barset
459 */
459 */
460 void QBarSet::setLabelBrush(const QBrush &brush)
460 void QBarSet::setLabelBrush(const QBrush &brush)
461 {
461 {
462 if(d_ptr->m_labelBrush!=brush){
462 if(d_ptr->m_labelBrush!=brush){
463 d_ptr->m_labelBrush = brush;
463 d_ptr->m_labelBrush = brush;
464 emit d_ptr->updatedBars();
464 emit d_ptr->updatedBars();
465 emit labelBrushChanged();
465 emit labelBrushChanged();
466 }
466 }
467 }
467 }
468
468
469 /*!
469 /*!
470 Returns brush of the values that are drawn on top of this barset
470 Returns brush of the values that are drawn on top of this barset
471 */
471 */
472 QBrush QBarSet::labelBrush() const
472 QBrush QBarSet::labelBrush() const
473 {
473 {
474 return d_ptr->m_labelBrush;
474 return d_ptr->m_labelBrush;
475 }
475 }
476
476
477 /*!
477 /*!
478 Sets the \a font for values that are drawn on top of this barset
478 Sets the \a font for values that are drawn on top of this barset
479 */
479 */
480 void QBarSet::setLabelFont(const QFont &font)
480 void QBarSet::setLabelFont(const QFont &font)
481 {
481 {
482 if(d_ptr->m_labelFont!=font) {
482 if(d_ptr->m_labelFont!=font) {
483 d_ptr->m_labelFont = font;
483 d_ptr->m_labelFont = font;
484 emit d_ptr->updatedBars();
484 emit d_ptr->updatedBars();
485 emit labelFontChanged();
485 emit labelFontChanged();
486 }
486 }
487
487
488 }
488 }
489
489
490 /*!
490 /*!
491 Returns the pen for values that are drawn on top of this set
491 Returns the pen for values that are drawn on top of this barset
492 */
492 */
493 QFont QBarSet::labelFont() const
493 QFont QBarSet::labelFont() const
494 {
494 {
495 return d_ptr->m_labelFont;
495 return d_ptr->m_labelFont;
496 }
496 }
497
497
498 /*!
499 Returns the color of the brush of barset.
500 */
498 QColor QBarSet::color()
501 QColor QBarSet::color()
499 {
502 {
500 return brush().color();
503 return brush().color();
501 }
504 }
502
505
506 /*!
507 Sets the \a color of brush for this barset
508 */
503 void QBarSet::setColor(QColor color)
509 void QBarSet::setColor(QColor color)
504 {
510 {
505 QBrush b = brush();
511 QBrush b = brush();
506 if (b.color() != color) {
512 if (b.color() != color) {
507 b.setColor(color);
513 b.setColor(color);
508 setBrush(b);
514 setBrush(b);
509 emit colorChanged(color);
515 emit colorChanged(color);
510 }
516 }
511 }
517 }
512
518
519 /*!
520 Returns the color of pen of this barset
521 */
513 QColor QBarSet::borderColor()
522 QColor QBarSet::borderColor()
514 {
523 {
515 return pen().color();
524 return pen().color();
516 }
525 }
517
526
527 /*!
528 Sets the color of pen for this barset
529 */
518 void QBarSet::setBorderColor(QColor color)
530 void QBarSet::setBorderColor(QColor color)
519 {
531 {
520 QPen p = pen();
532 QPen p = pen();
521 if (p.color() != color) {
533 if (p.color() != color) {
522 p.setColor(color);
534 p.setColor(color);
523 setPen(p);
535 setPen(p);
524 emit borderColorChanged(color);
536 emit borderColorChanged(color);
525 }
537 }
526 }
538 }
527
539
540 /*!
541 Returns the color of labels of this barset
542 */
528 QColor QBarSet::labelColor()
543 QColor QBarSet::labelColor()
529 {
544 {
530 return labelBrush().color();
545 return labelBrush().color();
531 }
546 }
532
547
548 /*!
549 Sets the color of labels for this barset
550 */
533 void QBarSet::setLabelColor(QColor color)
551 void QBarSet::setLabelColor(QColor color)
534 {
552 {
535 QBrush b = labelBrush();
553 QBrush b = labelBrush();
536 if (b.color() != color) {
554 if (b.color() != color) {
537 b.setColor(color);
555 b.setColor(color);
538 setLabelBrush(b);
556 setLabelBrush(b);
539 emit labelColorChanged(color);
557 emit labelColorChanged(color);
540 }
558 }
541 }
559 }
542
560
543 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
561 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
544
562
545 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
563 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
546 q_ptr(parent),
564 q_ptr(parent),
547 m_label(label)
565 m_label(label)
548 {
566 {
549 }
567 }
550
568
551 QBarSetPrivate::~QBarSetPrivate()
569 QBarSetPrivate::~QBarSetPrivate()
552 {
570 {
553 }
571 }
554
572
555 void QBarSetPrivate::append(QPointF value)
573 void QBarSetPrivate::append(QPointF value)
556 {
574 {
557 m_values.append(value);
575 m_values.append(value);
558 emit restructuredBars();
576 emit restructuredBars();
559 }
577 }
560
578
561 void QBarSetPrivate::append(QList<QPointF> values)
579 void QBarSetPrivate::append(QList<QPointF> values)
562 {
580 {
563 for (int i=0; i<values.count(); i++) {
581 for (int i=0; i<values.count(); i++) {
564 m_values.append(values.at(i));
582 m_values.append(values.at(i));
565 }
583 }
566 emit restructuredBars();
584 emit restructuredBars();
567 }
585 }
568
586
569 void QBarSetPrivate::append(QList<qreal> values)
587 void QBarSetPrivate::append(QList<qreal> values)
570 {
588 {
571 int index = m_values.count();
589 int index = m_values.count();
572 for (int i=0; i<values.count(); i++) {
590 for (int i=0; i<values.count(); i++) {
573 m_values.append(QPointF(index,values.at(i)));
591 m_values.append(QPointF(index,values.at(i)));
574 index++;
592 index++;
575 }
593 }
576 emit restructuredBars();
594 emit restructuredBars();
577 }
595 }
578
596
579 void QBarSetPrivate::insert(const int index, const qreal value)
597 void QBarSetPrivate::insert(const int index, const qreal value)
580 {
598 {
581 m_values.insert(index, QPointF(index, value));
599 m_values.insert(index, QPointF(index, value));
582 emit restructuredBars();
600 emit restructuredBars();
583 }
601 }
584
602
585 void QBarSetPrivate::insert(const int index, const QPointF value)
603 void QBarSetPrivate::insert(const int index, const QPointF value)
586 {
604 {
587 m_values.insert(index, value);
605 m_values.insert(index, value);
588 emit restructuredBars();
606 emit restructuredBars();
589 }
607 }
590
608
591 bool QBarSetPrivate::remove(const int index, const int count)
609 bool QBarSetPrivate::remove(const int index, const int count)
592 {
610 {
593 if ((index + count) > m_values.count()) {
611 if ((index + count) > m_values.count()) {
594 // cant remove more values than there are
612 // cant remove more values than there are
595 return false;
613 return false;
596 }
614 }
597 int c = count;
615 int c = count;
598 while (c > 0) {
616 while (c > 0) {
599 m_values.removeAt(index);
617 m_values.removeAt(index);
600 c--;
618 c--;
601 }
619 }
602 emit restructuredBars();
620 emit restructuredBars();
603 return true;
621 return true;
604 }
622 }
605
623
606 void QBarSetPrivate::replace(const int index, const qreal value)
624 void QBarSetPrivate::replace(const int index, const qreal value)
607 {
625 {
608 m_values.replace(index,QPointF(index,value));
626 m_values.replace(index,QPointF(index,value));
609 emit updatedBars();
627 emit updatedBars();
610 }
628 }
611
629
612 void QBarSetPrivate::replace(const int index, const QPointF value)
630 void QBarSetPrivate::replace(const int index, const QPointF value)
613 {
631 {
614 m_values.replace(index,value);
632 m_values.replace(index,value);
615 emit updatedBars();
633 emit updatedBars();
616 }
634 }
617
635
618 #include "moc_qbarset.cpp"
636 #include "moc_qbarset.cpp"
619 #include "moc_qbarset_p.cpp"
637 #include "moc_qbarset_p.cpp"
620
638
621 QTCOMMERCIALCHART_END_NAMESPACE
639 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now