@@ -1,782 +1,784 | |||||
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 "qabstractbarseries.h" |
|
21 | #include "qabstractbarseries.h" | |
22 | #include "qabstractbarseries_p.h" |
|
22 | #include "qabstractbarseries_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 "qvaluesaxis.h" |
|
29 | #include "qvaluesaxis.h" | |
30 | #include "qbarcategoriesaxis.h" |
|
30 | #include "qbarcategoriesaxis.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | /*! |
|
34 | /*! | |
35 | \class QAbstractBarSeries |
|
35 | \class QAbstractBarSeries | |
36 | \brief Series for creating a bar chart |
|
36 | \brief Series for creating a bar chart | |
37 | \mainclass |
|
37 | \mainclass | |
38 |
|
38 | |||
39 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
39 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
40 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
40 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
41 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
41 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
42 | shows the x-values. |
|
42 | shows the x-values. | |
43 |
|
43 | |||
44 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
44 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
45 | \image examples_barchart.png |
|
45 | \image examples_barchart.png | |
46 |
|
46 | |||
47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
47 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
48 | */ |
|
48 | */ | |
49 | /*! |
|
49 | /*! | |
50 | \qmlclass AbstractBarSeries QAbstractBarSeries |
|
50 | \qmlclass AbstractBarSeries QAbstractBarSeries | |
51 | \inherits QAbstractSeries |
|
51 | \inherits QAbstractSeries | |
52 |
|
52 | |||
53 | The following QML shows how to create a simple bar chart: |
|
53 | The following QML shows how to create a simple bar chart: | |
54 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
54 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
55 |
|
55 | |||
56 | \beginfloatleft |
|
56 | \beginfloatleft | |
57 | \image demos_qmlchart6.png |
|
57 | \image demos_qmlchart6.png | |
58 | \endfloat |
|
58 | \endfloat | |
59 | \clearfloat |
|
59 | \clearfloat | |
60 | */ |
|
60 | */ | |
61 |
|
61 | |||
62 | /*! |
|
62 | /*! | |
63 | \property QAbstractBarSeries::barWidth |
|
63 | \property QAbstractBarSeries::barWidth | |
64 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
64 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
65 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
65 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
66 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
66 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
67 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
67 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
68 | \sa QBarSeries |
|
68 | \sa QBarSeries | |
69 | */ |
|
69 | */ | |
70 | /*! |
|
70 | /*! | |
71 | \qmlproperty real AbstractBarSeries::barWidth |
|
71 | \qmlproperty real AbstractBarSeries::barWidth | |
72 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
72 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars | |
73 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
73 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
74 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
74 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
75 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
75 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \property QAbstractBarSeries::count |
|
79 | \property QAbstractBarSeries::count | |
80 | Holds the number of sets in series. |
|
80 | Holds the number of sets in series. | |
81 | */ |
|
81 | */ | |
82 | /*! |
|
82 | /*! | |
83 | \qmlproperty int AbstractBarSeries::count |
|
83 | \qmlproperty int AbstractBarSeries::count | |
84 | Holds the number of sets in series. |
|
84 | Holds the number of sets in series. | |
85 | */ |
|
85 | */ | |
86 |
|
86 | |||
87 | /*! |
|
87 | /*! | |
88 | \property QAbstractBarSeries::labelsVisible |
|
88 | \property QAbstractBarSeries::labelsVisible | |
89 | Defines the visibility of the labels in series |
|
89 | Defines the visibility of the labels in series | |
90 | */ |
|
90 | */ | |
91 | /*! |
|
91 | /*! | |
92 | \qmlproperty bool AbstractBarSeries::labelsVisible |
|
92 | \qmlproperty bool AbstractBarSeries::labelsVisible | |
93 | Defines the visibility of the labels in series |
|
93 | Defines the visibility of the labels in series | |
94 | */ |
|
94 | */ | |
95 |
|
95 | |||
96 | /*! |
|
96 | /*! | |
97 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
97 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) | |
98 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
98 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
99 | Clicked bar inside set is indexed by \a index |
|
99 | Clicked bar inside set is indexed by \a index | |
100 | */ |
|
100 | */ | |
101 | /*! |
|
101 | /*! | |
102 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) |
|
102 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) | |
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 QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
108 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) | |
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 AbstractBarSeries::onHovered(bool status, BarSet barset) |
|
115 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) | |
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 QAbstractBarSeries::countChanged() |
|
123 | \fn void QAbstractBarSeries::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 AbstractBarSeries::onCountChanged() |
|
127 | \qmlsignal AbstractBarSeries::onCountChanged() | |
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 QAbstractBarSeries::labelsVisibleChanged() |
|
132 | \fn void QAbstractBarSeries::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 QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
138 | \fn void QAbstractBarSeries::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 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) |
|
143 | \qmlsignal AbstractBarSeries::onAdded(BarSet barset) | |
144 | Emitted when \a barset has been added to the series. |
|
144 | Emitted when \a barset has been added to the series. | |
145 | */ |
|
145 | */ | |
146 |
|
146 | |||
147 | /*! |
|
147 | /*! | |
148 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
148 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
149 | This signal is emitted when \a sets have been removed from the series. |
|
149 | This signal is emitted when \a sets have been removed from the series. | |
150 | \sa remove() |
|
150 | \sa remove() | |
151 | */ |
|
151 | */ | |
152 | /*! |
|
152 | /*! | |
153 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) |
|
153 | \qmlsignal AbstractBarSeries::onRemoved(BarSet barset) | |
154 | Emitted when \a barset has been removed from the series. |
|
154 | Emitted when \a barset has been removed from the series. | |
155 | */ |
|
155 | */ | |
156 |
|
156 | |||
157 | /*! |
|
157 | /*! | |
158 | \qmlmethod BarSet AbstractBarSeries::at(int index) |
|
158 | \qmlmethod BarSet AbstractBarSeries::at(int index) | |
159 | Returns bar set at \a index. Returns null if the index is not valid. |
|
159 | Returns bar set at \a index. Returns null if the index is not valid. | |
160 | */ |
|
160 | */ | |
161 |
|
161 | |||
162 | /*! |
|
162 | /*! | |
163 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) |
|
163 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) | |
164 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
164 | Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
165 | For example: |
|
165 | For example: | |
166 | \code |
|
166 | \code | |
167 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
167 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); | |
168 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); |
|
168 | myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]); | |
169 | \endcode |
|
169 | \endcode | |
170 | */ |
|
170 | */ | |
171 |
|
171 | |||
172 | /*! |
|
172 | /*! | |
173 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) |
|
173 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) | |
174 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. |
|
174 | Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints. | |
175 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
175 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is | |
176 | appended. |
|
176 | appended. | |
177 | \sa AbstractBarSeries::append() |
|
177 | \sa AbstractBarSeries::append() | |
178 | */ |
|
178 | */ | |
179 |
|
179 | |||
180 | /*! |
|
180 | /*! | |
181 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) |
|
181 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) | |
182 | Removes the barset from the series. Returns true if successfull, false otherwise. |
|
182 | Removes the barset from the series. Returns true if successfull, false otherwise. | |
183 | */ |
|
183 | */ | |
184 |
|
184 | |||
185 | /*! |
|
185 | /*! | |
186 | \qmlmethod AbstractBarSeries::clear() |
|
186 | \qmlmethod AbstractBarSeries::clear() | |
187 | Removes all barsets from the series. |
|
187 | Removes all barsets from the series. | |
188 | */ |
|
188 | */ | |
189 |
|
189 | |||
190 | /*! |
|
190 | /*! | |
191 | This is depreciated constructor. |
|
191 | This is depreciated constructor. | |
192 | */ |
|
192 | */ | |
193 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : |
|
193 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : | |
194 | QAbstractSeries(*(QAbstractBarSeriesPrivate*)(0),parent) |
|
194 | QAbstractSeries(*(QAbstractBarSeriesPrivate*)(0),parent) | |
195 | { |
|
195 | { | |
196 | } |
|
196 | } | |
197 |
|
197 | |||
198 | /*! |
|
198 | /*! | |
199 | Destructs abstractbarseries and owned barsets. |
|
199 | Destructs abstractbarseries and owned barsets. | |
200 | */ |
|
200 | */ | |
201 | QAbstractBarSeries::~QAbstractBarSeries() |
|
201 | QAbstractBarSeries::~QAbstractBarSeries() | |
202 | { |
|
202 | { | |
203 |
|
203 | |||
204 | } |
|
204 | } | |
205 |
|
205 | |||
206 | /*! |
|
206 | /*! | |
207 | \internal |
|
207 | \internal | |
208 | */ |
|
208 | */ | |
209 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
209 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : | |
210 | QAbstractSeries(d,parent) |
|
210 | QAbstractSeries(d,parent) | |
211 | { |
|
211 | { | |
212 | } |
|
212 | } | |
213 |
|
213 | |||
214 | /*! |
|
214 | /*! | |
215 | 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 |
|
215 | 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 | |
216 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
216 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
217 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
217 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
218 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
218 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
219 | */ |
|
219 | */ | |
220 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
220 | void QAbstractBarSeries::setBarWidth(qreal width) | |
221 | { |
|
221 | { | |
222 | Q_D(QAbstractBarSeries); |
|
222 | Q_D(QAbstractBarSeries); | |
223 | d->setBarWidth(width); |
|
223 | d->setBarWidth(width); | |
224 | } |
|
224 | } | |
225 |
|
225 | |||
226 | /*! |
|
226 | /*! | |
227 | Returns the width of the bars of the series. |
|
227 | Returns the width of the bars of the series. | |
228 | \sa setBarWidth() |
|
228 | \sa setBarWidth() | |
229 | */ |
|
229 | */ | |
230 | qreal QAbstractBarSeries::barWidth() const |
|
230 | qreal QAbstractBarSeries::barWidth() const | |
231 | { |
|
231 | { | |
232 | Q_D(const QAbstractBarSeries); |
|
232 | Q_D(const QAbstractBarSeries); | |
233 | return d->barWidth(); |
|
233 | return d->barWidth(); | |
234 | } |
|
234 | } | |
235 |
|
235 | |||
236 | /*! |
|
236 | /*! | |
237 | 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. |
|
237 | 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. | |
238 | Returns true, if appending succeeded. |
|
238 | Returns true, if appending succeeded. | |
239 | */ |
|
239 | */ | |
240 | bool QAbstractBarSeries::append(QBarSet *set) |
|
240 | bool QAbstractBarSeries::append(QBarSet *set) | |
241 | { |
|
241 | { | |
242 | Q_D(QAbstractBarSeries); |
|
242 | Q_D(QAbstractBarSeries); | |
243 | bool success = d->append(set); |
|
243 | bool success = d->append(set); | |
244 | if (success) { |
|
244 | if (success) { | |
245 | QList<QBarSet*> sets; |
|
245 | QList<QBarSet*> sets; | |
246 | sets.append(set); |
|
246 | sets.append(set); | |
|
247 | set->setParent(this); | |||
247 | emit barsetsAdded(sets); |
|
248 | emit barsetsAdded(sets); | |
248 | emit countChanged(); |
|
249 | emit countChanged(); | |
249 | } |
|
250 | } | |
250 | return success; |
|
251 | return success; | |
251 | } |
|
252 | } | |
252 |
|
253 | |||
253 | /*! |
|
254 | /*! | |
254 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. |
|
255 | Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set. | |
255 | Returns true, if set was removed. |
|
256 | Returns true, if set was removed. | |
256 | */ |
|
257 | */ | |
257 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
258 | bool QAbstractBarSeries::remove(QBarSet *set) | |
258 | { |
|
259 | { | |
259 | Q_D(QAbstractBarSeries); |
|
260 | Q_D(QAbstractBarSeries); | |
260 | bool success = d->remove(set); |
|
261 | bool success = d->remove(set); | |
261 | if (success) { |
|
262 | if (success) { | |
262 | QList<QBarSet*> sets; |
|
263 | QList<QBarSet*> sets; | |
263 | sets.append(set); |
|
264 | sets.append(set); | |
|
265 | set->setParent(0); | |||
264 | emit barsetsRemoved(sets); |
|
266 | emit barsetsRemoved(sets); | |
265 | emit countChanged(); |
|
267 | emit countChanged(); | |
266 | } |
|
268 | } | |
267 | return success; |
|
269 | return success; | |
268 | } |
|
270 | } | |
269 |
|
271 | |||
270 | /*! |
|
272 | /*! | |
271 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
273 | Adds a list of barsets to series. Takes ownership of \a sets. | |
272 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
274 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
273 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
275 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
274 | and function returns false. |
|
276 | and function returns false. | |
275 | */ |
|
277 | */ | |
276 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
278 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) | |
277 | { |
|
279 | { | |
278 | Q_D(QAbstractBarSeries); |
|
280 | Q_D(QAbstractBarSeries); | |
279 | bool success = d->append(sets); |
|
281 | bool success = d->append(sets); | |
280 | if (success) { |
|
282 | if (success) { | |
281 | emit barsetsAdded(sets); |
|
283 | emit barsetsAdded(sets); | |
282 | emit countChanged(); |
|
284 | emit countChanged(); | |
283 | } |
|
285 | } | |
284 | return success; |
|
286 | return success; | |
285 | } |
|
287 | } | |
286 |
|
288 | |||
287 | /*! |
|
289 | /*! | |
288 | 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. |
|
290 | 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. | |
289 | Returns true, if inserting succeeded. |
|
291 | Returns true, if inserting succeeded. | |
290 |
|
292 | |||
291 | */ |
|
293 | */ | |
292 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
294 | bool QAbstractBarSeries::insert(int index, QBarSet *set) | |
293 | { |
|
295 | { | |
294 | Q_D(QAbstractBarSeries); |
|
296 | Q_D(QAbstractBarSeries); | |
295 | bool success = d->insert(index, set); |
|
297 | bool success = d->insert(index, set); | |
296 | if (success) { |
|
298 | if (success) { | |
297 | QList<QBarSet*> sets; |
|
299 | QList<QBarSet*> sets; | |
298 | sets.append(set); |
|
300 | sets.append(set); | |
299 | emit barsetsAdded(sets); |
|
301 | emit barsetsAdded(sets); | |
300 | emit countChanged(); |
|
302 | emit countChanged(); | |
301 | } |
|
303 | } | |
302 | return success; |
|
304 | return success; | |
303 | } |
|
305 | } | |
304 |
|
306 | |||
305 | /*! |
|
307 | /*! | |
306 | Removes all of the bar sets from the series |
|
308 | Removes all of the bar sets from the series | |
307 | */ |
|
309 | */ | |
308 | void QAbstractBarSeries::clear() |
|
310 | void QAbstractBarSeries::clear() | |
309 | { |
|
311 | { | |
310 | Q_D(QAbstractBarSeries); |
|
312 | Q_D(QAbstractBarSeries); | |
311 | QList<QBarSet *> sets = barSets(); |
|
313 | QList<QBarSet *> sets = barSets(); | |
312 | bool success = d->remove(sets); |
|
314 | bool success = d->remove(sets); | |
313 | if (success) { |
|
315 | if (success) { | |
314 | emit barsetsRemoved(sets); |
|
316 | emit barsetsRemoved(sets); | |
315 | emit countChanged(); |
|
317 | emit countChanged(); | |
316 | } |
|
318 | } | |
317 | } |
|
319 | } | |
318 |
|
320 | |||
319 | /*! |
|
321 | /*! | |
320 | Returns number of sets in series. |
|
322 | Returns number of sets in series. | |
321 | */ |
|
323 | */ | |
322 | int QAbstractBarSeries::count() const |
|
324 | int QAbstractBarSeries::count() const | |
323 | { |
|
325 | { | |
324 | Q_D(const QAbstractBarSeries); |
|
326 | Q_D(const QAbstractBarSeries); | |
325 | return d->m_barSets.count(); |
|
327 | return d->m_barSets.count(); | |
326 | } |
|
328 | } | |
327 |
|
329 | |||
328 | /*! |
|
330 | /*! | |
329 | Returns a list of sets in series. Keeps ownership of sets. |
|
331 | Returns a list of sets in series. Keeps ownership of sets. | |
330 | */ |
|
332 | */ | |
331 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
333 | QList<QBarSet*> QAbstractBarSeries::barSets() const | |
332 | { |
|
334 | { | |
333 | Q_D(const QAbstractBarSeries); |
|
335 | Q_D(const QAbstractBarSeries); | |
334 | return d->m_barSets; |
|
336 | return d->m_barSets; | |
335 | } |
|
337 | } | |
336 |
|
338 | |||
337 | /*! |
|
339 | /*! | |
338 | Sets the visibility of labels in series to \a visible |
|
340 | Sets the visibility of labels in series to \a visible | |
339 | */ |
|
341 | */ | |
340 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
342 | void QAbstractBarSeries::setLabelsVisible(bool visible) | |
341 | { |
|
343 | { | |
342 | Q_D(QAbstractBarSeries); |
|
344 | Q_D(QAbstractBarSeries); | |
343 | if (d->m_labelsVisible != visible) { |
|
345 | if (d->m_labelsVisible != visible) { | |
344 | d->setLabelsVisible(visible); |
|
346 | d->setLabelsVisible(visible); | |
345 | emit labelsVisibleChanged(); |
|
347 | emit labelsVisibleChanged(); | |
346 | } |
|
348 | } | |
347 | } |
|
349 | } | |
348 |
|
350 | |||
349 | /*! |
|
351 | /*! | |
350 | Returns the visibility of labels |
|
352 | Returns the visibility of labels | |
351 | */ |
|
353 | */ | |
352 | bool QAbstractBarSeries::isLabelsVisible() const |
|
354 | bool QAbstractBarSeries::isLabelsVisible() const | |
353 | { |
|
355 | { | |
354 | Q_D(const QAbstractBarSeries); |
|
356 | Q_D(const QAbstractBarSeries); | |
355 | return d->m_labelsVisible; |
|
357 | return d->m_labelsVisible; | |
356 | } |
|
358 | } | |
357 |
|
359 | |||
358 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
360 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
359 |
|
361 | |||
360 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
362 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : | |
361 | QAbstractSeriesPrivate(q), |
|
363 | QAbstractSeriesPrivate(q), | |
362 | m_barWidth(0.5), // Default value is 50% of category width |
|
364 | m_barWidth(0.5), // Default value is 50% of category width | |
363 | m_labelsVisible(false), |
|
365 | m_labelsVisible(false), | |
364 | m_visible(true) |
|
366 | m_visible(true) | |
365 | { |
|
367 | { | |
366 | } |
|
368 | } | |
367 |
|
369 | |||
368 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
370 | int QAbstractBarSeriesPrivate::categoryCount() const | |
369 | { |
|
371 | { | |
370 | // No categories defined. return count of longest set. |
|
372 | // No categories defined. return count of longest set. | |
371 | int count = 0; |
|
373 | int count = 0; | |
372 | for (int i=0; i<m_barSets.count(); i++) { |
|
374 | for (int i=0; i<m_barSets.count(); i++) { | |
373 | if (m_barSets.at(i)->count() > count) { |
|
375 | if (m_barSets.at(i)->count() > count) { | |
374 | count = m_barSets.at(i)->count(); |
|
376 | count = m_barSets.at(i)->count(); | |
375 | } |
|
377 | } | |
376 | } |
|
378 | } | |
377 |
|
379 | |||
378 | return count; |
|
380 | return count; | |
379 | } |
|
381 | } | |
380 |
|
382 | |||
381 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
383 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) | |
382 | { |
|
384 | { | |
383 | if (width < 0.0) { |
|
385 | if (width < 0.0) { | |
384 | width = 0.0; |
|
386 | width = 0.0; | |
385 | } |
|
387 | } | |
386 | m_barWidth = width; |
|
388 | m_barWidth = width; | |
387 | emit updatedBars(); |
|
389 | emit updatedBars(); | |
388 | } |
|
390 | } | |
389 |
|
391 | |||
390 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
392 | qreal QAbstractBarSeriesPrivate::barWidth() const | |
391 | { |
|
393 | { | |
392 | return m_barWidth; |
|
394 | return m_barWidth; | |
393 | } |
|
395 | } | |
394 |
|
396 | |||
395 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
397 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) | |
396 | { |
|
398 | { | |
397 | return m_barSets.at(index); |
|
399 | return m_barSets.at(index); | |
398 | } |
|
400 | } | |
399 |
|
401 | |||
400 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
402 | void QAbstractBarSeriesPrivate::setVisible(bool visible) | |
401 | { |
|
403 | { | |
402 | m_visible = visible; |
|
404 | m_visible = visible; | |
403 | emit updatedBars(); |
|
405 | emit updatedBars(); | |
404 | } |
|
406 | } | |
405 |
|
407 | |||
406 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
408 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) | |
407 | { |
|
409 | { | |
408 | m_labelsVisible = visible; |
|
410 | m_labelsVisible = visible; | |
409 | emit labelsVisibleChanged(visible); |
|
411 | emit labelsVisibleChanged(visible); | |
410 | } |
|
412 | } | |
411 |
|
413 | |||
412 | qreal QAbstractBarSeriesPrivate::min() |
|
414 | qreal QAbstractBarSeriesPrivate::min() | |
413 | { |
|
415 | { | |
414 | if (m_barSets.count() <= 0) { |
|
416 | if (m_barSets.count() <= 0) { | |
415 | return 0; |
|
417 | return 0; | |
416 | } |
|
418 | } | |
417 | qreal min = INT_MAX; |
|
419 | qreal min = INT_MAX; | |
418 |
|
420 | |||
419 | for (int i = 0; i < m_barSets.count(); i++) { |
|
421 | for (int i = 0; i < m_barSets.count(); i++) { | |
420 | int categoryCount = m_barSets.at(i)->count(); |
|
422 | int categoryCount = m_barSets.at(i)->count(); | |
421 | for (int j = 0; j < categoryCount; j++) { |
|
423 | for (int j = 0; j < categoryCount; j++) { | |
422 | qreal temp = m_barSets.at(i)->at(j); |
|
424 | qreal temp = m_barSets.at(i)->at(j); | |
423 | if (temp < min) |
|
425 | if (temp < min) | |
424 | min = temp; |
|
426 | min = temp; | |
425 | } |
|
427 | } | |
426 | } |
|
428 | } | |
427 | return min; |
|
429 | return min; | |
428 | } |
|
430 | } | |
429 |
|
431 | |||
430 | qreal QAbstractBarSeriesPrivate::max() |
|
432 | qreal QAbstractBarSeriesPrivate::max() | |
431 | { |
|
433 | { | |
432 | if (m_barSets.count() <= 0) { |
|
434 | if (m_barSets.count() <= 0) { | |
433 | return 0; |
|
435 | return 0; | |
434 | } |
|
436 | } | |
435 | qreal max = INT_MIN; |
|
437 | qreal max = INT_MIN; | |
436 |
|
438 | |||
437 | for (int i = 0; i < m_barSets.count(); i++) { |
|
439 | for (int i = 0; i < m_barSets.count(); i++) { | |
438 | int categoryCount = m_barSets.at(i)->count(); |
|
440 | int categoryCount = m_barSets.at(i)->count(); | |
439 | for (int j = 0; j < categoryCount; j++) { |
|
441 | for (int j = 0; j < categoryCount; j++) { | |
440 | qreal temp = m_barSets.at(i)->at(j); |
|
442 | qreal temp = m_barSets.at(i)->at(j); | |
441 | if (temp > max) |
|
443 | if (temp > max) | |
442 | max = temp; |
|
444 | max = temp; | |
443 | } |
|
445 | } | |
444 | } |
|
446 | } | |
445 |
|
447 | |||
446 | return max; |
|
448 | return max; | |
447 | } |
|
449 | } | |
448 |
|
450 | |||
449 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
451 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) | |
450 | { |
|
452 | { | |
451 | if ((set < 0) || (set >= m_barSets.count())) { |
|
453 | if ((set < 0) || (set >= m_barSets.count())) { | |
452 | // No set, no value. |
|
454 | // No set, no value. | |
453 | return 0; |
|
455 | return 0; | |
454 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
456 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
455 | // No category, no value. |
|
457 | // No category, no value. | |
456 | return 0; |
|
458 | return 0; | |
457 | } |
|
459 | } | |
458 |
|
460 | |||
459 | return m_barSets.at(set)->at(category); |
|
461 | return m_barSets.at(set)->at(category); | |
460 | } |
|
462 | } | |
461 |
|
463 | |||
462 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
464 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) | |
463 | { |
|
465 | { | |
464 | if ((set < 0) || (set >= m_barSets.count())) { |
|
466 | if ((set < 0) || (set >= m_barSets.count())) { | |
465 | // No set, no value. |
|
467 | // No set, no value. | |
466 | return 0; |
|
468 | return 0; | |
467 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
469 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
468 | // No category, no value. |
|
470 | // No category, no value. | |
469 | return 0; |
|
471 | return 0; | |
470 | } |
|
472 | } | |
471 |
|
473 | |||
472 | qreal value = m_barSets.at(set)->at(category); |
|
474 | qreal value = m_barSets.at(set)->at(category); | |
473 | qreal sum = categorySum(category); |
|
475 | qreal sum = categorySum(category); | |
474 | if ( qFuzzyIsNull(sum) ) { |
|
476 | if ( qFuzzyIsNull(sum) ) { | |
475 | return 0; |
|
477 | return 0; | |
476 | } |
|
478 | } | |
477 |
|
479 | |||
478 | return value / sum; |
|
480 | return value / sum; | |
479 | } |
|
481 | } | |
480 |
|
482 | |||
481 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
483 | qreal QAbstractBarSeriesPrivate::categorySum(int category) | |
482 | { |
|
484 | { | |
483 | qreal sum(0); |
|
485 | qreal sum(0); | |
484 | int count = m_barSets.count(); // Count sets |
|
486 | int count = m_barSets.count(); // Count sets | |
485 | for (int set = 0; set < count; set++) { |
|
487 | for (int set = 0; set < count; set++) { | |
486 | if (category < m_barSets.at(set)->count()) |
|
488 | if (category < m_barSets.at(set)->count()) | |
487 | sum += m_barSets.at(set)->at(category); |
|
489 | sum += m_barSets.at(set)->at(category); | |
488 | } |
|
490 | } | |
489 | return sum; |
|
491 | return sum; | |
490 | } |
|
492 | } | |
491 |
|
493 | |||
492 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
494 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) | |
493 | { |
|
495 | { | |
494 | qreal sum(0); |
|
496 | qreal sum(0); | |
495 | int count = m_barSets.count(); // Count sets |
|
497 | int count = m_barSets.count(); // Count sets | |
496 | for (int set = 0; set < count; set++) { |
|
498 | for (int set = 0; set < count; set++) { | |
497 | if (category < m_barSets.at(set)->count()) |
|
499 | if (category < m_barSets.at(set)->count()) | |
498 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
500 | sum += qAbs(m_barSets.at(set)->at(category)); | |
499 | } |
|
501 | } | |
500 | return sum; |
|
502 | return sum; | |
501 | } |
|
503 | } | |
502 |
|
504 | |||
503 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
505 | qreal QAbstractBarSeriesPrivate::maxCategorySum() | |
504 | { |
|
506 | { | |
505 | qreal max = INT_MIN; |
|
507 | qreal max = INT_MIN; | |
506 | int count = categoryCount(); |
|
508 | int count = categoryCount(); | |
507 | for (int i = 0; i < count; i++) { |
|
509 | for (int i = 0; i < count; i++) { | |
508 | qreal sum = categorySum(i); |
|
510 | qreal sum = categorySum(i); | |
509 | if (sum > max) |
|
511 | if (sum > max) | |
510 | max = sum; |
|
512 | max = sum; | |
511 | } |
|
513 | } | |
512 | return max; |
|
514 | return max; | |
513 | } |
|
515 | } | |
514 |
|
516 | |||
515 | qreal QAbstractBarSeriesPrivate::minX() |
|
517 | qreal QAbstractBarSeriesPrivate::minX() | |
516 | { |
|
518 | { | |
517 | if (m_barSets.count() <= 0) { |
|
519 | if (m_barSets.count() <= 0) { | |
518 | return 0; |
|
520 | return 0; | |
519 | } |
|
521 | } | |
520 | qreal min = INT_MAX; |
|
522 | qreal min = INT_MAX; | |
521 |
|
523 | |||
522 | for (int i = 0; i < m_barSets.count(); i++) { |
|
524 | for (int i = 0; i < m_barSets.count(); i++) { | |
523 | int categoryCount = m_barSets.at(i)->count(); |
|
525 | int categoryCount = m_barSets.at(i)->count(); | |
524 | for (int j = 0; j < categoryCount; j++) { |
|
526 | for (int j = 0; j < categoryCount; j++) { | |
525 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
527 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
526 | if (temp < min) |
|
528 | if (temp < min) | |
527 | min = temp; |
|
529 | min = temp; | |
528 | } |
|
530 | } | |
529 | } |
|
531 | } | |
530 | return min; |
|
532 | return min; | |
531 | } |
|
533 | } | |
532 |
|
534 | |||
533 | qreal QAbstractBarSeriesPrivate::maxX() |
|
535 | qreal QAbstractBarSeriesPrivate::maxX() | |
534 | { |
|
536 | { | |
535 | if (m_barSets.count() <= 0) { |
|
537 | if (m_barSets.count() <= 0) { | |
536 | return 0; |
|
538 | return 0; | |
537 | } |
|
539 | } | |
538 | qreal max = INT_MIN; |
|
540 | qreal max = INT_MIN; | |
539 |
|
541 | |||
540 | for (int i = 0; i < m_barSets.count(); i++) { |
|
542 | for (int i = 0; i < m_barSets.count(); i++) { | |
541 | int categoryCount = m_barSets.at(i)->count(); |
|
543 | int categoryCount = m_barSets.at(i)->count(); | |
542 | for (int j = 0; j < categoryCount; j++) { |
|
544 | for (int j = 0; j < categoryCount; j++) { | |
543 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
545 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
544 | if (temp > max) |
|
546 | if (temp > max) | |
545 | max = temp; |
|
547 | max = temp; | |
546 | } |
|
548 | } | |
547 | } |
|
549 | } | |
548 |
|
550 | |||
549 | return max; |
|
551 | return max; | |
550 | } |
|
552 | } | |
551 |
|
553 | |||
552 |
|
554 | |||
553 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
555 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) | |
554 | { |
|
556 | { | |
555 | qreal minX(domain.minX()); |
|
557 | qreal minX(domain.minX()); | |
556 | qreal minY(domain.minY()); |
|
558 | qreal minY(domain.minY()); | |
557 | qreal maxX(domain.maxX()); |
|
559 | qreal maxX(domain.maxX()); | |
558 | qreal maxY(domain.maxY()); |
|
560 | qreal maxY(domain.maxY()); | |
559 |
|
561 | |||
560 | qreal seriesMinX = this->minX(); |
|
562 | qreal seriesMinX = this->minX(); | |
561 | qreal seriesMaxX = this->maxX(); |
|
563 | qreal seriesMaxX = this->maxX(); | |
562 | qreal y = max(); |
|
564 | qreal y = max(); | |
563 | minX = qMin(minX, seriesMinX - (qreal)0.5); |
|
565 | minX = qMin(minX, seriesMinX - (qreal)0.5); | |
564 | minY = qMin(minY, y); |
|
566 | minY = qMin(minY, y); | |
565 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); |
|
567 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); | |
566 | maxY = qMax(maxY, y); |
|
568 | maxY = qMax(maxY, y); | |
567 |
|
569 | |||
568 | domain.setRange(minX,maxX,minY,maxY); |
|
570 | domain.setRange(minX,maxX,minY,maxY); | |
569 | } |
|
571 | } | |
570 |
|
572 | |||
571 | ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
573 | ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
572 | { |
|
574 | { | |
573 | Q_UNUSED(presenter); |
|
575 | Q_UNUSED(presenter); | |
574 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; |
|
576 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; | |
575 | return 0; |
|
577 | return 0; | |
576 | } |
|
578 | } | |
577 |
|
579 | |||
578 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
580 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
579 | { |
|
581 | { | |
580 | Q_Q(QAbstractBarSeries); |
|
582 | Q_Q(QAbstractBarSeries); | |
581 | QList<LegendMarker*> markers; |
|
583 | QList<LegendMarker*> markers; | |
582 | foreach(QBarSet* set, q->barSets()) { |
|
584 | foreach(QBarSet* set, q->barSets()) { | |
583 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
585 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
584 | markers << marker; |
|
586 | markers << marker; | |
585 | } |
|
587 | } | |
586 |
|
588 | |||
587 | return markers; |
|
589 | return markers; | |
588 | } |
|
590 | } | |
589 |
|
591 | |||
590 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
592 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) | |
591 | { |
|
593 | { | |
592 | Q_Q(QAbstractBarSeries); |
|
594 | Q_Q(QAbstractBarSeries); | |
593 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
595 | if ((m_barSets.contains(set)) || (set == 0)) { | |
594 | // Fail if set is already in list or set is null. |
|
596 | // Fail if set is already in list or set is null. | |
595 | return false; |
|
597 | return false; | |
596 | } |
|
598 | } | |
597 | m_barSets.append(set); |
|
599 | m_barSets.append(set); | |
598 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
600 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
599 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
601 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
600 | emit restructuredBars(); // this notifies barchartitem |
|
602 | emit restructuredBars(); // this notifies barchartitem | |
601 | if (m_dataset) { |
|
603 | if (m_dataset) { | |
602 | m_dataset->updateSeries(q); // this notifies legend |
|
604 | m_dataset->updateSeries(q); // this notifies legend | |
603 | } |
|
605 | } | |
604 | return true; |
|
606 | return true; | |
605 | } |
|
607 | } | |
606 |
|
608 | |||
607 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
609 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) | |
608 | { |
|
610 | { | |
609 | Q_Q(QAbstractBarSeries); |
|
611 | Q_Q(QAbstractBarSeries); | |
610 | if (!m_barSets.contains(set)) { |
|
612 | if (!m_barSets.contains(set)) { | |
611 | // Fail if set is not in list |
|
613 | // Fail if set is not in list | |
612 | return false; |
|
614 | return false; | |
613 | } |
|
615 | } | |
614 | m_barSets.removeOne(set); |
|
616 | m_barSets.removeOne(set); | |
615 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
617 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
616 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
618 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
617 | emit restructuredBars(); // this notifies barchartitem |
|
619 | emit restructuredBars(); // this notifies barchartitem | |
618 | if (m_dataset) { |
|
620 | if (m_dataset) { | |
619 | m_dataset->updateSeries(q); // this notifies legend |
|
621 | m_dataset->updateSeries(q); // this notifies legend | |
620 | } |
|
622 | } | |
621 | return true; |
|
623 | return true; | |
622 | } |
|
624 | } | |
623 |
|
625 | |||
624 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
626 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) | |
625 | { |
|
627 | { | |
626 | Q_Q(QAbstractBarSeries); |
|
628 | Q_Q(QAbstractBarSeries); | |
627 | foreach (QBarSet* set, sets) { |
|
629 | foreach (QBarSet* set, sets) { | |
628 | if ((set == 0) || (m_barSets.contains(set))) { |
|
630 | if ((set == 0) || (m_barSets.contains(set))) { | |
629 | // Fail if any of the sets is null or is already appended. |
|
631 | // Fail if any of the sets is null or is already appended. | |
630 | return false; |
|
632 | return false; | |
631 | } |
|
633 | } | |
632 | if (sets.count(set) != 1) { |
|
634 | if (sets.count(set) != 1) { | |
633 | // Also fail if same set is more than once in given list. |
|
635 | // Also fail if same set is more than once in given list. | |
634 | return false; |
|
636 | return false; | |
635 | } |
|
637 | } | |
636 | } |
|
638 | } | |
637 |
|
639 | |||
638 | foreach (QBarSet* set, sets) { |
|
640 | foreach (QBarSet* set, sets) { | |
639 | m_barSets.append(set); |
|
641 | m_barSets.append(set); | |
640 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
642 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
641 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
643 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
642 | } |
|
644 | } | |
643 | emit restructuredBars(); // this notifies barchartitem |
|
645 | emit restructuredBars(); // this notifies barchartitem | |
644 | if (m_dataset) { |
|
646 | if (m_dataset) { | |
645 | m_dataset->updateSeries(q); // this notifies legend |
|
647 | m_dataset->updateSeries(q); // this notifies legend | |
646 | } |
|
648 | } | |
647 | return true; |
|
649 | return true; | |
648 | } |
|
650 | } | |
649 |
|
651 | |||
650 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
652 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
651 | { |
|
653 | { | |
652 | Q_Q(QAbstractBarSeries); |
|
654 | Q_Q(QAbstractBarSeries); | |
653 | if (sets.count() == 0) { |
|
655 | if (sets.count() == 0) { | |
654 | return false; |
|
656 | return false; | |
655 | } |
|
657 | } | |
656 | foreach (QBarSet* set, sets) { |
|
658 | foreach (QBarSet* set, sets) { | |
657 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
659 | if ((set == 0) || (!m_barSets.contains(set))) { | |
658 | // Fail if any of the sets is null or is not in series |
|
660 | // Fail if any of the sets is null or is not in series | |
659 | return false; |
|
661 | return false; | |
660 | } |
|
662 | } | |
661 | if (sets.count(set) != 1) { |
|
663 | if (sets.count(set) != 1) { | |
662 | // Also fail if same set is more than once in given list. |
|
664 | // Also fail if same set is more than once in given list. | |
663 | return false; |
|
665 | return false; | |
664 | } |
|
666 | } | |
665 | } |
|
667 | } | |
666 |
|
668 | |||
667 | foreach (QBarSet* set, sets) { |
|
669 | foreach (QBarSet* set, sets) { | |
668 | m_barSets.removeOne(set); |
|
670 | m_barSets.removeOne(set); | |
669 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
671 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
670 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
672 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
671 | } |
|
673 | } | |
672 |
|
674 | |||
673 | emit restructuredBars(); // this notifies barchartitem |
|
675 | emit restructuredBars(); // this notifies barchartitem | |
674 | if (m_dataset) { |
|
676 | if (m_dataset) { | |
675 | m_dataset->updateSeries(q); // this notifies legend |
|
677 | m_dataset->updateSeries(q); // this notifies legend | |
676 | } |
|
678 | } | |
677 | return true; |
|
679 | return true; | |
678 | } |
|
680 | } | |
679 |
|
681 | |||
680 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
682 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) | |
681 | { |
|
683 | { | |
682 | Q_Q(QAbstractBarSeries); |
|
684 | Q_Q(QAbstractBarSeries); | |
683 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
685 | if ((m_barSets.contains(set)) || (set == 0)) { | |
684 | // Fail if set is already in list or set is null. |
|
686 | // Fail if set is already in list or set is null. | |
685 | return false; |
|
687 | return false; | |
686 | } |
|
688 | } | |
687 | m_barSets.insert(index, set); |
|
689 | m_barSets.insert(index, set); | |
688 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
690 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
689 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
691 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
690 | emit restructuredBars(); // this notifies barchartitem |
|
692 | emit restructuredBars(); // this notifies barchartitem | |
691 | if (m_dataset) { |
|
693 | if (m_dataset) { | |
692 | m_dataset->updateSeries(q); // this notifies legend |
|
694 | m_dataset->updateSeries(q); // this notifies legend | |
693 | } |
|
695 | } | |
694 | return true; |
|
696 | return true; | |
695 | } |
|
697 | } | |
696 |
|
698 | |||
697 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) |
|
699 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) | |
698 | { |
|
700 | { | |
699 | Q_Q(QAbstractBarSeries); |
|
701 | Q_Q(QAbstractBarSeries); | |
700 |
|
702 | |||
701 | if(axis->type()==QAbstractAxis::AxisTypeCategories) { |
|
703 | if(axis->type()==QAbstractAxis::AxisTypeCategories) { | |
702 |
|
704 | |||
703 | switch(q->type()) { |
|
705 | switch(q->type()) { | |
704 |
|
706 | |||
705 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
707 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
706 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
708 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
707 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { |
|
709 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { | |
708 |
|
710 | |||
709 | if(axis->orientation()==Qt::Vertical) |
|
711 | if(axis->orientation()==Qt::Vertical) | |
710 | { |
|
712 | { | |
711 | populateCategories(qobject_cast<QBarCategoriesAxis*>(axis)); |
|
713 | populateCategories(qobject_cast<QBarCategoriesAxis*>(axis)); | |
712 | } |
|
714 | } | |
713 | break; |
|
715 | break; | |
714 | } |
|
716 | } | |
715 | case QAbstractSeries::SeriesTypeBar: |
|
717 | case QAbstractSeries::SeriesTypeBar: | |
716 | case QAbstractSeries::SeriesTypePercentBar: |
|
718 | case QAbstractSeries::SeriesTypePercentBar: | |
717 | case QAbstractSeries::SeriesTypeStackedBar: { |
|
719 | case QAbstractSeries::SeriesTypeStackedBar: { | |
718 |
|
720 | |||
719 | if(axis->orientation()==Qt::Horizontal) |
|
721 | if(axis->orientation()==Qt::Horizontal) | |
720 | { |
|
722 | { | |
721 | populateCategories(qobject_cast<QBarCategoriesAxis*>(axis)); |
|
723 | populateCategories(qobject_cast<QBarCategoriesAxis*>(axis)); | |
722 | } |
|
724 | } | |
723 | break; |
|
725 | break; | |
724 | } |
|
726 | } | |
725 | default: |
|
727 | default: | |
726 | qWarning()<<"Unexpected series type"; |
|
728 | qWarning()<<"Unexpected series type"; | |
727 | break; |
|
729 | break; | |
728 |
|
730 | |||
729 | } |
|
731 | } | |
730 | } |
|
732 | } | |
731 | } |
|
733 | } | |
732 |
|
734 | |||
733 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
735 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
734 | { |
|
736 | { | |
735 | Q_Q(const QAbstractBarSeries); |
|
737 | Q_Q(const QAbstractBarSeries); | |
736 |
|
738 | |||
737 | switch(q->type()) { |
|
739 | switch(q->type()) { | |
738 |
|
740 | |||
739 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
741 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
740 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
742 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
741 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { |
|
743 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { | |
742 |
|
744 | |||
743 | if(orientation==Qt::Vertical) |
|
745 | if(orientation==Qt::Vertical) | |
744 | { |
|
746 | { | |
745 | return QAbstractAxis::AxisTypeCategories; |
|
747 | return QAbstractAxis::AxisTypeCategories; | |
746 | } |
|
748 | } | |
747 | break; |
|
749 | break; | |
748 | } |
|
750 | } | |
749 | case QAbstractSeries::SeriesTypeBar: |
|
751 | case QAbstractSeries::SeriesTypeBar: | |
750 | case QAbstractSeries::SeriesTypePercentBar: |
|
752 | case QAbstractSeries::SeriesTypePercentBar: | |
751 | case QAbstractSeries::SeriesTypeStackedBar: { |
|
753 | case QAbstractSeries::SeriesTypeStackedBar: { | |
752 |
|
754 | |||
753 | if(orientation==Qt::Horizontal) |
|
755 | if(orientation==Qt::Horizontal) | |
754 | { |
|
756 | { | |
755 | return QAbstractAxis::AxisTypeCategories; |
|
757 | return QAbstractAxis::AxisTypeCategories; | |
756 | } |
|
758 | } | |
757 | break; |
|
759 | break; | |
758 | } |
|
760 | } | |
759 | default: |
|
761 | default: | |
760 | qWarning()<<"Unexpected series type"; |
|
762 | qWarning()<<"Unexpected series type"; | |
761 | break; |
|
763 | break; | |
762 |
|
764 | |||
763 | } |
|
765 | } | |
764 | return QAbstractAxis::AxisTypeValues; |
|
766 | return QAbstractAxis::AxisTypeValues; | |
765 |
|
767 | |||
766 | } |
|
768 | } | |
767 |
|
769 | |||
768 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoriesAxis* axis) |
|
770 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoriesAxis* axis) | |
769 | { |
|
771 | { | |
770 | QStringList categories; |
|
772 | QStringList categories; | |
771 | if(axis->categories().isEmpty()) { |
|
773 | if(axis->categories().isEmpty()) { | |
772 | for (int i(1); i < categoryCount()+1; i++) |
|
774 | for (int i(1); i < categoryCount()+1; i++) | |
773 | categories << QString::number(i); |
|
775 | categories << QString::number(i); | |
774 | axis->append(categories); |
|
776 | axis->append(categories); | |
775 | } |
|
777 | } | |
776 | } |
|
778 | } | |
777 |
|
779 | |||
778 | #include "moc_qabstractbarseries.cpp" |
|
780 | #include "moc_qabstractbarseries.cpp" | |
779 | #include "moc_qabstractbarseries_p.cpp" |
|
781 | #include "moc_qabstractbarseries_p.cpp" | |
780 |
|
782 | |||
781 |
|
783 | |||
782 | QTCOMMERCIALCHART_END_NAMESPACE |
|
784 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now