@@ -1,690 +1,701 | |||||
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 | \property QBarSeries::barWidth |
|
50 | \property QBarSeries::barWidth | |
51 | \brief 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 |
|
51 | \brief 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 | |
52 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
52 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
53 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
53 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
54 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. This is |
|
54 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. This is | |
55 | because with grouped series it is more logical to set width of whole group and let the chart calculate correct |
|
55 | because with grouped series it is more logical to set width of whole group and let the chart calculate correct | |
56 | width for bar. |
|
56 | width for bar. | |
57 | \sa QGroupedBarSeries |
|
57 | \sa QGroupedBarSeries | |
58 | */ |
|
58 | */ | |
59 |
|
59 | |||
60 | /*! |
|
60 | /*! | |
61 | \property QBarSeries::count |
|
61 | \property QBarSeries::count | |
62 | \brief Holds the number of sets in series. |
|
62 | \brief Holds the number of sets in series. | |
63 | */ |
|
63 | */ | |
64 |
|
64 | |||
65 | /*! |
|
65 | /*! | |
66 | \property QBarSeries::labelsVisible |
|
66 | \property QBarSeries::labelsVisible | |
67 | \brief Defines the visibility of the labels in series |
|
67 | \brief Defines the visibility of the labels in series | |
68 | */ |
|
68 | */ | |
69 |
|
69 | |||
70 | /*! |
|
70 | /*! | |
71 | \fn void QBarSeries::clicked(QBarSet *barset, int index) |
|
71 | \fn void QBarSeries::clicked(QBarSet *barset, int index) | |
72 |
|
72 | |||
73 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
73 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
74 | Clicked bar inside set is indexed by \a index |
|
74 | Clicked bar inside set is indexed by \a index | |
75 | */ |
|
75 | */ | |
76 |
|
76 | |||
77 | /*! |
|
77 | /*! | |
78 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) |
|
78 | \fn void QBarSeries::hovered(QBarSet* barset, bool status) | |
79 |
|
79 | |||
80 | The signal is emitted if mouse is hovered on top of series. |
|
80 | The signal is emitted if mouse is hovered on top of series. | |
81 | Parameter \a barset is the pointer of barset, where hover happened. |
|
81 | Parameter \a barset is the pointer of barset, where hover happened. | |
82 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
82 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
83 | */ |
|
83 | */ | |
|
84 | /*! | |||
|
85 | \fn void QBarSeries::barWidthChanged() | |||
|
86 | ||||
|
87 | This signal is emitted when bar width has been changed. | |||
|
88 | */ | |||
|
89 | ||||
|
90 | /*! | |||
|
91 | \fn void QBarSeries::barsetCountChanged() | |||
|
92 | ||||
|
93 | This signal is emitted when barset count has been changed, for example by append or remove. | |||
|
94 | */ | |||
84 |
|
95 | |||
85 | /*! |
|
96 | /*! | |
86 | \fn void QBarSeries::labelsVisibleChanged() |
|
97 | \fn void QBarSeries::labelsVisibleChanged() | |
87 |
|
98 | |||
88 | This signal is emitted when labels visibility have changed. |
|
99 | This signal is emitted when labels visibility have changed. | |
89 |
|
100 | |||
90 | \sa isLabelsVisible(), setLabelsVisible() |
|
101 | \sa isLabelsVisible(), setLabelsVisible() | |
91 | */ |
|
102 | */ | |
92 |
|
103 | |||
93 | /*! |
|
104 | /*! | |
94 | \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
105 | \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets) | |
95 |
|
106 | |||
96 | This signal is emitted when \a sets have been added to the series. |
|
107 | This signal is emitted when \a sets have been added to the series. | |
97 |
|
108 | |||
98 | \sa append(), insert() |
|
109 | \sa append(), insert() | |
99 | */ |
|
110 | */ | |
100 |
|
111 | |||
101 | /*! |
|
112 | /*! | |
102 | \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
113 | \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
103 |
|
114 | |||
104 | This signal is emitted when \a sets have been removed from the series. |
|
115 | This signal is emitted when \a sets have been removed from the series. | |
105 |
|
116 | |||
106 | \sa remove() |
|
117 | \sa remove() | |
107 | */ |
|
118 | */ | |
108 |
|
119 | |||
109 | /*! |
|
120 | /*! | |
110 | Constructs empty QBarSeries. |
|
121 | Constructs empty QBarSeries. | |
111 | QBarSeries is QObject which is a child of a \a parent. |
|
122 | QBarSeries is QObject which is a child of a \a parent. | |
112 | */ |
|
123 | */ | |
113 | QBarSeries::QBarSeries(QObject *parent) : |
|
124 | QBarSeries::QBarSeries(QObject *parent) : | |
114 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) |
|
125 | QAbstractSeries(*new QBarSeriesPrivate(this),parent) | |
115 | { |
|
126 | { | |
116 | } |
|
127 | } | |
117 |
|
128 | |||
118 | /*! |
|
129 | /*! | |
119 | Destructs barseries and owned barsets. |
|
130 | Destructs barseries and owned barsets. | |
120 | */ |
|
131 | */ | |
121 | QBarSeries::~QBarSeries() |
|
132 | QBarSeries::~QBarSeries() | |
122 | { |
|
133 | { | |
123 | Q_D(QBarSeries); |
|
134 | Q_D(QBarSeries); | |
124 | if(d->m_dataset){ |
|
135 | if(d->m_dataset){ | |
125 | d->m_dataset->removeSeries(this); |
|
136 | d->m_dataset->removeSeries(this); | |
126 | } |
|
137 | } | |
127 | } |
|
138 | } | |
128 |
|
139 | |||
129 | /*! |
|
140 | /*! | |
130 | \internal |
|
141 | \internal | |
131 | */ |
|
142 | */ | |
132 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : |
|
143 | QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) : | |
133 | QAbstractSeries(d,parent) |
|
144 | QAbstractSeries(d,parent) | |
134 | { |
|
145 | { | |
135 | } |
|
146 | } | |
136 |
|
147 | |||
137 | /*! |
|
148 | /*! | |
138 | Returns the type of series. Derived classes override this. |
|
149 | Returns the type of series. Derived classes override this. | |
139 | */ |
|
150 | */ | |
140 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
151 | QAbstractSeries::SeriesType QBarSeries::type() const | |
141 | { |
|
152 | { | |
142 | return QAbstractSeries::SeriesTypeBar; |
|
153 | return QAbstractSeries::SeriesTypeBar; | |
143 | } |
|
154 | } | |
144 |
|
155 | |||
145 | /*! |
|
156 | /*! | |
146 | 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 |
|
157 | 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 | |
147 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
158 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
148 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
159 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
149 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. This is |
|
160 | Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. This is | |
150 | because with grouped series it is more logical to set widht of whole group and let the chart calculate correct |
|
161 | because with grouped series it is more logical to set widht of whole group and let the chart calculate correct | |
151 | width for bar. |
|
162 | width for bar. | |
152 | \sa QGroupedBarSeries |
|
163 | \sa QGroupedBarSeries | |
153 | */ |
|
164 | */ | |
154 | void QBarSeries::setBarWidth(qreal width) |
|
165 | void QBarSeries::setBarWidth(qreal width) | |
155 | { |
|
166 | { | |
156 | Q_D(QBarSeries); |
|
167 | Q_D(QBarSeries); | |
157 | d->setBarWidth(width); |
|
168 | d->setBarWidth(width); | |
158 | emit barWidthChanged(); |
|
169 | emit barWidthChanged(); | |
159 | } |
|
170 | } | |
160 |
|
171 | |||
161 | /*! |
|
172 | /*! | |
162 | Returns the width of bars. |
|
173 | Returns the width of bars. | |
163 | */ |
|
174 | */ | |
164 | qreal QBarSeries::barWidth() const |
|
175 | qreal QBarSeries::barWidth() const | |
165 | { |
|
176 | { | |
166 | Q_D(const QBarSeries); |
|
177 | Q_D(const QBarSeries); | |
167 | return d->barWidth(); |
|
178 | return d->barWidth(); | |
168 | } |
|
179 | } | |
169 |
|
180 | |||
170 | /*! |
|
181 | /*! | |
171 | 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. |
|
182 | 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. | |
172 | Returns true, if appending succeeded. |
|
183 | Returns true, if appending succeeded. | |
173 |
|
184 | |||
174 | */ |
|
185 | */ | |
175 | bool QBarSeries::append(QBarSet *set) |
|
186 | bool QBarSeries::append(QBarSet *set) | |
176 | { |
|
187 | { | |
177 | Q_D(QBarSeries); |
|
188 | Q_D(QBarSeries); | |
178 | bool success = d->append(set); |
|
189 | bool success = d->append(set); | |
179 | if (success) { |
|
190 | if (success) { | |
180 | QList<QBarSet*> sets; |
|
191 | QList<QBarSet*> sets; | |
181 | sets.append(set); |
|
192 | sets.append(set); | |
182 | emit barsetsAdded(sets); |
|
193 | emit barsetsAdded(sets); | |
183 | emit barsetCountChanged(); |
|
194 | emit barsetCountChanged(); | |
184 | } |
|
195 | } | |
185 | return success; |
|
196 | return success; | |
186 | } |
|
197 | } | |
187 |
|
198 | |||
188 | /*! |
|
199 | /*! | |
189 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
200 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
190 | Returns true, if set was removed. |
|
201 | Returns true, if set was removed. | |
191 | */ |
|
202 | */ | |
192 | bool QBarSeries::remove(QBarSet *set) |
|
203 | bool QBarSeries::remove(QBarSet *set) | |
193 | { |
|
204 | { | |
194 | Q_D(QBarSeries); |
|
205 | Q_D(QBarSeries); | |
195 | bool success = d->remove(set); |
|
206 | bool success = d->remove(set); | |
196 | if (success) { |
|
207 | if (success) { | |
197 | QList<QBarSet*> sets; |
|
208 | QList<QBarSet*> sets; | |
198 | sets.append(set); |
|
209 | sets.append(set); | |
199 | emit barsetsRemoved(sets); |
|
210 | emit barsetsRemoved(sets); | |
200 | emit barsetCountChanged(); |
|
211 | emit barsetCountChanged(); | |
201 | } |
|
212 | } | |
202 | return success; |
|
213 | return success; | |
203 | } |
|
214 | } | |
204 |
|
215 | |||
205 | /*! |
|
216 | /*! | |
206 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
217 | Adds a list of barsets to series. Takes ownership of \a sets. | |
207 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
218 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
208 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
219 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
209 | and function returns false. |
|
220 | and function returns false. | |
210 | */ |
|
221 | */ | |
211 | bool QBarSeries::append(QList<QBarSet* > sets) |
|
222 | bool QBarSeries::append(QList<QBarSet* > sets) | |
212 | { |
|
223 | { | |
213 | Q_D(QBarSeries); |
|
224 | Q_D(QBarSeries); | |
214 | bool success = d->append(sets); |
|
225 | bool success = d->append(sets); | |
215 | if (success) { |
|
226 | if (success) { | |
216 | emit barsetsAdded(sets); |
|
227 | emit barsetsAdded(sets); | |
217 | emit barsetCountChanged(); |
|
228 | emit barsetCountChanged(); | |
218 | } |
|
229 | } | |
219 | return success; |
|
230 | return success; | |
220 | } |
|
231 | } | |
221 |
|
232 | |||
222 | /*! |
|
233 | /*! | |
223 | 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. |
|
234 | 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. | |
224 | Returns true, if inserting succeeded. |
|
235 | Returns true, if inserting succeeded. | |
225 |
|
236 | |||
226 | */ |
|
237 | */ | |
227 | bool QBarSeries::insert(int index, QBarSet *set) |
|
238 | bool QBarSeries::insert(int index, QBarSet *set) | |
228 | { |
|
239 | { | |
229 | Q_D(QBarSeries); |
|
240 | Q_D(QBarSeries); | |
230 | bool success = d->insert(index, set); |
|
241 | bool success = d->insert(index, set); | |
231 | if (success) { |
|
242 | if (success) { | |
232 | QList<QBarSet*> sets; |
|
243 | QList<QBarSet*> sets; | |
233 | sets.append(set); |
|
244 | sets.append(set); | |
234 | emit barsetsAdded(sets); |
|
245 | emit barsetsAdded(sets); | |
235 | emit barsetCountChanged(); |
|
246 | emit barsetCountChanged(); | |
236 | } |
|
247 | } | |
237 | return success; |
|
248 | return success; | |
238 | } |
|
249 | } | |
239 |
|
250 | |||
240 | /*! |
|
251 | /*! | |
241 | Removes all of the bar sets from the series |
|
252 | Removes all of the bar sets from the series | |
242 | */ |
|
253 | */ | |
243 | void QBarSeries::clear() |
|
254 | void QBarSeries::clear() | |
244 | { |
|
255 | { | |
245 | Q_D(QBarSeries); |
|
256 | Q_D(QBarSeries); | |
246 | QList<QBarSet *> sets = barSets(); |
|
257 | QList<QBarSet *> sets = barSets(); | |
247 | bool success = d->remove(sets); |
|
258 | bool success = d->remove(sets); | |
248 | if (success) { |
|
259 | if (success) { | |
249 | emit barsetsRemoved(sets); |
|
260 | emit barsetsRemoved(sets); | |
250 | emit barsetCountChanged(); |
|
261 | emit barsetCountChanged(); | |
251 | } |
|
262 | } | |
252 | } |
|
263 | } | |
253 |
|
264 | |||
254 | /*! |
|
265 | /*! | |
255 | Returns number of sets in series. |
|
266 | Returns number of sets in series. | |
256 | */ |
|
267 | */ | |
257 | int QBarSeries::barsetCount() const |
|
268 | int QBarSeries::barsetCount() const | |
258 | { |
|
269 | { | |
259 | Q_D(const QBarSeries); |
|
270 | Q_D(const QBarSeries); | |
260 | return d->m_barSets.count(); |
|
271 | return d->m_barSets.count(); | |
261 | } |
|
272 | } | |
262 |
|
273 | |||
263 | /*! |
|
274 | /*! | |
264 | Returns a list of sets in series. Keeps ownership of sets. |
|
275 | Returns a list of sets in series. Keeps ownership of sets. | |
265 | */ |
|
276 | */ | |
266 | QList<QBarSet*> QBarSeries::barSets() const |
|
277 | QList<QBarSet*> QBarSeries::barSets() const | |
267 | { |
|
278 | { | |
268 | Q_D(const QBarSeries); |
|
279 | Q_D(const QBarSeries); | |
269 | return d->m_barSets; |
|
280 | return d->m_barSets; | |
270 | } |
|
281 | } | |
271 |
|
282 | |||
272 | /*! |
|
283 | /*! | |
273 | Sets the visibility of labels in series to \a visible |
|
284 | Sets the visibility of labels in series to \a visible | |
274 | */ |
|
285 | */ | |
275 | void QBarSeries::setLabelsVisible(bool visible) |
|
286 | void QBarSeries::setLabelsVisible(bool visible) | |
276 | { |
|
287 | { | |
277 | Q_D(QBarSeries); |
|
288 | Q_D(QBarSeries); | |
278 | if (d->m_labelsVisible != visible) { |
|
289 | if (d->m_labelsVisible != visible) { | |
279 | d->setLabelsVisible(visible); |
|
290 | d->setLabelsVisible(visible); | |
280 | emit labelsVisibleChanged(); |
|
291 | emit labelsVisibleChanged(); | |
281 | } |
|
292 | } | |
282 | } |
|
293 | } | |
283 |
|
294 | |||
284 | /*! |
|
295 | /*! | |
285 | Returns the visibility of labels |
|
296 | Returns the visibility of labels | |
286 | */ |
|
297 | */ | |
287 | bool QBarSeries::isLabelsVisible() const |
|
298 | bool QBarSeries::isLabelsVisible() const | |
288 | { |
|
299 | { | |
289 | Q_D(const QBarSeries); |
|
300 | Q_D(const QBarSeries); | |
290 | return d->m_labelsVisible; |
|
301 | return d->m_labelsVisible; | |
291 | } |
|
302 | } | |
292 |
|
303 | |||
293 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
304 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
294 |
|
305 | |||
295 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : |
|
306 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : | |
296 | QAbstractSeriesPrivate(q), |
|
307 | QAbstractSeriesPrivate(q), | |
297 | m_barWidth(0.5), // Default value is 50% of category width |
|
308 | m_barWidth(0.5), // Default value is 50% of category width | |
298 | m_labelsVisible(false), |
|
309 | m_labelsVisible(false), | |
299 | m_visible(true) |
|
310 | m_visible(true) | |
300 | { |
|
311 | { | |
301 | } |
|
312 | } | |
302 |
|
313 | |||
303 | void QBarSeriesPrivate::setCategories(QStringList categories) |
|
314 | void QBarSeriesPrivate::setCategories(QStringList categories) | |
304 | { |
|
315 | { | |
305 | m_categories = categories; |
|
316 | m_categories = categories; | |
306 | } |
|
317 | } | |
307 |
|
318 | |||
308 | void QBarSeriesPrivate::insertCategory(int index, const QString category) |
|
319 | void QBarSeriesPrivate::insertCategory(int index, const QString category) | |
309 | { |
|
320 | { | |
310 | m_categories.insert(index, category); |
|
321 | m_categories.insert(index, category); | |
311 | emit categoriesUpdated(); |
|
322 | emit categoriesUpdated(); | |
312 | } |
|
323 | } | |
313 |
|
324 | |||
314 | void QBarSeriesPrivate::removeCategory(int index) |
|
325 | void QBarSeriesPrivate::removeCategory(int index) | |
315 | { |
|
326 | { | |
316 | m_categories.removeAt(index); |
|
327 | m_categories.removeAt(index); | |
317 | emit categoriesUpdated(); |
|
328 | emit categoriesUpdated(); | |
318 | } |
|
329 | } | |
319 |
|
330 | |||
320 | int QBarSeriesPrivate::categoryCount() const |
|
331 | int QBarSeriesPrivate::categoryCount() const | |
321 | { |
|
332 | { | |
322 | if (m_categories.count() > 0) { |
|
333 | if (m_categories.count() > 0) { | |
323 | return m_categories.count(); |
|
334 | return m_categories.count(); | |
324 | } |
|
335 | } | |
325 |
|
336 | |||
326 | // No categories defined. return count of longest set. |
|
337 | // No categories defined. return count of longest set. | |
327 | int count = 0; |
|
338 | int count = 0; | |
328 | for (int i=0; i<m_barSets.count(); i++) { |
|
339 | for (int i=0; i<m_barSets.count(); i++) { | |
329 | if (m_barSets.at(i)->count() > count) { |
|
340 | if (m_barSets.at(i)->count() > count) { | |
330 | count = m_barSets.at(i)->count(); |
|
341 | count = m_barSets.at(i)->count(); | |
331 | } |
|
342 | } | |
332 | } |
|
343 | } | |
333 |
|
344 | |||
334 | return count; |
|
345 | return count; | |
335 | } |
|
346 | } | |
336 |
|
347 | |||
337 | QStringList QBarSeriesPrivate::categories() const |
|
348 | QStringList QBarSeriesPrivate::categories() const | |
338 | { |
|
349 | { | |
339 | if (m_categories.count() > 0) { |
|
350 | if (m_categories.count() > 0) { | |
340 | return m_categories; |
|
351 | return m_categories; | |
341 | } |
|
352 | } | |
342 |
|
353 | |||
343 | // No categories defined. retun list of indices. |
|
354 | // No categories defined. retun list of indices. | |
344 | QStringList categories; |
|
355 | QStringList categories; | |
345 |
|
356 | |||
346 | int count = categoryCount(); |
|
357 | int count = categoryCount(); | |
347 | for (int i = 0; i < count; i++) { |
|
358 | for (int i = 0; i < count; i++) { | |
348 | categories.append(QString::number(i)); |
|
359 | categories.append(QString::number(i)); | |
349 | } |
|
360 | } | |
350 | return categories; |
|
361 | return categories; | |
351 | } |
|
362 | } | |
352 |
|
363 | |||
353 | void QBarSeriesPrivate::setBarWidth(qreal width) |
|
364 | void QBarSeriesPrivate::setBarWidth(qreal width) | |
354 | { |
|
365 | { | |
355 | if (width < 0.0) { |
|
366 | if (width < 0.0) { | |
356 | width = 0.0; |
|
367 | width = 0.0; | |
357 | } |
|
368 | } | |
358 | m_barWidth = width; |
|
369 | m_barWidth = width; | |
359 | emit updatedBars(); |
|
370 | emit updatedBars(); | |
360 | } |
|
371 | } | |
361 |
|
372 | |||
362 | qreal QBarSeriesPrivate::barWidth() const |
|
373 | qreal QBarSeriesPrivate::barWidth() const | |
363 | { |
|
374 | { | |
364 | return m_barWidth; |
|
375 | return m_barWidth; | |
365 | } |
|
376 | } | |
366 |
|
377 | |||
367 | QBarSet* QBarSeriesPrivate::barsetAt(int index) |
|
378 | QBarSet* QBarSeriesPrivate::barsetAt(int index) | |
368 | { |
|
379 | { | |
369 | return m_barSets.at(index); |
|
380 | return m_barSets.at(index); | |
370 | } |
|
381 | } | |
371 |
|
382 | |||
372 | void QBarSeriesPrivate::setVisible(bool visible) |
|
383 | void QBarSeriesPrivate::setVisible(bool visible) | |
373 | { |
|
384 | { | |
374 | m_visible = visible; |
|
385 | m_visible = visible; | |
375 | emit updatedBars(); |
|
386 | emit updatedBars(); | |
376 | } |
|
387 | } | |
377 |
|
388 | |||
378 | void QBarSeriesPrivate::setLabelsVisible(bool visible) |
|
389 | void QBarSeriesPrivate::setLabelsVisible(bool visible) | |
379 | { |
|
390 | { | |
380 | m_labelsVisible = visible; |
|
391 | m_labelsVisible = visible; | |
381 | emit labelsVisibleChanged(visible); |
|
392 | emit labelsVisibleChanged(visible); | |
382 | } |
|
393 | } | |
383 |
|
394 | |||
384 | QString QBarSeriesPrivate::categoryName(int category) |
|
395 | QString QBarSeriesPrivate::categoryName(int category) | |
385 | { |
|
396 | { | |
386 | if ((category >= 0) && (category < m_categories.count())) { |
|
397 | if ((category >= 0) && (category < m_categories.count())) { | |
387 | return m_categories.at(category); |
|
398 | return m_categories.at(category); | |
388 | } |
|
399 | } | |
389 |
|
400 | |||
390 | return QString::number(category); |
|
401 | return QString::number(category); | |
391 | } |
|
402 | } | |
392 |
|
403 | |||
393 | qreal QBarSeriesPrivate::min() |
|
404 | qreal QBarSeriesPrivate::min() | |
394 | { |
|
405 | { | |
395 | if (m_barSets.count() <= 0) { |
|
406 | if (m_barSets.count() <= 0) { | |
396 | return 0; |
|
407 | return 0; | |
397 | } |
|
408 | } | |
398 | qreal min = INT_MAX; |
|
409 | qreal min = INT_MAX; | |
399 |
|
410 | |||
400 | for (int i = 0; i < m_barSets.count(); i++) { |
|
411 | for (int i = 0; i < m_barSets.count(); i++) { | |
401 | int categoryCount = m_barSets.at(i)->count(); |
|
412 | int categoryCount = m_barSets.at(i)->count(); | |
402 | for (int j = 0; j < categoryCount; j++) { |
|
413 | for (int j = 0; j < categoryCount; j++) { | |
403 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
414 | qreal temp = m_barSets.at(i)->at(j).y(); | |
404 | if (temp < min) |
|
415 | if (temp < min) | |
405 | min = temp; |
|
416 | min = temp; | |
406 | } |
|
417 | } | |
407 | } |
|
418 | } | |
408 | return min; |
|
419 | return min; | |
409 | } |
|
420 | } | |
410 |
|
421 | |||
411 | qreal QBarSeriesPrivate::max() |
|
422 | qreal QBarSeriesPrivate::max() | |
412 | { |
|
423 | { | |
413 | if (m_barSets.count() <= 0) { |
|
424 | if (m_barSets.count() <= 0) { | |
414 | return 0; |
|
425 | return 0; | |
415 | } |
|
426 | } | |
416 | qreal max = INT_MIN; |
|
427 | qreal max = INT_MIN; | |
417 |
|
428 | |||
418 | for (int i = 0; i < m_barSets.count(); i++) { |
|
429 | for (int i = 0; i < m_barSets.count(); i++) { | |
419 | int categoryCount = m_barSets.at(i)->count(); |
|
430 | int categoryCount = m_barSets.at(i)->count(); | |
420 | for (int j = 0; j < categoryCount; j++) { |
|
431 | for (int j = 0; j < categoryCount; j++) { | |
421 | qreal temp = m_barSets.at(i)->at(j).y(); |
|
432 | qreal temp = m_barSets.at(i)->at(j).y(); | |
422 | if (temp > max) |
|
433 | if (temp > max) | |
423 | max = temp; |
|
434 | max = temp; | |
424 | } |
|
435 | } | |
425 | } |
|
436 | } | |
426 |
|
437 | |||
427 | return max; |
|
438 | return max; | |
428 | } |
|
439 | } | |
429 |
|
440 | |||
430 | qreal QBarSeriesPrivate::valueAt(int set, int category) |
|
441 | qreal QBarSeriesPrivate::valueAt(int set, int category) | |
431 | { |
|
442 | { | |
432 | if ((set < 0) || (set >= m_barSets.count())) { |
|
443 | if ((set < 0) || (set >= m_barSets.count())) { | |
433 | // No set, no value. |
|
444 | // No set, no value. | |
434 | return 0; |
|
445 | return 0; | |
435 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
446 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
436 | // No category, no value. |
|
447 | // No category, no value. | |
437 | return 0; |
|
448 | return 0; | |
438 | } |
|
449 | } | |
439 |
|
450 | |||
440 | return m_barSets.at(set)->at(category).y(); |
|
451 | return m_barSets.at(set)->at(category).y(); | |
441 | } |
|
452 | } | |
442 |
|
453 | |||
443 | qreal QBarSeriesPrivate::percentageAt(int set, int category) |
|
454 | qreal QBarSeriesPrivate::percentageAt(int set, int category) | |
444 | { |
|
455 | { | |
445 | if ((set < 0) || (set >= m_barSets.count())) { |
|
456 | if ((set < 0) || (set >= m_barSets.count())) { | |
446 | // No set, no value. |
|
457 | // No set, no value. | |
447 | return 0; |
|
458 | return 0; | |
448 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
459 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
449 | // No category, no value. |
|
460 | // No category, no value. | |
450 | return 0; |
|
461 | return 0; | |
451 | } |
|
462 | } | |
452 |
|
463 | |||
453 | qreal value = m_barSets.at(set)->at(category).y(); |
|
464 | qreal value = m_barSets.at(set)->at(category).y(); | |
454 | qreal sum = categorySum(category); |
|
465 | qreal sum = categorySum(category); | |
455 | if ( qFuzzyIsNull(sum) ) { |
|
466 | if ( qFuzzyIsNull(sum) ) { | |
456 | return 0; |
|
467 | return 0; | |
457 | } |
|
468 | } | |
458 |
|
469 | |||
459 | return value / sum; |
|
470 | return value / sum; | |
460 | } |
|
471 | } | |
461 |
|
472 | |||
462 | qreal QBarSeriesPrivate::categorySum(int category) |
|
473 | qreal QBarSeriesPrivate::categorySum(int category) | |
463 | { |
|
474 | { | |
464 | qreal sum(0); |
|
475 | qreal sum(0); | |
465 | int count = m_barSets.count(); // Count sets |
|
476 | int count = m_barSets.count(); // Count sets | |
466 | for (int set = 0; set < count; set++) { |
|
477 | for (int set = 0; set < count; set++) { | |
467 | if (category < m_barSets.at(set)->count()) |
|
478 | if (category < m_barSets.at(set)->count()) | |
468 | sum += m_barSets.at(set)->at(category).y(); |
|
479 | sum += m_barSets.at(set)->at(category).y(); | |
469 | } |
|
480 | } | |
470 | return sum; |
|
481 | return sum; | |
471 | } |
|
482 | } | |
472 |
|
483 | |||
473 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) |
|
484 | qreal QBarSeriesPrivate::absoluteCategorySum(int category) | |
474 | { |
|
485 | { | |
475 | qreal sum(0); |
|
486 | qreal sum(0); | |
476 | int count = m_barSets.count(); // Count sets |
|
487 | int count = m_barSets.count(); // Count sets | |
477 | for (int set = 0; set < count; set++) { |
|
488 | for (int set = 0; set < count; set++) { | |
478 | if (category < m_barSets.at(set)->count()) |
|
489 | if (category < m_barSets.at(set)->count()) | |
479 | sum += qAbs(m_barSets.at(set)->at(category).y()); |
|
490 | sum += qAbs(m_barSets.at(set)->at(category).y()); | |
480 | } |
|
491 | } | |
481 | return sum; |
|
492 | return sum; | |
482 | } |
|
493 | } | |
483 |
|
494 | |||
484 | qreal QBarSeriesPrivate::maxCategorySum() |
|
495 | qreal QBarSeriesPrivate::maxCategorySum() | |
485 | { |
|
496 | { | |
486 | qreal max = INT_MIN; |
|
497 | qreal max = INT_MIN; | |
487 | int count = categoryCount(); |
|
498 | int count = categoryCount(); | |
488 | for (int i = 0; i < count; i++) { |
|
499 | for (int i = 0; i < count; i++) { | |
489 | qreal sum = categorySum(i); |
|
500 | qreal sum = categorySum(i); | |
490 | if (sum > max) |
|
501 | if (sum > max) | |
491 | max = sum; |
|
502 | max = sum; | |
492 | } |
|
503 | } | |
493 | return max; |
|
504 | return max; | |
494 | } |
|
505 | } | |
495 |
|
506 | |||
496 | qreal QBarSeriesPrivate::minX() |
|
507 | qreal QBarSeriesPrivate::minX() | |
497 | { |
|
508 | { | |
498 | if (m_barSets.count() <= 0) { |
|
509 | if (m_barSets.count() <= 0) { | |
499 | return 0; |
|
510 | return 0; | |
500 | } |
|
511 | } | |
501 | qreal min = INT_MAX; |
|
512 | qreal min = INT_MAX; | |
502 |
|
513 | |||
503 | for (int i = 0; i < m_barSets.count(); i++) { |
|
514 | for (int i = 0; i < m_barSets.count(); i++) { | |
504 | int categoryCount = m_barSets.at(i)->count(); |
|
515 | int categoryCount = m_barSets.at(i)->count(); | |
505 | for (int j = 0; j < categoryCount; j++) { |
|
516 | for (int j = 0; j < categoryCount; j++) { | |
506 | qreal temp = m_barSets.at(i)->at(j).x(); |
|
517 | qreal temp = m_barSets.at(i)->at(j).x(); | |
507 | if (temp < min) |
|
518 | if (temp < min) | |
508 | min = temp; |
|
519 | min = temp; | |
509 | } |
|
520 | } | |
510 | } |
|
521 | } | |
511 | return min; |
|
522 | return min; | |
512 | } |
|
523 | } | |
513 |
|
524 | |||
514 | qreal QBarSeriesPrivate::maxX() |
|
525 | qreal QBarSeriesPrivate::maxX() | |
515 | { |
|
526 | { | |
516 | if (m_barSets.count() <= 0) { |
|
527 | if (m_barSets.count() <= 0) { | |
517 | return 0; |
|
528 | return 0; | |
518 | } |
|
529 | } | |
519 | qreal max = INT_MIN; |
|
530 | qreal max = INT_MIN; | |
520 |
|
531 | |||
521 | for (int i = 0; i < m_barSets.count(); i++) { |
|
532 | for (int i = 0; i < m_barSets.count(); i++) { | |
522 | int categoryCount = m_barSets.at(i)->count(); |
|
533 | int categoryCount = m_barSets.at(i)->count(); | |
523 | for (int j = 0; j < categoryCount; j++) { |
|
534 | for (int j = 0; j < categoryCount; j++) { | |
524 | qreal temp = m_barSets.at(i)->at(j).x(); |
|
535 | qreal temp = m_barSets.at(i)->at(j).x(); | |
525 | if (temp > max) |
|
536 | if (temp > max) | |
526 | max = temp; |
|
537 | max = temp; | |
527 | } |
|
538 | } | |
528 | } |
|
539 | } | |
529 |
|
540 | |||
530 | return max; |
|
541 | return max; | |
531 | } |
|
542 | } | |
532 |
|
543 | |||
533 |
|
544 | |||
534 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
545 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
535 | { |
|
546 | { | |
536 | qreal minX(domain.minX()); |
|
547 | qreal minX(domain.minX()); | |
537 | qreal minY(domain.minY()); |
|
548 | qreal minY(domain.minY()); | |
538 | qreal maxX(domain.maxX()); |
|
549 | qreal maxX(domain.maxX()); | |
539 | qreal maxY(domain.maxY()); |
|
550 | qreal maxY(domain.maxY()); | |
540 | int tickXCount(domain.tickXCount()); |
|
551 | int tickXCount(domain.tickXCount()); | |
541 | int tickYCount(domain.tickYCount()); |
|
552 | int tickYCount(domain.tickYCount()); | |
542 |
|
553 | |||
543 | qreal seriesMinX = this->minX(); |
|
554 | qreal seriesMinX = this->minX(); | |
544 | qreal seriesMaxX = this->maxX(); |
|
555 | qreal seriesMaxX = this->maxX(); | |
545 | qreal y = max(); |
|
556 | qreal y = max(); | |
546 | minX = qMin(minX, seriesMinX - 0.5); |
|
557 | minX = qMin(minX, seriesMinX - 0.5); | |
547 | minY = qMin(minY, y); |
|
558 | minY = qMin(minY, y); | |
548 | maxX = qMax(maxX, seriesMaxX + 0.5); |
|
559 | maxX = qMax(maxX, seriesMaxX + 0.5); | |
549 | maxY = qMax(maxY, y); |
|
560 | maxY = qMax(maxY, y); | |
550 | tickXCount = categoryCount()+1; |
|
561 | tickXCount = categoryCount()+1; | |
551 |
|
562 | |||
552 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); |
|
563 | domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount); | |
553 | } |
|
564 | } | |
554 |
|
565 | |||
555 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
566 | Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
556 | { |
|
567 | { | |
557 | Q_Q(QBarSeries); |
|
568 | Q_Q(QBarSeries); | |
558 |
|
569 | |||
559 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
570 | BarChartItem* bar = new BarChartItem(q,presenter); | |
560 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
571 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
561 | presenter->animator()->addAnimation(bar); |
|
572 | presenter->animator()->addAnimation(bar); | |
562 | } |
|
573 | } | |
563 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
574 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
564 | return bar; |
|
575 | return bar; | |
565 |
|
576 | |||
566 | } |
|
577 | } | |
567 |
|
578 | |||
568 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
579 | QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
569 | { |
|
580 | { | |
570 | Q_Q(QBarSeries); |
|
581 | Q_Q(QBarSeries); | |
571 | QList<LegendMarker*> markers; |
|
582 | QList<LegendMarker*> markers; | |
572 | foreach(QBarSet* set, q->barSets()) { |
|
583 | foreach(QBarSet* set, q->barSets()) { | |
573 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
584 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
574 | markers << marker; |
|
585 | markers << marker; | |
575 | } |
|
586 | } | |
576 |
|
587 | |||
577 | return markers; |
|
588 | return markers; | |
578 | } |
|
589 | } | |
579 |
|
590 | |||
580 | bool QBarSeriesPrivate::append(QBarSet *set) |
|
591 | bool QBarSeriesPrivate::append(QBarSet *set) | |
581 | { |
|
592 | { | |
582 | Q_Q(QBarSeries); |
|
593 | Q_Q(QBarSeries); | |
583 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
594 | if ((m_barSets.contains(set)) || (set == 0)) { | |
584 | // Fail if set is already in list or set is null. |
|
595 | // Fail if set is already in list or set is null. | |
585 | return false; |
|
596 | return false; | |
586 | } |
|
597 | } | |
587 | m_barSets.append(set); |
|
598 | m_barSets.append(set); | |
588 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
599 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
589 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
600 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
590 | emit restructuredBars(); // this notifies barchartitem |
|
601 | emit restructuredBars(); // this notifies barchartitem | |
591 | if (m_dataset) { |
|
602 | if (m_dataset) { | |
592 | m_dataset->updateSeries(q); // this notifies legend |
|
603 | m_dataset->updateSeries(q); // this notifies legend | |
593 | } |
|
604 | } | |
594 | return true; |
|
605 | return true; | |
595 | } |
|
606 | } | |
596 |
|
607 | |||
597 | bool QBarSeriesPrivate::remove(QBarSet *set) |
|
608 | bool QBarSeriesPrivate::remove(QBarSet *set) | |
598 | { |
|
609 | { | |
599 | Q_Q(QBarSeries); |
|
610 | Q_Q(QBarSeries); | |
600 | if (!m_barSets.contains(set)) { |
|
611 | if (!m_barSets.contains(set)) { | |
601 | // Fail if set is not in list |
|
612 | // Fail if set is not in list | |
602 | return false; |
|
613 | return false; | |
603 | } |
|
614 | } | |
604 | m_barSets.removeOne(set); |
|
615 | m_barSets.removeOne(set); | |
605 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
616 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
606 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
617 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
607 | emit restructuredBars(); // this notifies barchartitem |
|
618 | emit restructuredBars(); // this notifies barchartitem | |
608 | if (m_dataset) { |
|
619 | if (m_dataset) { | |
609 | m_dataset->updateSeries(q); // this notifies legend |
|
620 | m_dataset->updateSeries(q); // this notifies legend | |
610 | } |
|
621 | } | |
611 | return true; |
|
622 | return true; | |
612 | } |
|
623 | } | |
613 |
|
624 | |||
614 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
625 | bool QBarSeriesPrivate::append(QList<QBarSet* > sets) | |
615 | { |
|
626 | { | |
616 | Q_Q(QBarSeries); |
|
627 | Q_Q(QBarSeries); | |
617 | foreach (QBarSet* set, sets) { |
|
628 | foreach (QBarSet* set, sets) { | |
618 | if ((set == 0) || (m_barSets.contains(set))) { |
|
629 | if ((set == 0) || (m_barSets.contains(set))) { | |
619 | // Fail if any of the sets is null or is already appended. |
|
630 | // Fail if any of the sets is null or is already appended. | |
620 | return false; |
|
631 | return false; | |
621 | } |
|
632 | } | |
622 | if (sets.count(set) != 1) { |
|
633 | if (sets.count(set) != 1) { | |
623 | // Also fail if same set is more than once in given list. |
|
634 | // Also fail if same set is more than once in given list. | |
624 | return false; |
|
635 | return false; | |
625 | } |
|
636 | } | |
626 | } |
|
637 | } | |
627 |
|
638 | |||
628 | foreach (QBarSet* set, sets) { |
|
639 | foreach (QBarSet* set, sets) { | |
629 | m_barSets.append(set); |
|
640 | m_barSets.append(set); | |
630 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
641 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
631 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
642 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
632 | } |
|
643 | } | |
633 | emit restructuredBars(); // this notifies barchartitem |
|
644 | emit restructuredBars(); // this notifies barchartitem | |
634 | if (m_dataset) { |
|
645 | if (m_dataset) { | |
635 | m_dataset->updateSeries(q); // this notifies legend |
|
646 | m_dataset->updateSeries(q); // this notifies legend | |
636 | } |
|
647 | } | |
637 | return true; |
|
648 | return true; | |
638 | } |
|
649 | } | |
639 |
|
650 | |||
640 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
651 | bool QBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
641 | { |
|
652 | { | |
642 | Q_Q(QBarSeries); |
|
653 | Q_Q(QBarSeries); | |
643 | if (sets.count() == 0) { |
|
654 | if (sets.count() == 0) { | |
644 | return false; |
|
655 | return false; | |
645 | } |
|
656 | } | |
646 | foreach (QBarSet* set, sets) { |
|
657 | foreach (QBarSet* set, sets) { | |
647 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
658 | if ((set == 0) || (!m_barSets.contains(set))) { | |
648 | // Fail if any of the sets is null or is not in series |
|
659 | // Fail if any of the sets is null or is not in series | |
649 | return false; |
|
660 | return false; | |
650 | } |
|
661 | } | |
651 | if (sets.count(set) != 1) { |
|
662 | if (sets.count(set) != 1) { | |
652 | // Also fail if same set is more than once in given list. |
|
663 | // Also fail if same set is more than once in given list. | |
653 | return false; |
|
664 | return false; | |
654 | } |
|
665 | } | |
655 | } |
|
666 | } | |
656 |
|
667 | |||
657 | foreach (QBarSet* set, sets) { |
|
668 | foreach (QBarSet* set, sets) { | |
658 | m_barSets.removeOne(set); |
|
669 | m_barSets.removeOne(set); | |
659 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
670 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
660 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
671 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
661 | } |
|
672 | } | |
662 |
|
673 | |||
663 | emit restructuredBars(); // this notifies barchartitem |
|
674 | emit restructuredBars(); // this notifies barchartitem | |
664 | if (m_dataset) { |
|
675 | if (m_dataset) { | |
665 | m_dataset->updateSeries(q); // this notifies legend |
|
676 | m_dataset->updateSeries(q); // this notifies legend | |
666 | } |
|
677 | } | |
667 | return true; |
|
678 | return true; | |
668 | } |
|
679 | } | |
669 |
|
680 | |||
670 | bool QBarSeriesPrivate::insert(int index, QBarSet *set) |
|
681 | bool QBarSeriesPrivate::insert(int index, QBarSet *set) | |
671 | { |
|
682 | { | |
672 | Q_Q(QBarSeries); |
|
683 | Q_Q(QBarSeries); | |
673 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
684 | if ((m_barSets.contains(set)) || (set == 0)) { | |
674 | // Fail if set is already in list or set is null. |
|
685 | // Fail if set is already in list or set is null. | |
675 | return false; |
|
686 | return false; | |
676 | } |
|
687 | } | |
677 | m_barSets.insert(index, set); |
|
688 | m_barSets.insert(index, set); | |
678 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
689 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
679 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
690 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
680 | emit restructuredBars(); // this notifies barchartitem |
|
691 | emit restructuredBars(); // this notifies barchartitem | |
681 | if (m_dataset) { |
|
692 | if (m_dataset) { | |
682 | m_dataset->updateSeries(q); // this notifies legend |
|
693 | m_dataset->updateSeries(q); // this notifies legend | |
683 | } |
|
694 | } | |
684 | return true; |
|
695 | return true; | |
685 | } |
|
696 | } | |
686 |
|
697 | |||
687 | #include "moc_qbarseries.cpp" |
|
698 | #include "moc_qbarseries.cpp" | |
688 | #include "moc_qbarseries_p.cpp" |
|
699 | #include "moc_qbarseries_p.cpp" | |
689 |
|
700 | |||
690 | QTCOMMERCIALCHART_END_NAMESPACE |
|
701 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now