@@ -1,828 +1,834 | |||||
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 "qvalueaxis.h" |
|
29 | #include "qvalueaxis.h" | |
30 | #include "qbarcategoryaxis.h" |
|
30 | #include "qbarcategoryaxis.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 | \a parent | |||
192 | */ |
|
193 | */ | |
193 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : |
|
194 | QAbstractBarSeries::QAbstractBarSeries(QObject *parent) : | |
194 | QAbstractSeries(*(QAbstractBarSeriesPrivate*)(0),parent) |
|
195 | QAbstractSeries(*(QAbstractBarSeriesPrivate*)(0),parent) | |
195 | { |
|
196 | { | |
196 | } |
|
197 | } | |
197 |
|
198 | |||
198 | /*! |
|
199 | /*! | |
199 | Destructs abstractbarseries and owned barsets. |
|
200 | Destructs abstractbarseries and owned barsets. | |
200 | */ |
|
201 | */ | |
201 | QAbstractBarSeries::~QAbstractBarSeries() |
|
202 | QAbstractBarSeries::~QAbstractBarSeries() | |
202 | { |
|
203 | { | |
203 |
|
204 | |||
204 | } |
|
205 | } | |
205 |
|
206 | |||
206 | /*! |
|
207 | /*! | |
207 | \internal |
|
208 | \internal | |
208 | */ |
|
209 | */ | |
209 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : |
|
210 | QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) : | |
210 | QAbstractSeries(d,parent) |
|
211 | QAbstractSeries(d,parent) | |
211 | { |
|
212 | { | |
212 | } |
|
213 | } | |
213 |
|
214 | |||
214 | /*! |
|
215 | /*! | |
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 | 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 |
|
217 | 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. |
|
218 | 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. |
|
219 | Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar. | |
219 | */ |
|
220 | */ | |
220 | void QAbstractBarSeries::setBarWidth(qreal width) |
|
221 | void QAbstractBarSeries::setBarWidth(qreal width) | |
221 | { |
|
222 | { | |
222 | Q_D(QAbstractBarSeries); |
|
223 | Q_D(QAbstractBarSeries); | |
223 | d->setBarWidth(width); |
|
224 | d->setBarWidth(width); | |
224 | } |
|
225 | } | |
225 |
|
226 | |||
226 | /*! |
|
227 | /*! | |
227 | Returns the width of the bars of the series. |
|
228 | Returns the width of the bars of the series. | |
228 | \sa setBarWidth() |
|
229 | \sa setBarWidth() | |
229 | */ |
|
230 | */ | |
230 | qreal QAbstractBarSeries::barWidth() const |
|
231 | qreal QAbstractBarSeries::barWidth() const | |
231 | { |
|
232 | { | |
232 | Q_D(const QAbstractBarSeries); |
|
233 | Q_D(const QAbstractBarSeries); | |
233 | return d->barWidth(); |
|
234 | return d->barWidth(); | |
234 | } |
|
235 | } | |
235 |
|
236 | |||
236 | /*! |
|
237 | /*! | |
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 | 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. |
|
239 | Returns true, if appending succeeded. | |
239 | */ |
|
240 | */ | |
240 | bool QAbstractBarSeries::append(QBarSet *set) |
|
241 | bool QAbstractBarSeries::append(QBarSet *set) | |
241 | { |
|
242 | { | |
242 | Q_D(QAbstractBarSeries); |
|
243 | Q_D(QAbstractBarSeries); | |
243 | bool success = d->append(set); |
|
244 | bool success = d->append(set); | |
244 | if (success) { |
|
245 | if (success) { | |
245 | QList<QBarSet*> sets; |
|
246 | QList<QBarSet*> sets; | |
246 | sets.append(set); |
|
247 | sets.append(set); | |
247 | set->setParent(this); |
|
248 | set->setParent(this); | |
248 | emit barsetsAdded(sets); |
|
249 | emit barsetsAdded(sets); | |
249 | emit countChanged(); |
|
250 | emit countChanged(); | |
250 | } |
|
251 | } | |
251 | return success; |
|
252 | return success; | |
252 | } |
|
253 | } | |
253 |
|
254 | |||
254 | /*! |
|
255 | /*! | |
255 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove |
|
256 | Removes barset from series. Releases ownership of \a set. Deletes the set, if remove | |
256 | was successful. |
|
257 | was successful. | |
257 | Returns true, if set was removed. |
|
258 | Returns true, if set was removed. | |
258 | */ |
|
259 | */ | |
259 | bool QAbstractBarSeries::remove(QBarSet *set) |
|
260 | bool QAbstractBarSeries::remove(QBarSet *set) | |
260 | { |
|
261 | { | |
261 | Q_D(QAbstractBarSeries); |
|
262 | Q_D(QAbstractBarSeries); | |
262 | bool success = d->remove(set); |
|
263 | bool success = d->remove(set); | |
263 | if (success) { |
|
264 | if (success) { | |
264 | QList<QBarSet*> sets; |
|
265 | QList<QBarSet*> sets; | |
265 | sets.append(set); |
|
266 | sets.append(set); | |
266 | set->setParent(0); |
|
267 | set->setParent(0); | |
267 | emit barsetsRemoved(sets); |
|
268 | emit barsetsRemoved(sets); | |
268 | emit countChanged(); |
|
269 | emit countChanged(); | |
269 | delete set; |
|
270 | delete set; | |
270 | set = 0; |
|
271 | set = 0; | |
271 | } |
|
272 | } | |
272 | return success; |
|
273 | return success; | |
273 | } |
|
274 | } | |
274 |
|
275 | |||
275 | /*! |
|
276 | /*! | |
276 | Takes a single \a set from the series. Does not delete the barset object. |
|
277 | Takes a single \a set from the series. Does not delete the barset object. | |
277 |
|
278 | |||
278 | NOTE: The series remains as the barset's parent object. You must set the |
|
279 | NOTE: The series remains as the barset's parent object. You must set the | |
279 | parent object to take full ownership. |
|
280 | parent object to take full ownership. | |
280 |
|
281 | |||
281 | Returns true if take was successfull. |
|
282 | Returns true if take was successfull. | |
282 | */ |
|
283 | */ | |
283 | bool QAbstractBarSeries::take(QBarSet *set) |
|
284 | bool QAbstractBarSeries::take(QBarSet *set) | |
284 | { |
|
285 | { | |
285 | Q_D(QAbstractBarSeries); |
|
286 | Q_D(QAbstractBarSeries); | |
286 | bool success = d->remove(set); |
|
287 | bool success = d->remove(set); | |
287 | if (success) { |
|
288 | if (success) { | |
288 | QList<QBarSet*> sets; |
|
289 | QList<QBarSet*> sets; | |
289 | sets.append(set); |
|
290 | sets.append(set); | |
290 | emit barsetsRemoved(sets); |
|
291 | emit barsetsRemoved(sets); | |
291 | emit countChanged(); |
|
292 | emit countChanged(); | |
292 | } |
|
293 | } | |
293 | return success; |
|
294 | return success; | |
294 | } |
|
295 | } | |
295 |
|
296 | |||
296 | /*! |
|
297 | /*! | |
297 | Adds a list of barsets to series. Takes ownership of \a sets. |
|
298 | Adds a list of barsets to series. Takes ownership of \a sets. | |
298 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, |
|
299 | Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series, | |
299 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended |
|
300 | nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended | |
300 | and function returns false. |
|
301 | and function returns false. | |
301 | */ |
|
302 | */ | |
302 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) |
|
303 | bool QAbstractBarSeries::append(QList<QBarSet* > sets) | |
303 | { |
|
304 | { | |
304 | Q_D(QAbstractBarSeries); |
|
305 | Q_D(QAbstractBarSeries); | |
305 | bool success = d->append(sets); |
|
306 | bool success = d->append(sets); | |
306 | if (success) { |
|
307 | if (success) { | |
307 | emit barsetsAdded(sets); |
|
308 | emit barsetsAdded(sets); | |
308 | emit countChanged(); |
|
309 | emit countChanged(); | |
309 | } |
|
310 | } | |
310 | return success; |
|
311 | return success; | |
311 | } |
|
312 | } | |
312 |
|
313 | |||
313 | /*! |
|
314 | /*! | |
314 | 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. |
|
315 | 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. | |
315 | Returns true, if inserting succeeded. |
|
316 | Returns true, if inserting succeeded. | |
316 |
|
317 | |||
317 | */ |
|
318 | */ | |
318 | bool QAbstractBarSeries::insert(int index, QBarSet *set) |
|
319 | bool QAbstractBarSeries::insert(int index, QBarSet *set) | |
319 | { |
|
320 | { | |
320 | Q_D(QAbstractBarSeries); |
|
321 | Q_D(QAbstractBarSeries); | |
321 | bool success = d->insert(index, set); |
|
322 | bool success = d->insert(index, set); | |
322 | if (success) { |
|
323 | if (success) { | |
323 | QList<QBarSet*> sets; |
|
324 | QList<QBarSet*> sets; | |
324 | sets.append(set); |
|
325 | sets.append(set); | |
325 | emit barsetsAdded(sets); |
|
326 | emit barsetsAdded(sets); | |
326 | emit countChanged(); |
|
327 | emit countChanged(); | |
327 | } |
|
328 | } | |
328 | return success; |
|
329 | return success; | |
329 | } |
|
330 | } | |
330 |
|
331 | |||
331 | /*! |
|
332 | /*! | |
332 | Removes all barsets from the series. Deletes removed sets. |
|
333 | Removes all barsets from the series. Deletes removed sets. | |
333 | */ |
|
334 | */ | |
334 | void QAbstractBarSeries::clear() |
|
335 | void QAbstractBarSeries::clear() | |
335 | { |
|
336 | { | |
336 | Q_D(QAbstractBarSeries); |
|
337 | Q_D(QAbstractBarSeries); | |
337 | QList<QBarSet *> sets = barSets(); |
|
338 | QList<QBarSet *> sets = barSets(); | |
338 | bool success = d->remove(sets); |
|
339 | bool success = d->remove(sets); | |
339 | if (success) { |
|
340 | if (success) { | |
340 | emit barsetsRemoved(sets); |
|
341 | emit barsetsRemoved(sets); | |
341 | emit countChanged(); |
|
342 | emit countChanged(); | |
342 | foreach (QBarSet* set, sets) { |
|
343 | foreach (QBarSet* set, sets) { | |
343 | delete set; |
|
344 | delete set; | |
344 | } |
|
345 | } | |
345 | } |
|
346 | } | |
346 | } |
|
347 | } | |
347 |
|
348 | |||
348 | /*! |
|
349 | /*! | |
349 | Returns number of sets in series. |
|
350 | Returns number of sets in series. | |
350 | */ |
|
351 | */ | |
351 | int QAbstractBarSeries::count() const |
|
352 | int QAbstractBarSeries::count() const | |
352 | { |
|
353 | { | |
353 | Q_D(const QAbstractBarSeries); |
|
354 | Q_D(const QAbstractBarSeries); | |
354 | return d->m_barSets.count(); |
|
355 | return d->m_barSets.count(); | |
355 | } |
|
356 | } | |
356 |
|
357 | |||
357 | /*! |
|
358 | /*! | |
358 | Returns a list of sets in series. Keeps ownership of sets. |
|
359 | Returns a list of sets in series. Keeps ownership of sets. | |
359 | */ |
|
360 | */ | |
360 | QList<QBarSet*> QAbstractBarSeries::barSets() const |
|
361 | QList<QBarSet*> QAbstractBarSeries::barSets() const | |
361 | { |
|
362 | { | |
362 | Q_D(const QAbstractBarSeries); |
|
363 | Q_D(const QAbstractBarSeries); | |
363 | return d->m_barSets; |
|
364 | return d->m_barSets; | |
364 | } |
|
365 | } | |
365 |
|
366 | |||
366 | /*! |
|
367 | /*! | |
367 | Sets the visibility of labels in series to \a visible |
|
368 | Sets the visibility of labels in series to \a visible | |
368 | */ |
|
369 | */ | |
369 | void QAbstractBarSeries::setLabelsVisible(bool visible) |
|
370 | void QAbstractBarSeries::setLabelsVisible(bool visible) | |
370 | { |
|
371 | { | |
371 | Q_D(QAbstractBarSeries); |
|
372 | Q_D(QAbstractBarSeries); | |
372 | if (d->m_labelsVisible != visible) { |
|
373 | if (d->m_labelsVisible != visible) { | |
373 | d->setLabelsVisible(visible); |
|
374 | d->setLabelsVisible(visible); | |
374 | emit labelsVisibleChanged(); |
|
375 | emit labelsVisibleChanged(); | |
375 | } |
|
376 | } | |
376 | } |
|
377 | } | |
377 |
|
378 | |||
378 | /*! |
|
379 | /*! | |
379 | Returns the visibility of labels |
|
380 | Returns the visibility of labels | |
380 | */ |
|
381 | */ | |
381 | bool QAbstractBarSeries::isLabelsVisible() const |
|
382 | bool QAbstractBarSeries::isLabelsVisible() const | |
382 | { |
|
383 | { | |
383 | Q_D(const QAbstractBarSeries); |
|
384 | Q_D(const QAbstractBarSeries); | |
384 | return d->m_labelsVisible; |
|
385 | return d->m_labelsVisible; | |
385 | } |
|
386 | } | |
386 |
|
387 | |||
|
388 | /*! | |||
|
389 | Sets the grouped drawing mode for bars. If \a grouping is true, then the bars | |||
|
390 | are drawn at same position inside group. Can be used for example to draw negative bars | |||
|
391 | at same position on axis than positive bars. | |||
|
392 | */ | |||
387 | void QAbstractBarSeries::setGrouping(bool grouping) |
|
393 | void QAbstractBarSeries::setGrouping(bool grouping) | |
388 | { |
|
394 | { | |
389 | Q_D(QAbstractBarSeries); |
|
395 | Q_D(QAbstractBarSeries); | |
390 | d->setGrouping(grouping); |
|
396 | d->setGrouping(grouping); | |
391 | } |
|
397 | } | |
392 |
|
398 | |||
393 |
|
399 | |||
394 |
|
400 | |||
395 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
401 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
396 |
|
402 | |||
397 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : |
|
403 | QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) : | |
398 | QAbstractSeriesPrivate(q), |
|
404 | QAbstractSeriesPrivate(q), | |
399 | m_barWidth(0.5), // Default value is 50% of category width |
|
405 | m_barWidth(0.5), // Default value is 50% of category width | |
400 | m_labelsVisible(false), |
|
406 | m_labelsVisible(false), | |
401 | m_visible(true), |
|
407 | m_visible(true), | |
402 | m_grouping(true) |
|
408 | m_grouping(true) | |
403 | { |
|
409 | { | |
404 | } |
|
410 | } | |
405 |
|
411 | |||
406 | int QAbstractBarSeriesPrivate::categoryCount() const |
|
412 | int QAbstractBarSeriesPrivate::categoryCount() const | |
407 | { |
|
413 | { | |
408 | // No categories defined. return count of longest set. |
|
414 | // No categories defined. return count of longest set. | |
409 | int count = 0; |
|
415 | int count = 0; | |
410 | for (int i=0; i<m_barSets.count(); i++) { |
|
416 | for (int i=0; i<m_barSets.count(); i++) { | |
411 | if (m_barSets.at(i)->count() > count) { |
|
417 | if (m_barSets.at(i)->count() > count) { | |
412 | count = m_barSets.at(i)->count(); |
|
418 | count = m_barSets.at(i)->count(); | |
413 | } |
|
419 | } | |
414 | } |
|
420 | } | |
415 |
|
421 | |||
416 | return count; |
|
422 | return count; | |
417 | } |
|
423 | } | |
418 |
|
424 | |||
419 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) |
|
425 | void QAbstractBarSeriesPrivate::setBarWidth(qreal width) | |
420 | { |
|
426 | { | |
421 | if (width < 0.0) { |
|
427 | if (width < 0.0) { | |
422 | width = 0.0; |
|
428 | width = 0.0; | |
423 | } |
|
429 | } | |
424 | m_barWidth = width; |
|
430 | m_barWidth = width; | |
425 | emit updatedBars(); |
|
431 | emit updatedBars(); | |
426 | } |
|
432 | } | |
427 |
|
433 | |||
428 | qreal QAbstractBarSeriesPrivate::barWidth() const |
|
434 | qreal QAbstractBarSeriesPrivate::barWidth() const | |
429 | { |
|
435 | { | |
430 | return m_barWidth; |
|
436 | return m_barWidth; | |
431 | } |
|
437 | } | |
432 |
|
438 | |||
433 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) |
|
439 | QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index) | |
434 | { |
|
440 | { | |
435 | return m_barSets.at(index); |
|
441 | return m_barSets.at(index); | |
436 | } |
|
442 | } | |
437 |
|
443 | |||
438 | void QAbstractBarSeriesPrivate::setVisible(bool visible) |
|
444 | void QAbstractBarSeriesPrivate::setVisible(bool visible) | |
439 | { |
|
445 | { | |
440 | m_visible = visible; |
|
446 | m_visible = visible; | |
441 | emit updatedBars(); |
|
447 | emit updatedBars(); | |
442 | } |
|
448 | } | |
443 |
|
449 | |||
444 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) |
|
450 | void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible) | |
445 | { |
|
451 | { | |
446 | m_labelsVisible = visible; |
|
452 | m_labelsVisible = visible; | |
447 | emit labelsVisibleChanged(visible); |
|
453 | emit labelsVisibleChanged(visible); | |
448 | } |
|
454 | } | |
449 |
|
455 | |||
450 | void QAbstractBarSeriesPrivate::setGrouping(bool grouping) |
|
456 | void QAbstractBarSeriesPrivate::setGrouping(bool grouping) | |
451 | { |
|
457 | { | |
452 | if (m_grouping != grouping) { |
|
458 | if (m_grouping != grouping) { | |
453 | m_grouping = grouping; |
|
459 | m_grouping = grouping; | |
454 | emit updatedBars(); |
|
460 | emit updatedBars(); | |
455 | } |
|
461 | } | |
456 | } |
|
462 | } | |
457 |
|
463 | |||
458 | qreal QAbstractBarSeriesPrivate::min() |
|
464 | qreal QAbstractBarSeriesPrivate::min() | |
459 | { |
|
465 | { | |
460 | if (m_barSets.count() <= 0) { |
|
466 | if (m_barSets.count() <= 0) { | |
461 | return 0; |
|
467 | return 0; | |
462 | } |
|
468 | } | |
463 | qreal min = INT_MAX; |
|
469 | qreal min = INT_MAX; | |
464 |
|
470 | |||
465 | for (int i = 0; i < m_barSets.count(); i++) { |
|
471 | for (int i = 0; i < m_barSets.count(); i++) { | |
466 | int categoryCount = m_barSets.at(i)->count(); |
|
472 | int categoryCount = m_barSets.at(i)->count(); | |
467 | for (int j = 0; j < categoryCount; j++) { |
|
473 | for (int j = 0; j < categoryCount; j++) { | |
468 | qreal temp = m_barSets.at(i)->at(j); |
|
474 | qreal temp = m_barSets.at(i)->at(j); | |
469 | if (temp < min) |
|
475 | if (temp < min) | |
470 | min = temp; |
|
476 | min = temp; | |
471 | } |
|
477 | } | |
472 | } |
|
478 | } | |
473 | return min; |
|
479 | return min; | |
474 | } |
|
480 | } | |
475 |
|
481 | |||
476 | qreal QAbstractBarSeriesPrivate::max() |
|
482 | qreal QAbstractBarSeriesPrivate::max() | |
477 | { |
|
483 | { | |
478 | if (m_barSets.count() <= 0) { |
|
484 | if (m_barSets.count() <= 0) { | |
479 | return 0; |
|
485 | return 0; | |
480 | } |
|
486 | } | |
481 | qreal max = INT_MIN; |
|
487 | qreal max = INT_MIN; | |
482 |
|
488 | |||
483 | for (int i = 0; i < m_barSets.count(); i++) { |
|
489 | for (int i = 0; i < m_barSets.count(); i++) { | |
484 | int categoryCount = m_barSets.at(i)->count(); |
|
490 | int categoryCount = m_barSets.at(i)->count(); | |
485 | for (int j = 0; j < categoryCount; j++) { |
|
491 | for (int j = 0; j < categoryCount; j++) { | |
486 | qreal temp = m_barSets.at(i)->at(j); |
|
492 | qreal temp = m_barSets.at(i)->at(j); | |
487 | if (temp > max) |
|
493 | if (temp > max) | |
488 | max = temp; |
|
494 | max = temp; | |
489 | } |
|
495 | } | |
490 | } |
|
496 | } | |
491 |
|
497 | |||
492 | return max; |
|
498 | return max; | |
493 | } |
|
499 | } | |
494 |
|
500 | |||
495 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) |
|
501 | qreal QAbstractBarSeriesPrivate::valueAt(int set, int category) | |
496 | { |
|
502 | { | |
497 | if ((set < 0) || (set >= m_barSets.count())) { |
|
503 | if ((set < 0) || (set >= m_barSets.count())) { | |
498 | // No set, no value. |
|
504 | // No set, no value. | |
499 | return 0; |
|
505 | return 0; | |
500 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
506 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
501 | // No category, no value. |
|
507 | // No category, no value. | |
502 | return 0; |
|
508 | return 0; | |
503 | } |
|
509 | } | |
504 |
|
510 | |||
505 | return m_barSets.at(set)->at(category); |
|
511 | return m_barSets.at(set)->at(category); | |
506 | } |
|
512 | } | |
507 |
|
513 | |||
508 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) |
|
514 | qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category) | |
509 | { |
|
515 | { | |
510 | if ((set < 0) || (set >= m_barSets.count())) { |
|
516 | if ((set < 0) || (set >= m_barSets.count())) { | |
511 | // No set, no value. |
|
517 | // No set, no value. | |
512 | return 0; |
|
518 | return 0; | |
513 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { |
|
519 | } else if ((category < 0) || (category >= m_barSets.at(set)->count())) { | |
514 | // No category, no value. |
|
520 | // No category, no value. | |
515 | return 0; |
|
521 | return 0; | |
516 | } |
|
522 | } | |
517 |
|
523 | |||
518 | qreal value = m_barSets.at(set)->at(category); |
|
524 | qreal value = m_barSets.at(set)->at(category); | |
519 | qreal sum = categorySum(category); |
|
525 | qreal sum = categorySum(category); | |
520 | if ( qFuzzyIsNull(sum) ) { |
|
526 | if ( qFuzzyIsNull(sum) ) { | |
521 | return 0; |
|
527 | return 0; | |
522 | } |
|
528 | } | |
523 |
|
529 | |||
524 | return value / sum; |
|
530 | return value / sum; | |
525 | } |
|
531 | } | |
526 |
|
532 | |||
527 | qreal QAbstractBarSeriesPrivate::categorySum(int category) |
|
533 | qreal QAbstractBarSeriesPrivate::categorySum(int category) | |
528 | { |
|
534 | { | |
529 | qreal sum(0); |
|
535 | qreal sum(0); | |
530 | int count = m_barSets.count(); // Count sets |
|
536 | int count = m_barSets.count(); // Count sets | |
531 | for (int set = 0; set < count; set++) { |
|
537 | for (int set = 0; set < count; set++) { | |
532 | if (category < m_barSets.at(set)->count()) |
|
538 | if (category < m_barSets.at(set)->count()) | |
533 | sum += m_barSets.at(set)->at(category); |
|
539 | sum += m_barSets.at(set)->at(category); | |
534 | } |
|
540 | } | |
535 | return sum; |
|
541 | return sum; | |
536 | } |
|
542 | } | |
537 |
|
543 | |||
538 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) |
|
544 | qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category) | |
539 | { |
|
545 | { | |
540 | qreal sum(0); |
|
546 | qreal sum(0); | |
541 | int count = m_barSets.count(); // Count sets |
|
547 | int count = m_barSets.count(); // Count sets | |
542 | for (int set = 0; set < count; set++) { |
|
548 | for (int set = 0; set < count; set++) { | |
543 | if (category < m_barSets.at(set)->count()) |
|
549 | if (category < m_barSets.at(set)->count()) | |
544 | sum += qAbs(m_barSets.at(set)->at(category)); |
|
550 | sum += qAbs(m_barSets.at(set)->at(category)); | |
545 | } |
|
551 | } | |
546 | return sum; |
|
552 | return sum; | |
547 | } |
|
553 | } | |
548 |
|
554 | |||
549 | qreal QAbstractBarSeriesPrivate::maxCategorySum() |
|
555 | qreal QAbstractBarSeriesPrivate::maxCategorySum() | |
550 | { |
|
556 | { | |
551 | qreal max = INT_MIN; |
|
557 | qreal max = INT_MIN; | |
552 | int count = categoryCount(); |
|
558 | int count = categoryCount(); | |
553 | for (int i = 0; i < count; i++) { |
|
559 | for (int i = 0; i < count; i++) { | |
554 | qreal sum = categorySum(i); |
|
560 | qreal sum = categorySum(i); | |
555 | if (sum > max) |
|
561 | if (sum > max) | |
556 | max = sum; |
|
562 | max = sum; | |
557 | } |
|
563 | } | |
558 | return max; |
|
564 | return max; | |
559 | } |
|
565 | } | |
560 |
|
566 | |||
561 | qreal QAbstractBarSeriesPrivate::minX() |
|
567 | qreal QAbstractBarSeriesPrivate::minX() | |
562 | { |
|
568 | { | |
563 | if (m_barSets.count() <= 0) { |
|
569 | if (m_barSets.count() <= 0) { | |
564 | return 0; |
|
570 | return 0; | |
565 | } |
|
571 | } | |
566 | qreal min = INT_MAX; |
|
572 | qreal min = INT_MAX; | |
567 |
|
573 | |||
568 | for (int i = 0; i < m_barSets.count(); i++) { |
|
574 | for (int i = 0; i < m_barSets.count(); i++) { | |
569 | int categoryCount = m_barSets.at(i)->count(); |
|
575 | int categoryCount = m_barSets.at(i)->count(); | |
570 | for (int j = 0; j < categoryCount; j++) { |
|
576 | for (int j = 0; j < categoryCount; j++) { | |
571 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
577 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
572 | if (temp < min) |
|
578 | if (temp < min) | |
573 | min = temp; |
|
579 | min = temp; | |
574 | } |
|
580 | } | |
575 | } |
|
581 | } | |
576 | return min; |
|
582 | return min; | |
577 | } |
|
583 | } | |
578 |
|
584 | |||
579 | qreal QAbstractBarSeriesPrivate::maxX() |
|
585 | qreal QAbstractBarSeriesPrivate::maxX() | |
580 | { |
|
586 | { | |
581 | if (m_barSets.count() <= 0) { |
|
587 | if (m_barSets.count() <= 0) { | |
582 | return 0; |
|
588 | return 0; | |
583 | } |
|
589 | } | |
584 | qreal max = INT_MIN; |
|
590 | qreal max = INT_MIN; | |
585 |
|
591 | |||
586 | for (int i = 0; i < m_barSets.count(); i++) { |
|
592 | for (int i = 0; i < m_barSets.count(); i++) { | |
587 | int categoryCount = m_barSets.at(i)->count(); |
|
593 | int categoryCount = m_barSets.at(i)->count(); | |
588 | for (int j = 0; j < categoryCount; j++) { |
|
594 | for (int j = 0; j < categoryCount; j++) { | |
589 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); |
|
595 | qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x(); | |
590 | if (temp > max) |
|
596 | if (temp > max) | |
591 | max = temp; |
|
597 | max = temp; | |
592 | } |
|
598 | } | |
593 | } |
|
599 | } | |
594 |
|
600 | |||
595 | return max; |
|
601 | return max; | |
596 | } |
|
602 | } | |
597 |
|
603 | |||
598 |
|
604 | |||
599 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) |
|
605 | void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain) | |
600 | { |
|
606 | { | |
601 | qreal minX(domain.minX()); |
|
607 | qreal minX(domain.minX()); | |
602 | qreal minY(domain.minY()); |
|
608 | qreal minY(domain.minY()); | |
603 | qreal maxX(domain.maxX()); |
|
609 | qreal maxX(domain.maxX()); | |
604 | qreal maxY(domain.maxY()); |
|
610 | qreal maxY(domain.maxY()); | |
605 |
|
611 | |||
606 | qreal seriesMinX = this->minX(); |
|
612 | qreal seriesMinX = this->minX(); | |
607 | qreal seriesMaxX = this->maxX(); |
|
613 | qreal seriesMaxX = this->maxX(); | |
608 | qreal y = max(); |
|
614 | qreal y = max(); | |
609 | minX = qMin(minX, seriesMinX - (qreal)0.5); |
|
615 | minX = qMin(minX, seriesMinX - (qreal)0.5); | |
610 | minY = qMin(minY, y); |
|
616 | minY = qMin(minY, y); | |
611 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); |
|
617 | maxX = qMax(maxX, seriesMaxX + (qreal)0.5); | |
612 | maxY = qMax(maxY, y); |
|
618 | maxY = qMax(maxY, y); | |
613 |
|
619 | |||
614 | domain.setRange(minX,maxX,minY,maxY); |
|
620 | domain.setRange(minX,maxX,minY,maxY); | |
615 | } |
|
621 | } | |
616 |
|
622 | |||
617 | ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
623 | ChartElement* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
618 | { |
|
624 | { | |
619 | Q_UNUSED(presenter); |
|
625 | Q_UNUSED(presenter); | |
620 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; |
|
626 | qWarning() << "QAbstractBarSeriesPrivate::createGraphics called"; | |
621 | return 0; |
|
627 | return 0; | |
622 | } |
|
628 | } | |
623 |
|
629 | |||
624 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) |
|
630 | QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend) | |
625 | { |
|
631 | { | |
626 | Q_Q(QAbstractBarSeries); |
|
632 | Q_Q(QAbstractBarSeries); | |
627 | QList<LegendMarker*> markers; |
|
633 | QList<LegendMarker*> markers; | |
628 | foreach(QBarSet* set, q->barSets()) { |
|
634 | foreach(QBarSet* set, q->barSets()) { | |
629 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); |
|
635 | BarLegendMarker* marker = new BarLegendMarker(q,set,legend); | |
630 | markers << marker; |
|
636 | markers << marker; | |
631 | } |
|
637 | } | |
632 |
|
638 | |||
633 | return markers; |
|
639 | return markers; | |
634 | } |
|
640 | } | |
635 |
|
641 | |||
636 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) |
|
642 | bool QAbstractBarSeriesPrivate::append(QBarSet *set) | |
637 | { |
|
643 | { | |
638 | Q_Q(QAbstractBarSeries); |
|
644 | Q_Q(QAbstractBarSeries); | |
639 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
645 | if ((m_barSets.contains(set)) || (set == 0)) { | |
640 | // Fail if set is already in list or set is null. |
|
646 | // Fail if set is already in list or set is null. | |
641 | return false; |
|
647 | return false; | |
642 | } |
|
648 | } | |
643 | m_barSets.append(set); |
|
649 | m_barSets.append(set); | |
644 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
650 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
645 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
651 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
646 | emit restructuredBars(); // this notifies barchartitem |
|
652 | emit restructuredBars(); // this notifies barchartitem | |
647 | if (m_dataset) { |
|
653 | if (m_dataset) { | |
648 | m_dataset->updateSeries(q); // this notifies legend |
|
654 | m_dataset->updateSeries(q); // this notifies legend | |
649 | } |
|
655 | } | |
650 | return true; |
|
656 | return true; | |
651 | } |
|
657 | } | |
652 |
|
658 | |||
653 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) |
|
659 | bool QAbstractBarSeriesPrivate::remove(QBarSet *set) | |
654 | { |
|
660 | { | |
655 | Q_Q(QAbstractBarSeries); |
|
661 | Q_Q(QAbstractBarSeries); | |
656 | if (!m_barSets.contains(set)) { |
|
662 | if (!m_barSets.contains(set)) { | |
657 | // Fail if set is not in list |
|
663 | // Fail if set is not in list | |
658 | return false; |
|
664 | return false; | |
659 | } |
|
665 | } | |
660 | m_barSets.removeOne(set); |
|
666 | m_barSets.removeOne(set); | |
661 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
667 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
662 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
668 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
663 | emit restructuredBars(); // this notifies barchartitem |
|
669 | emit restructuredBars(); // this notifies barchartitem | |
664 | if (m_dataset) { |
|
670 | if (m_dataset) { | |
665 | m_dataset->updateSeries(q); // this notifies legend |
|
671 | m_dataset->updateSeries(q); // this notifies legend | |
666 | } |
|
672 | } | |
667 | return true; |
|
673 | return true; | |
668 | } |
|
674 | } | |
669 |
|
675 | |||
670 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) |
|
676 | bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets) | |
671 | { |
|
677 | { | |
672 | Q_Q(QAbstractBarSeries); |
|
678 | Q_Q(QAbstractBarSeries); | |
673 | foreach (QBarSet* set, sets) { |
|
679 | foreach (QBarSet* set, sets) { | |
674 | if ((set == 0) || (m_barSets.contains(set))) { |
|
680 | if ((set == 0) || (m_barSets.contains(set))) { | |
675 | // Fail if any of the sets is null or is already appended. |
|
681 | // Fail if any of the sets is null or is already appended. | |
676 | return false; |
|
682 | return false; | |
677 | } |
|
683 | } | |
678 | if (sets.count(set) != 1) { |
|
684 | if (sets.count(set) != 1) { | |
679 | // Also fail if same set is more than once in given list. |
|
685 | // Also fail if same set is more than once in given list. | |
680 | return false; |
|
686 | return false; | |
681 | } |
|
687 | } | |
682 | } |
|
688 | } | |
683 |
|
689 | |||
684 | foreach (QBarSet* set, sets) { |
|
690 | foreach (QBarSet* set, sets) { | |
685 | m_barSets.append(set); |
|
691 | m_barSets.append(set); | |
686 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
692 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
687 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
693 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
688 | } |
|
694 | } | |
689 | emit restructuredBars(); // this notifies barchartitem |
|
695 | emit restructuredBars(); // this notifies barchartitem | |
690 | if (m_dataset) { |
|
696 | if (m_dataset) { | |
691 | m_dataset->updateSeries(q); // this notifies legend |
|
697 | m_dataset->updateSeries(q); // this notifies legend | |
692 | } |
|
698 | } | |
693 | return true; |
|
699 | return true; | |
694 | } |
|
700 | } | |
695 |
|
701 | |||
696 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) |
|
702 | bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets) | |
697 | { |
|
703 | { | |
698 | Q_Q(QAbstractBarSeries); |
|
704 | Q_Q(QAbstractBarSeries); | |
699 | if (sets.count() == 0) { |
|
705 | if (sets.count() == 0) { | |
700 | return false; |
|
706 | return false; | |
701 | } |
|
707 | } | |
702 | foreach (QBarSet* set, sets) { |
|
708 | foreach (QBarSet* set, sets) { | |
703 | if ((set == 0) || (!m_barSets.contains(set))) { |
|
709 | if ((set == 0) || (!m_barSets.contains(set))) { | |
704 | // Fail if any of the sets is null or is not in series |
|
710 | // Fail if any of the sets is null or is not in series | |
705 | return false; |
|
711 | return false; | |
706 | } |
|
712 | } | |
707 | if (sets.count(set) != 1) { |
|
713 | if (sets.count(set) != 1) { | |
708 | // Also fail if same set is more than once in given list. |
|
714 | // Also fail if same set is more than once in given list. | |
709 | return false; |
|
715 | return false; | |
710 | } |
|
716 | } | |
711 | } |
|
717 | } | |
712 |
|
718 | |||
713 | foreach (QBarSet* set, sets) { |
|
719 | foreach (QBarSet* set, sets) { | |
714 | m_barSets.removeOne(set); |
|
720 | m_barSets.removeOne(set); | |
715 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
721 | QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
716 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
722 | QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
717 | } |
|
723 | } | |
718 |
|
724 | |||
719 | emit restructuredBars(); // this notifies barchartitem |
|
725 | emit restructuredBars(); // this notifies barchartitem | |
720 | if (m_dataset) { |
|
726 | if (m_dataset) { | |
721 | m_dataset->updateSeries(q); // this notifies legend |
|
727 | m_dataset->updateSeries(q); // this notifies legend | |
722 | } |
|
728 | } | |
723 | return true; |
|
729 | return true; | |
724 | } |
|
730 | } | |
725 |
|
731 | |||
726 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) |
|
732 | bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set) | |
727 | { |
|
733 | { | |
728 | Q_Q(QAbstractBarSeries); |
|
734 | Q_Q(QAbstractBarSeries); | |
729 | if ((m_barSets.contains(set)) || (set == 0)) { |
|
735 | if ((m_barSets.contains(set)) || (set == 0)) { | |
730 | // Fail if set is already in list or set is null. |
|
736 | // Fail if set is already in list or set is null. | |
731 | return false; |
|
737 | return false; | |
732 | } |
|
738 | } | |
733 | m_barSets.insert(index, set); |
|
739 | m_barSets.insert(index, set); | |
734 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); |
|
740 | QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars())); | |
735 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); |
|
741 | QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars())); | |
736 | emit restructuredBars(); // this notifies barchartitem |
|
742 | emit restructuredBars(); // this notifies barchartitem | |
737 | if (m_dataset) { |
|
743 | if (m_dataset) { | |
738 | m_dataset->updateSeries(q); // this notifies legend |
|
744 | m_dataset->updateSeries(q); // this notifies legend | |
739 | } |
|
745 | } | |
740 | return true; |
|
746 | return true; | |
741 | } |
|
747 | } | |
742 |
|
748 | |||
743 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) |
|
749 | void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis* axis) | |
744 | { |
|
750 | { | |
745 | Q_Q(QAbstractBarSeries); |
|
751 | Q_Q(QAbstractBarSeries); | |
746 |
|
752 | |||
747 | if(axis->type()==QAbstractAxis::AxisTypeBarCategory) { |
|
753 | if(axis->type()==QAbstractAxis::AxisTypeBarCategory) { | |
748 |
|
754 | |||
749 | switch(q->type()) { |
|
755 | switch(q->type()) { | |
750 |
|
756 | |||
751 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
757 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
752 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
758 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
753 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { |
|
759 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { | |
754 |
|
760 | |||
755 | if(axis->orientation()==Qt::Vertical) |
|
761 | if(axis->orientation()==Qt::Vertical) | |
756 | { |
|
762 | { | |
757 | populateCategories(qobject_cast<QBarCategoryAxis*>(axis)); |
|
763 | populateCategories(qobject_cast<QBarCategoryAxis*>(axis)); | |
758 | } |
|
764 | } | |
759 | break; |
|
765 | break; | |
760 | } |
|
766 | } | |
761 | case QAbstractSeries::SeriesTypeBar: |
|
767 | case QAbstractSeries::SeriesTypeBar: | |
762 | case QAbstractSeries::SeriesTypePercentBar: |
|
768 | case QAbstractSeries::SeriesTypePercentBar: | |
763 | case QAbstractSeries::SeriesTypeStackedBar: { |
|
769 | case QAbstractSeries::SeriesTypeStackedBar: { | |
764 |
|
770 | |||
765 | if(axis->orientation()==Qt::Horizontal) |
|
771 | if(axis->orientation()==Qt::Horizontal) | |
766 | { |
|
772 | { | |
767 | populateCategories(qobject_cast<QBarCategoryAxis*>(axis)); |
|
773 | populateCategories(qobject_cast<QBarCategoryAxis*>(axis)); | |
768 | } |
|
774 | } | |
769 | break; |
|
775 | break; | |
770 | } |
|
776 | } | |
771 | default: |
|
777 | default: | |
772 | qWarning()<<"Unexpected series type"; |
|
778 | qWarning()<<"Unexpected series type"; | |
773 | break; |
|
779 | break; | |
774 |
|
780 | |||
775 | } |
|
781 | } | |
776 | } |
|
782 | } | |
777 | } |
|
783 | } | |
778 |
|
784 | |||
779 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const |
|
785 | QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const | |
780 | { |
|
786 | { | |
781 | Q_Q(const QAbstractBarSeries); |
|
787 | Q_Q(const QAbstractBarSeries); | |
782 |
|
788 | |||
783 | switch(q->type()) { |
|
789 | switch(q->type()) { | |
784 |
|
790 | |||
785 | case QAbstractSeries::SeriesTypeHorizontalBar: |
|
791 | case QAbstractSeries::SeriesTypeHorizontalBar: | |
786 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: |
|
792 | case QAbstractSeries::SeriesTypeHorizontalPercentBar: | |
787 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { |
|
793 | case QAbstractSeries::SeriesTypeHorizontalStackedBar: { | |
788 |
|
794 | |||
789 | if(orientation==Qt::Vertical) |
|
795 | if(orientation==Qt::Vertical) | |
790 | { |
|
796 | { | |
791 | return QAbstractAxis::AxisTypeBarCategory; |
|
797 | return QAbstractAxis::AxisTypeBarCategory; | |
792 | } |
|
798 | } | |
793 | break; |
|
799 | break; | |
794 | } |
|
800 | } | |
795 | case QAbstractSeries::SeriesTypeBar: |
|
801 | case QAbstractSeries::SeriesTypeBar: | |
796 | case QAbstractSeries::SeriesTypePercentBar: |
|
802 | case QAbstractSeries::SeriesTypePercentBar: | |
797 | case QAbstractSeries::SeriesTypeStackedBar: { |
|
803 | case QAbstractSeries::SeriesTypeStackedBar: { | |
798 |
|
804 | |||
799 | if(orientation==Qt::Horizontal) |
|
805 | if(orientation==Qt::Horizontal) | |
800 | { |
|
806 | { | |
801 | return QAbstractAxis::AxisTypeBarCategory; |
|
807 | return QAbstractAxis::AxisTypeBarCategory; | |
802 | } |
|
808 | } | |
803 | break; |
|
809 | break; | |
804 | } |
|
810 | } | |
805 | default: |
|
811 | default: | |
806 | qWarning()<<"Unexpected series type"; |
|
812 | qWarning()<<"Unexpected series type"; | |
807 | break; |
|
813 | break; | |
808 |
|
814 | |||
809 | } |
|
815 | } | |
810 | return QAbstractAxis::AxisTypeValue; |
|
816 | return QAbstractAxis::AxisTypeValue; | |
811 |
|
817 | |||
812 | } |
|
818 | } | |
813 |
|
819 | |||
814 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis* axis) |
|
820 | void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis* axis) | |
815 | { |
|
821 | { | |
816 | QStringList categories; |
|
822 | QStringList categories; | |
817 | if(axis->categories().isEmpty()) { |
|
823 | if(axis->categories().isEmpty()) { | |
818 | for (int i(1); i < categoryCount()+1; i++) |
|
824 | for (int i(1); i < categoryCount()+1; i++) | |
819 | categories << QString::number(i); |
|
825 | categories << QString::number(i); | |
820 | axis->append(categories); |
|
826 | axis->append(categories); | |
821 | } |
|
827 | } | |
822 | } |
|
828 | } | |
823 |
|
829 | |||
824 | #include "moc_qabstractbarseries.cpp" |
|
830 | #include "moc_qabstractbarseries.cpp" | |
825 | #include "moc_qabstractbarseries_p.cpp" |
|
831 | #include "moc_qabstractbarseries_p.cpp" | |
826 |
|
832 | |||
827 |
|
833 | |||
828 | QTCOMMERCIALCHART_END_NAMESPACE |
|
834 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,91 +1,89 | |||||
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 | #ifndef ABSTRACTBARSERIES_H |
|
21 | #ifndef ABSTRACTBARSERIES_H | |
22 | #define ABSTRACTBARSERIES_H |
|
22 | #define ABSTRACTBARSERIES_H | |
23 |
|
23 | |||
24 | #include <qabstractseries.h> |
|
24 | #include <qabstractseries.h> | |
25 | #include <QStringList> |
|
25 | #include <QStringList> | |
26 |
|
26 | |||
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
28 |
|
28 | |||
29 | class QBarSet; |
|
29 | class QBarSet; | |
30 | class QAbstractBarSeriesPrivate; |
|
30 | class QAbstractBarSeriesPrivate; | |
31 |
|
31 | |||
32 | // Container for series |
|
32 | // Container for series | |
33 | class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries |
|
33 | class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries | |
34 | { |
|
34 | { | |
35 | Q_OBJECT |
|
35 | Q_OBJECT | |
36 | Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth) |
|
36 | Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth) | |
37 | Q_PROPERTY(int count READ count NOTIFY countChanged) |
|
37 | Q_PROPERTY(int count READ count NOTIFY countChanged) | |
38 | Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) |
|
38 | Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged) | |
39 |
|
39 | |||
40 | protected: |
|
40 | protected: | |
41 | //TODO DEPRECIATED |
|
41 | //TODO DEPRECIATED | |
42 | explicit QAbstractBarSeries(QObject *parent = 0); |
|
42 | explicit QAbstractBarSeries(QObject *parent = 0); | |
43 |
|
43 | |||
44 | public: |
|
44 | public: | |
45 | virtual ~QAbstractBarSeries(); |
|
45 | virtual ~QAbstractBarSeries(); | |
46 |
|
46 | |||
47 | void setBarWidth(qreal width); |
|
47 | void setBarWidth(qreal width); | |
48 | qreal barWidth() const; |
|
48 | qreal barWidth() const; | |
49 |
|
49 | |||
50 | bool append(QBarSet *set); |
|
50 | bool append(QBarSet *set); | |
51 | bool remove(QBarSet *set); |
|
51 | bool remove(QBarSet *set); | |
52 | bool take(QBarSet *set); |
|
52 | bool take(QBarSet *set); | |
53 | bool append(QList<QBarSet* > sets); |
|
53 | bool append(QList<QBarSet* > sets); | |
54 | bool insert(int index, QBarSet *set); |
|
54 | bool insert(int index, QBarSet *set); | |
55 | int count() const; |
|
55 | int count() const; | |
56 | QList<QBarSet*> barSets() const; |
|
56 | QList<QBarSet*> barSets() const; | |
57 | void clear(); |
|
57 | void clear(); | |
58 |
|
58 | |||
59 | void setLabelsVisible(bool visible = true); |
|
59 | void setLabelsVisible(bool visible = true); | |
60 | bool isLabelsVisible() const; |
|
60 | bool isLabelsVisible() const; | |
61 |
|
61 | |||
62 | // TODO. Good name for this. This affects how bars are laid out on chart. (for example with pyramid chart) |
|
|||
63 | // Also do we support same for stacked and percent bar charts or just normal bar charts? |
|
|||
64 | void setGrouping(bool grouping = true); |
|
62 | void setGrouping(bool grouping = true); | |
65 |
|
63 | |||
66 | protected: |
|
64 | protected: | |
67 | explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0); |
|
65 | explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0); | |
68 |
|
66 | |||
69 | Q_SIGNALS: |
|
67 | Q_SIGNALS: | |
70 | void clicked(int index, QBarSet *barset); |
|
68 | void clicked(int index, QBarSet *barset); | |
71 | void hovered(bool status, QBarSet *barset); |
|
69 | void hovered(bool status, QBarSet *barset); | |
72 | void countChanged(); |
|
70 | void countChanged(); | |
73 | void labelsVisibleChanged(); |
|
71 | void labelsVisibleChanged(); | |
74 |
|
72 | |||
75 | void barsetsAdded(QList<QBarSet*> sets); |
|
73 | void barsetsAdded(QList<QBarSet*> sets); | |
76 | void barsetsRemoved(QList<QBarSet*> sets); |
|
74 | void barsetsRemoved(QList<QBarSet*> sets); | |
77 |
|
75 | |||
78 | protected: |
|
76 | protected: | |
79 | Q_DECLARE_PRIVATE(QAbstractBarSeries) |
|
77 | Q_DECLARE_PRIVATE(QAbstractBarSeries) | |
80 | friend class AbstractBarChartItem; |
|
78 | friend class AbstractBarChartItem; | |
81 | friend class PercentBarChartItem; |
|
79 | friend class PercentBarChartItem; | |
82 | friend class StackedBarChartItem; |
|
80 | friend class StackedBarChartItem; | |
83 | friend class BarChartItem; |
|
81 | friend class BarChartItem; | |
84 | friend class HorizontalBarChartItem; |
|
82 | friend class HorizontalBarChartItem; | |
85 | friend class HorizontalStackedBarChartItem; |
|
83 | friend class HorizontalStackedBarChartItem; | |
86 | friend class HorizontalPercentBarChartItem; |
|
84 | friend class HorizontalPercentBarChartItem; | |
87 | }; |
|
85 | }; | |
88 |
|
86 | |||
89 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | QTCOMMERCIALCHART_END_NAMESPACE | |
90 |
|
88 | |||
91 | #endif // ABSTRACTBARSERIES_H |
|
89 | #endif // ABSTRACTBARSERIES_H |
@@ -1,121 +1,124 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "qbarseries.h" |
|
21 | #include "qbarseries.h" | |
22 | #include "qbarseries_p.h" |
|
22 | #include "qbarseries_p.h" | |
23 | #include "barchartitem_p.h" |
|
23 | #include "barchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "baranimation_p.h" |
|
26 | #include "baranimation_p.h" | |
27 | #include "qvalueaxis.h" |
|
27 | #include "qvalueaxis.h" | |
28 | #include "qbarcategoryaxis.h" |
|
28 | #include "qbarcategoryaxis.h" | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
30 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
31 |
|
31 | |||
32 | /*! |
|
32 | /*! | |
33 | \class QBarSeries |
|
33 | \class QBarSeries | |
34 | \brief Series for creating bar chart |
|
34 | \brief Series for creating bar chart | |
35 | \mainclass |
|
35 | \mainclass | |
36 |
|
36 | |||
37 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
37 | QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
38 | as groups, where bars in same category are grouped next to each other. QBarSeries groups the data |
|
38 | as groups, where bars in same category are grouped next to each other. QBarSeries groups the data | |
39 | from sets to categories, which are defined by a QStringList. |
|
39 | from sets to categories, which are defined by a QStringList. | |
40 |
|
40 | |||
41 | See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart. |
|
41 | See the \l {BarChart Example} {bar chart example} to learn how to create a grouped bar chart. | |
42 | \image examples_barchart.png |
|
42 | \image examples_barchart.png | |
43 |
|
43 | |||
44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries |
|
44 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries, QStackedBarSeries | |
45 | */ |
|
45 | */ | |
46 | /*! |
|
46 | /*! | |
47 | \qmlclass BarSeries QBarSeries |
|
47 | \qmlclass BarSeries QBarSeries | |
48 | \inherits AbstractBarSeries |
|
48 | \inherits AbstractBarSeries | |
49 |
|
49 | |||
50 | The following QML shows how to create a simple grouped bar chart: |
|
50 | The following QML shows how to create a simple grouped bar chart: | |
51 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 |
|
51 | \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1 | |
52 | \beginfloatleft |
|
52 | \beginfloatleft | |
53 | \image demos_qmlchart6.png |
|
53 | \image demos_qmlchart6.png | |
54 | \endfloat |
|
54 | \endfloat | |
55 | \clearfloat |
|
55 | \clearfloat | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | Constructs empty QBarSeries. |
|
59 | Constructs empty QBarSeries. | |
60 | QBarSeries is QObject which is a child of a \a parent. |
|
60 | QBarSeries is QObject which is a child of a \a parent. | |
61 | */ |
|
61 | */ | |
62 | QBarSeries::QBarSeries(QObject *parent) |
|
62 | QBarSeries::QBarSeries(QObject *parent) | |
63 | : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent) |
|
63 | : QAbstractBarSeries(*new QBarSeriesPrivate(this), parent) | |
64 | { |
|
64 | { | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | /*! |
|
67 | /*! | |
68 | Returns QChartSeries::SeriesTypeBar. |
|
68 | Returns QChartSeries::SeriesTypeBar. | |
69 | */ |
|
69 | */ | |
70 | QAbstractSeries::SeriesType QBarSeries::type() const |
|
70 | QAbstractSeries::SeriesType QBarSeries::type() const | |
71 | { |
|
71 | { | |
72 | return QAbstractSeries::SeriesTypeBar; |
|
72 | return QAbstractSeries::SeriesTypeBar; | |
73 | } |
|
73 | } | |
74 |
|
74 | |||
|
75 | /*! | |||
|
76 | Destructor. Removes series from chart. | |||
|
77 | */ | |||
75 | QBarSeries::~QBarSeries() |
|
78 | QBarSeries::~QBarSeries() | |
76 | { |
|
79 | { | |
77 | Q_D(QBarSeries); |
|
80 | Q_D(QBarSeries); | |
78 | if(d->m_dataset) { |
|
81 | if(d->m_dataset) { | |
79 | d->m_dataset->removeSeries(this); |
|
82 | d->m_dataset->removeSeries(this); | |
80 | } |
|
83 | } | |
81 | } |
|
84 | } | |
82 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
85 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
83 |
|
86 | |||
84 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
87 | QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
85 | { |
|
88 | { | |
86 |
|
89 | |||
87 | } |
|
90 | } | |
88 |
|
91 | |||
89 | void QBarSeriesPrivate::scaleDomain(Domain& domain) |
|
92 | void QBarSeriesPrivate::scaleDomain(Domain& domain) | |
90 | { |
|
93 | { | |
91 | qreal minX(domain.minX()); |
|
94 | qreal minX(domain.minX()); | |
92 | qreal minY(domain.minY()); |
|
95 | qreal minY(domain.minY()); | |
93 | qreal maxX(domain.maxX()); |
|
96 | qreal maxX(domain.maxX()); | |
94 | qreal maxY(domain.maxY()); |
|
97 | qreal maxY(domain.maxY()); | |
95 |
|
98 | |||
96 | qreal x = categoryCount(); |
|
99 | qreal x = categoryCount(); | |
97 | minX = qMin(minX, - (qreal)0.5); |
|
100 | minX = qMin(minX, - (qreal)0.5); | |
98 | minY = qMin(minY, min()); |
|
101 | minY = qMin(minY, min()); | |
99 | maxX = qMax(maxX, x - (qreal)0.5); |
|
102 | maxX = qMax(maxX, x - (qreal)0.5); | |
100 | maxY = qMax(maxY, max()); |
|
103 | maxY = qMax(maxY, max()); | |
101 |
|
104 | |||
102 | domain.setRange(minX,maxX,minY,maxY); |
|
105 | domain.setRange(minX,maxX,minY,maxY); | |
103 | } |
|
106 | } | |
104 |
|
107 | |||
105 |
|
108 | |||
106 | ChartElement* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
109 | ChartElement* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
107 | { |
|
110 | { | |
108 | Q_Q(QBarSeries); |
|
111 | Q_Q(QBarSeries); | |
109 |
|
112 | |||
110 | BarChartItem* bar = new BarChartItem(q,presenter); |
|
113 | BarChartItem* bar = new BarChartItem(q,presenter); | |
111 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
114 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
112 | bar->setAnimation(new BarAnimation(bar)); |
|
115 | bar->setAnimation(new BarAnimation(bar)); | |
113 | } |
|
116 | } | |
114 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
117 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
115 | return bar; |
|
118 | return bar; | |
116 | } |
|
119 | } | |
117 |
|
120 | |||
118 | #include "moc_qbarseries.cpp" |
|
121 | #include "moc_qbarseries.cpp" | |
119 |
|
122 | |||
120 | QTCOMMERCIALCHART_END_NAMESPACE |
|
123 | QTCOMMERCIALCHART_END_NAMESPACE | |
121 |
|
124 |
@@ -1,121 +1,124 | |||||
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 "qpercentbarseries.h" |
|
21 | #include "qpercentbarseries.h" | |
22 | #include "qpercentbarseries_p.h" |
|
22 | #include "qpercentbarseries_p.h" | |
23 | #include "percentbarchartitem_p.h" |
|
23 | #include "percentbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "qvalueaxis.h" |
|
26 | #include "qvalueaxis.h" | |
27 | #include "percentbaranimation_p.h" |
|
27 | #include "percentbaranimation_p.h" | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | /*! |
|
31 | /*! | |
32 | \class QPercentBarSeries |
|
32 | \class QPercentBarSeries | |
33 | \brief Series for creating percent bar chart |
|
33 | \brief Series for creating percent bar chart | |
34 | \mainclass |
|
34 | \mainclass | |
35 |
|
35 | |||
36 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
36 | QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
37 | as stacks, where each bar is shown as percentage of all bars in that category. |
|
37 | as stacks, where each bar is shown as percentage of all bars in that category. | |
38 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. |
|
38 | QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList. | |
39 |
|
39 | |||
40 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. |
|
40 | See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart. | |
41 | \image examples_percentbarchart.png |
|
41 | \image examples_percentbarchart.png | |
42 |
|
42 | |||
43 | \sa QBarSet, QStackedBarSeries, QAbstractBarSeries |
|
43 | \sa QBarSet, QStackedBarSeries, QAbstractBarSeries | |
44 | */ |
|
44 | */ | |
45 | /*! |
|
45 | /*! | |
46 | \qmlclass PercentBarSeries QPercentBarSeries |
|
46 | \qmlclass PercentBarSeries QPercentBarSeries | |
47 | \inherits QAbstractBarSeries |
|
47 | \inherits QAbstractBarSeries | |
48 |
|
48 | |||
49 | The following QML shows how to create a simple percent bar chart: |
|
49 | The following QML shows how to create a simple percent bar chart: | |
50 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 |
|
50 | \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1 | |
51 | \beginfloatleft |
|
51 | \beginfloatleft | |
52 | \image demos_qmlchart8.png |
|
52 | \image demos_qmlchart8.png | |
53 | \endfloat |
|
53 | \endfloat | |
54 | \clearfloat |
|
54 | \clearfloat | |
55 | */ |
|
55 | */ | |
56 |
|
56 | |||
57 | /*! |
|
57 | /*! | |
58 | Constructs empty QPercentBarSeries. |
|
58 | Constructs empty QPercentBarSeries. | |
59 | QPercentBarSeries is QObject which is a child of a \a parent. |
|
59 | QPercentBarSeries is QObject which is a child of a \a parent. | |
60 | */ |
|
60 | */ | |
61 | QPercentBarSeries::QPercentBarSeries(QObject *parent) |
|
61 | QPercentBarSeries::QPercentBarSeries(QObject *parent) | |
62 | : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent) |
|
62 | : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent) | |
63 | { |
|
63 | { | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
|
66 | /*! | |||
|
67 | Destructor. Removes series from chart. | |||
|
68 | */ | |||
66 | QPercentBarSeries::~QPercentBarSeries() |
|
69 | QPercentBarSeries::~QPercentBarSeries() | |
67 | { |
|
70 | { | |
68 | Q_D(QPercentBarSeries); |
|
71 | Q_D(QPercentBarSeries); | |
69 | if(d->m_dataset) { |
|
72 | if(d->m_dataset) { | |
70 | d->m_dataset->removeSeries(this); |
|
73 | d->m_dataset->removeSeries(this); | |
71 | } |
|
74 | } | |
72 | } |
|
75 | } | |
73 |
|
76 | |||
74 | /*! |
|
77 | /*! | |
75 | Returns QChartSeries::SeriesTypePercentBar. |
|
78 | Returns QChartSeries::SeriesTypePercentBar. | |
76 | */ |
|
79 | */ | |
77 | QAbstractSeries::SeriesType QPercentBarSeries::type() const |
|
80 | QAbstractSeries::SeriesType QPercentBarSeries::type() const | |
78 | { |
|
81 | { | |
79 | return QAbstractSeries::SeriesTypePercentBar; |
|
82 | return QAbstractSeries::SeriesTypePercentBar; | |
80 | } |
|
83 | } | |
81 |
|
84 | |||
82 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
85 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
83 |
|
86 | |||
84 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
87 | QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
85 | { |
|
88 | { | |
86 |
|
89 | |||
87 | } |
|
90 | } | |
88 |
|
91 | |||
89 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) |
|
92 | void QPercentBarSeriesPrivate::scaleDomain(Domain& domain) | |
90 | { |
|
93 | { | |
91 | qreal minX(domain.minX()); |
|
94 | qreal minX(domain.minX()); | |
92 | qreal minY(domain.minY()); |
|
95 | qreal minY(domain.minY()); | |
93 | qreal maxX(domain.maxX()); |
|
96 | qreal maxX(domain.maxX()); | |
94 | qreal maxY(domain.maxY()); |
|
97 | qreal maxY(domain.maxY()); | |
95 |
|
98 | |||
96 | qreal x = categoryCount(); |
|
99 | qreal x = categoryCount(); | |
97 | minX = qMin(minX, - (qreal)0.5); |
|
100 | minX = qMin(minX, - (qreal)0.5); | |
98 | maxX = qMax(maxX, x - (qreal)0.5); |
|
101 | maxX = qMax(maxX, x - (qreal)0.5); | |
99 | minY = 0; |
|
102 | minY = 0; | |
100 | maxY = 100; |
|
103 | maxY = 100; | |
101 |
|
104 | |||
102 | domain.setRange(minX,maxX,minY,maxY); |
|
105 | domain.setRange(minX,maxX,minY,maxY); | |
103 | } |
|
106 | } | |
104 |
|
107 | |||
105 |
|
108 | |||
106 | ChartElement* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
109 | ChartElement* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
107 | { |
|
110 | { | |
108 | Q_Q(QPercentBarSeries); |
|
111 | Q_Q(QPercentBarSeries); | |
109 |
|
112 | |||
110 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); |
|
113 | PercentBarChartItem* bar = new PercentBarChartItem(q,presenter); | |
111 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
114 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
112 | bar->setAnimation(new PercentBarAnimation(bar)); |
|
115 | bar->setAnimation(new PercentBarAnimation(bar)); | |
113 | } |
|
116 | } | |
114 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
117 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
115 | return bar; |
|
118 | return bar; | |
116 | } |
|
119 | } | |
117 |
|
120 | |||
118 | #include "moc_qpercentbarseries.cpp" |
|
121 | #include "moc_qpercentbarseries.cpp" | |
119 |
|
122 | |||
120 | QTCOMMERCIALCHART_END_NAMESPACE |
|
123 | QTCOMMERCIALCHART_END_NAMESPACE | |
121 |
|
124 |
@@ -1,122 +1,125 | |||||
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 "qstackedbarseries.h" |
|
21 | #include "qstackedbarseries.h" | |
22 | #include "qstackedbarseries_p.h" |
|
22 | #include "qstackedbarseries_p.h" | |
23 | #include "stackedbarchartitem_p.h" |
|
23 | #include "stackedbarchartitem_p.h" | |
24 | #include "chartdataset_p.h" |
|
24 | #include "chartdataset_p.h" | |
25 | #include "charttheme_p.h" |
|
25 | #include "charttheme_p.h" | |
26 | #include "qvalueaxis.h" |
|
26 | #include "qvalueaxis.h" | |
27 | #include "stackedbaranimation_p.h" |
|
27 | #include "stackedbaranimation_p.h" | |
28 |
|
28 | |||
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
29 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
30 |
|
30 | |||
31 | /*! |
|
31 | /*! | |
32 | \class QStackedBarSeries |
|
32 | \class QStackedBarSeries | |
33 | \brief Series for creating stacked bar chart |
|
33 | \brief Series for creating stacked bar chart | |
34 | \mainclass |
|
34 | \mainclass | |
35 |
|
35 | |||
36 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars |
|
36 | QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars | |
37 | as stacks, where bars in same category are stacked on top of each other. |
|
37 | as stacks, where bars in same category are stacked on top of each other. | |
38 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. |
|
38 | QStackedBarSeries groups the data from sets to categories, which are defined by QStringList. | |
39 |
|
39 | |||
40 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. |
|
40 | See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart. | |
41 | \image examples_stackedbarchart.png |
|
41 | \image examples_stackedbarchart.png | |
42 |
|
42 | |||
43 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries |
|
43 | \sa QBarSet, QPercentBarSeries, QAbstractBarSeries | |
44 | */ |
|
44 | */ | |
45 |
|
45 | |||
46 | /*! |
|
46 | /*! | |
47 | \qmlclass StackedBarSeries QStackedBarSeries |
|
47 | \qmlclass StackedBarSeries QStackedBarSeries | |
48 | \inherits AbstractBarSeries |
|
48 | \inherits AbstractBarSeries | |
49 |
|
49 | |||
50 | The following QML shows how to create a simple stacked bar chart: |
|
50 | The following QML shows how to create a simple stacked bar chart: | |
51 | \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1 |
|
51 | \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1 | |
52 | \beginfloatleft |
|
52 | \beginfloatleft | |
53 | \image demos_qmlchart7.png |
|
53 | \image demos_qmlchart7.png | |
54 | \endfloat |
|
54 | \endfloat | |
55 | \clearfloat |
|
55 | \clearfloat | |
56 | */ |
|
56 | */ | |
57 |
|
57 | |||
58 | /*! |
|
58 | /*! | |
59 | Constructs empty QStackedBarSeries. |
|
59 | Constructs empty QStackedBarSeries. | |
60 | QStackedBarSeries is QObject which is a child of a \a parent. |
|
60 | QStackedBarSeries is QObject which is a child of a \a parent. | |
61 | */ |
|
61 | */ | |
62 | QStackedBarSeries::QStackedBarSeries(QObject *parent) |
|
62 | QStackedBarSeries::QStackedBarSeries(QObject *parent) | |
63 | : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent) |
|
63 | : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent) | |
64 | { |
|
64 | { | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
|
67 | /*! | |||
|
68 | Destructor. Removes series from chart. | |||
|
69 | */ | |||
67 | QStackedBarSeries::~QStackedBarSeries() |
|
70 | QStackedBarSeries::~QStackedBarSeries() | |
68 | { |
|
71 | { | |
69 | Q_D(QStackedBarSeries); |
|
72 | Q_D(QStackedBarSeries); | |
70 | if(d->m_dataset) { |
|
73 | if(d->m_dataset) { | |
71 | d->m_dataset->removeSeries(this); |
|
74 | d->m_dataset->removeSeries(this); | |
72 | } |
|
75 | } | |
73 | } |
|
76 | } | |
74 | /*! |
|
77 | /*! | |
75 | Returns QChartSeries::SeriesTypeStackedBar. |
|
78 | Returns QChartSeries::SeriesTypeStackedBar. | |
76 | */ |
|
79 | */ | |
77 | QAbstractSeries::SeriesType QStackedBarSeries::type() const |
|
80 | QAbstractSeries::SeriesType QStackedBarSeries::type() const | |
78 | { |
|
81 | { | |
79 | return QAbstractSeries::SeriesTypeStackedBar; |
|
82 | return QAbstractSeries::SeriesTypeStackedBar; | |
80 | } |
|
83 | } | |
81 |
|
84 | |||
82 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
|
85 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | |
83 |
|
86 | |||
84 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) |
|
87 | QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q) | |
85 | { |
|
88 | { | |
86 |
|
89 | |||
87 | } |
|
90 | } | |
88 |
|
91 | |||
89 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) |
|
92 | void QStackedBarSeriesPrivate::scaleDomain(Domain& domain) | |
90 | { |
|
93 | { | |
91 | qreal minX(domain.minX()); |
|
94 | qreal minX(domain.minX()); | |
92 | qreal minY(domain.minY()); |
|
95 | qreal minY(domain.minY()); | |
93 | qreal maxX(domain.maxX()); |
|
96 | qreal maxX(domain.maxX()); | |
94 | qreal maxY(domain.maxY()); |
|
97 | qreal maxY(domain.maxY()); | |
95 |
|
98 | |||
96 | qreal x = categoryCount(); |
|
99 | qreal x = categoryCount(); | |
97 | qreal y = maxCategorySum(); |
|
100 | qreal y = maxCategorySum(); | |
98 | minX = qMin(minX, - (qreal)0.5); |
|
101 | minX = qMin(minX, - (qreal)0.5); | |
99 | minY = qMin(minY, y); |
|
102 | minY = qMin(minY, y); | |
100 | maxX = qMax(maxX, x - (qreal)0.5); |
|
103 | maxX = qMax(maxX, x - (qreal)0.5); | |
101 | maxY = qMax(maxY, y); |
|
104 | maxY = qMax(maxY, y); | |
102 |
|
105 | |||
103 | domain.setRange(minX,maxX,minY,maxY); |
|
106 | domain.setRange(minX,maxX,minY,maxY); | |
104 | } |
|
107 | } | |
105 |
|
108 | |||
106 |
|
109 | |||
107 | ChartElement* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) |
|
110 | ChartElement* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter) | |
108 | { |
|
111 | { | |
109 | Q_Q(QStackedBarSeries); |
|
112 | Q_Q(QStackedBarSeries); | |
110 |
|
113 | |||
111 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); |
|
114 | StackedBarChartItem* bar = new StackedBarChartItem(q,presenter); | |
112 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { |
|
115 | if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) { | |
113 | bar->setAnimation(new StackedBarAnimation(bar)); |
|
116 | bar->setAnimation(new StackedBarAnimation(bar)); | |
114 | } |
|
117 | } | |
115 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); |
|
118 | presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q)); | |
116 | return bar; |
|
119 | return bar; | |
117 | } |
|
120 | } | |
118 |
|
121 | |||
119 | #include "moc_qstackedbarseries.cpp" |
|
122 | #include "moc_qstackedbarseries.cpp" | |
120 |
|
123 | |||
121 | QTCOMMERCIALCHART_END_NAMESPACE |
|
124 | QTCOMMERCIALCHART_END_NAMESPACE | |
122 |
|
125 |
General Comments 0
You need to be logged in to leave comments.
Login now