@@ -1,901 +1,903 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2013 Digia Plc |
|
3 | ** Copyright (C) 2013 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 "abstractdomain_p.h" |
|
25 | #include "abstractdomain_p.h" | |
26 | #include "chartdataset_p.h" |
|
26 | #include "chartdataset_p.h" | |
27 | #include "charttheme_p.h" |
|
27 | #include "charttheme_p.h" | |
28 | #include "qvalueaxis.h" |
|
28 | #include "qvalueaxis.h" | |
29 | #include "qbarcategoryaxis.h" |
|
29 | #include "qbarcategoryaxis.h" | |
30 | #include "qbarlegendmarker.h" |
|
30 | #include "qbarlegendmarker.h" | |
31 | #include "baranimation_p.h" |
|
31 | #include "baranimation_p.h" | |
32 | #include "abstractbarchartitem_p.h" |
|
32 | #include "abstractbarchartitem_p.h" | |
33 |
|
33 | |||
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
35 |
|
35 | |||
36 | /*! |
|
36 | /*! | |
37 | \class QAbstractBarSeries |
|
37 | \class QAbstractBarSeries | |
38 | \brief Series for creating a bar chart |
|
38 | \brief Series for creating a bar chart | |
39 | \mainclass |
|
39 | \mainclass | |
40 |
|
40 | |||
41 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to |
|
41 | QAbstractBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to | |
42 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar |
|
42 | the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar | |
43 | and y-value is the height of the bar. The category names are ignored with this series and x-axis |
|
43 | and y-value is the height of the bar. The category names are ignored with this series and x-axis | |
44 | shows the x-values. |
|
44 | shows the x-values. | |
45 |
|
45 | |||
46 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. |
|
46 | See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart. | |
47 | \image examples_barchart.png |
|
47 | \image examples_barchart.png | |
48 |
|
48 | |||
49 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries |
|
49 | \sa QBarSet, QStackedBarSeries, QPercentBarSeries | |
50 | */ |
|
50 | */ | |
51 | /*! |
|
51 | /*! | |
52 | \qmlclass AbstractBarSeries QAbstractBarSeries |
|
52 | \qmlclass AbstractBarSeries QAbstractBarSeries | |
53 | \inherits QAbstractSeries |
|
53 | \inherits QAbstractSeries | |
54 |
|
54 | |||
55 | The following QML shows how to create a simple bar chart: |
|
55 | The following QML shows how to create a simple bar chart: | |
56 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
56 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
57 |
|
57 | |||
58 | \beginfloatleft |
|
58 | \beginfloatleft | |
59 | \image demos_qmlchart6.png |
|
59 | \image demos_qmlchart6.png | |
60 | \endfloat |
|
60 | \endfloat | |
61 | \clearfloat |
|
61 | \clearfloat | |
62 | */ |
|
62 | */ | |
63 |
|
63 | |||
64 | /*! |
|
64 | /*! | |
65 | \qmlproperty AbstractAxis AbstractBarSeries::axisX |
|
65 | \qmlproperty AbstractAxis AbstractBarSeries::axisX | |
66 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for |
|
66 | The x axis used for the series. If you leave both axisX and axisXTop undefined, a BarCategoriesAxis is created for | |
67 | the series. |
|
67 | the series. | |
68 | \sa axisXTop |
|
68 | \sa axisXTop | |
69 | */ |
|
69 | */ | |
70 |
|
70 | |||
71 | /*! |
|
71 | /*! | |
72 | \qmlproperty AbstractAxis AbstractBarSeries::axisY |
|
72 | \qmlproperty AbstractAxis AbstractBarSeries::axisY | |
73 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for |
|
73 | The y axis used for the series. If you leave both axisY and axisYRight undefined, a ValueAxis is created for | |
74 | the series. |
|
74 | the series. | |
75 | \sa axisYRight |
|
75 | \sa axisYRight | |
76 | */ |
|
76 | */ | |
77 |
|
77 | |||
78 | /*! |
|
78 | /*! | |
79 | \qmlproperty AbstractAxis AbstractBarSeries::axisXTop |
|
79 | \qmlproperty AbstractAxis AbstractBarSeries::axisXTop | |
80 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or |
|
80 | The x axis used for the series, drawn on top of the chart view. Note that you can only provide either axisX or | |
81 | axisXTop, but not both. |
|
81 | axisXTop, but not both. | |
82 | \sa axisX |
|
82 | \sa axisX | |
83 | */ |
|
83 | */ | |
84 |
|
84 | |||
85 | /*! |
|
85 | /*! | |
86 | \qmlproperty AbstractAxis AbstractBarSeries::axisYRight |
|
86 | \qmlproperty AbstractAxis AbstractBarSeries::axisYRight | |
87 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY |
|
87 | The y axis used for the series, drawn to the right on the chart view. Note that you can only provide either axisY | |
88 | or axisYRight, but not both. |
|
88 | or axisYRight, but not both. | |
89 | \sa axisY |
|
89 | \sa axisY | |
90 | */ |
|
90 | */ | |
91 |
|
91 | |||
92 | /*! |
|
92 | /*! | |
93 | \property QAbstractBarSeries::barWidth |
|
93 | \property QAbstractBarSeries::barWidth | |
94 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars |
|
94 | The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars | |
95 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
95 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
96 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
96 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
97 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
97 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
98 | \sa QBarSeries |
|
98 | \sa QBarSeries | |
99 | */ |
|
99 | */ | |
100 | /*! |
|
100 | /*! | |
101 | \qmlproperty real AbstractBarSeries::barWidth |
|
101 | \qmlproperty real AbstractBarSeries::barWidth | |
102 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars |
|
102 | The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars | |
103 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
103 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
104 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
104 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
105 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. |
|
105 | Note that with QBarSeries this value means the width of one group of bars instead of just one bar. | |
106 | */ |
|
106 | */ | |
107 |
|
107 | |||
108 | /*! |
|
108 | /*! | |
109 | \property QAbstractBarSeries::count |
|
109 | \property QAbstractBarSeries::count | |
110 | Holds the number of sets in series. |
|
110 | Holds the number of sets in series. | |
111 | */ |
|
111 | */ | |
112 | /*! |
|
112 | /*! | |
113 | \qmlproperty int AbstractBarSeries::count |
|
113 | \qmlproperty int AbstractBarSeries::count | |
114 | Holds the number of sets in series. |
|
114 | Holds the number of sets in series. | |
115 | */ |
|
115 | */ | |
116 |
|
116 | |||
117 | /*! |
|
117 | /*! | |
118 | \property QAbstractBarSeries::labelsVisible |
|
118 | \property QAbstractBarSeries::labelsVisible | |
119 | Defines the visibility of the labels in series |
|
119 | Defines the visibility of the labels in series | |
120 | */ |
|
120 | */ | |
121 | /*! |
|
121 | /*! | |
122 | \qmlproperty bool AbstractBarSeries::labelsVisible |
|
122 | \qmlproperty bool AbstractBarSeries::labelsVisible | |
123 | Defines the visibility of the labels in series |
|
123 | Defines the visibility of the labels in series | |
124 | */ |
|
124 | */ | |
125 |
|
125 | |||
126 | /*! |
|
126 | /*! | |
127 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) |
|
127 | \fn void QAbstractBarSeries::clicked(int index, QBarSet *barset) | |
128 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. |
|
128 | The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset. | |
129 | Clicked bar inside set is indexed by \a index |
|
129 | Clicked bar inside set is indexed by \a index | |
130 | */ |
|
130 | */ | |
131 | /*! |
|
131 | /*! | |
132 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) |
|
132 | \qmlsignal AbstractBarSeries::onClicked(int index, BarSet barset) | |
133 | The signal is emitted if the user clicks with a mouse on top of BarSet. |
|
133 | The signal is emitted if the user clicks with a mouse on top of BarSet. | |
134 | Clicked bar inside set is indexed by \a index |
|
134 | Clicked bar inside set is indexed by \a index | |
135 | */ |
|
135 | */ | |
136 |
|
136 | |||
137 | /*! |
|
137 | /*! | |
138 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) |
|
138 | \fn void QAbstractBarSeries::hovered(bool status, QBarSet* barset) | |
139 |
|
139 | |||
140 | The signal is emitted if mouse is hovered on top of series. |
|
140 | The signal is emitted if mouse is hovered on top of series. | |
141 | Parameter \a barset is the pointer of barset, where hover happened. |
|
141 | Parameter \a barset is the pointer of barset, where hover happened. | |
142 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
142 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
143 | */ |
|
143 | */ | |
144 | /*! |
|
144 | /*! | |
145 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) |
|
145 | \qmlsignal AbstractBarSeries::onHovered(bool status, BarSet barset) | |
146 |
|
146 | |||
147 | The signal is emitted if mouse is hovered on top of series. |
|
147 | The signal is emitted if mouse is hovered on top of series. | |
148 | Parameter \a barset is the pointer of barset, where hover happened. |
|
148 | Parameter \a barset is the pointer of barset, where hover happened. | |
149 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. |
|
149 | Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series. | |
150 | */ |
|
150 | */ | |
151 |
|
151 | |||
152 | /*! |
|
152 | /*! | |
153 | \fn void QAbstractBarSeries::countChanged() |
|
153 | \fn void QAbstractBarSeries::countChanged() | |
154 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
154 | This signal is emitted when barset count has been changed, for example by append or remove. | |
155 | */ |
|
155 | */ | |
156 | /*! |
|
156 | /*! | |
157 | \qmlsignal AbstractBarSeries::onCountChanged() |
|
157 | \qmlsignal AbstractBarSeries::onCountChanged() | |
158 | This signal is emitted when barset count has been changed, for example by append or remove. |
|
158 | This signal is emitted when barset count has been changed, for example by append or remove. | |
159 | */ |
|
159 | */ | |
160 |
|
160 | |||
161 | /*! |
|
161 | /*! | |
162 | \fn void QAbstractBarSeries::labelsVisibleChanged() |
|
162 | \fn void QAbstractBarSeries::labelsVisibleChanged() | |
163 | This signal is emitted when labels visibility have changed. |
|
163 | This signal is emitted when labels visibility have changed. | |
164 | \sa isLabelsVisible(), setLabelsVisible() |
|
164 | \sa isLabelsVisible(), setLabelsVisible() | |
165 | */ |
|
165 | */ | |
166 |
|
166 | |||
167 | /*! |
|
167 | /*! | |
168 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) |
|
168 | \fn void QAbstractBarSeries::barsetsAdded(QList<QBarSet*> sets) | |
169 | This signal is emitted when \a sets have been added to the series. |
|
169 | This signal is emitted when \a sets have been added to the series. | |
170 | \sa append(), insert() |
|
170 | \sa append(), insert() | |
171 | */ |
|
171 | */ | |
172 | /*! |
|
172 | /*! | |
173 | \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset) |
|
173 | \qmlsignal AbstractBarSeries::onBarsetsAdded(BarSet barset) | |
174 | Emitted when \a barset has been added to the series. |
|
174 | Emitted when \a barset has been added to the series. | |
175 | */ |
|
175 | */ | |
176 |
|
176 | |||
177 | /*! |
|
177 | /*! | |
178 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) |
|
178 | \fn void QAbstractBarSeries::barsetsRemoved(QList<QBarSet*> sets) | |
179 | This signal is emitted when \a sets have been removed from the series. |
|
179 | This signal is emitted when \a sets have been removed from the series. | |
180 | \sa remove() |
|
180 | \sa remove() | |
181 | */ |
|
181 | */ | |
182 | /*! |
|
182 | /*! | |
183 | \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset) |
|
183 | \qmlsignal AbstractBarSeries::onBarsetsRemoved(BarSet barset) | |
184 | Emitted when \a barset has been removed from the series. |
|
184 | Emitted when \a barset has been removed from the series. | |
185 | */ |
|
185 | */ | |
186 |
|
186 | |||
187 | /*! |
|
187 | /*! | |
188 | \qmlmethod BarSet AbstractBarSeries::at(int index) |
|
188 | \qmlmethod BarSet AbstractBarSeries::at(int index) | |
189 | Returns bar set at \a index. Returns null if the index is not valid. |
|
189 | Returns bar set at \a index. Returns null if the index is not valid. | |
190 | */ |
|
190 | */ | |
191 |
|
191 | |||
192 | /*! |
|
192 | /*! | |
193 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) |
|
193 | \qmlmethod BarSet AbstractBarSeries::append(string label, VariantList values) | |
194 | Adds a new bar set with \a label and \a values to \a index. Values is a list of reals. |
|
194 | Adds a new bar set with \a label and \a values to \a index. Values is a list of reals. | |
195 | For example: |
|
195 | For example: | |
196 | \code |
|
196 | \code | |
197 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); |
|
197 | myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]); | |
198 | \endcode |
|
198 | \endcode | |
199 | */ |
|
199 | */ | |
200 |
|
200 | |||
201 | /*! |
|
201 | /*! | |
202 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) |
|
202 | \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values) | |
203 | 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. |
|
203 | 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. | |
204 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is |
|
204 | If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is | |
205 | appended. |
|
205 | appended. | |
206 | \sa AbstractBarSeries::append() |
|
206 | \sa AbstractBarSeries::append() | |
207 | */ |
|
207 | */ | |
208 |
|
208 | |||
209 | /*! |
|
209 | /*! | |
210 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) |
|
210 | \qmlmethod bool AbstractBarSeries::remove(BarSet barset) | |
211 | Removes the barset from the series. Returns true if successful, false otherwise. |
|
211 | Removes the barset from the series. Returns true if successful, false otherwise. | |
212 | */ |
|
212 | */ | |
213 |
|
213 | |||
214 | /*! |
|
214 | /*! | |
215 | \qmlmethod AbstractBarSeries::clear() |
|
215 | \qmlmethod AbstractBarSeries::clear() | |
216 | Removes all barsets from the series. |
|
216 | Removes all barsets from the series. | |
217 | */ |
|
217 | */ | |
218 |
|
218 | |||
219 | /*! |
|
219 | /*! | |
220 | Destructs abstractbarseries and owned barsets. |
|
220 | Destructs abstractbarseries and owned barsets. | |
221 | */ |
|
221 | */ | |
222 | QAbstractBarSeries::~QAbstractBarSeries() |
|
222 | QAbstractBarSeries::~QAbstractBarSeries() | |
223 | { |
|
223 | { | |
224 |
|
224 | |||
225 | } |
|
225 | } | |
226 |
|
226 | |||
227 | /*! |
|
227 | /*! | |
228 | \internal |
|
228 | \internal | |
229 | */ |
|
229 | */ | |
230 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent) |
|
230 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent) | |
231 | : QAbstractSeries(o, parent) |
|
231 | : QAbstractSeries(o, parent) | |
232 | { |
|
232 | { | |
233 | Q_D(QAbstractSeries); |
|
233 | Q_D(QAbstractSeries); | |
234 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); |
|
234 | QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged())); | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | /*! |
|
237 | /*! | |
238 | 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 |
|
238 | 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 | |
239 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen |
|
239 | is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen | |
240 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. |
|
240 | is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis. | |
241 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. |
|
241 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
242 | */ |
|
242 | */ | |
243 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
243 | void QAbstractBarSeries::setBarWidth(qreal width) | |
244 | { |
|
244 | { | |
245 | Q_D(QAbstractBarSeries); |
|
245 | Q_D(QAbstractBarSeries); | |
246 | d->setBarWidth(width); |
|
246 | d->setBarWidth(width); | |
247 | } |
|
247 | } | |
248 |
|
248 | |||
249 | /*! |
|
249 | /*! | |
250 | Returns the width of the bars of the series. |
|
250 | Returns the width of the bars of the series. | |
251 | \sa setBarWidth() |
|
251 | \sa setBarWidth() | |
252 | */ |
|
252 | */ | |
253 | qreal QAbstractBarSeries::barWidth() const |
|
253 | qreal QAbstractBarSeries::barWidth() const | |
254 | { |
|
254 | { | |
255 | Q_D(const QAbstractBarSeries); |
|
255 | Q_D(const QAbstractBarSeries); | |
256 | return d->barWidth(); |
|
256 | return d->barWidth(); | |
257 | } |
|
257 | } | |
258 |
|
258 | |||
259 | /*! |
|
259 | /*! | |
260 | 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. |
|
260 | 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. | |
261 | Returns true, if appending succeeded. |
|
261 | Returns true, if appending succeeded. | |
262 | */ |
|
262 | */ | |
263 | bool QAbstractBarSeries::append(QBarSet *set) |
|
263 | bool QAbstractBarSeries::append(QBarSet *set) | |
264 | { |
|
264 | { | |
265 | Q_D(QAbstractBarSeries); |
|
265 | Q_D(QAbstractBarSeries); | |
266 | bool success = d->append(set); |
|
266 | bool success = d->append(set); | |
267 | if (success) { |
|
267 | if (success) { | |
268 | QList<QBarSet *> sets; |
|
268 | QList<QBarSet *> sets; | |
269 | sets.append(set); |
|
269 | sets.append(set); | |
270 | set->setParent(this); |
|
270 | set->setParent(this); | |
271 | emit barsetsAdded(sets); |
|
271 | emit barsetsAdded(sets); | |
272 | emit countChanged(); |
|
272 | emit countChanged(); | |
273 | } |
|
273 | } | |
274 | return success; |
|
274 | return success; | |
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | /*! |
|
277 | /*! | |
278 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove |
|
278 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove | |
279 | was successful. |
|
279 | was successful. | |
280 | Returns true, if set was removed. |
|
280 | Returns true, if set was removed. | |
281 | */ |
|
281 | */ | |
282 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
282 | bool QAbstractBarSeries::remove(QBarSet *set) | |
283 | { |
|
283 | { | |
284 | Q_D(QAbstractBarSeries); |
|
284 | Q_D(QAbstractBarSeries); | |
285 | bool success = d->remove(set); |
|
285 | bool success = d->remove(set); | |
286 | if (success) { |
|
286 | if (success) { | |
287 | QList<QBarSet *> sets; |
|
287 | QList<QBarSet *> sets; | |
288 | sets.append(set); |
|
288 | sets.append(set); | |
289 | set->setParent(0); |
|
289 | set->setParent(0); | |
290 | emit barsetsRemoved(sets); |
|
290 | emit barsetsRemoved(sets); | |
291 | emit countChanged(); |
|
291 | emit countChanged(); | |
292 | delete set; |
|
292 | delete set; | |
293 | set = 0; |
|
293 | set = 0; | |
294 | } |
|
294 | } | |
295 | return success; |
|
295 | return success; | |
296 | } |
|
296 | } | |
297 |
|
297 | |||
298 | /*! |
|
298 | /*! | |
299 | Takes a single \a set from the series. Does not delete the barset object. |
|
299 | Takes a single \a set from the series. Does not delete the barset object. | |
300 |
|
300 | |||
301 | NOTE: The series remains as the barset's parent object. You must set the |
|
301 | NOTE: The series remains as the barset's parent object. You must set the | |
302 | parent object to take full ownership. |
|
302 | parent object to take full ownership. | |
303 |
|
303 | |||
304 | Returns true if take was successful. |
|
304 | Returns true if take was successful. | |
305 | */ |
|
305 | */ | |
306 | bool QAbstractBarSeries::take(QBarSet *set) |
|
306 | bool QAbstractBarSeries::take(QBarSet *set) | |
307 | { |
|
307 | { | |
308 | Q_D(QAbstractBarSeries); |
|
308 | Q_D(QAbstractBarSeries); | |
309 | bool success = d->remove(set); |
|
309 | bool success = d->remove(set); | |
310 | if (success) { |
|
310 | if (success) { | |
311 | QList<QBarSet *> sets; |
|
311 | QList<QBarSet *> sets; | |
312 | sets.append(set); |
|
312 | sets.append(set); | |
313 | emit barsetsRemoved(sets); |
|
313 | emit barsetsRemoved(sets); | |
314 | emit countChanged(); |
|
314 | emit countChanged(); | |
315 | } |
|
315 | } | |
316 | return success; |
|
316 | return success; | |
317 | } |
|
317 | } | |
318 |
|
318 | |||
319 | /*! |
|
319 | /*! | |
320 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
320 | Adds a list of barsets to series. Takes ownership of \a sets. | |
321 | Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, |
|
321 | Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series, | |
322 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
322 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
323 | and function returns false. |
|
323 | and function returns false. | |
324 | */ |
|
324 | */ | |
325 | bool QAbstractBarSeries::append(QList<QBarSet *> sets) |
|
325 | bool QAbstractBarSeries::append(QList<QBarSet *> sets) | |
326 | { |
|
326 | { | |
327 | Q_D(QAbstractBarSeries); |
|
327 | Q_D(QAbstractBarSeries); | |
328 | bool success = d->append(sets); |
|
328 | bool success = d->append(sets); | |
329 | if (success) { |
|
329 | if (success) { | |
330 | emit barsetsAdded(sets); |
|
330 | emit barsetsAdded(sets); | |
331 | emit countChanged(); |
|
331 | emit countChanged(); | |
332 | } |
|
332 | } | |
333 | return success; |
|
333 | return success; | |
334 | } |
|
334 | } | |
335 |
|
335 | |||
336 | /*! |
|
336 | /*! | |
337 | 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. |
|
337 | 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. | |
338 | Returns true, if inserting succeeded. |
|
338 | Returns true, if inserting succeeded. | |
339 |
|
339 | |||
340 | */ |
|
340 | */ | |
341 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
341 | bool QAbstractBarSeries::insert(int index, QBarSet *set) | |
342 | { |
|
342 | { | |
343 | Q_D(QAbstractBarSeries); |
|
343 | Q_D(QAbstractBarSeries); | |
344 | bool success = d->insert(index, set); |
|
344 | bool success = d->insert(index, set); | |
345 | if (success) { |
|
345 | if (success) { | |
346 | QList<QBarSet *> sets; |
|
346 | QList<QBarSet *> sets; | |
347 | sets.append(set); |
|
347 | sets.append(set); | |
348 | emit barsetsAdded(sets); |
|
348 | emit barsetsAdded(sets); | |
349 | emit countChanged(); |
|
349 | emit countChanged(); | |
350 | } |
|
350 | } | |
351 | return success; |
|
351 | return success; | |
352 | } |
|
352 | } | |
353 |
|
353 | |||
354 | /*! |
|
354 | /*! | |
355 | Removes all barsets from the series. Deletes removed sets. |
|
355 | Removes all barsets from the series. Deletes removed sets. | |
356 | */ |
|
356 | */ | |
357 | void QAbstractBarSeries::clear() |
|
357 | void QAbstractBarSeries::clear() | |
358 | { |
|
358 | { | |
359 | Q_D(QAbstractBarSeries); |
|
359 | Q_D(QAbstractBarSeries); | |
360 | QList<QBarSet *> sets = barSets(); |
|
360 | QList<QBarSet *> sets = barSets(); | |
361 | bool success = d->remove(sets); |
|
361 | bool success = d->remove(sets); | |
362 | if (success) { |
|
362 | if (success) { | |
363 | emit barsetsRemoved(sets); |
|
363 | emit barsetsRemoved(sets); | |
364 | emit countChanged(); |
|
364 | emit countChanged(); | |
365 | foreach (QBarSet *set, sets) |
|
365 | foreach (QBarSet *set, sets) | |
366 | delete set; |
|
366 | delete set; | |
367 | } |
|
367 | } | |
368 | } |
|
368 | } | |
369 |
|
369 | |||
370 | /*! |
|
370 | /*! | |
371 | Returns number of sets in series. |
|
371 | Returns number of sets in series. | |
372 | */ |
|
372 | */ | |
373 | int QAbstractBarSeries::count() const |
|
373 | int QAbstractBarSeries::count() const | |
374 | { |
|
374 | { | |
375 | Q_D(const QAbstractBarSeries); |
|
375 | Q_D(const QAbstractBarSeries); | |
376 | return d->m_barSets.count(); |
|
376 | return d->m_barSets.count(); | |
377 | } |
|
377 | } | |
378 |
|
378 | |||
379 | /*! |
|
379 | /*! | |
380 | Returns a list of sets in series. Keeps ownership of sets. |
|
380 | Returns a list of sets in series. Keeps ownership of sets. | |
381 | */ |
|
381 | */ | |
382 | QList<QBarSet *> QAbstractBarSeries::barSets() const |
|
382 | QList<QBarSet *> QAbstractBarSeries::barSets() const | |
383 | { |
|
383 | { | |
384 | Q_D(const QAbstractBarSeries); |
|
384 | Q_D(const QAbstractBarSeries); | |
385 | return d->m_barSets; |
|
385 | return d->m_barSets; | |
386 | } |
|
386 | } | |
387 |
|
387 | |||
388 | /*! |
|
388 | /*! | |
389 | Sets the visibility of labels in series to \a visible |
|
389 | Sets the visibility of labels in series to \a visible | |
390 | */ |
|
390 | */ | |
391 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
391 | void QAbstractBarSeries::setLabelsVisible(bool visible) | |
392 | { |
|
392 | { | |
393 | Q_D(QAbstractBarSeries); |
|
393 | Q_D(QAbstractBarSeries); | |
394 | if (d->m_labelsVisible != visible) { |
|
394 | if (d->m_labelsVisible != visible) { | |
395 | d->setLabelsVisible(visible); |
|
395 | d->setLabelsVisible(visible); | |
396 | emit labelsVisibleChanged(); |
|
396 | emit labelsVisibleChanged(); | |
397 | } |
|
397 | } | |
398 | } |
|
398 | } | |
399 |
|
399 | |||
400 | /*! |
|
400 | /*! | |
401 | Returns the visibility of labels |
|
401 | Returns the visibility of labels | |
402 | */ |
|
402 | */ | |
403 | bool QAbstractBarSeries::isLabelsVisible() const |
|
403 | bool QAbstractBarSeries::isLabelsVisible() const | |
404 | { |
|
404 | { | |
405 | Q_D(const QAbstractBarSeries); |
|
405 | Q_D(const QAbstractBarSeries); | |
406 | return d->m_labelsVisible; |
|
406 | return d->m_labelsVisible; | |
407 | } |
|
407 | } | |
408 |
|
408 | |||
409 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
409 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
410 |
|
410 | |||
411 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
411 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : | |
412 | QAbstractSeriesPrivate(q), |
|
412 | QAbstractSeriesPrivate(q), | |
413 | m_barWidth(0.5), // Default value is 50% of category width |
|
413 | m_barWidth(0.5), // Default value is 50% of category width | |
414 | m_labelsVisible(false), |
|
414 | m_labelsVisible(false), | |
415 | m_visible(true) |
|
415 | m_visible(true) | |
416 | { |
|
416 | { | |
417 | } |
|
417 | } | |
418 |
|
418 | |||
419 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
419 | int QAbstractBarSeriesPrivate::categoryCount() const | |
420 | { |
|
420 | { | |
421 | // No categories defined. return count of longest set. |
|
421 | // No categories defined. return count of longest set. | |
422 | int count = 0; |
|
422 | int count = 0; | |
423 | for (int i = 0; i < m_barSets.count(); i++) { |
|
423 | for (int i = 0; i < m_barSets.count(); i++) { | |
424 | if (m_barSets.at(i)->count() > count) |
|
424 | if (m_barSets.at(i)->count() > count) | |
425 | count = m_barSets.at(i)->count(); |
|
425 | count = m_barSets.at(i)->count(); | |
426 | } |
|
426 | } | |
427 |
|
427 | |||
428 | return count; |
|
428 | return count; | |
429 | } |
|
429 | } | |
430 |
|
430 | |||
431 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
431 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) | |
432 | { |
|
432 | { | |
433 | if (width < 0.0) |
|
433 | if (width < 0.0) | |
434 | width = 0.0; |
|
434 | width = 0.0; | |
435 | m_barWidth = width; |
|
435 | m_barWidth = width; | |
436 | emit updatedLayout(); |
|
436 | emit updatedLayout(); | |
437 | } |
|
437 | } | |
438 |
|
438 | |||
439 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
439 | qreal QAbstractBarSeriesPrivate::barWidth() const | |
440 | { |
|
440 | { | |
441 | return m_barWidth; |
|
441 | return m_barWidth; | |
442 | } |
|
442 | } | |
443 |
|
443 | |||
444 | QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index) |
|
444 | QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index) | |
445 | { |
|
445 | { | |
446 | return m_barSets.at(index); |
|
446 | return m_barSets.at(index); | |
447 | } |
|
447 | } | |
448 |
|
448 | |||
449 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
449 | void QAbstractBarSeriesPrivate::setVisible(bool visible) | |
450 | { |
|
450 | { | |
451 | m_visible = visible; |
|
451 | m_visible = visible; | |
452 | emit visibleChanged(); |
|
452 | emit visibleChanged(); | |
453 | } |
|
453 | } | |
454 |
|
454 | |||
455 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
455 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) | |
456 | { |
|
456 | { | |
457 | m_labelsVisible = visible; |
|
457 | m_labelsVisible = visible; | |
458 | emit labelsVisibleChanged(visible); |
|
458 | emit labelsVisibleChanged(visible); | |
459 | } |
|
459 | } | |
460 |
|
460 | |||
461 | qreal QAbstractBarSeriesPrivate::min() |
|
461 | qreal QAbstractBarSeriesPrivate::min() | |
462 | { |
|
462 | { | |
463 | if (m_barSets.count() <= 0) |
|
463 | if (m_barSets.count() <= 0) | |
464 | return 0; |
|
464 | return 0; | |
465 |
|
465 | |||
466 | qreal min = INT_MAX; |
|
466 | qreal min = INT_MAX; | |
467 |
|
467 | |||
468 | for (int i = 0; i < m_barSets.count(); i++) { |
|
468 | for (int i = 0; i < m_barSets.count(); i++) { | |
469 | int categoryCount = m_barSets.at(i)->count(); |
|
469 | int categoryCount = m_barSets.at(i)->count(); | |
470 | for (int j = 0; j < categoryCount; j++) { |
|
470 | for (int j = 0; j < categoryCount; j++) { | |
471 | qreal temp = m_barSets.at(i)->at(j); |
|
471 | qreal temp = m_barSets.at(i)->at(j); | |
472 | if (temp < min) |
|
472 | if (temp < min) | |
473 | min = temp; |
|
473 | min = temp; | |
474 | } |
|
474 | } | |
475 | } |
|
475 | } | |
476 | return min; |
|
476 | return min; | |
477 | } |
|
477 | } | |
478 |
|
478 | |||
479 | qreal QAbstractBarSeriesPrivate::max() |
|
479 | qreal QAbstractBarSeriesPrivate::max() | |
480 | { |
|
480 | { | |
481 | if (m_barSets.count() <= 0) |
|
481 | if (m_barSets.count() <= 0) | |
482 | return 0; |
|
482 | return 0; | |
483 |
|
483 | |||
484 | qreal max = INT_MIN; |
|
484 | qreal max = INT_MIN; | |
485 |
|
485 | |||
486 | for (int i = 0; i < m_barSets.count(); i++) { |
|
486 | for (int i = 0; i < m_barSets.count(); i++) { | |
487 | int categoryCount = m_barSets.at(i)->count(); |
|
487 | int categoryCount = m_barSets.at(i)->count(); | |
488 | for (int j = 0; j < categoryCount; j++) { |
|
488 | for (int j = 0; j < categoryCount; j++) { | |
489 | qreal temp = m_barSets.at(i)->at(j); |
|
489 | qreal temp = m_barSets.at(i)->at(j); | |
490 | if (temp > max) |
|
490 | if (temp > max) | |
491 | max = temp; |
|
491 | max = temp; | |
492 | } |
|
492 | } | |
493 | } |
|
493 | } | |
494 |
|
494 | |||
495 | return max; |
|
495 | return max; | |
496 | } |
|
496 | } | |
497 |
|
497 | |||
498 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
498 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) | |
499 | { |
|
499 | { | |
500 | if ((set < 0) || (set >= m_barSets.count())) |
|
500 | if ((set < 0) || (set >= m_barSets.count())) | |
501 | return 0; // No set, no value. |
|
501 | return 0; // No set, no value. | |
502 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) |
|
502 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) | |
503 | return 0; // No category, no value. |
|
503 | return 0; // No category, no value. | |
504 |
|
504 | |||
505 | return m_barSets.at(set)->at(category); |
|
505 | return m_barSets.at(set)->at(category); | |
506 | } |
|
506 | } | |
507 |
|
507 | |||
508 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
508 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) | |
509 | { |
|
509 | { | |
510 | if ((set < 0) || (set >= m_barSets.count())) |
|
510 | if ((set < 0) || (set >= m_barSets.count())) | |
511 | return 0; // No set, no value. |
|
511 | return 0; // No set, no value. | |
512 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) |
|
512 | else if ((category < 0) || (category >= m_barSets.at(set)->count())) | |
513 | return 0; // No category, no value. |
|
513 | return 0; // No category, no value. | |
514 |
|
514 | |||
515 | qreal value = m_barSets.at(set)->at(category); |
|
515 | qreal value = m_barSets.at(set)->at(category); | |
516 | qreal sum = categorySum(category); |
|
516 | qreal sum = categorySum(category); | |
517 | if (qFuzzyCompare(sum, 0)) |
|
517 | if (qFuzzyCompare(sum, 0)) | |
518 | return 0; |
|
518 | return 0; | |
519 |
|
519 | |||
520 | return value / sum; |
|
520 | return value / sum; | |
521 | } |
|
521 | } | |
522 |
|
522 | |||
523 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
523 | qreal QAbstractBarSeriesPrivate::categorySum(int category) | |
524 | { |
|
524 | { | |
525 | qreal sum(0); |
|
525 | qreal sum(0); | |
526 | int count = m_barSets.count(); // Count sets |
|
526 | int count = m_barSets.count(); // Count sets | |
527 | for (int set = 0; set < count; set++) { |
|
527 | for (int set = 0; set < count; set++) { | |
528 | if (category < m_barSets.at(set)->count()) |
|
528 | if (category < m_barSets.at(set)->count()) | |
529 | sum += m_barSets.at(set)->at(category); |
|
529 | sum += m_barSets.at(set)->at(category); | |
530 | } |
|
530 | } | |
531 | return sum; |
|
531 | return sum; | |
532 | } |
|
532 | } | |
533 |
|
533 | |||
534 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
534 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) | |
535 | { |
|
535 | { | |
536 | qreal sum(0); |
|
536 | qreal sum(0); | |
537 | int count = m_barSets.count(); // Count sets |
|
537 | int count = m_barSets.count(); // Count sets | |
538 | for (int set = 0; set < count; set++) { |
|
538 | for (int set = 0; set < count; set++) { | |
539 | if (category < m_barSets.at(set)->count()) |
|
539 | if (category < m_barSets.at(set)->count()) | |
540 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
540 | sum += qAbs(m_barSets.at(set)->at(category)); | |
541 | } |
|
541 | } | |
542 | return sum; |
|
542 | return sum; | |
543 | } |
|
543 | } | |
544 |
|
544 | |||
545 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
545 | qreal QAbstractBarSeriesPrivate::maxCategorySum() | |
546 | { |
|
546 | { | |
547 | qreal max = INT_MIN; |
|
547 | qreal max = INT_MIN; | |
548 | int count = categoryCount(); |
|
548 | int count = categoryCount(); | |
549 | for (int i = 0; i < count; i++) { |
|
549 | for (int i = 0; i < count; i++) { | |
550 | qreal sum = categorySum(i); |
|
550 | qreal sum = categorySum(i); | |
551 | if (sum > max) |
|
551 | if (sum > max) | |
552 | max = sum; |
|
552 | max = sum; | |
553 | } |
|
553 | } | |
554 | return max; |
|
554 | return max; | |
555 | } |
|
555 | } | |
556 |
|
556 | |||
557 | qreal QAbstractBarSeriesPrivate::minX() |
|
557 | qreal QAbstractBarSeriesPrivate::minX() | |
558 | { |
|
558 | { | |
559 | if (m_barSets.count() <= 0) |
|
559 | if (m_barSets.count() <= 0) | |
560 | return 0; |
|
560 | return 0; | |
561 |
|
561 | |||
562 | qreal min = INT_MAX; |
|
562 | qreal min = INT_MAX; | |
563 |
|
563 | |||
564 | for (int i = 0; i < m_barSets.count(); i++) { |
|
564 | for (int i = 0; i < m_barSets.count(); i++) { | |
565 | int categoryCount = m_barSets.at(i)->count(); |
|
565 | int categoryCount = m_barSets.at(i)->count(); | |
566 | for (int j = 0; j < categoryCount; j++) { |
|
566 | for (int j = 0; j < categoryCount; j++) { | |
567 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
567 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
568 | if (temp < min) |
|
568 | if (temp < min) | |
569 | min = temp; |
|
569 | min = temp; | |
570 | } |
|
570 | } | |
571 | } |
|
571 | } | |
572 | return min; |
|
572 | return min; | |
573 | } |
|
573 | } | |
574 |
|
574 | |||
575 | qreal QAbstractBarSeriesPrivate::maxX() |
|
575 | qreal QAbstractBarSeriesPrivate::maxX() | |
576 | { |
|
576 | { | |
577 | if (m_barSets.count() <= 0) |
|
577 | if (m_barSets.count() <= 0) | |
578 | return 0; |
|
578 | return 0; | |
579 |
|
579 | |||
580 | qreal max = INT_MIN; |
|
580 | qreal max = INT_MIN; | |
581 |
|
581 | |||
582 | for (int i = 0; i < m_barSets.count(); i++) { |
|
582 | for (int i = 0; i < m_barSets.count(); i++) { | |
583 | int categoryCount = m_barSets.at(i)->count(); |
|
583 | int categoryCount = m_barSets.at(i)->count(); | |
584 | for (int j = 0; j < categoryCount; j++) { |
|
584 | for (int j = 0; j < categoryCount; j++) { | |
585 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
585 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
586 | if (temp > max) |
|
586 | if (temp > max) | |
587 | max = temp; |
|
587 | max = temp; | |
588 | } |
|
588 | } | |
589 | } |
|
589 | } | |
590 |
|
590 | |||
591 | return max; |
|
591 | return max; | |
592 | } |
|
592 | } | |
593 |
|
593 | |||
594 | qreal QAbstractBarSeriesPrivate::categoryTop(int category) |
|
594 | qreal QAbstractBarSeriesPrivate::categoryTop(int category) | |
595 | { |
|
595 | { | |
596 | // Returns top (sum of all positive values) of category. |
|
596 | // Returns top (sum of all positive values) of category. | |
597 | // Returns 0, if all values are negative |
|
597 | // Returns 0, if all values are negative | |
598 | qreal top(0); |
|
598 | qreal top(0); | |
599 | int count = m_barSets.count(); |
|
599 | int count = m_barSets.count(); | |
600 | for (int set = 0; set < count; set++) { |
|
600 | for (int set = 0; set < count; set++) { | |
601 | if (category < m_barSets.at(set)->count()) { |
|
601 | if (category < m_barSets.at(set)->count()) { | |
602 | qreal temp = m_barSets.at(set)->at(category); |
|
602 | qreal temp = m_barSets.at(set)->at(category); | |
603 | if (temp > 0) { |
|
603 | if (temp > 0) { | |
604 | top += temp; |
|
604 | top += temp; | |
605 | } |
|
605 | } | |
606 | } |
|
606 | } | |
607 | } |
|
607 | } | |
608 | return top; |
|
608 | return top; | |
609 | } |
|
609 | } | |
610 |
|
610 | |||
611 | qreal QAbstractBarSeriesPrivate::categoryBottom(int category) |
|
611 | qreal QAbstractBarSeriesPrivate::categoryBottom(int category) | |
612 | { |
|
612 | { | |
613 | // Returns bottom (sum of all negative values) of category |
|
613 | // Returns bottom (sum of all negative values) of category | |
614 | // Returns 0, if all values are positive |
|
614 | // Returns 0, if all values are positive | |
615 | qreal bottom(0); |
|
615 | qreal bottom(0); | |
616 | int count = m_barSets.count(); |
|
616 | int count = m_barSets.count(); | |
617 | for (int set = 0; set < count; set++) { |
|
617 | for (int set = 0; set < count; set++) { | |
618 | if (category < m_barSets.at(set)->count()) { |
|
618 | if (category < m_barSets.at(set)->count()) { | |
619 | qreal temp = m_barSets.at(set)->at(category); |
|
619 | qreal temp = m_barSets.at(set)->at(category); | |
620 | if (temp < 0) { |
|
620 | if (temp < 0) { | |
621 | bottom += temp; |
|
621 | bottom += temp; | |
622 | } |
|
622 | } | |
623 | } |
|
623 | } | |
624 | } |
|
624 | } | |
625 | return bottom; |
|
625 | return bottom; | |
626 | } |
|
626 | } | |
627 |
|
627 | |||
628 | qreal QAbstractBarSeriesPrivate::top() |
|
628 | qreal QAbstractBarSeriesPrivate::top() | |
629 | { |
|
629 | { | |
630 | // Returns top of all categories |
|
630 | // Returns top of all categories | |
631 | qreal top(0); |
|
631 | qreal top(0); | |
632 | int count = categoryCount(); |
|
632 | int count = categoryCount(); | |
633 | for (int i = 0; i < count; i++) { |
|
633 | for (int i = 0; i < count; i++) { | |
634 | qreal temp = categoryTop(i); |
|
634 | qreal temp = categoryTop(i); | |
635 | if (temp > top) |
|
635 | if (temp > top) | |
636 | top = temp; |
|
636 | top = temp; | |
637 | } |
|
637 | } | |
638 | return top; |
|
638 | return top; | |
639 | } |
|
639 | } | |
640 |
|
640 | |||
641 | qreal QAbstractBarSeriesPrivate::bottom() |
|
641 | qreal QAbstractBarSeriesPrivate::bottom() | |
642 | { |
|
642 | { | |
643 | // Returns bottom of all categories |
|
643 | // Returns bottom of all categories | |
644 | qreal bottom(0); |
|
644 | qreal bottom(0); | |
645 | int count = categoryCount(); |
|
645 | int count = categoryCount(); | |
646 | for (int i = 0; i < count; i++) { |
|
646 | for (int i = 0; i < count; i++) { | |
647 | qreal temp = categoryBottom(i); |
|
647 | qreal temp = categoryBottom(i); | |
648 | if (temp < bottom) |
|
648 | if (temp < bottom) | |
649 | bottom = temp; |
|
649 | bottom = temp; | |
650 | } |
|
650 | } | |
651 | return bottom; |
|
651 | return bottom; | |
652 | } |
|
652 | } | |
653 |
|
653 | |||
654 |
|
654 | |||
655 | void QAbstractBarSeriesPrivate::initializeDomain() |
|
655 | void QAbstractBarSeriesPrivate::initializeDomain() | |
656 | { |
|
656 | { | |
657 | qreal minX(domain()->minX()); |
|
657 | qreal minX(domain()->minX()); | |
658 | qreal minY(domain()->minY()); |
|
658 | qreal minY(domain()->minY()); | |
659 | qreal maxX(domain()->maxX()); |
|
659 | qreal maxX(domain()->maxX()); | |
660 | qreal maxY(domain()->maxY()); |
|
660 | qreal maxY(domain()->maxY()); | |
661 |
|
661 | |||
662 | qreal seriesMinX = this->minX(); |
|
662 | qreal seriesMinX = this->minX(); | |
663 | qreal seriesMaxX = this->maxX(); |
|
663 | qreal seriesMaxX = this->maxX(); | |
664 | qreal y = max(); |
|
664 | qreal y = max(); | |
665 | minX = qMin(minX, seriesMinX - (qreal)0.5); |
|
665 | minX = qMin(minX, seriesMinX - (qreal)0.5); | |
666 | minY = qMin(minY, y); |
|
666 | minY = qMin(minY, y); | |
667 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); |
|
667 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); | |
668 | maxY = qMax(maxY, y); |
|
668 | maxY = qMax(maxY, y); | |
669 |
|
669 | |||
670 | domain()->setRange(minX, maxX, minY, maxY); |
|
670 | domain()->setRange(minX, maxX, minY, maxY); | |
671 | } |
|
671 | } | |
672 |
|
672 | |||
673 | QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend) |
|
673 | QList<QLegendMarker*> QAbstractBarSeriesPrivate::createLegendMarkers(QLegend* legend) | |
674 | { |
|
674 | { | |
675 | Q_Q(QAbstractBarSeries); |
|
675 | Q_Q(QAbstractBarSeries); | |
676 | QList<QLegendMarker*> markers; |
|
676 | QList<QLegendMarker*> markers; | |
677 |
|
677 | |||
678 | foreach(QBarSet* set, q->barSets()) { |
|
678 | foreach(QBarSet* set, q->barSets()) { | |
679 | QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend); |
|
679 | QBarLegendMarker* marker = new QBarLegendMarker(q,set,legend); | |
680 | markers << marker; |
|
680 | markers << marker; | |
681 | } |
|
681 | } | |
682 | return markers; |
|
682 | return markers; | |
683 | } |
|
683 | } | |
684 |
|
684 | |||
685 |
|
685 | |||
686 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
686 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) | |
687 | { |
|
687 | { | |
688 | if ((m_barSets.contains(set)) || (set == 0)) |
|
688 | if ((m_barSets.contains(set)) || (set == 0)) | |
689 | return false; // Fail if set is already in list or set is null. |
|
689 | return false; // Fail if set is already in list or set is null. | |
690 |
|
690 | |||
691 | m_barSets.append(set); |
|
691 | m_barSets.append(set); | |
692 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
692 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
693 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
693 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
694 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
694 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
695 |
|
695 | |||
696 | emit restructuredBars(); // this notifies barchartitem |
|
696 | emit restructuredBars(); // this notifies barchartitem | |
697 | return true; |
|
697 | return true; | |
698 | } |
|
698 | } | |
699 |
|
699 | |||
700 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
700 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) | |
701 | { |
|
701 | { | |
702 | if (!m_barSets.contains(set)) |
|
702 | if (!m_barSets.contains(set)) | |
703 | return false; // Fail if set is not in list |
|
703 | return false; // Fail if set is not in list | |
704 |
|
704 | |||
705 | m_barSets.removeOne(set); |
|
705 | m_barSets.removeOne(set); | |
706 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
706 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
707 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
707 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
708 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
708 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
709 |
|
709 | |||
710 | emit restructuredBars(); // this notifies barchartitem |
|
710 | emit restructuredBars(); // this notifies barchartitem | |
711 | return true; |
|
711 | return true; | |
712 | } |
|
712 | } | |
713 |
|
713 | |||
714 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets) |
|
714 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets) | |
715 | { |
|
715 | { | |
716 | foreach (QBarSet *set, sets) { |
|
716 | foreach (QBarSet *set, sets) { | |
717 | if ((set == 0) || (m_barSets.contains(set))) |
|
717 | if ((set == 0) || (m_barSets.contains(set))) | |
718 | return false; // Fail if any of the sets is null or is already appended. |
|
718 | return false; // Fail if any of the sets is null or is already appended. | |
719 | if (sets.count(set) != 1) |
|
719 | if (sets.count(set) != 1) | |
720 | return false; // Also fail if same set is more than once in given list. |
|
720 | return false; // Also fail if same set is more than once in given list. | |
721 | } |
|
721 | } | |
722 |
|
722 | |||
723 | foreach (QBarSet *set, sets) { |
|
723 | foreach (QBarSet *set, sets) { | |
724 | m_barSets.append(set); |
|
724 | m_barSets.append(set); | |
725 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
725 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
726 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
726 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
727 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
727 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
728 | } |
|
728 | } | |
729 |
|
729 | |||
730 | emit restructuredBars(); // this notifies barchartitem |
|
730 | emit restructuredBars(); // this notifies barchartitem | |
731 | return true; |
|
731 | return true; | |
732 | } |
|
732 | } | |
733 |
|
733 | |||
734 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets) |
|
734 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets) | |
735 | { |
|
735 | { | |
736 | if (sets.count() == 0) |
|
736 | if (sets.count() == 0) | |
737 | return false; |
|
737 | return false; | |
738 |
|
738 | |||
739 | foreach (QBarSet *set, sets) { |
|
739 | foreach (QBarSet *set, sets) { | |
740 | if ((set == 0) || (!m_barSets.contains(set))) |
|
740 | if ((set == 0) || (!m_barSets.contains(set))) | |
741 | return false; // Fail if any of the sets is null or is not in series |
|
741 | return false; // Fail if any of the sets is null or is not in series | |
742 | if (sets.count(set) != 1) |
|
742 | if (sets.count(set) != 1) | |
743 | return false; // Also fail if same set is more than once in given list. |
|
743 | return false; // Also fail if same set is more than once in given list. | |
744 | } |
|
744 | } | |
745 |
|
745 | |||
746 | foreach (QBarSet *set, sets) { |
|
746 | foreach (QBarSet *set, sets) { | |
747 | m_barSets.removeOne(set); |
|
747 | m_barSets.removeOne(set); | |
748 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
748 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
749 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
749 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
750 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
750 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
751 | } |
|
751 | } | |
752 |
|
752 | |||
753 | emit restructuredBars(); // this notifies barchartitem |
|
753 | emit restructuredBars(); // this notifies barchartitem | |
754 |
|
754 | |||
755 | return true; |
|
755 | return true; | |
756 | } |
|
756 | } | |
757 |
|
757 | |||
758 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
758 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) | |
759 | { |
|
759 | { | |
760 | if ((m_barSets.contains(set)) || (set == 0)) |
|
760 | if ((m_barSets.contains(set)) || (set == 0)) | |
761 | return false; // Fail if set is already in list or set is null. |
|
761 | return false; // Fail if set is already in list or set is null. | |
762 |
|
762 | |||
763 | m_barSets.insert(index, set); |
|
763 | m_barSets.insert(index, set); | |
764 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); |
|
764 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout())); | |
765 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
765 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
766 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
766 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
767 |
|
767 | |||
768 | emit restructuredBars(); // this notifies barchartitem |
|
768 | emit restructuredBars(); // this notifies barchartitem | |
769 | return true; |
|
769 | return true; | |
770 | } |
|
770 | } | |
771 |
|
771 | |||
772 | void QAbstractBarSeriesPrivate::initializeAxes() |
|
772 | void QAbstractBarSeriesPrivate::initializeAxes() | |
773 | { |
|
773 | { | |
774 | Q_Q(QAbstractBarSeries); |
|
774 | Q_Q(QAbstractBarSeries); | |
775 |
|
775 | |||
776 | foreach(QAbstractAxis* axis, m_axes) { |
|
776 | foreach(QAbstractAxis* axis, m_axes) { | |
777 |
|
777 | |||
778 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { |
|
778 | if (axis->type() == QAbstractAxis::AxisTypeBarCategory) { | |
779 | switch (q->type()) { |
|
779 | switch (q->type()) { | |
780 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
780 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
781 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
781 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
782 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
782 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: | |
783 | if (axis->orientation() == Qt::Vertical) |
|
783 | if (axis->orientation() == Qt::Vertical) | |
784 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); |
|
784 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); | |
785 | break; |
|
785 | break; | |
786 | case QAbstractSeries::SeriesTypeBar: |
|
786 | case QAbstractSeries::SeriesTypeBar: | |
787 | case QAbstractSeries::SeriesTypePercentBar: |
|
787 | case QAbstractSeries::SeriesTypePercentBar: | |
788 | case QAbstractSeries::SeriesTypeStackedBar: |
|
788 | case QAbstractSeries::SeriesTypeStackedBar: | |
|
789 | case QAbstractSeries::SeriesTypeBoxPlot: | |||
789 | if (axis->orientation() == Qt::Horizontal) |
|
790 | if (axis->orientation() == Qt::Horizontal) | |
790 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); |
|
791 | populateCategories(qobject_cast<QBarCategoryAxis *>(axis)); | |
791 | break; |
|
792 | break; | |
792 | default: |
|
793 | default: | |
793 | qWarning() << "Unexpected series type"; |
|
794 | qWarning() << "Unexpected series type"; | |
794 | break; |
|
795 | break; | |
795 | } |
|
796 | } | |
796 | } |
|
797 | } | |
797 | } |
|
798 | } | |
798 | } |
|
799 | } | |
799 |
|
800 | |||
800 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
801 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
801 | { |
|
802 | { | |
802 | Q_Q(const QAbstractBarSeries); |
|
803 | Q_Q(const QAbstractBarSeries); | |
803 |
|
804 | |||
804 | switch (q->type()) { |
|
805 | switch (q->type()) { | |
805 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
806 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
806 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
807 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
807 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: |
|
808 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: | |
808 | if (orientation == Qt::Vertical) |
|
809 | if (orientation == Qt::Vertical) | |
809 | return QAbstractAxis::AxisTypeBarCategory; |
|
810 | return QAbstractAxis::AxisTypeBarCategory; | |
810 | break; |
|
811 | break; | |
811 | case QAbstractSeries::SeriesTypeBar: |
|
812 | case QAbstractSeries::SeriesTypeBar: | |
812 | case QAbstractSeries::SeriesTypePercentBar: |
|
813 | case QAbstractSeries::SeriesTypePercentBar: | |
813 | case QAbstractSeries::SeriesTypeStackedBar: |
|
814 | case QAbstractSeries::SeriesTypeStackedBar: | |
|
815 | case QAbstractSeries::SeriesTypeBoxPlot: | |||
814 | if (orientation == Qt::Horizontal) |
|
816 | if (orientation == Qt::Horizontal) | |
815 | return QAbstractAxis::AxisTypeBarCategory; |
|
817 | return QAbstractAxis::AxisTypeBarCategory; | |
816 | break; |
|
818 | break; | |
817 | default: |
|
819 | default: | |
818 | qWarning() << "Unexpected series type"; |
|
820 | qWarning() << "Unexpected series type"; | |
819 | break; |
|
821 | break; | |
820 | } |
|
822 | } | |
821 | return QAbstractAxis::AxisTypeValue; |
|
823 | return QAbstractAxis::AxisTypeValue; | |
822 |
|
824 | |||
823 | } |
|
825 | } | |
824 |
|
826 | |||
825 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis) |
|
827 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis) | |
826 | { |
|
828 | { | |
827 | QStringList categories; |
|
829 | QStringList categories; | |
828 | if (axis->categories().isEmpty()) { |
|
830 | if (axis->categories().isEmpty()) { | |
829 | for (int i(1); i < categoryCount() + 1; i++) |
|
831 | for (int i(1); i < categoryCount() + 1; i++) | |
830 | categories << QString::number(i); |
|
832 | categories << QString::number(i); | |
831 | axis->append(categories); |
|
833 | axis->append(categories); | |
832 | } |
|
834 | } | |
833 | } |
|
835 | } | |
834 |
|
836 | |||
835 | QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const |
|
837 | QAbstractAxis* QAbstractBarSeriesPrivate::createDefaultAxis(Qt::Orientation orientation) const | |
836 | { |
|
838 | { | |
837 | Q_UNUSED(orientation); |
|
839 | Q_UNUSED(orientation); | |
838 | return 0; |
|
840 | return 0; | |
839 | } |
|
841 | } | |
840 |
|
842 | |||
841 | void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) |
|
843 | void QAbstractBarSeriesPrivate::initializeTheme(int index, ChartTheme* theme, bool forced) | |
842 | { |
|
844 | { | |
843 | const QList<QGradient> gradients = theme->seriesGradients(); |
|
845 | const QList<QGradient> gradients = theme->seriesGradients(); | |
844 |
|
846 | |||
845 | QBrush brush; |
|
847 | QBrush brush; | |
846 | QPen pen; |
|
848 | QPen pen; | |
847 |
|
849 | |||
848 | qreal takeAtPos = 0.5; |
|
850 | qreal takeAtPos = 0.5; | |
849 | qreal step = 0.2; |
|
851 | qreal step = 0.2; | |
850 | if (m_barSets.count() > 1) { |
|
852 | if (m_barSets.count() > 1) { | |
851 | step = 1.0 / (qreal) m_barSets.count(); |
|
853 | step = 1.0 / (qreal) m_barSets.count(); | |
852 | if (m_barSets.count() % gradients.count()) |
|
854 | if (m_barSets.count() % gradients.count()) | |
853 | step *= gradients.count(); |
|
855 | step *= gradients.count(); | |
854 | else |
|
856 | else | |
855 | step *= (gradients.count() - 1); |
|
857 | step *= (gradients.count() - 1); | |
856 | } |
|
858 | } | |
857 |
|
859 | |||
858 | for (int i(0); i < m_barSets.count(); i++) { |
|
860 | for (int i(0); i < m_barSets.count(); i++) { | |
859 | int colorIndex = (index + i) % gradients.count(); |
|
861 | int colorIndex = (index + i) % gradients.count(); | |
860 | if (i > 0 && i %gradients.count() == 0) { |
|
862 | if (i > 0 && i %gradients.count() == 0) { | |
861 | // There is no dedicated base color for each sets, generate more colors |
|
863 | // There is no dedicated base color for each sets, generate more colors | |
862 | takeAtPos += step; |
|
864 | takeAtPos += step; | |
863 | if (takeAtPos == 1.0) |
|
865 | if (takeAtPos == 1.0) | |
864 | takeAtPos += step; |
|
866 | takeAtPos += step; | |
865 | takeAtPos -= (int) takeAtPos; |
|
867 | takeAtPos -= (int) takeAtPos; | |
866 | } |
|
868 | } | |
867 | if (forced || brush == m_barSets.at(i)->brush()) |
|
869 | if (forced || brush == m_barSets.at(i)->brush()) | |
868 | m_barSets.at(i)->setBrush(ChartThemeManager::colorAt(gradients.at(colorIndex), takeAtPos)); |
|
870 | m_barSets.at(i)->setBrush(ChartThemeManager::colorAt(gradients.at(colorIndex), takeAtPos)); | |
869 |
|
871 | |||
870 | // Pick label color from the opposite end of the gradient. |
|
872 | // Pick label color from the opposite end of the gradient. | |
871 | // 0.3 as a boundary seems to work well. |
|
873 | // 0.3 as a boundary seems to work well. | |
872 | if (forced || brush == m_barSets.at(i)->labelBrush()) { |
|
874 | if (forced || brush == m_barSets.at(i)->labelBrush()) { | |
873 | if (takeAtPos < 0.3) |
|
875 | if (takeAtPos < 0.3) | |
874 | m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 1)); |
|
876 | m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 1)); | |
875 | else |
|
877 | else | |
876 | m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0)); |
|
878 | m_barSets.at(i)->setLabelBrush(ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0)); | |
877 | } |
|
879 | } | |
878 |
|
880 | |||
879 | if (forced || pen == m_barSets.at(i)->pen()) { |
|
881 | if (forced || pen == m_barSets.at(i)->pen()) { | |
880 | QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0); |
|
882 | QColor c = ChartThemeManager::colorAt(gradients.at(index % gradients.size()), 0.0); | |
881 | m_barSets.at(i)->setPen(c); |
|
883 | m_barSets.at(i)->setPen(c); | |
882 | } |
|
884 | } | |
883 | } |
|
885 | } | |
884 | } |
|
886 | } | |
885 |
|
887 | |||
886 | void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) |
|
888 | void QAbstractBarSeriesPrivate::initializeAnimations(QChart::AnimationOptions options) | |
887 | { |
|
889 | { | |
888 | AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data()); |
|
890 | AbstractBarChartItem *bar = static_cast<AbstractBarChartItem *>(m_item.data()); | |
889 | Q_ASSERT(bar); |
|
891 | Q_ASSERT(bar); | |
890 | if (options.testFlag(QChart::SeriesAnimations)) { |
|
892 | if (options.testFlag(QChart::SeriesAnimations)) { | |
891 | bar->setAnimation(new BarAnimation(bar)); |
|
893 | bar->setAnimation(new BarAnimation(bar)); | |
892 | }else{ |
|
894 | }else{ | |
893 | bar->setAnimation(0); |
|
895 | bar->setAnimation(0); | |
894 | } |
|
896 | } | |
895 | QAbstractSeriesPrivate::initializeAnimations(options); |
|
897 | QAbstractSeriesPrivate::initializeAnimations(options); | |
896 | } |
|
898 | } | |
897 |
|
899 | |||
898 | #include "moc_qabstractbarseries.cpp" |
|
900 | #include "moc_qabstractbarseries.cpp" | |
899 | #include "moc_qabstractbarseries_p.cpp" |
|
901 | #include "moc_qabstractbarseries_p.cpp" | |
900 |
|
902 | |||
901 | QTCOMMERCIALCHART_END_NAMESPACE |
|
903 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now