##// END OF EJS Templates
Documentation fixes to QML ScatterSeries and AbstractBarSeries
Tero Ahola -
r2115:070dc48e7b5c
parent child
Show More
@@ -1,811 +1,810
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::onBarsetsAdded(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::onBarsetsRemoved(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 is a list of reals.
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)]);
169 \endcode
168 \endcode
170 */
169 */
171
170
172 /*!
171 /*!
173 \qmlmethod BarSet AbstractBarSeries::insert(int index, string label, VariantList values)
172 \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.
173 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
174 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
176 appended.
175 appended.
177 \sa AbstractBarSeries::append()
176 \sa AbstractBarSeries::append()
178 */
177 */
179
178
180 /*!
179 /*!
181 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
180 \qmlmethod bool AbstractBarSeries::remove(BarSet barset)
182 Removes the barset from the series. Returns true if successful, false otherwise.
181 Removes the barset from the series. Returns true if successful, false otherwise.
183 */
182 */
184
183
185 /*!
184 /*!
186 \qmlmethod AbstractBarSeries::clear()
185 \qmlmethod AbstractBarSeries::clear()
187 Removes all barsets from the series.
186 Removes all barsets from the series.
188 */
187 */
189
188
190 /*!
189 /*!
191 Destructs abstractbarseries and owned barsets.
190 Destructs abstractbarseries and owned barsets.
192 */
191 */
193 QAbstractBarSeries::~QAbstractBarSeries()
192 QAbstractBarSeries::~QAbstractBarSeries()
194 {
193 {
195
194
196 }
195 }
197
196
198 /*!
197 /*!
199 \internal
198 \internal
200 */
199 */
201 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
200 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &o, QObject *parent)
202 : QAbstractSeries(o, parent)
201 : QAbstractSeries(o, parent)
203 {
202 {
204 Q_D(QAbstractSeries);
203 Q_D(QAbstractSeries);
205 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
204 QObject::connect(this, SIGNAL(countChanged()), d, SIGNAL(countChanged()));
206 }
205 }
207
206
208 /*!
207 /*!
209 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
208 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
210 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
209 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
211 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
210 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
212 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
211 Note that with \link QBarSeries \endlink this value means the width of one group of bars instead of just one bar.
213 */
212 */
214 void QAbstractBarSeries::setBarWidth(qreal width)
213 void QAbstractBarSeries::setBarWidth(qreal width)
215 {
214 {
216 Q_D(QAbstractBarSeries);
215 Q_D(QAbstractBarSeries);
217 d->setBarWidth(width);
216 d->setBarWidth(width);
218 }
217 }
219
218
220 /*!
219 /*!
221 Returns the width of the bars of the series.
220 Returns the width of the bars of the series.
222 \sa setBarWidth()
221 \sa setBarWidth()
223 */
222 */
224 qreal QAbstractBarSeries::barWidth() const
223 qreal QAbstractBarSeries::barWidth() const
225 {
224 {
226 Q_D(const QAbstractBarSeries);
225 Q_D(const QAbstractBarSeries);
227 return d->barWidth();
226 return d->barWidth();
228 }
227 }
229
228
230 /*!
229 /*!
231 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.
230 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.
232 Returns true, if appending succeeded.
231 Returns true, if appending succeeded.
233 */
232 */
234 bool QAbstractBarSeries::append(QBarSet *set)
233 bool QAbstractBarSeries::append(QBarSet *set)
235 {
234 {
236 Q_D(QAbstractBarSeries);
235 Q_D(QAbstractBarSeries);
237 bool success = d->append(set);
236 bool success = d->append(set);
238 if (success) {
237 if (success) {
239 QList<QBarSet *> sets;
238 QList<QBarSet *> sets;
240 sets.append(set);
239 sets.append(set);
241 set->setParent(this);
240 set->setParent(this);
242 emit barsetsAdded(sets);
241 emit barsetsAdded(sets);
243 emit countChanged();
242 emit countChanged();
244 }
243 }
245 return success;
244 return success;
246 }
245 }
247
246
248 /*!
247 /*!
249 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
248 Removes barset from series. Releases ownership of \a set. Deletes the set, if remove
250 was successful.
249 was successful.
251 Returns true, if set was removed.
250 Returns true, if set was removed.
252 */
251 */
253 bool QAbstractBarSeries::remove(QBarSet *set)
252 bool QAbstractBarSeries::remove(QBarSet *set)
254 {
253 {
255 Q_D(QAbstractBarSeries);
254 Q_D(QAbstractBarSeries);
256 bool success = d->remove(set);
255 bool success = d->remove(set);
257 if (success) {
256 if (success) {
258 QList<QBarSet *> sets;
257 QList<QBarSet *> sets;
259 sets.append(set);
258 sets.append(set);
260 set->setParent(0);
259 set->setParent(0);
261 emit barsetsRemoved(sets);
260 emit barsetsRemoved(sets);
262 emit countChanged();
261 emit countChanged();
263 delete set;
262 delete set;
264 set = 0;
263 set = 0;
265 }
264 }
266 return success;
265 return success;
267 }
266 }
268
267
269 /*!
268 /*!
270 Takes a single \a set from the series. Does not delete the barset object.
269 Takes a single \a set from the series. Does not delete the barset object.
271
270
272 NOTE: The series remains as the barset's parent object. You must set the
271 NOTE: The series remains as the barset's parent object. You must set the
273 parent object to take full ownership.
272 parent object to take full ownership.
274
273
275 Returns true if take was successful.
274 Returns true if take was successful.
276 */
275 */
277 bool QAbstractBarSeries::take(QBarSet *set)
276 bool QAbstractBarSeries::take(QBarSet *set)
278 {
277 {
279 Q_D(QAbstractBarSeries);
278 Q_D(QAbstractBarSeries);
280 bool success = d->remove(set);
279 bool success = d->remove(set);
281 if (success) {
280 if (success) {
282 QList<QBarSet *> sets;
281 QList<QBarSet *> sets;
283 sets.append(set);
282 sets.append(set);
284 emit barsetsRemoved(sets);
283 emit barsetsRemoved(sets);
285 emit countChanged();
284 emit countChanged();
286 }
285 }
287 return success;
286 return success;
288 }
287 }
289
288
290 /*!
289 /*!
291 Adds a list of barsets to series. Takes ownership of \a sets.
290 Adds a list of barsets to series. Takes ownership of \a sets.
292 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
291 Returns true, if all sets were appended successfully. If any of the sets is null or is already appended to series,
293 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
292 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
294 and function returns false.
293 and function returns false.
295 */
294 */
296 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
295 bool QAbstractBarSeries::append(QList<QBarSet *> sets)
297 {
296 {
298 Q_D(QAbstractBarSeries);
297 Q_D(QAbstractBarSeries);
299 bool success = d->append(sets);
298 bool success = d->append(sets);
300 if (success) {
299 if (success) {
301 emit barsetsAdded(sets);
300 emit barsetsAdded(sets);
302 emit countChanged();
301 emit countChanged();
303 }
302 }
304 return success;
303 return success;
305 }
304 }
306
305
307 /*!
306 /*!
308 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.
307 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.
309 Returns true, if inserting succeeded.
308 Returns true, if inserting succeeded.
310
309
311 */
310 */
312 bool QAbstractBarSeries::insert(int index, QBarSet *set)
311 bool QAbstractBarSeries::insert(int index, QBarSet *set)
313 {
312 {
314 Q_D(QAbstractBarSeries);
313 Q_D(QAbstractBarSeries);
315 bool success = d->insert(index, set);
314 bool success = d->insert(index, set);
316 if (success) {
315 if (success) {
317 QList<QBarSet *> sets;
316 QList<QBarSet *> sets;
318 sets.append(set);
317 sets.append(set);
319 emit barsetsAdded(sets);
318 emit barsetsAdded(sets);
320 emit countChanged();
319 emit countChanged();
321 }
320 }
322 return success;
321 return success;
323 }
322 }
324
323
325 /*!
324 /*!
326 Removes all barsets from the series. Deletes removed sets.
325 Removes all barsets from the series. Deletes removed sets.
327 */
326 */
328 void QAbstractBarSeries::clear()
327 void QAbstractBarSeries::clear()
329 {
328 {
330 Q_D(QAbstractBarSeries);
329 Q_D(QAbstractBarSeries);
331 QList<QBarSet *> sets = barSets();
330 QList<QBarSet *> sets = barSets();
332 bool success = d->remove(sets);
331 bool success = d->remove(sets);
333 if (success) {
332 if (success) {
334 emit barsetsRemoved(sets);
333 emit barsetsRemoved(sets);
335 emit countChanged();
334 emit countChanged();
336 foreach (QBarSet *set, sets)
335 foreach (QBarSet *set, sets)
337 delete set;
336 delete set;
338 }
337 }
339 }
338 }
340
339
341 /*!
340 /*!
342 Returns number of sets in series.
341 Returns number of sets in series.
343 */
342 */
344 int QAbstractBarSeries::count() const
343 int QAbstractBarSeries::count() const
345 {
344 {
346 Q_D(const QAbstractBarSeries);
345 Q_D(const QAbstractBarSeries);
347 return d->m_barSets.count();
346 return d->m_barSets.count();
348 }
347 }
349
348
350 /*!
349 /*!
351 Returns a list of sets in series. Keeps ownership of sets.
350 Returns a list of sets in series. Keeps ownership of sets.
352 */
351 */
353 QList<QBarSet *> QAbstractBarSeries::barSets() const
352 QList<QBarSet *> QAbstractBarSeries::barSets() const
354 {
353 {
355 Q_D(const QAbstractBarSeries);
354 Q_D(const QAbstractBarSeries);
356 return d->m_barSets;
355 return d->m_barSets;
357 }
356 }
358
357
359 /*!
358 /*!
360 Sets the visibility of labels in series to \a visible
359 Sets the visibility of labels in series to \a visible
361 */
360 */
362 void QAbstractBarSeries::setLabelsVisible(bool visible)
361 void QAbstractBarSeries::setLabelsVisible(bool visible)
363 {
362 {
364 Q_D(QAbstractBarSeries);
363 Q_D(QAbstractBarSeries);
365 if (d->m_labelsVisible != visible) {
364 if (d->m_labelsVisible != visible) {
366 d->setLabelsVisible(visible);
365 d->setLabelsVisible(visible);
367 emit labelsVisibleChanged();
366 emit labelsVisibleChanged();
368 }
367 }
369 }
368 }
370
369
371 /*!
370 /*!
372 Returns the visibility of labels
371 Returns the visibility of labels
373 */
372 */
374 bool QAbstractBarSeries::isLabelsVisible() const
373 bool QAbstractBarSeries::isLabelsVisible() const
375 {
374 {
376 Q_D(const QAbstractBarSeries);
375 Q_D(const QAbstractBarSeries);
377 return d->m_labelsVisible;
376 return d->m_labelsVisible;
378 }
377 }
379
378
380 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
379 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
381
380
382 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
381 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
383 QAbstractSeriesPrivate(q),
382 QAbstractSeriesPrivate(q),
384 m_barWidth(0.5), // Default value is 50% of category width
383 m_barWidth(0.5), // Default value is 50% of category width
385 m_labelsVisible(false),
384 m_labelsVisible(false),
386 m_visible(true)
385 m_visible(true)
387 {
386 {
388 }
387 }
389
388
390 int QAbstractBarSeriesPrivate::categoryCount() const
389 int QAbstractBarSeriesPrivate::categoryCount() const
391 {
390 {
392 // No categories defined. return count of longest set.
391 // No categories defined. return count of longest set.
393 int count = 0;
392 int count = 0;
394 for (int i = 0; i < m_barSets.count(); i++) {
393 for (int i = 0; i < m_barSets.count(); i++) {
395 if (m_barSets.at(i)->count() > count)
394 if (m_barSets.at(i)->count() > count)
396 count = m_barSets.at(i)->count();
395 count = m_barSets.at(i)->count();
397 }
396 }
398
397
399 return count;
398 return count;
400 }
399 }
401
400
402 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
401 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
403 {
402 {
404 if (width < 0.0)
403 if (width < 0.0)
405 width = 0.0;
404 width = 0.0;
406 m_barWidth = width;
405 m_barWidth = width;
407 emit updatedLayout();
406 emit updatedLayout();
408 }
407 }
409
408
410 qreal QAbstractBarSeriesPrivate::barWidth() const
409 qreal QAbstractBarSeriesPrivate::barWidth() const
411 {
410 {
412 return m_barWidth;
411 return m_barWidth;
413 }
412 }
414
413
415 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
414 QBarSet *QAbstractBarSeriesPrivate::barsetAt(int index)
416 {
415 {
417 return m_barSets.at(index);
416 return m_barSets.at(index);
418 }
417 }
419
418
420 void QAbstractBarSeriesPrivate::setVisible(bool visible)
419 void QAbstractBarSeriesPrivate::setVisible(bool visible)
421 {
420 {
422 m_visible = visible;
421 m_visible = visible;
423 emit visibleChanged();
422 emit visibleChanged();
424 }
423 }
425
424
426 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
425 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
427 {
426 {
428 m_labelsVisible = visible;
427 m_labelsVisible = visible;
429 emit labelsVisibleChanged(visible);
428 emit labelsVisibleChanged(visible);
430 }
429 }
431
430
432 qreal QAbstractBarSeriesPrivate::min()
431 qreal QAbstractBarSeriesPrivate::min()
433 {
432 {
434 if (m_barSets.count() <= 0)
433 if (m_barSets.count() <= 0)
435 return 0;
434 return 0;
436
435
437 qreal min = INT_MAX;
436 qreal min = INT_MAX;
438
437
439 for (int i = 0; i < m_barSets.count(); i++) {
438 for (int i = 0; i < m_barSets.count(); i++) {
440 int categoryCount = m_barSets.at(i)->count();
439 int categoryCount = m_barSets.at(i)->count();
441 for (int j = 0; j < categoryCount; j++) {
440 for (int j = 0; j < categoryCount; j++) {
442 qreal temp = m_barSets.at(i)->at(j);
441 qreal temp = m_barSets.at(i)->at(j);
443 if (temp < min)
442 if (temp < min)
444 min = temp;
443 min = temp;
445 }
444 }
446 }
445 }
447 return min;
446 return min;
448 }
447 }
449
448
450 qreal QAbstractBarSeriesPrivate::max()
449 qreal QAbstractBarSeriesPrivate::max()
451 {
450 {
452 if (m_barSets.count() <= 0)
451 if (m_barSets.count() <= 0)
453 return 0;
452 return 0;
454
453
455 qreal max = INT_MIN;
454 qreal max = INT_MIN;
456
455
457 for (int i = 0; i < m_barSets.count(); i++) {
456 for (int i = 0; i < m_barSets.count(); i++) {
458 int categoryCount = m_barSets.at(i)->count();
457 int categoryCount = m_barSets.at(i)->count();
459 for (int j = 0; j < categoryCount; j++) {
458 for (int j = 0; j < categoryCount; j++) {
460 qreal temp = m_barSets.at(i)->at(j);
459 qreal temp = m_barSets.at(i)->at(j);
461 if (temp > max)
460 if (temp > max)
462 max = temp;
461 max = temp;
463 }
462 }
464 }
463 }
465
464
466 return max;
465 return max;
467 }
466 }
468
467
469 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
468 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
470 {
469 {
471 if ((set < 0) || (set >= m_barSets.count()))
470 if ((set < 0) || (set >= m_barSets.count()))
472 return 0; // No set, no value.
471 return 0; // No set, no value.
473 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
472 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
474 return 0; // No category, no value.
473 return 0; // No category, no value.
475
474
476 return m_barSets.at(set)->at(category);
475 return m_barSets.at(set)->at(category);
477 }
476 }
478
477
479 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
478 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
480 {
479 {
481 if ((set < 0) || (set >= m_barSets.count()))
480 if ((set < 0) || (set >= m_barSets.count()))
482 return 0; // No set, no value.
481 return 0; // No set, no value.
483 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
482 else if ((category < 0) || (category >= m_barSets.at(set)->count()))
484 return 0; // No category, no value.
483 return 0; // No category, no value.
485
484
486 qreal value = m_barSets.at(set)->at(category);
485 qreal value = m_barSets.at(set)->at(category);
487 qreal sum = categorySum(category);
486 qreal sum = categorySum(category);
488 if (qFuzzyIsNull(sum))
487 if (qFuzzyIsNull(sum))
489 return 0;
488 return 0;
490
489
491 return value / sum;
490 return value / sum;
492 }
491 }
493
492
494 qreal QAbstractBarSeriesPrivate::categorySum(int category)
493 qreal QAbstractBarSeriesPrivate::categorySum(int category)
495 {
494 {
496 qreal sum(0);
495 qreal sum(0);
497 int count = m_barSets.count(); // Count sets
496 int count = m_barSets.count(); // Count sets
498 for (int set = 0; set < count; set++) {
497 for (int set = 0; set < count; set++) {
499 if (category < m_barSets.at(set)->count())
498 if (category < m_barSets.at(set)->count())
500 sum += m_barSets.at(set)->at(category);
499 sum += m_barSets.at(set)->at(category);
501 }
500 }
502 return sum;
501 return sum;
503 }
502 }
504
503
505 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
504 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
506 {
505 {
507 qreal sum(0);
506 qreal sum(0);
508 int count = m_barSets.count(); // Count sets
507 int count = m_barSets.count(); // Count sets
509 for (int set = 0; set < count; set++) {
508 for (int set = 0; set < count; set++) {
510 if (category < m_barSets.at(set)->count())
509 if (category < m_barSets.at(set)->count())
511 sum += qAbs(m_barSets.at(set)->at(category));
510 sum += qAbs(m_barSets.at(set)->at(category));
512 }
511 }
513 return sum;
512 return sum;
514 }
513 }
515
514
516 qreal QAbstractBarSeriesPrivate::maxCategorySum()
515 qreal QAbstractBarSeriesPrivate::maxCategorySum()
517 {
516 {
518 qreal max = INT_MIN;
517 qreal max = INT_MIN;
519 int count = categoryCount();
518 int count = categoryCount();
520 for (int i = 0; i < count; i++) {
519 for (int i = 0; i < count; i++) {
521 qreal sum = categorySum(i);
520 qreal sum = categorySum(i);
522 if (sum > max)
521 if (sum > max)
523 max = sum;
522 max = sum;
524 }
523 }
525 return max;
524 return max;
526 }
525 }
527
526
528 qreal QAbstractBarSeriesPrivate::minX()
527 qreal QAbstractBarSeriesPrivate::minX()
529 {
528 {
530 if (m_barSets.count() <= 0)
529 if (m_barSets.count() <= 0)
531 return 0;
530 return 0;
532
531
533 qreal min = INT_MAX;
532 qreal min = INT_MAX;
534
533
535 for (int i = 0; i < m_barSets.count(); i++) {
534 for (int i = 0; i < m_barSets.count(); i++) {
536 int categoryCount = m_barSets.at(i)->count();
535 int categoryCount = m_barSets.at(i)->count();
537 for (int j = 0; j < categoryCount; j++) {
536 for (int j = 0; j < categoryCount; j++) {
538 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
537 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
539 if (temp < min)
538 if (temp < min)
540 min = temp;
539 min = temp;
541 }
540 }
542 }
541 }
543 return min;
542 return min;
544 }
543 }
545
544
546 qreal QAbstractBarSeriesPrivate::maxX()
545 qreal QAbstractBarSeriesPrivate::maxX()
547 {
546 {
548 if (m_barSets.count() <= 0)
547 if (m_barSets.count() <= 0)
549 return 0;
548 return 0;
550
549
551 qreal max = INT_MIN;
550 qreal max = INT_MIN;
552
551
553 for (int i = 0; i < m_barSets.count(); i++) {
552 for (int i = 0; i < m_barSets.count(); i++) {
554 int categoryCount = m_barSets.at(i)->count();
553 int categoryCount = m_barSets.at(i)->count();
555 for (int j = 0; j < categoryCount; j++) {
554 for (int j = 0; j < categoryCount; j++) {
556 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
555 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
557 if (temp > max)
556 if (temp > max)
558 max = temp;
557 max = temp;
559 }
558 }
560 }
559 }
561
560
562 return max;
561 return max;
563 }
562 }
564
563
565 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
564 qreal QAbstractBarSeriesPrivate::categoryTop(int category)
566 {
565 {
567 // Returns top (sum of all positive values) of category.
566 // Returns top (sum of all positive values) of category.
568 // Returns 0, if all values are negative
567 // Returns 0, if all values are negative
569 qreal top(0);
568 qreal top(0);
570 int count = m_barSets.count();
569 int count = m_barSets.count();
571 for (int set = 0; set < count; set++) {
570 for (int set = 0; set < count; set++) {
572 if (category < m_barSets.at(set)->count()) {
571 if (category < m_barSets.at(set)->count()) {
573 qreal temp = m_barSets.at(set)->at(category);
572 qreal temp = m_barSets.at(set)->at(category);
574 if (temp > 0) {
573 if (temp > 0) {
575 top += temp;
574 top += temp;
576 }
575 }
577 }
576 }
578 }
577 }
579 return top;
578 return top;
580 }
579 }
581
580
582 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
581 qreal QAbstractBarSeriesPrivate::categoryBottom(int category)
583 {
582 {
584 // Returns bottom (sum of all negative values) of category
583 // Returns bottom (sum of all negative values) of category
585 // Returns 0, if all values are positive
584 // Returns 0, if all values are positive
586 qreal bottom(0);
585 qreal bottom(0);
587 int count = m_barSets.count();
586 int count = m_barSets.count();
588 for (int set = 0; set < count; set++) {
587 for (int set = 0; set < count; set++) {
589 if (category < m_barSets.at(set)->count()) {
588 if (category < m_barSets.at(set)->count()) {
590 qreal temp = m_barSets.at(set)->at(category);
589 qreal temp = m_barSets.at(set)->at(category);
591 if (temp < 0) {
590 if (temp < 0) {
592 bottom += temp;
591 bottom += temp;
593 }
592 }
594 }
593 }
595 }
594 }
596 return bottom;
595 return bottom;
597 }
596 }
598
597
599 qreal QAbstractBarSeriesPrivate::top()
598 qreal QAbstractBarSeriesPrivate::top()
600 {
599 {
601 // Returns top of all categories
600 // Returns top of all categories
602 qreal top(0);
601 qreal top(0);
603 int count = categoryCount();
602 int count = categoryCount();
604 for (int i = 0; i < count; i++) {
603 for (int i = 0; i < count; i++) {
605 qreal temp = categoryTop(i);
604 qreal temp = categoryTop(i);
606 if (temp > top)
605 if (temp > top)
607 top = temp;
606 top = temp;
608 }
607 }
609 return top;
608 return top;
610 }
609 }
611
610
612 qreal QAbstractBarSeriesPrivate::bottom()
611 qreal QAbstractBarSeriesPrivate::bottom()
613 {
612 {
614 // Returns bottom of all categories
613 // Returns bottom of all categories
615 qreal bottom(0);
614 qreal bottom(0);
616 int count = categoryCount();
615 int count = categoryCount();
617 for (int i = 0; i < count; i++) {
616 for (int i = 0; i < count; i++) {
618 qreal temp = categoryBottom(i);
617 qreal temp = categoryBottom(i);
619 if (temp < bottom)
618 if (temp < bottom)
620 bottom = temp;
619 bottom = temp;
621 }
620 }
622 return bottom;
621 return bottom;
623 }
622 }
624
623
625
624
626 void QAbstractBarSeriesPrivate::scaleDomain(Domain &domain)
625 void QAbstractBarSeriesPrivate::scaleDomain(Domain &domain)
627 {
626 {
628 qreal minX(domain.minX());
627 qreal minX(domain.minX());
629 qreal minY(domain.minY());
628 qreal minY(domain.minY());
630 qreal maxX(domain.maxX());
629 qreal maxX(domain.maxX());
631 qreal maxY(domain.maxY());
630 qreal maxY(domain.maxY());
632
631
633 qreal seriesMinX = this->minX();
632 qreal seriesMinX = this->minX();
634 qreal seriesMaxX = this->maxX();
633 qreal seriesMaxX = this->maxX();
635 qreal y = max();
634 qreal y = max();
636 minX = qMin(minX, seriesMinX - (qreal)0.5);
635 minX = qMin(minX, seriesMinX - (qreal)0.5);
637 minY = qMin(minY, y);
636 minY = qMin(minY, y);
638 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
637 maxX = qMax(maxX, seriesMaxX + (qreal)0.5);
639 maxY = qMax(maxY, y);
638 maxY = qMax(maxY, y);
640
639
641 domain.setRange(minX, maxX, minY, maxY);
640 domain.setRange(minX, maxX, minY, maxY);
642 }
641 }
643
642
644 ChartElement *QAbstractBarSeriesPrivate::createGraphics(ChartPresenter *presenter)
643 ChartElement *QAbstractBarSeriesPrivate::createGraphics(ChartPresenter *presenter)
645 {
644 {
646 Q_UNUSED(presenter);
645 Q_UNUSED(presenter);
647 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
646 qWarning() << "QAbstractBarSeriesPrivate::createGraphics called";
648 return 0;
647 return 0;
649 }
648 }
650
649
651 QList<LegendMarker *> QAbstractBarSeriesPrivate::createLegendMarker(QLegend *legend)
650 QList<LegendMarker *> QAbstractBarSeriesPrivate::createLegendMarker(QLegend *legend)
652 {
651 {
653 Q_Q(QAbstractBarSeries);
652 Q_Q(QAbstractBarSeries);
654 QList<LegendMarker *> markers;
653 QList<LegendMarker *> markers;
655 foreach (QBarSet *set, q->barSets()) {
654 foreach (QBarSet *set, q->barSets()) {
656 BarLegendMarker* marker = new BarLegendMarker(q, set, legend);
655 BarLegendMarker* marker = new BarLegendMarker(q, set, legend);
657 markers << marker;
656 markers << marker;
658 }
657 }
659
658
660 return markers;
659 return markers;
661 }
660 }
662
661
663 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
662 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
664 {
663 {
665 if ((m_barSets.contains(set)) || (set == 0))
664 if ((m_barSets.contains(set)) || (set == 0))
666 return false; // Fail if set is already in list or set is null.
665 return false; // Fail if set is already in list or set is null.
667
666
668 m_barSets.append(set);
667 m_barSets.append(set);
669 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
668 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
670 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
669 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
671 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
670 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
672
671
673 emit restructuredBars(); // this notifies barchartitem
672 emit restructuredBars(); // this notifies barchartitem
674 return true;
673 return true;
675 }
674 }
676
675
677 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
676 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
678 {
677 {
679 if (!m_barSets.contains(set))
678 if (!m_barSets.contains(set))
680 return false; // Fail if set is not in list
679 return false; // Fail if set is not in list
681
680
682 m_barSets.removeOne(set);
681 m_barSets.removeOne(set);
683 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
682 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
684 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
683 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
685 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
684 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
686
685
687 emit restructuredBars(); // this notifies barchartitem
686 emit restructuredBars(); // this notifies barchartitem
688 return true;
687 return true;
689 }
688 }
690
689
691 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
690 bool QAbstractBarSeriesPrivate::append(QList<QBarSet * > sets)
692 {
691 {
693 foreach (QBarSet *set, sets) {
692 foreach (QBarSet *set, sets) {
694 if ((set == 0) || (m_barSets.contains(set)))
693 if ((set == 0) || (m_barSets.contains(set)))
695 return false; // Fail if any of the sets is null or is already appended.
694 return false; // Fail if any of the sets is null or is already appended.
696 if (sets.count(set) != 1)
695 if (sets.count(set) != 1)
697 return false; // Also fail if same set is more than once in given list.
696 return false; // Also fail if same set is more than once in given list.
698 }
697 }
699
698
700 foreach (QBarSet *set, sets) {
699 foreach (QBarSet *set, sets) {
701 m_barSets.append(set);
700 m_barSets.append(set);
702 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
701 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
703 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
702 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
704 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
703 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
705 }
704 }
706
705
707 emit restructuredBars(); // this notifies barchartitem
706 emit restructuredBars(); // this notifies barchartitem
708 return true;
707 return true;
709 }
708 }
710
709
711 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
710 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet * > sets)
712 {
711 {
713 if (sets.count() == 0)
712 if (sets.count() == 0)
714 return false;
713 return false;
715
714
716 foreach (QBarSet *set, sets) {
715 foreach (QBarSet *set, sets) {
717 if ((set == 0) || (!m_barSets.contains(set)))
716 if ((set == 0) || (!m_barSets.contains(set)))
718 return false; // Fail if any of the sets is null or is not in series
717 return false; // Fail if any of the sets is null or is not in series
719 if (sets.count(set) != 1)
718 if (sets.count(set) != 1)
720 return false; // Also fail if same set is more than once in given list.
719 return false; // Also fail if same set is more than once in given list.
721 }
720 }
722
721
723 foreach (QBarSet *set, sets) {
722 foreach (QBarSet *set, sets) {
724 m_barSets.removeOne(set);
723 m_barSets.removeOne(set);
725 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
724 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
726 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
725 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
727 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
726 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
728 }
727 }
729
728
730 emit restructuredBars(); // this notifies barchartitem
729 emit restructuredBars(); // this notifies barchartitem
731 return true;
730 return true;
732 }
731 }
733
732
734 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
733 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
735 {
734 {
736 if ((m_barSets.contains(set)) || (set == 0))
735 if ((m_barSets.contains(set)) || (set == 0))
737 return false; // Fail if set is already in list or set is null.
736 return false; // Fail if set is already in list or set is null.
738
737
739 m_barSets.insert(index, set);
738 m_barSets.insert(index, set);
740 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
739 QObject::connect(set->d_ptr.data(), SIGNAL(updatedLayout()), this, SIGNAL(updatedLayout()));
741 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
740 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
742 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
741 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
743
742
744 emit restructuredBars(); // this notifies barchartitem
743 emit restructuredBars(); // this notifies barchartitem
745 return true;
744 return true;
746 }
745 }
747
746
748 void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis *axis)
747 void QAbstractBarSeriesPrivate::initializeAxis(QAbstractAxis *axis)
749 {
748 {
750 Q_Q(QAbstractBarSeries);
749 Q_Q(QAbstractBarSeries);
751
750
752 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
751 if (axis->type() == QAbstractAxis::AxisTypeBarCategory) {
753 switch (q->type()) {
752 switch (q->type()) {
754 case QAbstractSeries::SeriesTypeHorizontalBar:
753 case QAbstractSeries::SeriesTypeHorizontalBar:
755 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
754 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
756 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
755 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
757 if (axis->orientation() == Qt::Vertical)
756 if (axis->orientation() == Qt::Vertical)
758 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
757 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
759 break;
758 break;
760 case QAbstractSeries::SeriesTypeBar:
759 case QAbstractSeries::SeriesTypeBar:
761 case QAbstractSeries::SeriesTypePercentBar:
760 case QAbstractSeries::SeriesTypePercentBar:
762 case QAbstractSeries::SeriesTypeStackedBar:
761 case QAbstractSeries::SeriesTypeStackedBar:
763 if (axis->orientation() == Qt::Horizontal)
762 if (axis->orientation() == Qt::Horizontal)
764 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
763 populateCategories(qobject_cast<QBarCategoryAxis *>(axis));
765 break;
764 break;
766 default:
765 default:
767 qWarning() << "Unexpected series type";
766 qWarning() << "Unexpected series type";
768 break;
767 break;
769 }
768 }
770 }
769 }
771 }
770 }
772
771
773 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
772 QAbstractAxis::AxisType QAbstractBarSeriesPrivate::defaultAxisType(Qt::Orientation orientation) const
774 {
773 {
775 Q_Q(const QAbstractBarSeries);
774 Q_Q(const QAbstractBarSeries);
776
775
777 switch (q->type()) {
776 switch (q->type()) {
778 case QAbstractSeries::SeriesTypeHorizontalBar:
777 case QAbstractSeries::SeriesTypeHorizontalBar:
779 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
778 case QAbstractSeries::SeriesTypeHorizontalPercentBar:
780 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
779 case QAbstractSeries::SeriesTypeHorizontalStackedBar:
781 if (orientation == Qt::Vertical)
780 if (orientation == Qt::Vertical)
782 return QAbstractAxis::AxisTypeBarCategory;
781 return QAbstractAxis::AxisTypeBarCategory;
783 break;
782 break;
784 case QAbstractSeries::SeriesTypeBar:
783 case QAbstractSeries::SeriesTypeBar:
785 case QAbstractSeries::SeriesTypePercentBar:
784 case QAbstractSeries::SeriesTypePercentBar:
786 case QAbstractSeries::SeriesTypeStackedBar:
785 case QAbstractSeries::SeriesTypeStackedBar:
787 if (orientation == Qt::Horizontal)
786 if (orientation == Qt::Horizontal)
788 return QAbstractAxis::AxisTypeBarCategory;
787 return QAbstractAxis::AxisTypeBarCategory;
789 break;
788 break;
790 default:
789 default:
791 qWarning() << "Unexpected series type";
790 qWarning() << "Unexpected series type";
792 break;
791 break;
793 }
792 }
794 return QAbstractAxis::AxisTypeValue;
793 return QAbstractAxis::AxisTypeValue;
795
794
796 }
795 }
797
796
798 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
797 void QAbstractBarSeriesPrivate::populateCategories(QBarCategoryAxis *axis)
799 {
798 {
800 QStringList categories;
799 QStringList categories;
801 if (axis->categories().isEmpty()) {
800 if (axis->categories().isEmpty()) {
802 for (int i(1); i < categoryCount() + 1; i++)
801 for (int i(1); i < categoryCount() + 1; i++)
803 categories << QString::number(i);
802 categories << QString::number(i);
804 axis->append(categories);
803 axis->append(categories);
805 }
804 }
806 }
805 }
807
806
808 #include "moc_qabstractbarseries.cpp"
807 #include "moc_qabstractbarseries.cpp"
809 #include "moc_qabstractbarseries_p.cpp"
808 #include "moc_qabstractbarseries_p.cpp"
810
809
811 QTCOMMERCIALCHART_END_NAMESPACE
810 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,265 +1,269
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 "qscatterseries.h"
21 #include "qscatterseries.h"
22 #include "qscatterseries_p.h"
22 #include "qscatterseries_p.h"
23 #include "scatterchartitem_p.h"
23 #include "scatterchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26
26
27 /*!
27 /*!
28 \class QScatterSeries
28 \class QScatterSeries
29 \brief The QScatterSeries class is used for making scatter charts.
29 \brief The QScatterSeries class is used for making scatter charts.
30
30
31 \mainclass
31 \mainclass
32
32
33 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
33 The scatter data is displayed as a collection of points on the chart. Each point determines the position on the horizontal axis
34 and the vertical axis.
34 and the vertical axis.
35
35
36 \image examples_scatterchart.png
36 \image examples_scatterchart.png
37
37
38 Creating basic scatter chart is simple:
38 Creating basic scatter chart is simple:
39 \code
39 \code
40 QScatterSeries* series = new QScatterSeries();
40 QScatterSeries* series = new QScatterSeries();
41 series->append(0, 6);
41 series->append(0, 6);
42 series->append(2, 4);
42 series->append(2, 4);
43 ...
43 ...
44 chart->addSeries(series);
44 chart->addSeries(series);
45 \endcode
45 \endcode
46 */
46 */
47 /*!
47 /*!
48 \qmlclass ScatterSeries QScatterSeries
48 \qmlclass ScatterSeries QScatterSeries
49 \inherits XYSeries
49 \inherits XYSeries
50
50
51 The following QML shows how to create a chart with two simple scatter series:
51 The following QML shows how to create a chart with two simple scatter series:
52 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
52 \snippet ../demos/qmlchart/qml/qmlchart/View5.qml 1
53
53
54 \beginfloatleft
54 \beginfloatleft
55 \image demos_qmlchart5.png
55 \image demos_qmlchart5.png
56 \endfloat
56 \endfloat
57 \clearfloat
57 \clearfloat
58 */
58 */
59
59
60 /*!
60 /*!
61 \enum QScatterSeries::MarkerShape
61 \enum QScatterSeries::MarkerShape
62
62
63 This enum describes the shape used when rendering marker items.
63 This enum describes the shape used when rendering marker items.
64
64
65 \value MarkerShapeCircle
65 \value MarkerShapeCircle
66 \value MarkerShapeRectangle
66 \value MarkerShapeRectangle
67 */
67 */
68
68
69 /*!
69 /*!
70 \property QScatterSeries::color
70 \property QScatterSeries::color
71 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
71 Fill (brush) color of the series. This is a convenience property for modifying the color of brush.
72 \sa QScatterSeries::brush()
72 \sa QScatterSeries::brush()
73 */
73 */
74
74
75 /*!
75 /*!
76 \property QScatterSeries::borderColor
76 \property QScatterSeries::borderColor
77 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
77 Line (pen) color of the series. This is a convenience property for modifying the color of pen.
78 \sa QScatterSeries::pen()
78 \sa QScatterSeries::pen()
79 */
79 */
80 /*!
81 \qmlproperty color ScatterSeries::borderColor
82 Border (pen) color of the series.
83 */
80
84
81 /*!
85 /*!
82 \qmlproperty real ScatterSeries::borderWidth
86 \qmlproperty real ScatterSeries::borderWidth
83 The width of the border line. By default the width is 2.0.
87 The width of the border line. By default the width is 2.0.
84 */
88 */
85
89
86 /*!
90 /*!
87 \property QScatterSeries::markerShape
91 \property QScatterSeries::markerShape
88 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
92 Defines the shape of the marker used to draw the points in the series. The default shape is MarkerShapeCircle.
89 */
93 */
90 /*!
94 /*!
91 \qmlproperty MarkerShape ScatterSeries::markerShape
95 \qmlproperty MarkerShape ScatterSeries::markerShape
92 Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
96 Defines the shape of the marker used to draw the points in the series. One of ScatterSeries
93 ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
97 ScatterSeries.MarkerShapeCircle or ScatterSeries.MarkerShapeRectangle.
94 The default shape is ScatterSeries.MarkerShapeCircle.
98 The default shape is ScatterSeries.MarkerShapeCircle.
95 */
99 */
96
100
97 /*!
101 /*!
98 \property QScatterSeries::markerSize
102 \property QScatterSeries::markerSize
99 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
103 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
100 */
104 */
101 /*!
105 /*!
102 \qmlproperty real ScatterSeries::markerSize
106 \qmlproperty real ScatterSeries::markerSize
103 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
107 Defines the size of the marker used to draw the points in the series. The default size is 15.0.
104 */
108 */
105
109
106 /*!
110 /*!
107 \fn void QScatterSeries::colorChanged(QColor color)
111 \fn void QScatterSeries::colorChanged(QColor color)
108 Signal is emitted when the fill (brush) color has changed to \a color.
112 Signal is emitted when the fill (brush) color has changed to \a color.
109 */
113 */
110
114
111 /*!
115 /*!
112 \fn void QScatterSeries::borderColorChanged(QColor color)
116 \fn void QScatterSeries::borderColorChanged(QColor color)
113 Signal is emitted when the line (pen) color has changed to \a color.
117 Signal is emitted when the line (pen) color has changed to \a color.
114 */
118 */
115 /*!
119 /*!
116 \qmlsignal ScatterSeries::borderColorChanged(color color)
120 \qmlsignal ScatterSeries::borderColorChanged(color color)
117 Signal is emitted when the line (pen) color has changed to \a color.
121 Signal is emitted when the line (pen) color has changed to \a color.
118 */
122 */
119
123
120 /*!
124 /*!
121 \fn QChartSeriesType QScatterSeries::type() const
125 \fn QChartSeriesType QScatterSeries::type() const
122 Returns QChartSeries::SeriesTypeScatter.
126 Returns QChartSeries::SeriesTypeScatter.
123 \sa QAbstractSeries, SeriesType
127 \sa QAbstractSeries, SeriesType
124 */
128 */
125
129
126 QTCOMMERCIALCHART_BEGIN_NAMESPACE
130 QTCOMMERCIALCHART_BEGIN_NAMESPACE
127
131
128 /*!
132 /*!
129 Constructs a series object which is a child of \a parent.
133 Constructs a series object which is a child of \a parent.
130 */
134 */
131 QScatterSeries::QScatterSeries(QObject *parent)
135 QScatterSeries::QScatterSeries(QObject *parent)
132 : QXYSeries(*new QScatterSeriesPrivate(this), parent)
136 : QXYSeries(*new QScatterSeriesPrivate(this), parent)
133 {
137 {
134 }
138 }
135
139
136 /*!
140 /*!
137 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
141 Destroys the object. Note that adding series to QChart transfers the ownership to the chart.
138 */
142 */
139 QScatterSeries::~QScatterSeries()
143 QScatterSeries::~QScatterSeries()
140 {
144 {
141 Q_D(QScatterSeries);
145 Q_D(QScatterSeries);
142 if (d->m_dataset)
146 if (d->m_dataset)
143 d->m_dataset->removeSeries(this);
147 d->m_dataset->removeSeries(this);
144 }
148 }
145
149
146 QAbstractSeries::SeriesType QScatterSeries::type() const
150 QAbstractSeries::SeriesType QScatterSeries::type() const
147 {
151 {
148 return QAbstractSeries::SeriesTypeScatter;
152 return QAbstractSeries::SeriesTypeScatter;
149 }
153 }
150
154
151 /*!
155 /*!
152 Sets \a pen used for drawing points' border on the chart. If the pen is not defined, the
156 Sets \a pen used for drawing points' border on the chart. If the pen is not defined, the
153 pen from chart theme is used.
157 pen from chart theme is used.
154 \sa QChart::setTheme()
158 \sa QChart::setTheme()
155 */
159 */
156 void QScatterSeries::setPen(const QPen &pen)
160 void QScatterSeries::setPen(const QPen &pen)
157 {
161 {
158 Q_D(QXYSeries);
162 Q_D(QXYSeries);
159 if (d->m_pen != pen) {
163 if (d->m_pen != pen) {
160 bool emitColorChanged = d->m_pen.color() != pen.color();
164 bool emitColorChanged = d->m_pen.color() != pen.color();
161 d->m_pen = pen;
165 d->m_pen = pen;
162 emit d->updated();
166 emit d->updated();
163 if (emitColorChanged)
167 if (emitColorChanged)
164 emit borderColorChanged(pen.color());
168 emit borderColorChanged(pen.color());
165 }
169 }
166 }
170 }
167
171
168 /*!
172 /*!
169 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
173 Sets \a brush used for drawing points on the chart. If the brush is not defined, brush
170 from chart theme setting is used.
174 from chart theme setting is used.
171 \sa QChart::setTheme()
175 \sa QChart::setTheme()
172 */
176 */
173 void QScatterSeries::setBrush(const QBrush &brush)
177 void QScatterSeries::setBrush(const QBrush &brush)
174 {
178 {
175 Q_D(QScatterSeries);
179 Q_D(QScatterSeries);
176 if (d->m_brush != brush) {
180 if (d->m_brush != brush) {
177 bool emitColorChanged = d->m_brush.color() != brush.color();
181 bool emitColorChanged = d->m_brush.color() != brush.color();
178 d->m_brush = brush;
182 d->m_brush = brush;
179 emit d->updated();
183 emit d->updated();
180 if (emitColorChanged)
184 if (emitColorChanged)
181 emit colorChanged(brush.color());
185 emit colorChanged(brush.color());
182 }
186 }
183 }
187 }
184
188
185 void QScatterSeries::setColor(const QColor &color)
189 void QScatterSeries::setColor(const QColor &color)
186 {
190 {
187 QBrush b = brush();
191 QBrush b = brush();
188 if (b == QBrush())
192 if (b == QBrush())
189 b.setStyle(Qt::SolidPattern);
193 b.setStyle(Qt::SolidPattern);
190 b.setColor(color);
194 b.setColor(color);
191 setBrush(b);
195 setBrush(b);
192 }
196 }
193
197
194 QColor QScatterSeries::color() const
198 QColor QScatterSeries::color() const
195 {
199 {
196 return brush().color();
200 return brush().color();
197 }
201 }
198
202
199 void QScatterSeries::setBorderColor(const QColor &color)
203 void QScatterSeries::setBorderColor(const QColor &color)
200 {
204 {
201 QPen p = pen();
205 QPen p = pen();
202 if (p.color() != color) {
206 if (p.color() != color) {
203 p.setColor(color);
207 p.setColor(color);
204 setPen(p);
208 setPen(p);
205 }
209 }
206 }
210 }
207
211
208 QColor QScatterSeries::borderColor() const
212 QColor QScatterSeries::borderColor() const
209 {
213 {
210 return pen().color();
214 return pen().color();
211 }
215 }
212
216
213 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
217 QScatterSeries::MarkerShape QScatterSeries::markerShape() const
214 {
218 {
215 Q_D(const QScatterSeries);
219 Q_D(const QScatterSeries);
216 return d->m_shape;
220 return d->m_shape;
217 }
221 }
218
222
219 void QScatterSeries::setMarkerShape(MarkerShape shape)
223 void QScatterSeries::setMarkerShape(MarkerShape shape)
220 {
224 {
221 Q_D(QScatterSeries);
225 Q_D(QScatterSeries);
222 if (d->m_shape != shape) {
226 if (d->m_shape != shape) {
223 d->m_shape = shape;
227 d->m_shape = shape;
224 emit d->updated();
228 emit d->updated();
225 }
229 }
226 }
230 }
227
231
228 qreal QScatterSeries::markerSize() const
232 qreal QScatterSeries::markerSize() const
229 {
233 {
230 Q_D(const QScatterSeries);
234 Q_D(const QScatterSeries);
231 return d->m_size;
235 return d->m_size;
232 }
236 }
233
237
234 void QScatterSeries::setMarkerSize(qreal size)
238 void QScatterSeries::setMarkerSize(qreal size)
235 {
239 {
236 Q_D(QScatterSeries);
240 Q_D(QScatterSeries);
237
241
238 if (!qFuzzyIsNull(d->m_size - size)) {
242 if (!qFuzzyIsNull(d->m_size - size)) {
239 d->m_size = size;
243 d->m_size = size;
240 emit d->updated();
244 emit d->updated();
241 }
245 }
242 }
246 }
243
247
244 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
248 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
245
249
246 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries *q)
250 QScatterSeriesPrivate::QScatterSeriesPrivate(QScatterSeries *q)
247 : QXYSeriesPrivate(q),
251 : QXYSeriesPrivate(q),
248 m_shape(QScatterSeries::MarkerShapeCircle),
252 m_shape(QScatterSeries::MarkerShapeCircle),
249 m_size(15.0)
253 m_size(15.0)
250 {
254 {
251 }
255 }
252
256
253 ChartElement *QScatterSeriesPrivate::createGraphics(ChartPresenter *presenter)
257 ChartElement *QScatterSeriesPrivate::createGraphics(ChartPresenter *presenter)
254 {
258 {
255 Q_Q(QScatterSeries);
259 Q_Q(QScatterSeries);
256 ScatterChartItem *scatter = new ScatterChartItem(q, presenter);
260 ScatterChartItem *scatter = new ScatterChartItem(q, presenter);
257 if (presenter->animationOptions().testFlag(QChart::SeriesAnimations))
261 if (presenter->animationOptions().testFlag(QChart::SeriesAnimations))
258 scatter->setAnimation(new XYAnimation(scatter));
262 scatter->setAnimation(new XYAnimation(scatter));
259 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
263 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
260 return scatter;
264 return scatter;
261 }
265 }
262
266
263 #include "moc_qscatterseries.cpp"
267 #include "moc_qscatterseries.cpp"
264
268
265 QTCOMMERCIALCHART_END_NAMESPACE
269 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now