##// END OF EJS Templates
Documenting QML bar series API
Tero Ahola -
r1489:ca99ef5d7b00
parent child
Show More
@@ -1,300 +1,244
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 "declarativebarseries.h"
21 #include "declarativebarseries.h"
22 #include "declarativechart.h"
22 #include "declarativechart.h"
23 #include <QBarSet>
23 #include <QBarSet>
24 #include <QVBarModelMapper>
24 #include <QVBarModelMapper>
25 #include <QHBarModelMapper>
25 #include <QHBarModelMapper>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 /*!
30 \qmlclass BarSeries QBarSeries
31
32 \section1 Example Usage
33
34 \beginfloatleft
35 \image demos_qmlchart6.png
36 \endfloat
37 \clearfloat
38
39 The following QML shows how to create a simple bar chart:
40 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
41 */
42
43 /*!
44 \qmlclass GroupedBarSeries QGroupedBarSeries
45
46 \section1 Example Usage
47
48 \beginfloatleft
49 \image demos_qmlchart7.png
50 \endfloat
51 \clearfloat
52
53 The following QML shows how to create a simple grouped bar chart:
54 \snippet ../demos/qmlchart/qml/qmlchart/View7.qml 1
55 */
56
57 /*!
58 \qmlclass StackedBarSeries QStackedBarSeries
59
60 \section1 Example Usage
61
62 \beginfloatleft
63 \image demos_qmlchart8.png
64 \endfloat
65 \clearfloat
66
67 The following QML shows how to create a simple stacked bar chart:
68 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
69 */
70
71 /*!
72 \qmlclass PercentBarSeries QPercentBarSeries
73
74 \section1 Example Usage
75
76 \beginfloatleft
77 \image demos_qmlchart9.png
78 \endfloat
79 \clearfloat
80
81 The following QML shows how to create a simple percent bar chart:
82 \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1
83 */
84
85 DeclarativeBarSet::DeclarativeBarSet(QObject *parent) :
29 DeclarativeBarSet::DeclarativeBarSet(QObject *parent) :
86 QBarSet("", parent)
30 QBarSet("", parent)
87 {
31 {
88 connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, int)));
32 connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, int)));
89 connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, int)));
33 connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, int)));
90 }
34 }
91
35
92 void DeclarativeBarSet::handleCountChanged(int index, int count)
36 void DeclarativeBarSet::handleCountChanged(int index, int count)
93 {
37 {
94 Q_UNUSED(index)
38 Q_UNUSED(index)
95 Q_UNUSED(count)
39 Q_UNUSED(count)
96 emit countChanged(QBarSet::count());
40 emit countChanged(QBarSet::count());
97 }
41 }
98
42
99 QVariantList DeclarativeBarSet::values()
43 QVariantList DeclarativeBarSet::values()
100 {
44 {
101 QVariantList values;
45 QVariantList values;
102 for (int i(0); i < count(); i++)
46 for (int i(0); i < count(); i++)
103 values.append(QVariant(at(i)));
47 values.append(QVariant(at(i)));
104 return values;
48 return values;
105 }
49 }
106
50
107 void DeclarativeBarSet::setValues(QVariantList values)
51 void DeclarativeBarSet::setValues(QVariantList values)
108 {
52 {
109 while (count())
53 while (count())
110 remove(count() - 1);
54 remove(count() - 1);
111
55
112 for (int i(0); i < values.count(); i++) {
56 for (int i(0); i < values.count(); i++) {
113 if (values.at(i).canConvert(QVariant::Double))
57 if (values.at(i).canConvert(QVariant::Double))
114 append(values[i].toDouble());
58 append(values[i].toDouble());
115 }
59 }
116 }
60 }
117
61
118 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
62 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
119 QBarSeries(parent)
63 QBarSeries(parent)
120 {
64 {
121 }
65 }
122
66
123 void DeclarativeBarSeries::classBegin()
67 void DeclarativeBarSeries::classBegin()
124 {
68 {
125 }
69 }
126
70
127 void DeclarativeBarSeries::componentComplete()
71 void DeclarativeBarSeries::componentComplete()
128 {
72 {
129 foreach(QObject *child, children()) {
73 foreach(QObject *child, children()) {
130 if (qobject_cast<DeclarativeBarSet *>(child)) {
74 if (qobject_cast<DeclarativeBarSet *>(child)) {
131 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
75 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
132 } else if(qobject_cast<QVBarModelMapper *>(child)) {
76 } else if(qobject_cast<QVBarModelMapper *>(child)) {
133 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
77 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
134 mapper->setSeries(this);
78 mapper->setSeries(this);
135 } else if(qobject_cast<QHBarModelMapper *>(child)) {
79 } else if(qobject_cast<QHBarModelMapper *>(child)) {
136 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
80 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
137 mapper->setSeries(this);
81 mapper->setSeries(this);
138 }
82 }
139 }
83 }
140 }
84 }
141
85
142 QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren()
86 QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren()
143 {
87 {
144 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
88 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
145 }
89 }
146
90
147 void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
91 void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
148 {
92 {
149 // Empty implementation; the children are parsed in componentComplete instead
93 // Empty implementation; the children are parsed in componentComplete instead
150 Q_UNUSED(list);
94 Q_UNUSED(list);
151 Q_UNUSED(element);
95 Q_UNUSED(element);
152 }
96 }
153
97
154 DeclarativeBarSet *DeclarativeBarSeries::at(int index)
98 DeclarativeBarSet *DeclarativeBarSeries::at(int index)
155 {
99 {
156 QList<QBarSet*> setList = barSets();
100 QList<QBarSet*> setList = barSets();
157 if (index < setList.count())
101 if (index < setList.count())
158 return qobject_cast<DeclarativeBarSet *>(setList[index]);
102 return qobject_cast<DeclarativeBarSet *>(setList[index]);
159
103
160 return 0;
104 return 0;
161 }
105 }
162
106
163 DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) :
107 DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) :
164 QGroupedBarSeries(parent)
108 QGroupedBarSeries(parent)
165 {
109 {
166 }
110 }
167
111
168 void DeclarativeGroupedBarSeries::classBegin()
112 void DeclarativeGroupedBarSeries::classBegin()
169 {
113 {
170 }
114 }
171
115
172 void DeclarativeGroupedBarSeries::componentComplete()
116 void DeclarativeGroupedBarSeries::componentComplete()
173 {
117 {
174 foreach(QObject *child, children()) {
118 foreach(QObject *child, children()) {
175 if (qobject_cast<DeclarativeBarSet *>(child)) {
119 if (qobject_cast<DeclarativeBarSet *>(child)) {
176 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
120 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
177 } else if(qobject_cast<QVBarModelMapper *>(child)) {
121 } else if(qobject_cast<QVBarModelMapper *>(child)) {
178 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
122 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
179 mapper->setSeries(this);
123 mapper->setSeries(this);
180 } else if(qobject_cast<QHBarModelMapper *>(child)) {
124 } else if(qobject_cast<QHBarModelMapper *>(child)) {
181 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
125 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
182 mapper->setSeries(this);
126 mapper->setSeries(this);
183 }
127 }
184 }
128 }
185 }
129 }
186
130
187 QDeclarativeListProperty<QObject> DeclarativeGroupedBarSeries::seriesChildren()
131 QDeclarativeListProperty<QObject> DeclarativeGroupedBarSeries::seriesChildren()
188 {
132 {
189 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
133 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
190 }
134 }
191
135
192 void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
136 void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
193 {
137 {
194 // Empty implementation; the children are parsed in componentComplete instead
138 // Empty implementation; the children are parsed in componentComplete instead
195 Q_UNUSED(list);
139 Q_UNUSED(list);
196 Q_UNUSED(element);
140 Q_UNUSED(element);
197 }
141 }
198
142
199 DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index)
143 DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index)
200 {
144 {
201 QList<QBarSet*> setList = barSets();
145 QList<QBarSet*> setList = barSets();
202 if (index < setList.count())
146 if (index < setList.count())
203 return qobject_cast<DeclarativeBarSet *>(setList[index]);
147 return qobject_cast<DeclarativeBarSet *>(setList[index]);
204
148
205 return 0;
149 return 0;
206 }
150 }
207
151
208 DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) :
152 DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) :
209 QStackedBarSeries(parent)
153 QStackedBarSeries(parent)
210 {
154 {
211 }
155 }
212
156
213 void DeclarativeStackedBarSeries::classBegin()
157 void DeclarativeStackedBarSeries::classBegin()
214 {
158 {
215 }
159 }
216
160
217 void DeclarativeStackedBarSeries::componentComplete()
161 void DeclarativeStackedBarSeries::componentComplete()
218 {
162 {
219 foreach(QObject *child, children()) {
163 foreach(QObject *child, children()) {
220 if (qobject_cast<DeclarativeBarSet *>(child)) {
164 if (qobject_cast<DeclarativeBarSet *>(child)) {
221 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
165 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
222 } else if(qobject_cast<QVBarModelMapper *>(child)) {
166 } else if(qobject_cast<QVBarModelMapper *>(child)) {
223 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
167 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
224 mapper->setSeries(this);
168 mapper->setSeries(this);
225 } else if(qobject_cast<QHBarModelMapper *>(child)) {
169 } else if(qobject_cast<QHBarModelMapper *>(child)) {
226 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
170 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
227 mapper->setSeries(this);
171 mapper->setSeries(this);
228 }
172 }
229 }
173 }
230 }
174 }
231
175
232 QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren()
176 QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren()
233 {
177 {
234 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
178 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
235 }
179 }
236
180
237 void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
181 void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
238 {
182 {
239 // Empty implementation; the children are parsed in componentComplete instead
183 // Empty implementation; the children are parsed in componentComplete instead
240 Q_UNUSED(list);
184 Q_UNUSED(list);
241 Q_UNUSED(element);
185 Q_UNUSED(element);
242 }
186 }
243
187
244 DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index)
188 DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index)
245 {
189 {
246 QList<QBarSet*> setList = barSets();
190 QList<QBarSet*> setList = barSets();
247 if (index < setList.count())
191 if (index < setList.count())
248 return qobject_cast<DeclarativeBarSet *>(setList[index]);
192 return qobject_cast<DeclarativeBarSet *>(setList[index]);
249
193
250 return 0;
194 return 0;
251 }
195 }
252
196
253 DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) :
197 DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) :
254 QPercentBarSeries(parent)
198 QPercentBarSeries(parent)
255 {
199 {
256 }
200 }
257
201
258 void DeclarativePercentBarSeries::classBegin()
202 void DeclarativePercentBarSeries::classBegin()
259 {
203 {
260 }
204 }
261
205
262 void DeclarativePercentBarSeries::componentComplete()
206 void DeclarativePercentBarSeries::componentComplete()
263 {
207 {
264 foreach(QObject *child, children()) {
208 foreach(QObject *child, children()) {
265 if (qobject_cast<DeclarativeBarSet *>(child)) {
209 if (qobject_cast<DeclarativeBarSet *>(child)) {
266 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
210 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
267 } else if(qobject_cast<QVBarModelMapper *>(child)) {
211 } else if(qobject_cast<QVBarModelMapper *>(child)) {
268 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
212 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
269 mapper->setSeries(this);
213 mapper->setSeries(this);
270 } else if(qobject_cast<QHBarModelMapper *>(child)) {
214 } else if(qobject_cast<QHBarModelMapper *>(child)) {
271 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
215 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
272 mapper->setSeries(this);
216 mapper->setSeries(this);
273 }
217 }
274 }
218 }
275 }
219 }
276
220
277 QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren()
221 QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren()
278 {
222 {
279 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
223 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
280 }
224 }
281
225
282 void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
226 void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
283 {
227 {
284 // Empty implementation; the children are parsed in componentComplete instead
228 // Empty implementation; the children are parsed in componentComplete instead
285 Q_UNUSED(list);
229 Q_UNUSED(list);
286 Q_UNUSED(element);
230 Q_UNUSED(element);
287 }
231 }
288
232
289 DeclarativeBarSet *DeclarativePercentBarSeries::at(int index)
233 DeclarativeBarSet *DeclarativePercentBarSeries::at(int index)
290 {
234 {
291 QList<QBarSet*> setList = barSets();
235 QList<QBarSet*> setList = barSets();
292 if (index < setList.count())
236 if (index < setList.count())
293 return qobject_cast<DeclarativeBarSet *>(setList[index]);
237 return qobject_cast<DeclarativeBarSet *>(setList[index]);
294
238
295 return 0;
239 return 0;
296 }
240 }
297
241
298 #include "moc_declarativebarseries.cpp"
242 #include "moc_declarativebarseries.cpp"
299
243
300 QTCOMMERCIALCHART_END_NAMESPACE
244 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,636 +1,670
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "qbarseries.h"
21 #include "qbarseries.h"
22 #include "qbarseries_p.h"
22 #include "qbarseries_p.h"
23 #include "qbarset.h"
23 #include "qbarset.h"
24 #include "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "legendmarker_p.h"
26 #include "legendmarker_p.h"
27 #include "chartdataset_p.h"
27 #include "chartdataset_p.h"
28 #include "charttheme_p.h"
28 #include "charttheme_p.h"
29 #include "chartanimator_p.h"
29 #include "chartanimator_p.h"
30
30
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32
32
33 /*!
33 /*!
34 \class QBarSeries
34 \class QBarSeries
35 \brief part of QtCommercial chart API.
35 \brief part of QtCommercial chart API.
36 \mainclass
36 \mainclass
37
37
38 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
38 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
39 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
39 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
40 and y-value is the height of the bar. The category names are ignored with this series and x-axis
40 and y-value is the height of the bar. The category names are ignored with this series and x-axis
41 shows the x-values.
41 shows the x-values.
42
42
43 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
43 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
44 \image examples_barchart.png
44 \image examples_barchart.png
45
45
46 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
46 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
47 */
47 */
48 /*!
49 \qmlclass BarSeries QBarSeries
50
51 \beginfloatleft
52 \image demos_qmlchart6.png
53 \endfloat
54 \clearfloat
55
56 The following QML shows how to create a simple bar chart:
57 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
58 */
48
59
49 /*!
60 /*!
50 \property QBarSeries::barWidth
61 \property QBarSeries::barWidth
51 \brief The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
62 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
52 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
63 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
53 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
64 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
54 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar. This is
65 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
55 because with grouped series it is more logical to set width of whole group and let the chart calculate correct
56 width for bar.
57 \sa QGroupedBarSeries
66 \sa QGroupedBarSeries
58 */
67 */
68 /*!
69 \qmlproperty real BarSeries::barWidth
70 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
71 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
72 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
73 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
74 */
59
75
60 /*!
76 /*!
61 \property QBarSeries::count
77 \property QBarSeries::count
62 \brief Holds the number of sets in series.
78 Holds the number of sets in series.
79 */
80 /*!
81 \qmlproperty int BarSeries::count
82 Holds the number of sets in series.
63 */
83 */
64
84
65 /*!
85 /*!
66 \property QBarSeries::labelsVisible
86 \property QBarSeries::labelsVisible
67 \brief Defines the visibility of the labels in series
87 Defines the visibility of the labels in series
88 */
89 /*!
90 \qmlproperty bool BarSeries::labelsVisible
91 Defines the visibility of the labels in series
68 */
92 */
69
93
70 /*!
94 /*!
71 \fn void QBarSeries::clicked(QBarSet *barset, int index)
95 \fn void QBarSeries::clicked(QBarSet *barset, int index)
72
96
73 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
97 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
74 Clicked bar inside set is indexed by \a index
98 Clicked bar inside set is indexed by \a index
75 */
99 */
100 /*!
101 \qmlsignal BarSeries::onClicked(BarSet barset, int index)
102
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
105 */
76
106
77 /*!
107 /*!
78 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
108 \fn void QBarSeries::hovered(QBarSet* barset, bool status)
79
109
80 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.
81 Parameter \a barset is the pointer of barset, where hover happened.
111 Parameter \a barset is the pointer of barset, where hover happened.
82 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
112 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
83 */
113 */
114 /*!
115 \qmlsignal BarSeries::onHovered(BarSet barset, bool status)
116
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.
119 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 */
84
121
85 /*!
122 /*!
86 \fn void QBarSeries::countChanged()
123 \fn void QBarSeries::countChanged()
87
124 This signal is emitted when barset count has been changed, for example by append or remove.
125 */
126 /*!
127 \qmlsignal BarSeries::countChanged()
88 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.
89 */
129 */
90
130
91 /*!
131 /*!
92 \fn void QBarSeries::labelsVisibleChanged()
132 \fn void QBarSeries::labelsVisibleChanged()
93
94 This signal is emitted when labels visibility have changed.
133 This signal is emitted when labels visibility have changed.
95
96 \sa isLabelsVisible(), setLabelsVisible()
134 \sa isLabelsVisible(), setLabelsVisible()
97 */
135 */
98
136
99 /*!
137 /*!
100 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
138 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
101
102 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.
103
104 \sa append(), insert()
140 \sa append(), insert()
105 */
141 */
106
142
107 /*!
143 /*!
108 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
144 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
109
110 This signal is emitted when \a sets have been removed from the series.
145 This signal is emitted when \a sets have been removed from the series.
111
112 \sa remove()
146 \sa remove()
113 */
147 */
114
148
115 /*!
149 /*!
116 Constructs empty QBarSeries.
150 Constructs empty QBarSeries.
117 QBarSeries is QObject which is a child of a \a parent.
151 QBarSeries is QObject which is a child of a \a parent.
118 */
152 */
119 QBarSeries::QBarSeries(QObject *parent) :
153 QBarSeries::QBarSeries(QObject *parent) :
120 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
154 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
121 {
155 {
122 }
156 }
123
157
124 /*!
158 /*!
125 Destructs barseries and owned barsets.
159 Destructs barseries and owned barsets.
126 */
160 */
127 QBarSeries::~QBarSeries()
161 QBarSeries::~QBarSeries()
128 {
162 {
129 Q_D(QBarSeries);
163 Q_D(QBarSeries);
130 if(d->m_dataset){
164 if(d->m_dataset){
131 d->m_dataset->removeSeries(this);
165 d->m_dataset->removeSeries(this);
132 }
166 }
133 }
167 }
134
168
135 /*!
169 /*!
136 \internal
170 \internal
137 */
171 */
138 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
172 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
139 QAbstractSeries(d,parent)
173 QAbstractSeries(d,parent)
140 {
174 {
141 }
175 }
142
176
143 /*!
177 /*!
144 Returns the type of series. Derived classes override this.
178 Returns the type of series. Derived classes override this.
145 */
179 */
146 QAbstractSeries::SeriesType QBarSeries::type() const
180 QAbstractSeries::SeriesType QBarSeries::type() const
147 {
181 {
148 return QAbstractSeries::SeriesTypeBar;
182 return QAbstractSeries::SeriesTypeBar;
149 }
183 }
150
184
151 void QBarSeries::setBarWidth(qreal width)
185 void QBarSeries::setBarWidth(qreal width)
152 {
186 {
153 Q_D(QBarSeries);
187 Q_D(QBarSeries);
154 d->setBarWidth(width);
188 d->setBarWidth(width);
155 }
189 }
156
190
157 qreal QBarSeries::barWidth() const
191 qreal QBarSeries::barWidth() const
158 {
192 {
159 Q_D(const QBarSeries);
193 Q_D(const QBarSeries);
160 return d->barWidth();
194 return d->barWidth();
161 }
195 }
162
196
163 /*!
197 /*!
164 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.
198 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.
165 Returns true, if appending succeeded.
199 Returns true, if appending succeeded.
166 */
200 */
167 bool QBarSeries::append(QBarSet *set)
201 bool QBarSeries::append(QBarSet *set)
168 {
202 {
169 Q_D(QBarSeries);
203 Q_D(QBarSeries);
170 bool success = d->append(set);
204 bool success = d->append(set);
171 if (success) {
205 if (success) {
172 QList<QBarSet*> sets;
206 QList<QBarSet*> sets;
173 sets.append(set);
207 sets.append(set);
174 emit barsetsAdded(sets);
208 emit barsetsAdded(sets);
175 emit countChanged();
209 emit countChanged();
176 }
210 }
177 return success;
211 return success;
178 }
212 }
179
213
180 /*!
214 /*!
181 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
215 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
182 Returns true, if set was removed.
216 Returns true, if set was removed.
183 */
217 */
184 bool QBarSeries::remove(QBarSet *set)
218 bool QBarSeries::remove(QBarSet *set)
185 {
219 {
186 Q_D(QBarSeries);
220 Q_D(QBarSeries);
187 bool success = d->remove(set);
221 bool success = d->remove(set);
188 if (success) {
222 if (success) {
189 QList<QBarSet*> sets;
223 QList<QBarSet*> sets;
190 sets.append(set);
224 sets.append(set);
191 emit barsetsRemoved(sets);
225 emit barsetsRemoved(sets);
192 emit countChanged();
226 emit countChanged();
193 }
227 }
194 return success;
228 return success;
195 }
229 }
196
230
197 /*!
231 /*!
198 Adds a list of barsets to series. Takes ownership of \a sets.
232 Adds a list of barsets to series. Takes ownership of \a sets.
199 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
233 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
200 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
234 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
201 and function returns false.
235 and function returns false.
202 */
236 */
203 bool QBarSeries::append(QList<QBarSet* > sets)
237 bool QBarSeries::append(QList<QBarSet* > sets)
204 {
238 {
205 Q_D(QBarSeries);
239 Q_D(QBarSeries);
206 bool success = d->append(sets);
240 bool success = d->append(sets);
207 if (success) {
241 if (success) {
208 emit barsetsAdded(sets);
242 emit barsetsAdded(sets);
209 emit countChanged();
243 emit countChanged();
210 }
244 }
211 return success;
245 return success;
212 }
246 }
213
247
214 /*!
248 /*!
215 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.
249 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.
216 Returns true, if inserting succeeded.
250 Returns true, if inserting succeeded.
217
251
218 */
252 */
219 bool QBarSeries::insert(int index, QBarSet *set)
253 bool QBarSeries::insert(int index, QBarSet *set)
220 {
254 {
221 Q_D(QBarSeries);
255 Q_D(QBarSeries);
222 bool success = d->insert(index, set);
256 bool success = d->insert(index, set);
223 if (success) {
257 if (success) {
224 QList<QBarSet*> sets;
258 QList<QBarSet*> sets;
225 sets.append(set);
259 sets.append(set);
226 emit barsetsAdded(sets);
260 emit barsetsAdded(sets);
227 emit countChanged();
261 emit countChanged();
228 }
262 }
229 return success;
263 return success;
230 }
264 }
231
265
232 /*!
266 /*!
233 Removes all of the bar sets from the series
267 Removes all of the bar sets from the series
234 */
268 */
235 void QBarSeries::clear()
269 void QBarSeries::clear()
236 {
270 {
237 Q_D(QBarSeries);
271 Q_D(QBarSeries);
238 QList<QBarSet *> sets = barSets();
272 QList<QBarSet *> sets = barSets();
239 bool success = d->remove(sets);
273 bool success = d->remove(sets);
240 if (success) {
274 if (success) {
241 emit barsetsRemoved(sets);
275 emit barsetsRemoved(sets);
242 emit countChanged();
276 emit countChanged();
243 }
277 }
244 }
278 }
245
279
246 /*!
280 /*!
247 Returns number of sets in series.
281 Returns number of sets in series.
248 */
282 */
249 int QBarSeries::count() const
283 int QBarSeries::count() const
250 {
284 {
251 Q_D(const QBarSeries);
285 Q_D(const QBarSeries);
252 return d->m_barSets.count();
286 return d->m_barSets.count();
253 }
287 }
254
288
255 /*!
289 /*!
256 Returns a list of sets in series. Keeps ownership of sets.
290 Returns a list of sets in series. Keeps ownership of sets.
257 */
291 */
258 QList<QBarSet*> QBarSeries::barSets() const
292 QList<QBarSet*> QBarSeries::barSets() const
259 {
293 {
260 Q_D(const QBarSeries);
294 Q_D(const QBarSeries);
261 return d->m_barSets;
295 return d->m_barSets;
262 }
296 }
263
297
264 /*!
298 /*!
265 Sets the visibility of labels in series to \a visible
299 Sets the visibility of labels in series to \a visible
266 */
300 */
267 void QBarSeries::setLabelsVisible(bool visible)
301 void QBarSeries::setLabelsVisible(bool visible)
268 {
302 {
269 Q_D(QBarSeries);
303 Q_D(QBarSeries);
270 if (d->m_labelsVisible != visible) {
304 if (d->m_labelsVisible != visible) {
271 d->setLabelsVisible(visible);
305 d->setLabelsVisible(visible);
272 emit labelsVisibleChanged();
306 emit labelsVisibleChanged();
273 }
307 }
274 }
308 }
275
309
276 /*!
310 /*!
277 Returns the visibility of labels
311 Returns the visibility of labels
278 */
312 */
279 bool QBarSeries::isLabelsVisible() const
313 bool QBarSeries::isLabelsVisible() const
280 {
314 {
281 Q_D(const QBarSeries);
315 Q_D(const QBarSeries);
282 return d->m_labelsVisible;
316 return d->m_labelsVisible;
283 }
317 }
284
318
285 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
319 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
286
320
287 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
321 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
288 QAbstractSeriesPrivate(q),
322 QAbstractSeriesPrivate(q),
289 m_barWidth(0.5), // Default value is 50% of category width
323 m_barWidth(0.5), // Default value is 50% of category width
290 m_labelsVisible(false),
324 m_labelsVisible(false),
291 m_visible(true)
325 m_visible(true)
292 {
326 {
293 }
327 }
294
328
295 int QBarSeriesPrivate::categoryCount() const
329 int QBarSeriesPrivate::categoryCount() const
296 {
330 {
297 // No categories defined. return count of longest set.
331 // No categories defined. return count of longest set.
298 int count = 0;
332 int count = 0;
299 for (int i=0; i<m_barSets.count(); i++) {
333 for (int i=0; i<m_barSets.count(); i++) {
300 if (m_barSets.at(i)->count() > count) {
334 if (m_barSets.at(i)->count() > count) {
301 count = m_barSets.at(i)->count();
335 count = m_barSets.at(i)->count();
302 }
336 }
303 }
337 }
304
338
305 return count;
339 return count;
306 }
340 }
307
341
308 void QBarSeriesPrivate::setBarWidth(qreal width)
342 void QBarSeriesPrivate::setBarWidth(qreal width)
309 {
343 {
310 if (width < 0.0) {
344 if (width < 0.0) {
311 width = 0.0;
345 width = 0.0;
312 }
346 }
313 m_barWidth = width;
347 m_barWidth = width;
314 emit updatedBars();
348 emit updatedBars();
315 }
349 }
316
350
317 qreal QBarSeriesPrivate::barWidth() const
351 qreal QBarSeriesPrivate::barWidth() const
318 {
352 {
319 return m_barWidth;
353 return m_barWidth;
320 }
354 }
321
355
322 QBarSet* QBarSeriesPrivate::barsetAt(int index)
356 QBarSet* QBarSeriesPrivate::barsetAt(int index)
323 {
357 {
324 return m_barSets.at(index);
358 return m_barSets.at(index);
325 }
359 }
326
360
327 void QBarSeriesPrivate::setVisible(bool visible)
361 void QBarSeriesPrivate::setVisible(bool visible)
328 {
362 {
329 m_visible = visible;
363 m_visible = visible;
330 emit updatedBars();
364 emit updatedBars();
331 }
365 }
332
366
333 void QBarSeriesPrivate::setLabelsVisible(bool visible)
367 void QBarSeriesPrivate::setLabelsVisible(bool visible)
334 {
368 {
335 m_labelsVisible = visible;
369 m_labelsVisible = visible;
336 emit labelsVisibleChanged(visible);
370 emit labelsVisibleChanged(visible);
337 }
371 }
338
372
339 qreal QBarSeriesPrivate::min()
373 qreal QBarSeriesPrivate::min()
340 {
374 {
341 if (m_barSets.count() <= 0) {
375 if (m_barSets.count() <= 0) {
342 return 0;
376 return 0;
343 }
377 }
344 qreal min = INT_MAX;
378 qreal min = INT_MAX;
345
379
346 for (int i = 0; i < m_barSets.count(); i++) {
380 for (int i = 0; i < m_barSets.count(); i++) {
347 int categoryCount = m_barSets.at(i)->count();
381 int categoryCount = m_barSets.at(i)->count();
348 for (int j = 0; j < categoryCount; j++) {
382 for (int j = 0; j < categoryCount; j++) {
349 qreal temp = m_barSets.at(i)->at(j).y();
383 qreal temp = m_barSets.at(i)->at(j).y();
350 if (temp < min)
384 if (temp < min)
351 min = temp;
385 min = temp;
352 }
386 }
353 }
387 }
354 return min;
388 return min;
355 }
389 }
356
390
357 qreal QBarSeriesPrivate::max()
391 qreal QBarSeriesPrivate::max()
358 {
392 {
359 if (m_barSets.count() <= 0) {
393 if (m_barSets.count() <= 0) {
360 return 0;
394 return 0;
361 }
395 }
362 qreal max = INT_MIN;
396 qreal max = INT_MIN;
363
397
364 for (int i = 0; i < m_barSets.count(); i++) {
398 for (int i = 0; i < m_barSets.count(); i++) {
365 int categoryCount = m_barSets.at(i)->count();
399 int categoryCount = m_barSets.at(i)->count();
366 for (int j = 0; j < categoryCount; j++) {
400 for (int j = 0; j < categoryCount; j++) {
367 qreal temp = m_barSets.at(i)->at(j).y();
401 qreal temp = m_barSets.at(i)->at(j).y();
368 if (temp > max)
402 if (temp > max)
369 max = temp;
403 max = temp;
370 }
404 }
371 }
405 }
372
406
373 return max;
407 return max;
374 }
408 }
375
409
376 qreal QBarSeriesPrivate::valueAt(int set, int category)
410 qreal QBarSeriesPrivate::valueAt(int set, int category)
377 {
411 {
378 if ((set < 0) || (set >= m_barSets.count())) {
412 if ((set < 0) || (set >= m_barSets.count())) {
379 // No set, no value.
413 // No set, no value.
380 return 0;
414 return 0;
381 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
415 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
382 // No category, no value.
416 // No category, no value.
383 return 0;
417 return 0;
384 }
418 }
385
419
386 return m_barSets.at(set)->at(category).y();
420 return m_barSets.at(set)->at(category).y();
387 }
421 }
388
422
389 qreal QBarSeriesPrivate::percentageAt(int set, int category)
423 qreal QBarSeriesPrivate::percentageAt(int set, int category)
390 {
424 {
391 if ((set < 0) || (set >= m_barSets.count())) {
425 if ((set < 0) || (set >= m_barSets.count())) {
392 // No set, no value.
426 // No set, no value.
393 return 0;
427 return 0;
394 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
428 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
395 // No category, no value.
429 // No category, no value.
396 return 0;
430 return 0;
397 }
431 }
398
432
399 qreal value = m_barSets.at(set)->at(category).y();
433 qreal value = m_barSets.at(set)->at(category).y();
400 qreal sum = categorySum(category);
434 qreal sum = categorySum(category);
401 if ( qFuzzyIsNull(sum) ) {
435 if ( qFuzzyIsNull(sum) ) {
402 return 0;
436 return 0;
403 }
437 }
404
438
405 return value / sum;
439 return value / sum;
406 }
440 }
407
441
408 qreal QBarSeriesPrivate::categorySum(int category)
442 qreal QBarSeriesPrivate::categorySum(int category)
409 {
443 {
410 qreal sum(0);
444 qreal sum(0);
411 int count = m_barSets.count(); // Count sets
445 int count = m_barSets.count(); // Count sets
412 for (int set = 0; set < count; set++) {
446 for (int set = 0; set < count; set++) {
413 if (category < m_barSets.at(set)->count())
447 if (category < m_barSets.at(set)->count())
414 sum += m_barSets.at(set)->at(category).y();
448 sum += m_barSets.at(set)->at(category).y();
415 }
449 }
416 return sum;
450 return sum;
417 }
451 }
418
452
419 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
453 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
420 {
454 {
421 qreal sum(0);
455 qreal sum(0);
422 int count = m_barSets.count(); // Count sets
456 int count = m_barSets.count(); // Count sets
423 for (int set = 0; set < count; set++) {
457 for (int set = 0; set < count; set++) {
424 if (category < m_barSets.at(set)->count())
458 if (category < m_barSets.at(set)->count())
425 sum += qAbs(m_barSets.at(set)->at(category).y());
459 sum += qAbs(m_barSets.at(set)->at(category).y());
426 }
460 }
427 return sum;
461 return sum;
428 }
462 }
429
463
430 qreal QBarSeriesPrivate::maxCategorySum()
464 qreal QBarSeriesPrivate::maxCategorySum()
431 {
465 {
432 qreal max = INT_MIN;
466 qreal max = INT_MIN;
433 int count = categoryCount();
467 int count = categoryCount();
434 for (int i = 0; i < count; i++) {
468 for (int i = 0; i < count; i++) {
435 qreal sum = categorySum(i);
469 qreal sum = categorySum(i);
436 if (sum > max)
470 if (sum > max)
437 max = sum;
471 max = sum;
438 }
472 }
439 return max;
473 return max;
440 }
474 }
441
475
442 qreal QBarSeriesPrivate::minX()
476 qreal QBarSeriesPrivate::minX()
443 {
477 {
444 if (m_barSets.count() <= 0) {
478 if (m_barSets.count() <= 0) {
445 return 0;
479 return 0;
446 }
480 }
447 qreal min = INT_MAX;
481 qreal min = INT_MAX;
448
482
449 for (int i = 0; i < m_barSets.count(); i++) {
483 for (int i = 0; i < m_barSets.count(); i++) {
450 int categoryCount = m_barSets.at(i)->count();
484 int categoryCount = m_barSets.at(i)->count();
451 for (int j = 0; j < categoryCount; j++) {
485 for (int j = 0; j < categoryCount; j++) {
452 qreal temp = m_barSets.at(i)->at(j).x();
486 qreal temp = m_barSets.at(i)->at(j).x();
453 if (temp < min)
487 if (temp < min)
454 min = temp;
488 min = temp;
455 }
489 }
456 }
490 }
457 return min;
491 return min;
458 }
492 }
459
493
460 qreal QBarSeriesPrivate::maxX()
494 qreal QBarSeriesPrivate::maxX()
461 {
495 {
462 if (m_barSets.count() <= 0) {
496 if (m_barSets.count() <= 0) {
463 return 0;
497 return 0;
464 }
498 }
465 qreal max = INT_MIN;
499 qreal max = INT_MIN;
466
500
467 for (int i = 0; i < m_barSets.count(); i++) {
501 for (int i = 0; i < m_barSets.count(); i++) {
468 int categoryCount = m_barSets.at(i)->count();
502 int categoryCount = m_barSets.at(i)->count();
469 for (int j = 0; j < categoryCount; j++) {
503 for (int j = 0; j < categoryCount; j++) {
470 qreal temp = m_barSets.at(i)->at(j).x();
504 qreal temp = m_barSets.at(i)->at(j).x();
471 if (temp > max)
505 if (temp > max)
472 max = temp;
506 max = temp;
473 }
507 }
474 }
508 }
475
509
476 return max;
510 return max;
477 }
511 }
478
512
479
513
480 void QBarSeriesPrivate::scaleDomain(Domain& domain)
514 void QBarSeriesPrivate::scaleDomain(Domain& domain)
481 {
515 {
482 qreal minX(domain.minX());
516 qreal minX(domain.minX());
483 qreal minY(domain.minY());
517 qreal minY(domain.minY());
484 qreal maxX(domain.maxX());
518 qreal maxX(domain.maxX());
485 qreal maxY(domain.maxY());
519 qreal maxY(domain.maxY());
486 int tickXCount(domain.tickXCount());
520 int tickXCount(domain.tickXCount());
487 int tickYCount(domain.tickYCount());
521 int tickYCount(domain.tickYCount());
488
522
489 qreal seriesMinX = this->minX();
523 qreal seriesMinX = this->minX();
490 qreal seriesMaxX = this->maxX();
524 qreal seriesMaxX = this->maxX();
491 qreal y = max();
525 qreal y = max();
492 minX = qMin(minX, seriesMinX - 0.5);
526 minX = qMin(minX, seriesMinX - 0.5);
493 minY = qMin(minY, y);
527 minY = qMin(minY, y);
494 maxX = qMax(maxX, seriesMaxX + 0.5);
528 maxX = qMax(maxX, seriesMaxX + 0.5);
495 maxY = qMax(maxY, y);
529 maxY = qMax(maxY, y);
496 tickXCount = categoryCount()+1;
530 tickXCount = categoryCount()+1;
497
531
498 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
532 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
499 }
533 }
500
534
501 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
535 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
502 {
536 {
503 Q_Q(QBarSeries);
537 Q_Q(QBarSeries);
504
538
505 BarChartItem* bar = new BarChartItem(q,presenter);
539 BarChartItem* bar = new BarChartItem(q,presenter);
506 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
540 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
507 presenter->animator()->addAnimation(bar);
541 presenter->animator()->addAnimation(bar);
508 }
542 }
509 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
543 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
510 return bar;
544 return bar;
511
545
512 }
546 }
513
547
514 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
548 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
515 {
549 {
516 Q_Q(QBarSeries);
550 Q_Q(QBarSeries);
517 QList<LegendMarker*> markers;
551 QList<LegendMarker*> markers;
518 foreach(QBarSet* set, q->barSets()) {
552 foreach(QBarSet* set, q->barSets()) {
519 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
553 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
520 markers << marker;
554 markers << marker;
521 }
555 }
522
556
523 return markers;
557 return markers;
524 }
558 }
525
559
526 bool QBarSeriesPrivate::append(QBarSet *set)
560 bool QBarSeriesPrivate::append(QBarSet *set)
527 {
561 {
528 Q_Q(QBarSeries);
562 Q_Q(QBarSeries);
529 if ((m_barSets.contains(set)) || (set == 0)) {
563 if ((m_barSets.contains(set)) || (set == 0)) {
530 // Fail if set is already in list or set is null.
564 // Fail if set is already in list or set is null.
531 return false;
565 return false;
532 }
566 }
533 m_barSets.append(set);
567 m_barSets.append(set);
534 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
568 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
535 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
569 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
536 emit restructuredBars(); // this notifies barchartitem
570 emit restructuredBars(); // this notifies barchartitem
537 if (m_dataset) {
571 if (m_dataset) {
538 m_dataset->updateSeries(q); // this notifies legend
572 m_dataset->updateSeries(q); // this notifies legend
539 }
573 }
540 return true;
574 return true;
541 }
575 }
542
576
543 bool QBarSeriesPrivate::remove(QBarSet *set)
577 bool QBarSeriesPrivate::remove(QBarSet *set)
544 {
578 {
545 Q_Q(QBarSeries);
579 Q_Q(QBarSeries);
546 if (!m_barSets.contains(set)) {
580 if (!m_barSets.contains(set)) {
547 // Fail if set is not in list
581 // Fail if set is not in list
548 return false;
582 return false;
549 }
583 }
550 m_barSets.removeOne(set);
584 m_barSets.removeOne(set);
551 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
585 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
552 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
586 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
553 emit restructuredBars(); // this notifies barchartitem
587 emit restructuredBars(); // this notifies barchartitem
554 if (m_dataset) {
588 if (m_dataset) {
555 m_dataset->updateSeries(q); // this notifies legend
589 m_dataset->updateSeries(q); // this notifies legend
556 }
590 }
557 return true;
591 return true;
558 }
592 }
559
593
560 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
594 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
561 {
595 {
562 Q_Q(QBarSeries);
596 Q_Q(QBarSeries);
563 foreach (QBarSet* set, sets) {
597 foreach (QBarSet* set, sets) {
564 if ((set == 0) || (m_barSets.contains(set))) {
598 if ((set == 0) || (m_barSets.contains(set))) {
565 // Fail if any of the sets is null or is already appended.
599 // Fail if any of the sets is null or is already appended.
566 return false;
600 return false;
567 }
601 }
568 if (sets.count(set) != 1) {
602 if (sets.count(set) != 1) {
569 // Also fail if same set is more than once in given list.
603 // Also fail if same set is more than once in given list.
570 return false;
604 return false;
571 }
605 }
572 }
606 }
573
607
574 foreach (QBarSet* set, sets) {
608 foreach (QBarSet* set, sets) {
575 m_barSets.append(set);
609 m_barSets.append(set);
576 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
610 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
577 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
611 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
578 }
612 }
579 emit restructuredBars(); // this notifies barchartitem
613 emit restructuredBars(); // this notifies barchartitem
580 if (m_dataset) {
614 if (m_dataset) {
581 m_dataset->updateSeries(q); // this notifies legend
615 m_dataset->updateSeries(q); // this notifies legend
582 }
616 }
583 return true;
617 return true;
584 }
618 }
585
619
586 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
620 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
587 {
621 {
588 Q_Q(QBarSeries);
622 Q_Q(QBarSeries);
589 if (sets.count() == 0) {
623 if (sets.count() == 0) {
590 return false;
624 return false;
591 }
625 }
592 foreach (QBarSet* set, sets) {
626 foreach (QBarSet* set, sets) {
593 if ((set == 0) || (!m_barSets.contains(set))) {
627 if ((set == 0) || (!m_barSets.contains(set))) {
594 // Fail if any of the sets is null or is not in series
628 // Fail if any of the sets is null or is not in series
595 return false;
629 return false;
596 }
630 }
597 if (sets.count(set) != 1) {
631 if (sets.count(set) != 1) {
598 // Also fail if same set is more than once in given list.
632 // Also fail if same set is more than once in given list.
599 return false;
633 return false;
600 }
634 }
601 }
635 }
602
636
603 foreach (QBarSet* set, sets) {
637 foreach (QBarSet* set, sets) {
604 m_barSets.removeOne(set);
638 m_barSets.removeOne(set);
605 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
639 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
606 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
640 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
607 }
641 }
608
642
609 emit restructuredBars(); // this notifies barchartitem
643 emit restructuredBars(); // this notifies barchartitem
610 if (m_dataset) {
644 if (m_dataset) {
611 m_dataset->updateSeries(q); // this notifies legend
645 m_dataset->updateSeries(q); // this notifies legend
612 }
646 }
613 return true;
647 return true;
614 }
648 }
615
649
616 bool QBarSeriesPrivate::insert(int index, QBarSet *set)
650 bool QBarSeriesPrivate::insert(int index, QBarSet *set)
617 {
651 {
618 Q_Q(QBarSeries);
652 Q_Q(QBarSeries);
619 if ((m_barSets.contains(set)) || (set == 0)) {
653 if ((m_barSets.contains(set)) || (set == 0)) {
620 // Fail if set is already in list or set is null.
654 // Fail if set is already in list or set is null.
621 return false;
655 return false;
622 }
656 }
623 m_barSets.insert(index, set);
657 m_barSets.insert(index, set);
624 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
658 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
625 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
659 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
626 emit restructuredBars(); // this notifies barchartitem
660 emit restructuredBars(); // this notifies barchartitem
627 if (m_dataset) {
661 if (m_dataset) {
628 m_dataset->updateSeries(q); // this notifies legend
662 m_dataset->updateSeries(q); // this notifies legend
629 }
663 }
630 return true;
664 return true;
631 }
665 }
632
666
633 #include "moc_qbarseries.cpp"
667 #include "moc_qbarseries.cpp"
634 #include "moc_qbarseries_p.cpp"
668 #include "moc_qbarseries_p.cpp"
635
669
636 QTCOMMERCIALCHART_END_NAMESPACE
670 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,569 +1,606
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 "qbarset.h"
21 #include "qbarset.h"
22 #include "qbarset_p.h"
22 #include "qbarset_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 /*!
26 /*!
27 \class QBarSet
27 \class QBarSet
28 \brief part of QtCommercial chart API.
28 \brief part of QtCommercial chart API.
29
29
30 QBarSet represents one set of bars. Set of bars contains one data value for each category.
30 QBarSet represents one set of bars. Set of bars contains one data value for each category.
31 First value of set is assumed to belong to first category, second to second category and so on.
31 First value of set is assumed to belong to first category, second to second category and so on.
32 If set has fewer values than there are categories, then the missing values are assumed to be
32 If set has fewer values than there are categories, then the missing values are assumed to be
33 at the end of set. For missing values in middle of a set, numerical value of zero is used.
33 at the end of set. For missing values in middle of a set, numerical value of zero is used.
34
34
35 \mainclass
35 \mainclass
36
36
37 \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries
37 \sa QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries
38 */
38 */
39 /*!
40 \qmlclass BarSet QBarSet
41
42 BarSet represents one set of bars. Set of bars contains one data value for each category.
43 First value of set is assumed to belong to first category, second to second category and so on.
44 If set has fewer values than there are categories, then the missing values are assumed to be
45 at the end of set. For missing values in middle of a set, numerical value of zero is used.
46 \sa BarSeries, GroupedBarSeries, StackedBarSeries, PercentBarSeries
47 */
39
48
40 /*!
49 /*!
41 \property QBarSet::label
50 \property QBarSet::label
42 \brief Defines the label of the barSet.
51 Defines the label of the barSet.
52 */
53 /*!
54 \qmlproperty string BarSet::label
55 Defines the label of the barSet.
43 */
56 */
44
57
45 /*!
58 /*!
46 \property QBarSet::pen
59 \property QBarSet::pen
47 \brief Defines the pen used by the barSet.
60 \brief Defines the pen used by the barSet.
48 */
61 */
49
62
50 /*!
63 /*!
51 \property QBarSet::brush
64 \property QBarSet::brush
52 \brief Defines the brush used by the barSet.
65 \brief Defines the brush used by the barSet.
53 */
66 */
54
67
55 /*!
68 /*!
56 \property QBarSet::labelBrush
69 \property QBarSet::labelBrush
57 \brief Defines the brush used by the barSet's label.
70 \brief Defines the brush used by the barSet's label.
58 */
71 */
59
72
60 /*!
73 /*!
61 \property QBarSet::labelFont
74 \property QBarSet::labelFont
62 \brief Defines the font used by the barSet's label.
75 \brief Defines the font used by the barSet's label.
63 */
76 */
64
77
65 /*!
78 /*!
66 \property QBarSet::color
79 \property QBarSet::color
67 \brief The fill (brush) color of the bar set.
80 The fill (brush) color of the bar set.
81 */
82 /*!
83 \qmlproperty color BarSet::color
84 The fill (brush) color of the bar set.
68 */
85 */
69
86
70 /*!
87 /*!
71 \property QBarSet::borderColor
88 \property QBarSet::borderColor
72 \brief The line (pen) color of the bar set.
89 The line (pen) color of the bar set.
90 */
91 /*!
92 \qmlproperty color BarSet::borderColor
93 The line (pen) color of the bar set.
73 */
94 */
74
95
75 /*!
96 /*!
76 \property QBarSet::labelColor
97 \property QBarSet::labelColor
77 \brief The text (label) color of the bar set.
98 The text (label) color of the bar set.
99 */
100 /*!
101 \qmlproperty color BarSet::labelColor
102 The text (label) color of the bar set.
78 */
103 */
79
104
80 /*!
105 /*!
81 \fn void QBarSet::labelChanged()
106 \fn void QBarSet::labelChanged()
82
83 This signal is emitted when the label of the barSet has changed.
107 This signal is emitted when the label of the barSet has changed.
84
85 \sa label
108 \sa label
86 */
109 */
87
110
88 /*!
111 /*!
89 \fn void QBarSet::penChanged()
112 \fn void QBarSet::penChanged()
90
91 This signal is emitted when the pen of the barSet has changed.
113 This signal is emitted when the pen of the barSet has changed.
92
93 \sa pen
114 \sa pen
94 */
115 */
95
116
96 /*!
117 /*!
97 \fn void QBarSet::brushChanged()
118 \fn void QBarSet::brushChanged()
98
99 This signal is emitted when the brush of the barSet has changed.
119 This signal is emitted when the brush of the barSet has changed.
100
101 \sa brush
120 \sa brush
102 */
121 */
103
122
104 /*!
123 /*!
105 \fn void QBarSet::labelBrushChanged()
124 \fn void QBarSet::labelBrushChanged()
106
107 This signal is emitted when the brush of the barSet's label has changed.
125 This signal is emitted when the brush of the barSet's label has changed.
108
109 \sa labelBrush
126 \sa labelBrush
110 */
127 */
111
128
112 /*!
129 /*!
113 \fn void QBarSet::labelFontChanged()
130 \fn void QBarSet::labelFontChanged()
114
115 This signal is emitted when the font of the barSet's label has changed.
131 This signal is emitted when the font of the barSet's label has changed.
116
117 \sa labelBrush
132 \sa labelBrush
118 */
133 */
119
134
120 /*!
135 /*!
121 \fn void QBarSet::colorChanged(QColor)
136 \fn void QBarSet::colorChanged(QColor)
122 This signal is emitted when the fill (brush) color of the set has changed to \a color.
137 This signal is emitted when the fill (brush) color of the set has changed to \a color.
123 */
138 */
139 /*!
140 \qmlsignal BarSet::onColorChanged(color color)
141 This signal is emitted when the fill (brush) color of the set has changed to \a color.
142 */
124
143
125 /*!
144 /*!
126 \fn void QBarSet::borderColorChanged(QColor)
145 \fn void QBarSet::borderColorChanged(QColor)
127 This signal is emitted when the line (pen) color of the set has changed to \a color.
146 This signal is emitted when the line (pen) color of the set has changed to \a color.
128 */
147 */
148 /*!
149 \qmlsignal BarSet::onBorderColorChanged(color color)
150 This signal is emitted when the line (pen) color of the set has changed to \a color.
151 */
129
152
130 /*!
153 /*!
131 \fn void QBarSet::labelColorChanged(QColor)
154 \fn void QBarSet::labelColorChanged(QColor)
132 This signal is emitted when the text (label) color of the set has changed to \a color.
155 This signal is emitted when the text (label) color of the set has changed to \a color.
133 */
156 */
157 /*!
158 \qmlsignal BarSet::onLabelColorChanged(color color)
159 This signal is emitted when the text (label) color of the set has changed to \a color.
160 */
134
161
135 /*!
162 /*!
136 \fn void QBarSet::valuesAdded(int index, int count)
163 \fn void QBarSet::valuesAdded(int index, int count)
137
138 This signal is emitted when new values have been added to the set.
164 This signal is emitted when new values have been added to the set.
139 Parameter \a index indicates the position of the first inserted value.
165 Parameter \a index indicates the position of the first inserted value.
140 Parameter \a count is the number of iserted values.
166 Parameter \a count is the number of iserted values.
141
142 \sa append(), insert()
167 \sa append(), insert()
143 */
168 */
169 /*!
170 \qmlsignal BarSet::onValuesAdded(int index, int count)
171 This signal is emitted when new values have been added to the set.
172 Parameter \a index indicates the position of the first inserted value.
173 Parameter \a count is the number of iserted values.
174 */
144
175
145 /*!
176 /*!
146 \fn void QBarSet::valuesRemoved(int index, int count)
177 \fn void QBarSet::valuesRemoved(int index, int count)
147
148 This signal is emitted values have been removed from the set.
178 This signal is emitted values have been removed from the set.
149 Parameter \a index indicates the position of the first removed value.
179 Parameter \a index indicates the position of the first removed value.
150 Parameter \a count is the number of removed values.
180 Parameter \a count is the number of removed values.
151
152 \sa remove()
181 \sa remove()
153 */
182 */
183 /*!
184 \qmlsignal BarSet::onValuesRemoved(int index, int count)
185 This signal is emitted values have been removed from the set.
186 Parameter \a index indicates the position of the first removed value.
187 Parameter \a count is the number of removed values.
188 */
154
189
155 /*!
190 /*!
156 \fn void QBarSet::valueChanged(int index)
191 \fn void QBarSet::valueChanged(int index)
157
158 This signal is emitted values the value in the set has been modified.
192 This signal is emitted values the value in the set has been modified.
159 Parameter \a index indicates the position of the modified value.
193 Parameter \a index indicates the position of the modified value.
160
161 \sa at()
194 \sa at()
162 */
195 */
163 void valueChanged(int index);
196 /*!
197 \qmlsignal BarSet::onValueChanged(int index)
198 This signal is emitted values the value in the set has been modified.
199 Parameter \a index indicates the position of the modified value.
200 */
164
201
165 /*!
202 /*!
166 Constructs QBarSet with a label of \a label and with parent of \a parent
203 Constructs QBarSet with a label of \a label and with parent of \a parent
167 */
204 */
168 QBarSet::QBarSet(const QString label, QObject *parent)
205 QBarSet::QBarSet(const QString label, QObject *parent)
169 : QObject(parent)
206 : QObject(parent)
170 ,d_ptr(new QBarSetPrivate(label,this))
207 ,d_ptr(new QBarSetPrivate(label,this))
171 {
208 {
172 }
209 }
173
210
174 /*!
211 /*!
175 Destroys the barset
212 Destroys the barset
176 */
213 */
177 QBarSet::~QBarSet()
214 QBarSet::~QBarSet()
178 {
215 {
179 // NOTE: d_ptr destroyed by QObject
216 // NOTE: d_ptr destroyed by QObject
180 }
217 }
181
218
182 /*!
219 /*!
183 Sets new \a label for set.
220 Sets new \a label for set.
184 */
221 */
185 void QBarSet::setLabel(const QString label)
222 void QBarSet::setLabel(const QString label)
186 {
223 {
187 d_ptr->m_label = label;
224 d_ptr->m_label = label;
188 emit labelChanged();
225 emit labelChanged();
189 }
226 }
190
227
191 /*!
228 /*!
192 Returns label of the set.
229 Returns label of the set.
193 */
230 */
194 QString QBarSet::label() const
231 QString QBarSet::label() const
195 {
232 {
196 return d_ptr->m_label;
233 return d_ptr->m_label;
197 }
234 }
198
235
199 /*!
236 /*!
200 Appends a point to set. Parameter \a value x coordinate defines the
237 Appends a point to set. Parameter \a value x coordinate defines the
201 position in x-axis and y coordinate defines the height of bar.
238 position in x-axis and y coordinate defines the height of bar.
202 Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries)
239 Depending on presentation (QBarSeries, QGroupedBarSeries, QStackedBarSeries, QPercentBarSeries)
203 the x values are used or ignored.
240 the x values are used or ignored.
204 */
241 */
205 void QBarSet::append(const QPointF value)
242 void QBarSet::append(const QPointF value)
206 {
243 {
207 int index = d_ptr->m_values.count();
244 int index = d_ptr->m_values.count();
208 d_ptr->append(value);
245 d_ptr->append(value);
209 emit valuesAdded(index, 1);
246 emit valuesAdded(index, 1);
210 }
247 }
211
248
212 /*!
249 /*!
213 Appends a list of \a values to set. Works like append with single point.
250 Appends a list of \a values to set. Works like append with single point.
214 \sa append()
251 \sa append()
215 */
252 */
216 void QBarSet::append(const QList<QPointF> values)
253 void QBarSet::append(const QList<QPointF> values)
217 {
254 {
218 int index = d_ptr->m_values.count();
255 int index = d_ptr->m_values.count();
219 d_ptr->append(values);
256 d_ptr->append(values);
220 emit valuesAdded(index, values.count());
257 emit valuesAdded(index, values.count());
221 }
258 }
222
259
223 /*!
260 /*!
224 Appends new value \a value to the end of set. Internally the value is converted to QPointF,
261 Appends new value \a value to the end of set. Internally the value is converted to QPointF,
225 with x coordinate being the index of appended value and y coordinate is the value.
262 with x coordinate being the index of appended value and y coordinate is the value.
226 */
263 */
227 void QBarSet::append(const qreal value)
264 void QBarSet::append(const qreal value)
228 {
265 {
229 // Convert to QPointF and use other append(QPointF) method.
266 // Convert to QPointF and use other append(QPointF) method.
230 append(QPointF(d_ptr->m_values.count(), value));
267 append(QPointF(d_ptr->m_values.count(), value));
231 }
268 }
232
269
233 /*!
270 /*!
234 Appends a list of reals to set. Works like append with single real value. The \a values in list
271 Appends a list of reals to set. Works like append with single real value. The \a values in list
235 are converted to QPointF, where x coordinate is the index of point and y coordinate is the value.
272 are converted to QPointF, where x coordinate is the index of point and y coordinate is the value.
236 \sa append()
273 \sa append()
237 */
274 */
238 void QBarSet::append(const QList<qreal> values)
275 void QBarSet::append(const QList<qreal> values)
239 {
276 {
240 int index = d_ptr->m_values.count();
277 int index = d_ptr->m_values.count();
241 d_ptr->append(values);
278 d_ptr->append(values);
242 emit valuesAdded(index, values.count());
279 emit valuesAdded(index, values.count());
243 }
280 }
244
281
245 /*!
282 /*!
246 Convinience operator. Same as append, with real \a value.
283 Convinience operator. Same as append, with real \a value.
247 \sa append()
284 \sa append()
248 */
285 */
249 QBarSet& QBarSet::operator << (const qreal &value)
286 QBarSet& QBarSet::operator << (const qreal &value)
250 {
287 {
251 append(value);
288 append(value);
252 return *this;
289 return *this;
253 }
290 }
254
291
255 /*!
292 /*!
256 Convinience operator. Same as append, with QPointF \a value.
293 Convinience operator. Same as append, with QPointF \a value.
257 \sa append()
294 \sa append()
258 */
295 */
259 QBarSet& QBarSet::operator << (const QPointF &value)
296 QBarSet& QBarSet::operator << (const QPointF &value)
260 {
297 {
261 append(value);
298 append(value);
262 return *this;
299 return *this;
263 }
300 }
264
301
265 /*!
302 /*!
266 Inserts new \a value on the \a index position.
303 Inserts new \a value on the \a index position.
267 The value that is currently at this postion is moved to postion index + 1
304 The value that is currently at this postion is moved to postion index + 1
268 \sa remove()
305 \sa remove()
269 */
306 */
270 void QBarSet::insert(const int index, const qreal value)
307 void QBarSet::insert(const int index, const qreal value)
271 {
308 {
272 d_ptr->insert(index, value);
309 d_ptr->insert(index, value);
273 emit valuesAdded(index,1);
310 emit valuesAdded(index,1);
274 }
311 }
275
312
276 /*!
313 /*!
277 Inserts new \a value on the \a index position.
314 Inserts new \a value on the \a index position.
278 The value that is currently at this postion is moved to postion index + 1
315 The value that is currently at this postion is moved to postion index + 1
279 \sa remove()
316 \sa remove()
280 */
317 */
281 void QBarSet::insert(const int index, const QPointF value)
318 void QBarSet::insert(const int index, const QPointF value)
282 {
319 {
283 d_ptr->insert(index,value);
320 d_ptr->insert(index,value);
284 emit valuesAdded(index,1);
321 emit valuesAdded(index,1);
285 }
322 }
286
323
287 /*!
324 /*!
288 Removes \a count number of values from the set starting at \a index.
325 Removes \a count number of values from the set starting at \a index.
289 Returns true if remove operation was succesfull.
326 Returns true if remove operation was succesfull.
290 \sa insert()
327 \sa insert()
291 */
328 */
292 bool QBarSet::remove(const int index, const int count)
329 bool QBarSet::remove(const int index, const int count)
293 {
330 {
294 bool success = d_ptr->remove(index,count);
331 bool success = d_ptr->remove(index,count);
295 if (success) {
332 if (success) {
296 emit valuesRemoved(index,count);
333 emit valuesRemoved(index,count);
297 }
334 }
298 return success;
335 return success;
299 }
336 }
300
337
301 /*!
338 /*!
302 Sets a new value \a value to set, indexed by \a index
339 Sets a new value \a value to set, indexed by \a index
303 */
340 */
304 void QBarSet::replace(const int index, const qreal value)
341 void QBarSet::replace(const int index, const qreal value)
305 {
342 {
306 d_ptr->replace(index,value);
343 d_ptr->replace(index,value);
307 emit valueChanged(index);
344 emit valueChanged(index);
308 }
345 }
309
346
310 /*!
347 /*!
311 Sets a new value \a value to set, indexed by \a index
348 Sets a new value \a value to set, indexed by \a index
312 */
349 */
313 void QBarSet::replace(const int index, const QPointF value)
350 void QBarSet::replace(const int index, const QPointF value)
314 {
351 {
315 d_ptr->replace(index,value);
352 d_ptr->replace(index,value);
316 emit valueChanged(index);
353 emit valueChanged(index);
317 }
354 }
318
355
319 /*!
356 /*!
320 Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF.
357 Returns value of set indexed by \a index. Note that all appended values are stored internally as QPointF.
321 The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
358 The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
322 of the QPointF (if appended with QPointF append).
359 of the QPointF (if appended with QPointF append).
323 If the index is out of bounds QPointF(0, 0.0) is returned.
360 If the index is out of bounds QPointF(0, 0.0) is returned.
324 */
361 */
325 QPointF QBarSet::at(const int index) const
362 QPointF QBarSet::at(const int index) const
326 {
363 {
327 if (index < 0 || index >= d_ptr->m_values.count()) {
364 if (index < 0 || index >= d_ptr->m_values.count()) {
328 return QPointF(index, 0.0);
365 return QPointF(index, 0.0);
329 }
366 }
330
367
331 return d_ptr->m_values.at(index);
368 return d_ptr->m_values.at(index);
332 }
369 }
333
370
334 /*!
371 /*!
335 Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF.
372 Returns value of set indexed by \a index. ote that all appended values are stored internally as QPointF.
336 The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
373 The returned QPointF has x coordinate, which is index (if appended with qreal append) or the x value
337 of the QPointF (if appended with QPointF append).
374 of the QPointF (if appended with QPointF append).
338 */
375 */
339 QPointF QBarSet::operator [](const int index) const
376 QPointF QBarSet::operator [](const int index) const
340 {
377 {
341 return d_ptr->m_values.at(index);
378 return d_ptr->m_values.at(index);
342 }
379 }
343
380
344 /*!
381 /*!
345 Returns count of values in set.
382 Returns count of values in set.
346 */
383 */
347 int QBarSet::count() const
384 int QBarSet::count() const
348 {
385 {
349 return d_ptr->m_values.count();
386 return d_ptr->m_values.count();
350 }
387 }
351
388
352 /*!
389 /*!
353 Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation.
390 Returns sum of all values in barset. The sum is sum of y coordinates in the QPointF representation.
354 */
391 */
355 qreal QBarSet::sum() const
392 qreal QBarSet::sum() const
356 {
393 {
357 qreal total(0);
394 qreal total(0);
358 for (int i=0; i < d_ptr->m_values.count(); i++) {
395 for (int i=0; i < d_ptr->m_values.count(); i++) {
359 //total += d_ptr->m_values.at(i);
396 //total += d_ptr->m_values.at(i);
360 total += d_ptr->m_values.at(i).y();
397 total += d_ptr->m_values.at(i).y();
361 }
398 }
362 return total;
399 return total;
363 }
400 }
364
401
365 /*!
402 /*!
366 Sets pen for set. Bars of this set are drawn using \a pen
403 Sets pen for set. Bars of this set are drawn using \a pen
367 */
404 */
368 void QBarSet::setPen(const QPen &pen)
405 void QBarSet::setPen(const QPen &pen)
369 {
406 {
370 if(d_ptr->m_pen!=pen){
407 if(d_ptr->m_pen!=pen){
371 d_ptr->m_pen = pen;
408 d_ptr->m_pen = pen;
372 emit d_ptr->updatedBars();
409 emit d_ptr->updatedBars();
373 emit penChanged();
410 emit penChanged();
374 }
411 }
375 }
412 }
376
413
377 /*!
414 /*!
378 Returns pen of the set.
415 Returns pen of the set.
379 */
416 */
380 QPen QBarSet::pen() const
417 QPen QBarSet::pen() const
381 {
418 {
382 return d_ptr->m_pen;
419 return d_ptr->m_pen;
383 }
420 }
384
421
385 /*!
422 /*!
386 Sets brush for the set. Bars of this set are drawn using \a brush
423 Sets brush for the set. Bars of this set are drawn using \a brush
387 */
424 */
388 void QBarSet::setBrush(const QBrush &brush)
425 void QBarSet::setBrush(const QBrush &brush)
389 {
426 {
390 if(d_ptr->m_brush!=brush){
427 if(d_ptr->m_brush!=brush){
391 d_ptr->m_brush = brush;
428 d_ptr->m_brush = brush;
392 emit d_ptr->updatedBars();
429 emit d_ptr->updatedBars();
393 emit brushChanged();
430 emit brushChanged();
394 }
431 }
395 }
432 }
396
433
397 /*!
434 /*!
398 Returns brush of the set.
435 Returns brush of the set.
399 */
436 */
400 QBrush QBarSet::brush() const
437 QBrush QBarSet::brush() const
401 {
438 {
402 return d_ptr->m_brush;
439 return d_ptr->m_brush;
403 }
440 }
404
441
405 /*!
442 /*!
406 Sets \a brush of the values that are drawn on top of this barset
443 Sets \a brush of the values that are drawn on top of this barset
407 */
444 */
408 void QBarSet::setLabelBrush(const QBrush &brush)
445 void QBarSet::setLabelBrush(const QBrush &brush)
409 {
446 {
410 if(d_ptr->m_labelBrush!=brush){
447 if(d_ptr->m_labelBrush!=brush){
411 d_ptr->m_labelBrush = brush;
448 d_ptr->m_labelBrush = brush;
412 emit d_ptr->updatedBars();
449 emit d_ptr->updatedBars();
413 emit labelBrushChanged();
450 emit labelBrushChanged();
414 }
451 }
415 }
452 }
416
453
417 /*!
454 /*!
418 Returns brush of the values that are drawn on top of this barset
455 Returns brush of the values that are drawn on top of this barset
419 */
456 */
420 QBrush QBarSet::labelBrush() const
457 QBrush QBarSet::labelBrush() const
421 {
458 {
422 return d_ptr->m_labelBrush;
459 return d_ptr->m_labelBrush;
423 }
460 }
424
461
425 /*!
462 /*!
426 Sets the \a font for values that are drawn on top of this barset
463 Sets the \a font for values that are drawn on top of this barset
427 */
464 */
428 void QBarSet::setLabelFont(const QFont &font)
465 void QBarSet::setLabelFont(const QFont &font)
429 {
466 {
430 if(d_ptr->m_labelFont!=font) {
467 if(d_ptr->m_labelFont!=font) {
431 d_ptr->m_labelFont = font;
468 d_ptr->m_labelFont = font;
432 emit d_ptr->updatedBars();
469 emit d_ptr->updatedBars();
433 emit labelFontChanged();
470 emit labelFontChanged();
434 }
471 }
435
472
436 }
473 }
437
474
438 /*!
475 /*!
439 Returns the pen for values that are drawn on top of this set
476 Returns the pen for values that are drawn on top of this set
440 */
477 */
441 QFont QBarSet::labelFont() const
478 QFont QBarSet::labelFont() const
442 {
479 {
443 return d_ptr->m_labelFont;
480 return d_ptr->m_labelFont;
444 }
481 }
445
482
446 QColor QBarSet::color()
483 QColor QBarSet::color()
447 {
484 {
448 return brush().color();
485 return brush().color();
449 }
486 }
450
487
451 void QBarSet::setColor(QColor color)
488 void QBarSet::setColor(QColor color)
452 {
489 {
453 QBrush b = brush();
490 QBrush b = brush();
454 if (b.color() != color) {
491 if (b.color() != color) {
455 b.setColor(color);
492 b.setColor(color);
456 setBrush(b);
493 setBrush(b);
457 emit colorChanged(color);
494 emit colorChanged(color);
458 }
495 }
459 }
496 }
460
497
461 QColor QBarSet::borderColor()
498 QColor QBarSet::borderColor()
462 {
499 {
463 return pen().color();
500 return pen().color();
464 }
501 }
465
502
466 void QBarSet::setBorderColor(QColor color)
503 void QBarSet::setBorderColor(QColor color)
467 {
504 {
468 QPen p = pen();
505 QPen p = pen();
469 if (p.color() != color) {
506 if (p.color() != color) {
470 p.setColor(color);
507 p.setColor(color);
471 setPen(p);
508 setPen(p);
472 emit borderColorChanged(color);
509 emit borderColorChanged(color);
473 }
510 }
474 }
511 }
475
512
476 QColor QBarSet::labelColor()
513 QColor QBarSet::labelColor()
477 {
514 {
478 return labelBrush().color();
515 return labelBrush().color();
479 }
516 }
480
517
481 void QBarSet::setLabelColor(QColor color)
518 void QBarSet::setLabelColor(QColor color)
482 {
519 {
483 QBrush b = labelBrush();
520 QBrush b = labelBrush();
484 if (b.color() != color) {
521 if (b.color() != color) {
485 b.setColor(color);
522 b.setColor(color);
486 setLabelBrush(b);
523 setLabelBrush(b);
487 emit labelColorChanged(color);
524 emit labelColorChanged(color);
488 }
525 }
489 }
526 }
490
527
491 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
528 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
492
529
493 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
530 QBarSetPrivate::QBarSetPrivate(const QString label, QBarSet *parent) : QObject(parent),
494 q_ptr(parent),
531 q_ptr(parent),
495 m_label(label)
532 m_label(label)
496 {
533 {
497 }
534 }
498
535
499 QBarSetPrivate::~QBarSetPrivate()
536 QBarSetPrivate::~QBarSetPrivate()
500 {
537 {
501 }
538 }
502
539
503 void QBarSetPrivate::append(QPointF value)
540 void QBarSetPrivate::append(QPointF value)
504 {
541 {
505 m_values.append(value);
542 m_values.append(value);
506 emit restructuredBars();
543 emit restructuredBars();
507 }
544 }
508
545
509 void QBarSetPrivate::append(QList<QPointF> values)
546 void QBarSetPrivate::append(QList<QPointF> values)
510 {
547 {
511 for (int i=0; i<values.count(); i++) {
548 for (int i=0; i<values.count(); i++) {
512 m_values.append(values.at(i));
549 m_values.append(values.at(i));
513 }
550 }
514 emit restructuredBars();
551 emit restructuredBars();
515 }
552 }
516
553
517 void QBarSetPrivate::append(QList<qreal> values)
554 void QBarSetPrivate::append(QList<qreal> values)
518 {
555 {
519 int index = m_values.count();
556 int index = m_values.count();
520 for (int i=0; i<values.count(); i++) {
557 for (int i=0; i<values.count(); i++) {
521 m_values.append(QPointF(index,values.at(i)));
558 m_values.append(QPointF(index,values.at(i)));
522 index++;
559 index++;
523 }
560 }
524 emit restructuredBars();
561 emit restructuredBars();
525 }
562 }
526
563
527 void QBarSetPrivate::insert(const int index, const qreal value)
564 void QBarSetPrivate::insert(const int index, const qreal value)
528 {
565 {
529 m_values.insert(index, QPointF(index, value));
566 m_values.insert(index, QPointF(index, value));
530 emit restructuredBars();
567 emit restructuredBars();
531 }
568 }
532
569
533 void QBarSetPrivate::insert(const int index, const QPointF value)
570 void QBarSetPrivate::insert(const int index, const QPointF value)
534 {
571 {
535 m_values.insert(index, value);
572 m_values.insert(index, value);
536 emit restructuredBars();
573 emit restructuredBars();
537 }
574 }
538
575
539 bool QBarSetPrivate::remove(const int index, const int count)
576 bool QBarSetPrivate::remove(const int index, const int count)
540 {
577 {
541 if ((index + count) > m_values.count()) {
578 if ((index + count) > m_values.count()) {
542 // cant remove more values than there are
579 // cant remove more values than there are
543 return false;
580 return false;
544 }
581 }
545 int c = count;
582 int c = count;
546 while (c > 0) {
583 while (c > 0) {
547 m_values.removeAt(index);
584 m_values.removeAt(index);
548 c--;
585 c--;
549 }
586 }
550 emit restructuredBars();
587 emit restructuredBars();
551 return true;
588 return true;
552 }
589 }
553
590
554 void QBarSetPrivate::replace(const int index, const qreal value)
591 void QBarSetPrivate::replace(const int index, const qreal value)
555 {
592 {
556 m_values.replace(index,QPointF(index,value));
593 m_values.replace(index,QPointF(index,value));
557 emit updatedBars();
594 emit updatedBars();
558 }
595 }
559
596
560 void QBarSetPrivate::replace(const int index, const QPointF value)
597 void QBarSetPrivate::replace(const int index, const QPointF value)
561 {
598 {
562 m_values.replace(index,value);
599 m_values.replace(index,value);
563 emit updatedBars();
600 emit updatedBars();
564 }
601 }
565
602
566 #include "moc_qbarset.cpp"
603 #include "moc_qbarset.cpp"
567 #include "moc_qbarset_p.cpp"
604 #include "moc_qbarset_p.cpp"
568
605
569 QTCOMMERCIALCHART_END_NAMESPACE
606 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,105 +1,116
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 "qgroupedbarseries.h"
21 #include "qgroupedbarseries.h"
22 #include "qgroupedbarseries_p.h"
22 #include "qgroupedbarseries_p.h"
23 #include "groupedbarchartitem_p.h"
23 #include "groupedbarchartitem_p.h"
24 #include "chartdataset_p.h"
24 #include "chartdataset_p.h"
25 #include "charttheme_p.h"
25 #include "charttheme_p.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 /*!
30 /*!
31 \class QGroupedBarSeries
31 \class QGroupedBarSeries
32 \brief part of QtCommercial chart API.
32 \brief part of QtCommercial chart API.
33 \mainclass
33 \mainclass
34
34
35 QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
35 QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
36 as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data
36 as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data
37 from sets to categories, which are defined by a QStringList.
37 from sets to categories, which are defined by a QStringList.
38
38
39 See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart.
39 See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart.
40 \image examples_groupedbarchart.png
40 \image examples_groupedbarchart.png
41
41
42 \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries
42 \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries
43 */
43 */
44 /*!
45 \qmlclass GroupedBarSeries QGroupedBarSeries
46 \inherits BarSeries
47
48 The following QML shows how to create a simple grouped bar chart:
49 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
50 \beginfloatleft
51 \image demos_qmlchart7.png
52 \endfloat
53 \clearfloat
54 */
44
55
45 /*!
56 /*!
46 Constructs empty QGroupedBarSeries.
57 Constructs empty QGroupedBarSeries.
47 QGroupedBarSeries is QObject which is a child of a \a parent.
58 QGroupedBarSeries is QObject which is a child of a \a parent.
48 */
59 */
49 QGroupedBarSeries::QGroupedBarSeries(QObject *parent)
60 QGroupedBarSeries::QGroupedBarSeries(QObject *parent)
50 : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent)
61 : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent)
51 {
62 {
52 }
63 }
53
64
54 /*!
65 /*!
55 Returns QChartSeries::SeriesTypeGroupedBar.
66 Returns QChartSeries::SeriesTypeGroupedBar.
56 */
67 */
57 QAbstractSeries::SeriesType QGroupedBarSeries::type() const
68 QAbstractSeries::SeriesType QGroupedBarSeries::type() const
58 {
69 {
59 return QAbstractSeries::SeriesTypeGroupedBar;
70 return QAbstractSeries::SeriesTypeGroupedBar;
60 }
71 }
61
72
62 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
73 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
63
74
64 QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QBarSeriesPrivate(q)
75 QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QBarSeriesPrivate(q)
65 {
76 {
66
77
67 }
78 }
68
79
69 void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain)
80 void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain)
70 {
81 {
71 qreal minX(domain.minX());
82 qreal minX(domain.minX());
72 qreal minY(domain.minY());
83 qreal minY(domain.minY());
73 qreal maxX(domain.maxX());
84 qreal maxX(domain.maxX());
74 qreal maxY(domain.maxY());
85 qreal maxY(domain.maxY());
75 int tickXCount(domain.tickXCount());
86 int tickXCount(domain.tickXCount());
76 int tickYCount(domain.tickYCount());
87 int tickYCount(domain.tickYCount());
77
88
78 qreal x = categoryCount();
89 qreal x = categoryCount();
79 qreal y = max();
90 qreal y = max();
80 minX = qMin(minX, -0.5);
91 minX = qMin(minX, -0.5);
81 minY = qMin(minY, y);
92 minY = qMin(minY, y);
82 maxX = qMax(maxX, x - 0.5);
93 maxX = qMax(maxX, x - 0.5);
83 maxY = qMax(maxY, y);
94 maxY = qMax(maxY, y);
84 tickXCount = x+1;
95 tickXCount = x+1;
85
96
86 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
97 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
87 }
98 }
88
99
89
100
90 Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
101 Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
91 {
102 {
92 Q_Q(QGroupedBarSeries);
103 Q_Q(QGroupedBarSeries);
93
104
94 GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter);
105 GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter);
95 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
106 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
96 presenter->animator()->addAnimation(bar);
107 presenter->animator()->addAnimation(bar);
97 }
108 }
98 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
109 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
99 return bar;
110 return bar;
100 }
111 }
101
112
102 #include "moc_qgroupedbarseries.cpp"
113 #include "moc_qgroupedbarseries.cpp"
103
114
104 QTCOMMERCIALCHART_END_NAMESPACE
115 QTCOMMERCIALCHART_END_NAMESPACE
105
116
@@ -1,104 +1,115
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 "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 /*!
30 /*!
31 \class QPercentBarSeries
31 \class QPercentBarSeries
32 \brief part of QtCommercial chart API.
32 \brief part of QtCommercial chart API.
33 \mainclass
33 \mainclass
34
34
35 QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
35 QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
36 as stacks, where each bar is shown as percentage of all bars in that category.
36 as stacks, where each bar is shown as percentage of all bars in that category.
37 QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList.
37 QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList.
38
38
39 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
39 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
40 \image examples_percentbarchart.png
40 \image examples_percentbarchart.png
41
41
42 \sa QBarSet, QStackedBarSeries, QBarSeries
42 \sa QBarSet, QStackedBarSeries, QBarSeries
43 */
43 */
44 /*!
45 \qmlclass PercentBarSeries QPercentBarSeries
46 \inherits BarSeries
47
48 The following QML shows how to create a simple percent bar chart:
49 \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1
50 \beginfloatleft
51 \image demos_qmlchart9.png
52 \endfloat
53 \clearfloat
54 */
44
55
45 /*!
56 /*!
46 Constructs empty QPercentBarSeries.
57 Constructs empty QPercentBarSeries.
47 QPercentBarSeries is QObject which is a child of a \a parent.
58 QPercentBarSeries is QObject which is a child of a \a parent.
48 */
59 */
49 QPercentBarSeries::QPercentBarSeries(QObject *parent)
60 QPercentBarSeries::QPercentBarSeries(QObject *parent)
50 : QBarSeries(*new QPercentBarSeriesPrivate(this), parent)
61 : QBarSeries(*new QPercentBarSeriesPrivate(this), parent)
51 {
62 {
52 }
63 }
53
64
54 /*!
65 /*!
55 Returns QChartSeries::SeriesTypePercentBar.
66 Returns QChartSeries::SeriesTypePercentBar.
56 */
67 */
57 QAbstractSeries::SeriesType QPercentBarSeries::type() const
68 QAbstractSeries::SeriesType QPercentBarSeries::type() const
58 {
69 {
59 return QAbstractSeries::SeriesTypePercentBar;
70 return QAbstractSeries::SeriesTypePercentBar;
60 }
71 }
61
72
62 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
73 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
63
74
64 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QBarSeriesPrivate(q)
75 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QBarSeriesPrivate(q)
65 {
76 {
66
77
67 }
78 }
68
79
69 void QPercentBarSeriesPrivate::scaleDomain(Domain& domain)
80 void QPercentBarSeriesPrivate::scaleDomain(Domain& domain)
70 {
81 {
71 qreal minX(domain.minX());
82 qreal minX(domain.minX());
72 qreal minY(domain.minY());
83 qreal minY(domain.minY());
73 qreal maxX(domain.maxX());
84 qreal maxX(domain.maxX());
74 qreal maxY(domain.maxY());
85 qreal maxY(domain.maxY());
75 int tickXCount(domain.tickXCount());
86 int tickXCount(domain.tickXCount());
76 int tickYCount(domain.tickYCount());
87 int tickYCount(domain.tickYCount());
77
88
78 qreal x = categoryCount();
89 qreal x = categoryCount();
79 minX = qMin(minX, -0.5);
90 minX = qMin(minX, -0.5);
80 maxX = qMax(maxX, x - 0.5);
91 maxX = qMax(maxX, x - 0.5);
81 minY = 0;
92 minY = 0;
82 maxY = 100;
93 maxY = 100;
83 tickXCount = x+1;
94 tickXCount = x+1;
84
95
85 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
96 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
86 }
97 }
87
98
88
99
89 Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
100 Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
90 {
101 {
91 Q_Q(QPercentBarSeries);
102 Q_Q(QPercentBarSeries);
92
103
93 PercentBarChartItem* bar = new PercentBarChartItem(q,presenter);
104 PercentBarChartItem* bar = new PercentBarChartItem(q,presenter);
94 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
105 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
95 presenter->animator()->addAnimation(bar);
106 presenter->animator()->addAnimation(bar);
96 }
107 }
97 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
108 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
98 return bar;
109 return bar;
99 }
110 }
100
111
101 #include "moc_qpercentbarseries.cpp"
112 #include "moc_qpercentbarseries.cpp"
102
113
103 QTCOMMERCIALCHART_END_NAMESPACE
114 QTCOMMERCIALCHART_END_NAMESPACE
104
115
@@ -1,105 +1,117
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 "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 /*!
30 /*!
31 \class QStackedBarSeries
31 \class QStackedBarSeries
32 \brief part of QtCommercial chart API.
32 \brief part of QtCommercial chart API.
33 \mainclass
33 \mainclass
34
34
35 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
35 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
36 as stacks, where bars in same category are stacked on top of each other.
36 as stacks, where bars in same category are stacked on top of each other.
37 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
37 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
38
38
39 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
39 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
40 \image examples_stackedbarchart.png
40 \image examples_stackedbarchart.png
41
41
42 \sa QBarSet, QPercentBarSeries, QBarSeries
42 \sa QBarSet, QPercentBarSeries, QBarSeries
43 */
43 */
44
44
45 /*!
45 /*!
46 \qmlclass StackedBarSeries QStackedBarSeries
47 \inherits BarSeries
48
49 The following QML shows how to create a simple stacked bar chart:
50 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
51 \beginfloatleft
52 \image demos_qmlchart8.png
53 \endfloat
54 \clearfloat
55 */
56
57 /*!
46 Constructs empty QStackedBarSeries.
58 Constructs empty QStackedBarSeries.
47 QStackedBarSeries is QObject which is a child of a \a parent.
59 QStackedBarSeries is QObject which is a child of a \a parent.
48 */
60 */
49 QStackedBarSeries::QStackedBarSeries(QObject *parent)
61 QStackedBarSeries::QStackedBarSeries(QObject *parent)
50 : QBarSeries(*new QStackedBarSeriesPrivate(this), parent)
62 : QBarSeries(*new QStackedBarSeriesPrivate(this), parent)
51 {
63 {
52 }
64 }
53
65
54 /*!
66 /*!
55 Returns QChartSeries::SeriesTypeStackedBar.
67 Returns QChartSeries::SeriesTypeStackedBar.
56 */
68 */
57 QAbstractSeries::SeriesType QStackedBarSeries::type() const
69 QAbstractSeries::SeriesType QStackedBarSeries::type() const
58 {
70 {
59 return QAbstractSeries::SeriesTypeStackedBar;
71 return QAbstractSeries::SeriesTypeStackedBar;
60 }
72 }
61
73
62 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
74 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
63
75
64 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q)
76 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q)
65 {
77 {
66
78
67 }
79 }
68
80
69 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
81 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
70 {
82 {
71 qreal minX(domain.minX());
83 qreal minX(domain.minX());
72 qreal minY(domain.minY());
84 qreal minY(domain.minY());
73 qreal maxX(domain.maxX());
85 qreal maxX(domain.maxX());
74 qreal maxY(domain.maxY());
86 qreal maxY(domain.maxY());
75 int tickXCount(domain.tickXCount());
87 int tickXCount(domain.tickXCount());
76 int tickYCount(domain.tickYCount());
88 int tickYCount(domain.tickYCount());
77
89
78 qreal x = categoryCount();
90 qreal x = categoryCount();
79 qreal y = maxCategorySum();
91 qreal y = maxCategorySum();
80 minX = qMin(minX, -0.5);
92 minX = qMin(minX, -0.5);
81 minY = qMin(minY, y);
93 minY = qMin(minY, y);
82 maxX = qMax(maxX, x - 0.5);
94 maxX = qMax(maxX, x - 0.5);
83 maxY = qMax(maxY, y);
95 maxY = qMax(maxY, y);
84 tickXCount = x+1;
96 tickXCount = x+1;
85
97
86 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
98 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
87 }
99 }
88
100
89
101
90 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
102 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
91 {
103 {
92 Q_Q(QStackedBarSeries);
104 Q_Q(QStackedBarSeries);
93
105
94 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
106 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
95 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
107 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
96 presenter->animator()->addAnimation(bar);
108 presenter->animator()->addAnimation(bar);
97 }
109 }
98 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
110 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
99 return bar;
111 return bar;
100 }
112 }
101
113
102 #include "moc_qstackedbarseries.cpp"
114 #include "moc_qstackedbarseries.cpp"
103
115
104 QTCOMMERCIALCHART_END_NAMESPACE
116 QTCOMMERCIALCHART_END_NAMESPACE
105
117
@@ -1,40 +1,42
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 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 ChartView {
24 ChartView {
25 title: "Bar series"
25 title: "Bar series"
26 anchors.fill: parent
26 anchors.fill: parent
27 theme: ChartView.ChartThemeLight
27 theme: ChartView.ChartThemeLight
28 legend.alignment: Qt.AlignBottom
28 legend.alignment: Qt.AlignBottom
29 axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"]
29 axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"]
30
30
31 property variant series: daSeries
31 property variant series: daSeries
32
32
33 BarSeries {
33 BarSeries {
34 id: daSeries
34 id: daSeries
35 name: "bar"
35 name: "bar"
36 onClicked: console.log("onClicked: " + barset + " " + index);
37 onHovered: console.log("onHovered: " + barset + " " + status);
36 BarSet { label: "Bob"; values: [4, 7, 3, 10, 5, 6] }
38 BarSet { label: "Bob"; values: [4, 7, 3, 10, 5, 6] }
37 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 8] }
39 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 8] }
38 BarSet { label: "James"; values: [3, 5, 8, 5, 4, 7] }
40 BarSet { label: "James"; values: [3, 5, 8, 5, 4, 7] }
39 }
41 }
40 }
42 }
@@ -1,40 +1,42
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 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 ChartView {
24 ChartView {
25 title: "Grouped bar series"
25 title: "Grouped bar series"
26 anchors.fill: parent
26 anchors.fill: parent
27 theme: ChartView.ChartThemeLight
27 theme: ChartView.ChartThemeLight
28 legend.alignment: Qt.AlignBottom
28 legend.alignment: Qt.AlignBottom
29 axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"]
29 axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"]
30
30
31 property variant series: daSeries
31 property variant series: daSeries
32
32
33 GroupedBarSeries {
33 GroupedBarSeries {
34 id: daSeries
34 id: daSeries
35 name: "bar"
35 name: "bar"
36 onClicked: console.log("onClicked: " + barset + " " + index);
37 onHovered: console.log("onHovered: " + barset + " " + status);
36 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
38 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
37 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
39 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
38 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
40 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
39 }
41 }
40 }
42 }
@@ -1,40 +1,42
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 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 ChartView {
24 ChartView {
25 title: "Percent bar series"
25 title: "Percent bar series"
26 anchors.fill: parent
26 anchors.fill: parent
27 theme: ChartView.ChartThemeLight
27 theme: ChartView.ChartThemeLight
28 legend.alignment: Qt.AlignBottom
28 legend.alignment: Qt.AlignBottom
29 axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"]
29 axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"]
30
30
31 property variant series: daSeries
31 property variant series: daSeries
32
32
33 PercentBarSeries {
33 PercentBarSeries {
34 id: daSeries
34 id: daSeries
35 name: "bar"
35 name: "bar"
36 onClicked: console.log("onClicked: " + barset + " " + index);
37 onHovered: console.log("onHovered: " + barset + " " + status);
36 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
38 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
37 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
39 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
38 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
40 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
39 }
41 }
40 }
42 }
@@ -1,38 +1,38
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 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 ChartView {
24 ChartView {
25 id: chart
25 id: chart
26 title: "pie series"
26 title: "pie series"
27 animationOptions: ChartView.SeriesAnimations
27 animationOptions: ChartView.SeriesAnimations
28
28
29 property variant series: pieSeries
29 property variant series: pieSeries
30
30
31 PieSeries {
31 PieSeries {
32 id: pieSeries
32 id: pieSeries
33 name: "pie"
33 name: "pie"
34 PieSlice { id: daSlice; label: "slice1"; value: 11 }
34 PieSlice { label: "slice1"; value: 11 }
35 PieSlice { label: "slice2"; value: 22 }
35 PieSlice { label: "slice2"; value: 22 }
36 PieSlice { label: "slice3"; value: 33 }
36 PieSlice { label: "slice3"; value: 33 }
37 }
37 }
38 }
38 }
@@ -1,40 +1,42
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 import QtQuick 1.0
21 import QtQuick 1.0
22 import QtCommercial.Chart 1.0
22 import QtCommercial.Chart 1.0
23
23
24 ChartView {
24 ChartView {
25 title: "Stacked bar series"
25 title: "Stacked bar series"
26 anchors.fill: parent
26 anchors.fill: parent
27 theme: ChartView.ChartThemeLight
27 theme: ChartView.ChartThemeLight
28 legend.alignment: Qt.AlignBottom
28 legend.alignment: Qt.AlignBottom
29 axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"]
29 axisXLabels: ["0", "2007", "1", "2008", "2", "2009", "3", "2010", "4", "2011", "5", "2012"]
30
30
31 property variant series: daSeries
31 property variant series: daSeries
32
32
33 StackedBarSeries {
33 StackedBarSeries {
34 id: daSeries
34 id: daSeries
35 name: "bar"
35 name: "bar"
36 onClicked: console.log("onClicked: " + barset + " " + index);
37 onHovered: console.log("onHovered: " + barset + " " + status);
36 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
38 BarSet { label: "Bob"; values: [2, 2, 3, 4, 5, 6] }
37 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
39 BarSet { label: "Susan"; values: [5, 1, 2, 4, 1, 7] }
38 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
40 BarSet { label: "James"; values: [3, 5, 8, 13, 5, 8] }
39 }
41 }
40 }
42 }
General Comments 0
You need to be logged in to leave comments. Login now