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