##// END OF EJS Templates
QBarSeries to QAbstractBarSeries
sauimone -
r1584:900775017aef
parent child
Show More
@@ -1,393 +1,393
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 #include <QAbstractAxis>
26 #include <QAbstractAxis>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 DeclarativeBarSet::DeclarativeBarSet(QObject *parent) :
30 DeclarativeBarSet::DeclarativeBarSet(QObject *parent) :
31 QBarSet("", parent)
31 QBarSet("", parent)
32 {
32 {
33 connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, int)));
33 connect(this, SIGNAL(valuesAdded(int,int)), this, SLOT(handleCountChanged(int, int)));
34 connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, int)));
34 connect(this, SIGNAL(valuesRemoved(int,int)), this, SLOT(handleCountChanged(int, int)));
35 }
35 }
36
36
37 void DeclarativeBarSet::handleCountChanged(int index, int count)
37 void DeclarativeBarSet::handleCountChanged(int index, int count)
38 {
38 {
39 Q_UNUSED(index)
39 Q_UNUSED(index)
40 Q_UNUSED(count)
40 Q_UNUSED(count)
41 emit countChanged(QBarSet::count());
41 emit countChanged(QBarSet::count());
42 }
42 }
43
43
44 QVariantList DeclarativeBarSet::values()
44 QVariantList DeclarativeBarSet::values()
45 {
45 {
46 QVariantList values;
46 QVariantList values;
47 for (int i(0); i < count(); i++)
47 for (int i(0); i < count(); i++)
48 values.append(QVariant(QBarSet::at(i)));
48 values.append(QVariant(QBarSet::at(i)));
49 return values;
49 return values;
50 }
50 }
51
51
52 void DeclarativeBarSet::setValues(QVariantList values)
52 void DeclarativeBarSet::setValues(QVariantList values)
53 {
53 {
54 while (count())
54 while (count())
55 remove(count() - 1);
55 remove(count() - 1);
56
56
57 for (int i(0); i < values.count(); i++) {
57 for (int i(0); i < values.count(); i++) {
58 if (values.at(i).canConvert(QVariant::Double))
58 if (values.at(i).canConvert(QVariant::Double))
59 QBarSet::append(values[i].toDouble());
59 QBarSet::append(values[i].toDouble());
60 }
60 }
61 }
61 }
62
62
63 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
63 DeclarativeBarSeries::DeclarativeBarSeries(QDeclarativeItem *parent) :
64 QBarSeries(parent)
64 QAbstractBarSeries(parent)
65 {
65 {
66 connect(this, SIGNAL(barsetsAdded(QList<QBarSet*>)), this, SLOT(handleAdded(QList<QBarSet*>)));
66 connect(this, SIGNAL(barsetsAdded(QList<QBarSet*>)), this, SLOT(handleAdded(QList<QBarSet*>)));
67 connect(this, SIGNAL(barsetsRemoved(QList<QBarSet*>)), this, SLOT(handleRemoved(QList<QBarSet*>)));
67 connect(this, SIGNAL(barsetsRemoved(QList<QBarSet*>)), this, SLOT(handleRemoved(QList<QBarSet*>)));
68 }
68 }
69
69
70 void DeclarativeBarSeries::handleAdded(QList<QBarSet* > barsets)
70 void DeclarativeBarSeries::handleAdded(QList<QBarSet* > barsets)
71 {
71 {
72 foreach(QBarSet *b, barsets) {
72 foreach(QBarSet *b, barsets) {
73 DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b);
73 DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b);
74 emit added(barset);
74 emit added(barset);
75 }
75 }
76 }
76 }
77
77
78 void DeclarativeBarSeries::handleRemoved(QList<QBarSet* > barsets)
78 void DeclarativeBarSeries::handleRemoved(QList<QBarSet* > barsets)
79 {
79 {
80 foreach(QBarSet *b, barsets) {
80 foreach(QBarSet *b, barsets) {
81 DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b);
81 DeclarativeBarSet *barset = qobject_cast<DeclarativeBarSet *>(b);
82 emit removed(barset);
82 emit removed(barset);
83 }
83 }
84 }
84 }
85
85
86 void DeclarativeBarSeries::classBegin()
86 void DeclarativeBarSeries::classBegin()
87 {
87 {
88 }
88 }
89
89
90 void DeclarativeBarSeries::componentComplete()
90 void DeclarativeBarSeries::componentComplete()
91 {
91 {
92 foreach(QObject *child, children()) {
92 foreach(QObject *child, children()) {
93 if (qobject_cast<DeclarativeBarSet *>(child)) {
93 if (qobject_cast<DeclarativeBarSet *>(child)) {
94 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
94 QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
95 } else if (qobject_cast<QVBarModelMapper *>(child)) {
95 } else if (qobject_cast<QVBarModelMapper *>(child)) {
96 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
96 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
97 mapper->setSeries(this);
97 mapper->setSeries(this);
98 } else if (qobject_cast<QHBarModelMapper *>(child)) {
98 } else if (qobject_cast<QHBarModelMapper *>(child)) {
99 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
99 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
100 mapper->setSeries(this);
100 mapper->setSeries(this);
101 }
101 }
102 }
102 }
103 }
103 }
104
104
105 void DeclarativeBarSeries::setAxisX(QAbstractAxis *axis)
105 void DeclarativeBarSeries::setAxisX(QAbstractAxis *axis)
106 {
106 {
107 chart()->setAxisX(axis, this);
107 chart()->setAxisX(axis, this);
108 }
108 }
109
109
110 QAbstractAxis *DeclarativeBarSeries::axisX()
110 QAbstractAxis *DeclarativeBarSeries::axisX()
111 {
111 {
112 return chart()->axisX(this);
112 return chart()->axisX(this);
113 }
113 }
114
114
115 void DeclarativeBarSeries::setAxisY(QAbstractAxis *axis)
115 void DeclarativeBarSeries::setAxisY(QAbstractAxis *axis)
116 {
116 {
117 chart()->setAxisY(axis, this);
117 chart()->setAxisY(axis, this);
118 }
118 }
119
119
120 QAbstractAxis *DeclarativeBarSeries::axisY()
120 QAbstractAxis *DeclarativeBarSeries::axisY()
121 {
121 {
122 return chart()->axisY(this);
122 return chart()->axisY(this);
123 }
123 }
124
124
125 QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren()
125 QDeclarativeListProperty<QObject> DeclarativeBarSeries::seriesChildren()
126 {
126 {
127 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
127 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
128 }
128 }
129
129
130 void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
130 void DeclarativeBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
131 {
131 {
132 // Empty implementation; the children are parsed in componentComplete instead
132 // Empty implementation; the children are parsed in componentComplete instead
133 Q_UNUSED(list);
133 Q_UNUSED(list);
134 Q_UNUSED(element);
134 Q_UNUSED(element);
135 }
135 }
136
136
137 DeclarativeBarSet *DeclarativeBarSeries::at(int index)
137 DeclarativeBarSet *DeclarativeBarSeries::at(int index)
138 {
138 {
139 QList<QBarSet*> setList = barSets();
139 QList<QBarSet*> setList = barSets();
140 if (index >= 0 && index < setList.count())
140 if (index >= 0 && index < setList.count())
141 return qobject_cast<DeclarativeBarSet *>(setList[index]);
141 return qobject_cast<DeclarativeBarSet *>(setList[index]);
142
142
143 return 0;
143 return 0;
144 }
144 }
145
145
146 DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values)
146 DeclarativeBarSet *DeclarativeBarSeries::insert(int index, QString label, QVariantList values)
147 {
147 {
148 int insertIndex = index;
148 int insertIndex = index;
149 if (insertIndex < 0)
149 if (insertIndex < 0)
150 insertIndex = 0;
150 insertIndex = 0;
151 else if (insertIndex > count())
151 else if (insertIndex > count())
152 insertIndex = count();
152 insertIndex = count();
153
153
154 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
154 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
155 barset->setLabel(label);
155 barset->setLabel(label);
156 barset->setValues(values);
156 barset->setValues(values);
157 if (QBarSeries::insert(insertIndex, barset))
157 if (QAbstractBarSeries::insert(insertIndex, barset))
158 return barset;
158 return barset;
159 delete barset;
159 delete barset;
160 return 0;
160 return 0;
161 }
161 }
162
162
163 DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) :
163 DeclarativeGroupedBarSeries::DeclarativeGroupedBarSeries(QDeclarativeItem *parent) :
164 QGroupedBarSeries(parent)
164 QGroupedBarSeries(parent)
165 {
165 {
166 }
166 }
167
167
168 void DeclarativeGroupedBarSeries::classBegin()
168 void DeclarativeGroupedBarSeries::classBegin()
169 {
169 {
170 }
170 }
171
171
172 void DeclarativeGroupedBarSeries::componentComplete()
172 void DeclarativeGroupedBarSeries::componentComplete()
173 {
173 {
174 foreach(QObject *child, children()) {
174 foreach(QObject *child, children()) {
175 if (qobject_cast<DeclarativeBarSet *>(child)) {
175 if (qobject_cast<DeclarativeBarSet *>(child)) {
176 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
176 QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
177 } else if(qobject_cast<QVBarModelMapper *>(child)) {
177 } else if(qobject_cast<QVBarModelMapper *>(child)) {
178 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
178 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
179 mapper->setSeries(this);
179 mapper->setSeries(this);
180 } else if(qobject_cast<QHBarModelMapper *>(child)) {
180 } else if(qobject_cast<QHBarModelMapper *>(child)) {
181 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
181 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
182 mapper->setSeries(this);
182 mapper->setSeries(this);
183 }
183 }
184 }
184 }
185 }
185 }
186
186
187 void DeclarativeGroupedBarSeries::setAxisX(QAbstractAxis *axis)
187 void DeclarativeGroupedBarSeries::setAxisX(QAbstractAxis *axis)
188 {
188 {
189 chart()->setAxisX(axis, this);
189 chart()->setAxisX(axis, this);
190 }
190 }
191
191
192 QAbstractAxis *DeclarativeGroupedBarSeries::axisX()
192 QAbstractAxis *DeclarativeGroupedBarSeries::axisX()
193 {
193 {
194 return chart()->axisX(this);
194 return chart()->axisX(this);
195 }
195 }
196
196
197 void DeclarativeGroupedBarSeries::setAxisY(QAbstractAxis *axis)
197 void DeclarativeGroupedBarSeries::setAxisY(QAbstractAxis *axis)
198 {
198 {
199 chart()->setAxisY(axis, this);
199 chart()->setAxisY(axis, this);
200 }
200 }
201
201
202 QAbstractAxis *DeclarativeGroupedBarSeries::axisY()
202 QAbstractAxis *DeclarativeGroupedBarSeries::axisY()
203 {
203 {
204 return chart()->axisY(this);
204 return chart()->axisY(this);
205 }
205 }
206
206
207 QDeclarativeListProperty<QObject> DeclarativeGroupedBarSeries::seriesChildren()
207 QDeclarativeListProperty<QObject> DeclarativeGroupedBarSeries::seriesChildren()
208 {
208 {
209 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
209 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
210 }
210 }
211
211
212 void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
212 void DeclarativeGroupedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
213 {
213 {
214 // Empty implementation; the children are parsed in componentComplete instead
214 // Empty implementation; the children are parsed in componentComplete instead
215 Q_UNUSED(list);
215 Q_UNUSED(list);
216 Q_UNUSED(element);
216 Q_UNUSED(element);
217 }
217 }
218
218
219 DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index)
219 DeclarativeBarSet *DeclarativeGroupedBarSeries::at(int index)
220 {
220 {
221 QList<QBarSet*> setList = barSets();
221 QList<QBarSet*> setList = barSets();
222 if (index >= 0 && index < setList.count())
222 if (index >= 0 && index < setList.count())
223 return qobject_cast<DeclarativeBarSet *>(setList[index]);
223 return qobject_cast<DeclarativeBarSet *>(setList[index]);
224
224
225 return 0;
225 return 0;
226 }
226 }
227
227
228 DeclarativeBarSet *DeclarativeGroupedBarSeries::insert(int index, QString label, QVariantList values)
228 DeclarativeBarSet *DeclarativeGroupedBarSeries::insert(int index, QString label, QVariantList values)
229 {
229 {
230 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
230 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
231 barset->setLabel(label);
231 barset->setLabel(label);
232 barset->setValues(values);
232 barset->setValues(values);
233 if (QGroupedBarSeries::insert(index, barset))
233 if (QGroupedBarSeries::insert(index, barset))
234 return barset;
234 return barset;
235 delete barset;
235 delete barset;
236 return 0;
236 return 0;
237 }
237 }
238
238
239 DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) :
239 DeclarativeStackedBarSeries::DeclarativeStackedBarSeries(QDeclarativeItem *parent) :
240 QStackedBarSeries(parent)
240 QStackedBarSeries(parent)
241 {
241 {
242 }
242 }
243
243
244 void DeclarativeStackedBarSeries::classBegin()
244 void DeclarativeStackedBarSeries::classBegin()
245 {
245 {
246 }
246 }
247
247
248 void DeclarativeStackedBarSeries::componentComplete()
248 void DeclarativeStackedBarSeries::componentComplete()
249 {
249 {
250 foreach(QObject *child, children()) {
250 foreach(QObject *child, children()) {
251 if (qobject_cast<DeclarativeBarSet *>(child)) {
251 if (qobject_cast<DeclarativeBarSet *>(child)) {
252 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
252 QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
253 } else if(qobject_cast<QVBarModelMapper *>(child)) {
253 } else if(qobject_cast<QVBarModelMapper *>(child)) {
254 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
254 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
255 mapper->setSeries(this);
255 mapper->setSeries(this);
256 } else if(qobject_cast<QHBarModelMapper *>(child)) {
256 } else if(qobject_cast<QHBarModelMapper *>(child)) {
257 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
257 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
258 mapper->setSeries(this);
258 mapper->setSeries(this);
259 }
259 }
260 }
260 }
261 }
261 }
262
262
263 void DeclarativeStackedBarSeries::setAxisX(QAbstractAxis *axis)
263 void DeclarativeStackedBarSeries::setAxisX(QAbstractAxis *axis)
264 {
264 {
265 chart()->setAxisX(axis, this);
265 chart()->setAxisX(axis, this);
266 }
266 }
267
267
268 QAbstractAxis *DeclarativeStackedBarSeries::axisX()
268 QAbstractAxis *DeclarativeStackedBarSeries::axisX()
269 {
269 {
270 return chart()->axisX(this);
270 return chart()->axisX(this);
271 }
271 }
272
272
273 void DeclarativeStackedBarSeries::setAxisY(QAbstractAxis *axis)
273 void DeclarativeStackedBarSeries::setAxisY(QAbstractAxis *axis)
274 {
274 {
275 chart()->setAxisY(axis, this);
275 chart()->setAxisY(axis, this);
276 }
276 }
277
277
278 QAbstractAxis *DeclarativeStackedBarSeries::axisY()
278 QAbstractAxis *DeclarativeStackedBarSeries::axisY()
279 {
279 {
280 return chart()->axisY(this);
280 return chart()->axisY(this);
281 }
281 }
282
282
283 QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren()
283 QDeclarativeListProperty<QObject> DeclarativeStackedBarSeries::seriesChildren()
284 {
284 {
285 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
285 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
286 }
286 }
287
287
288 void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
288 void DeclarativeStackedBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
289 {
289 {
290 // Empty implementation; the children are parsed in componentComplete instead
290 // Empty implementation; the children are parsed in componentComplete instead
291 Q_UNUSED(list);
291 Q_UNUSED(list);
292 Q_UNUSED(element);
292 Q_UNUSED(element);
293 }
293 }
294
294
295 DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index)
295 DeclarativeBarSet *DeclarativeStackedBarSeries::at(int index)
296 {
296 {
297 QList<QBarSet*> setList = barSets();
297 QList<QBarSet*> setList = barSets();
298 if (index >= 0 && index < setList.count())
298 if (index >= 0 && index < setList.count())
299 return qobject_cast<DeclarativeBarSet *>(setList[index]);
299 return qobject_cast<DeclarativeBarSet *>(setList[index]);
300
300
301 return 0;
301 return 0;
302 }
302 }
303
303
304 DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values)
304 DeclarativeBarSet *DeclarativeStackedBarSeries::insert(int index, QString label, QVariantList values)
305 {
305 {
306 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
306 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
307 barset->setLabel(label);
307 barset->setLabel(label);
308 barset->setValues(values);
308 barset->setValues(values);
309 if (QStackedBarSeries::insert(index, barset))
309 if (QStackedBarSeries::insert(index, barset))
310 return barset;
310 return barset;
311 delete barset;
311 delete barset;
312 return 0;
312 return 0;
313 }
313 }
314
314
315 DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) :
315 DeclarativePercentBarSeries::DeclarativePercentBarSeries(QDeclarativeItem *parent) :
316 QPercentBarSeries(parent)
316 QPercentBarSeries(parent)
317 {
317 {
318 }
318 }
319
319
320 void DeclarativePercentBarSeries::classBegin()
320 void DeclarativePercentBarSeries::classBegin()
321 {
321 {
322 }
322 }
323
323
324 void DeclarativePercentBarSeries::componentComplete()
324 void DeclarativePercentBarSeries::componentComplete()
325 {
325 {
326 foreach(QObject *child, children()) {
326 foreach(QObject *child, children()) {
327 if (qobject_cast<DeclarativeBarSet *>(child)) {
327 if (qobject_cast<DeclarativeBarSet *>(child)) {
328 QBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
328 QAbstractBarSeries::append(qobject_cast<DeclarativeBarSet *>(child));
329 } else if(qobject_cast<QVBarModelMapper *>(child)) {
329 } else if(qobject_cast<QVBarModelMapper *>(child)) {
330 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
330 QVBarModelMapper *mapper = qobject_cast<QVBarModelMapper *>(child);
331 mapper->setSeries(this);
331 mapper->setSeries(this);
332 } else if(qobject_cast<QHBarModelMapper *>(child)) {
332 } else if(qobject_cast<QHBarModelMapper *>(child)) {
333 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
333 QHBarModelMapper *mapper = qobject_cast<QHBarModelMapper *>(child);
334 mapper->setSeries(this);
334 mapper->setSeries(this);
335 }
335 }
336 }
336 }
337 }
337 }
338
338
339 void DeclarativePercentBarSeries::setAxisX(QAbstractAxis *axis)
339 void DeclarativePercentBarSeries::setAxisX(QAbstractAxis *axis)
340 {
340 {
341 chart()->setAxisX(axis, this);
341 chart()->setAxisX(axis, this);
342 }
342 }
343
343
344 QAbstractAxis *DeclarativePercentBarSeries::axisX()
344 QAbstractAxis *DeclarativePercentBarSeries::axisX()
345 {
345 {
346 return chart()->axisX(this);
346 return chart()->axisX(this);
347 }
347 }
348
348
349 void DeclarativePercentBarSeries::setAxisY(QAbstractAxis *axis)
349 void DeclarativePercentBarSeries::setAxisY(QAbstractAxis *axis)
350 {
350 {
351 chart()->setAxisY(axis, this);
351 chart()->setAxisY(axis, this);
352 }
352 }
353
353
354 QAbstractAxis *DeclarativePercentBarSeries::axisY()
354 QAbstractAxis *DeclarativePercentBarSeries::axisY()
355 {
355 {
356 return chart()->axisY(this);
356 return chart()->axisY(this);
357 }
357 }
358
358
359 QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren()
359 QDeclarativeListProperty<QObject> DeclarativePercentBarSeries::seriesChildren()
360 {
360 {
361 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
361 return QDeclarativeListProperty<QObject>(this, 0, &DeclarativeBarSeries::appendSeriesChildren);
362 }
362 }
363
363
364 void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
364 void DeclarativePercentBarSeries::appendSeriesChildren(QDeclarativeListProperty<QObject> * list, QObject *element)
365 {
365 {
366 // Empty implementation; the children are parsed in componentComplete instead
366 // Empty implementation; the children are parsed in componentComplete instead
367 Q_UNUSED(list);
367 Q_UNUSED(list);
368 Q_UNUSED(element);
368 Q_UNUSED(element);
369 }
369 }
370
370
371 DeclarativeBarSet *DeclarativePercentBarSeries::at(int index)
371 DeclarativeBarSet *DeclarativePercentBarSeries::at(int index)
372 {
372 {
373 QList<QBarSet*> setList = barSets();
373 QList<QBarSet*> setList = barSets();
374 if (index >= 0 && index < setList.count())
374 if (index >= 0 && index < setList.count())
375 return qobject_cast<DeclarativeBarSet *>(setList[index]);
375 return qobject_cast<DeclarativeBarSet *>(setList[index]);
376
376
377 return 0;
377 return 0;
378 }
378 }
379
379
380 DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values)
380 DeclarativeBarSet *DeclarativePercentBarSeries::insert(int index, QString label, QVariantList values)
381 {
381 {
382 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
382 DeclarativeBarSet *barset = new DeclarativeBarSet(this);
383 barset->setLabel(label);
383 barset->setLabel(label);
384 barset->setValues(values);
384 barset->setValues(values);
385 if (QPercentBarSeries::insert(index, barset))
385 if (QPercentBarSeries::insert(index, barset))
386 return barset;
386 return barset;
387 delete barset;
387 delete barset;
388 return 0;
388 return 0;
389 }
389 }
390
390
391 #include "moc_declarativebarseries.cpp"
391 #include "moc_declarativebarseries.cpp"
392
392
393 QTCOMMERCIALCHART_END_NAMESPACE
393 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,189 +1,189
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef DECLARATIVEBARSERIES_H
21 #ifndef DECLARATIVEBARSERIES_H
22 #define DECLARATIVEBARSERIES_H
22 #define DECLARATIVEBARSERIES_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include "qgroupedbarseries.h"
25 #include "qgroupedbarseries.h"
26 #include "qstackedbarseries.h"
26 #include "qstackedbarseries.h"
27 #include "qpercentbarseries.h"
27 #include "qpercentbarseries.h"
28 #include "qbarset.h"
28 #include "qbarset.h"
29 #include "qabstractaxis.h"
29 #include "qabstractaxis.h"
30 #include <QDeclarativeItem>
30 #include <QDeclarativeItem>
31 #include <QDeclarativeParserStatus>
31 #include <QDeclarativeParserStatus>
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 class QChart;
35 class QChart;
36
36
37 class DeclarativeBarSet : public QBarSet
37 class DeclarativeBarSet : public QBarSet
38 {
38 {
39 Q_OBJECT
39 Q_OBJECT
40 Q_PROPERTY(QVariantList values READ values WRITE setValues)
40 Q_PROPERTY(QVariantList values READ values WRITE setValues)
41 Q_PROPERTY(int count READ count NOTIFY countChanged)
41 Q_PROPERTY(int count READ count NOTIFY countChanged)
42
42
43 public:
43 public:
44 explicit DeclarativeBarSet(QObject *parent = 0);
44 explicit DeclarativeBarSet(QObject *parent = 0);
45 QVariantList values();
45 QVariantList values();
46 void setValues(QVariantList values);
46 void setValues(QVariantList values);
47
47
48 public: // From QBarSet
48 public: // From QBarSet
49 Q_INVOKABLE void append(qreal value) { QBarSet::append(value); }
49 Q_INVOKABLE void append(qreal value) { QBarSet::append(value); }
50 Q_INVOKABLE void remove(const int index, const int count = 1) { QBarSet::remove(index, count); }
50 Q_INVOKABLE void remove(const int index, const int count = 1) { QBarSet::remove(index, count); }
51 Q_INVOKABLE void replace(int index, qreal value) { QBarSet::replace(index, value); }
51 Q_INVOKABLE void replace(int index, qreal value) { QBarSet::replace(index, value); }
52 Q_INVOKABLE qreal at(int index) { return QBarSet::at(index); }
52 Q_INVOKABLE qreal at(int index) { return QBarSet::at(index); }
53
53
54 Q_SIGNALS:
54 Q_SIGNALS:
55 void countChanged(int count);
55 void countChanged(int count);
56
56
57 private Q_SLOTS:
57 private Q_SLOTS:
58 void handleCountChanged(int index, int count);
58 void handleCountChanged(int index, int count);
59 };
59 };
60
60
61 class DeclarativeBarSeries : public QBarSeries, public QDeclarativeParserStatus
61 class DeclarativeBarSeries : public QAbstractBarSeries, public QDeclarativeParserStatus
62 {
62 {
63 Q_OBJECT
63 Q_OBJECT
64 Q_INTERFACES(QDeclarativeParserStatus)
64 Q_INTERFACES(QDeclarativeParserStatus)
65 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
65 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
66 Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX)
66 Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX)
67 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY)
67 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY)
68 Q_CLASSINFO("DefaultProperty", "seriesChildren")
68 Q_CLASSINFO("DefaultProperty", "seriesChildren")
69
69
70 public:
70 public:
71 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
71 explicit DeclarativeBarSeries(QDeclarativeItem *parent = 0);
72 void setAxisX(QAbstractAxis *axis);
72 void setAxisX(QAbstractAxis *axis);
73 QAbstractAxis *axisX();
73 QAbstractAxis *axisX();
74 void setAxisY(QAbstractAxis *axis);
74 void setAxisY(QAbstractAxis *axis);
75 QAbstractAxis *axisY();
75 QAbstractAxis *axisY();
76 QDeclarativeListProperty<QObject> seriesChildren();
76 QDeclarativeListProperty<QObject> seriesChildren();
77 Q_INVOKABLE DeclarativeBarSet *at(int index);
77 Q_INVOKABLE DeclarativeBarSet *at(int index);
78 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
78 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
79 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
79 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
80 Q_INVOKABLE bool remove(QBarSet *barset) { return QBarSeries::remove(barset); }
80 Q_INVOKABLE bool remove(QBarSet *barset) { return QAbstractBarSeries::remove(barset); }
81 Q_INVOKABLE void clear() { return QBarSeries::clear(); }
81 Q_INVOKABLE void clear() { return QAbstractBarSeries::clear(); }
82
82
83 public: // from QDeclarativeParserStatus
83 public: // from QDeclarativeParserStatus
84 void classBegin();
84 void classBegin();
85 void componentComplete();
85 void componentComplete();
86
86
87 Q_SIGNALS:
87 Q_SIGNALS:
88 void added(DeclarativeBarSet *barset);
88 void added(DeclarativeBarSet *barset);
89 void removed(DeclarativeBarSet *barset);
89 void removed(DeclarativeBarSet *barset);
90
90
91 public Q_SLOTS:
91 public Q_SLOTS:
92 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
92 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
93 void handleAdded(QList<QBarSet* > barsets);
93 void handleAdded(QList<QBarSet* > barsets);
94 void handleRemoved(QList<QBarSet* > barsets);
94 void handleRemoved(QList<QBarSet* > barsets);
95 };
95 };
96
96
97 class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus
97 class DeclarativeGroupedBarSeries : public QGroupedBarSeries, public QDeclarativeParserStatus
98 {
98 {
99 Q_OBJECT
99 Q_OBJECT
100 Q_INTERFACES(QDeclarativeParserStatus)
100 Q_INTERFACES(QDeclarativeParserStatus)
101 Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX)
101 Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX)
102 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY)
102 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY)
103 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
103 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
104 Q_CLASSINFO("DefaultProperty", "seriesChildren")
104 Q_CLASSINFO("DefaultProperty", "seriesChildren")
105
105
106 public:
106 public:
107 explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0);
107 explicit DeclarativeGroupedBarSeries(QDeclarativeItem *parent = 0);
108 void setAxisX(QAbstractAxis *axis);
108 void setAxisX(QAbstractAxis *axis);
109 QAbstractAxis *axisX();
109 QAbstractAxis *axisX();
110 void setAxisY(QAbstractAxis *axis);
110 void setAxisY(QAbstractAxis *axis);
111 QAbstractAxis *axisY();
111 QAbstractAxis *axisY();
112 QDeclarativeListProperty<QObject> seriesChildren();
112 QDeclarativeListProperty<QObject> seriesChildren();
113 Q_INVOKABLE DeclarativeBarSet *at(int index);
113 Q_INVOKABLE DeclarativeBarSet *at(int index);
114 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
114 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
115 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
115 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
116 Q_INVOKABLE bool remove(QBarSet *barset) { return QGroupedBarSeries::remove(barset); }
116 Q_INVOKABLE bool remove(QBarSet *barset) { return QGroupedBarSeries::remove(barset); }
117 Q_INVOKABLE void clear() { return QGroupedBarSeries::clear(); }
117 Q_INVOKABLE void clear() { return QGroupedBarSeries::clear(); }
118
118
119 public: // from QDeclarativeParserStatus
119 public: // from QDeclarativeParserStatus
120 void classBegin();
120 void classBegin();
121 void componentComplete();
121 void componentComplete();
122
122
123 public Q_SLOTS:
123 public Q_SLOTS:
124 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
124 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
125 };
125 };
126
126
127 class DeclarativeStackedBarSeries : public QStackedBarSeries, public QDeclarativeParserStatus
127 class DeclarativeStackedBarSeries : public QStackedBarSeries, public QDeclarativeParserStatus
128 {
128 {
129 Q_OBJECT
129 Q_OBJECT
130 Q_INTERFACES(QDeclarativeParserStatus)
130 Q_INTERFACES(QDeclarativeParserStatus)
131 Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX)
131 Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX)
132 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY)
132 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY)
133 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
133 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
134 Q_CLASSINFO("DefaultProperty", "seriesChildren")
134 Q_CLASSINFO("DefaultProperty", "seriesChildren")
135
135
136 public:
136 public:
137 explicit DeclarativeStackedBarSeries(QDeclarativeItem *parent = 0);
137 explicit DeclarativeStackedBarSeries(QDeclarativeItem *parent = 0);
138 void setAxisX(QAbstractAxis *axis);
138 void setAxisX(QAbstractAxis *axis);
139 QAbstractAxis *axisX();
139 QAbstractAxis *axisX();
140 void setAxisY(QAbstractAxis *axis);
140 void setAxisY(QAbstractAxis *axis);
141 QAbstractAxis *axisY();
141 QAbstractAxis *axisY();
142 QDeclarativeListProperty<QObject> seriesChildren();
142 QDeclarativeListProperty<QObject> seriesChildren();
143 Q_INVOKABLE DeclarativeBarSet *at(int index);
143 Q_INVOKABLE DeclarativeBarSet *at(int index);
144 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
144 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
145 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
145 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
146 Q_INVOKABLE bool remove(QBarSet *barset) { return QStackedBarSeries::remove(barset); }
146 Q_INVOKABLE bool remove(QBarSet *barset) { return QStackedBarSeries::remove(barset); }
147 Q_INVOKABLE void clear() { return QStackedBarSeries::clear(); }
147 Q_INVOKABLE void clear() { return QStackedBarSeries::clear(); }
148
148
149 public: // from QDeclarativeParserStatus
149 public: // from QDeclarativeParserStatus
150 void classBegin();
150 void classBegin();
151 void componentComplete();
151 void componentComplete();
152
152
153 public Q_SLOTS:
153 public Q_SLOTS:
154 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
154 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
155 };
155 };
156
156
157 class DeclarativePercentBarSeries : public QPercentBarSeries, public QDeclarativeParserStatus
157 class DeclarativePercentBarSeries : public QPercentBarSeries, public QDeclarativeParserStatus
158 {
158 {
159 Q_OBJECT
159 Q_OBJECT
160 Q_INTERFACES(QDeclarativeParserStatus)
160 Q_INTERFACES(QDeclarativeParserStatus)
161 Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX)
161 Q_PROPERTY(QAbstractAxis *axisX READ axisX WRITE setAxisX)
162 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY)
162 Q_PROPERTY(QAbstractAxis *axisY READ axisY WRITE setAxisY)
163 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
163 Q_PROPERTY(QDeclarativeListProperty<QObject> seriesChildren READ seriesChildren)
164 Q_CLASSINFO("DefaultProperty", "seriesChildren")
164 Q_CLASSINFO("DefaultProperty", "seriesChildren")
165
165
166 public:
166 public:
167 explicit DeclarativePercentBarSeries(QDeclarativeItem *parent = 0);
167 explicit DeclarativePercentBarSeries(QDeclarativeItem *parent = 0);
168 void setAxisX(QAbstractAxis *axis);
168 void setAxisX(QAbstractAxis *axis);
169 QAbstractAxis *axisX();
169 QAbstractAxis *axisX();
170 void setAxisY(QAbstractAxis *axis);
170 void setAxisY(QAbstractAxis *axis);
171 QAbstractAxis *axisY();
171 QAbstractAxis *axisY();
172 QDeclarativeListProperty<QObject> seriesChildren();
172 QDeclarativeListProperty<QObject> seriesChildren();
173 Q_INVOKABLE DeclarativeBarSet *at(int index);
173 Q_INVOKABLE DeclarativeBarSet *at(int index);
174 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
174 Q_INVOKABLE DeclarativeBarSet *append(QString label, QVariantList values) { return insert(count(), label, values); }
175 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
175 Q_INVOKABLE DeclarativeBarSet *insert(int index, QString label, QVariantList values);
176 Q_INVOKABLE bool remove(QBarSet *barset) { return QPercentBarSeries::remove(barset); }
176 Q_INVOKABLE bool remove(QBarSet *barset) { return QPercentBarSeries::remove(barset); }
177 Q_INVOKABLE void clear() { return QPercentBarSeries::clear(); }
177 Q_INVOKABLE void clear() { return QPercentBarSeries::clear(); }
178
178
179 public: // from QDeclarativeParserStatus
179 public: // from QDeclarativeParserStatus
180 void classBegin();
180 void classBegin();
181 void componentComplete();
181 void componentComplete();
182
182
183 public Q_SLOTS:
183 public Q_SLOTS:
184 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
184 static void appendSeriesChildren(QDeclarativeListProperty<QObject> *list, QObject *element);
185 };
185 };
186
186
187 QTCOMMERCIALCHART_END_NAMESPACE
187 QTCOMMERCIALCHART_END_NAMESPACE
188
188
189 #endif // DECLARATIVEBARSERIES_H
189 #endif // DECLARATIVEBARSERIES_H
@@ -1,226 +1,226
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 "barchartitem_p.h"
21 #include "barchartitem_p.h"
22 #include "bar_p.h"
22 #include "bar_p.h"
23 #include "qbarset.h"
23 #include "qbarset.h"
24 #include "qbarset_p.h"
24 #include "qbarset_p.h"
25 #include "qbarseries.h"
25 #include "qbarseries.h"
26 #include "qbarseries_p.h"
26 #include "qbarseries_p.h"
27 #include "qchart.h"
27 #include "qchart.h"
28 #include "chartpresenter_p.h"
28 #include "chartpresenter_p.h"
29 #include "chartanimator_p.h"
29 #include "chartanimator_p.h"
30 #include "chartdataset_p.h"
30 #include "chartdataset_p.h"
31 #include <QPainter>
31 #include <QPainter>
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 BarChartItem::BarChartItem(QBarSeries *series, ChartPresenter *presenter) :
35 BarChartItem::BarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
36 ChartItem(presenter),
36 ChartItem(presenter),
37 m_series(series)
37 m_series(series)
38 {
38 {
39 setFlag(ItemClipsChildrenToShape);
39 setFlag(ItemClipsChildrenToShape);
40 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
40 connect(series->d_func(), SIGNAL(updatedBars()), this, SLOT(handleLayoutChanged()));
41 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
41 connect(series->d_func(), SIGNAL(labelsVisibleChanged(bool)), this, SLOT(handleLabelsVisibleChanged(bool)));
42 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
42 connect(series->d_func(), SIGNAL(restructuredBars()), this, SLOT(handleDataStructureChanged()));
43 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged()));
43 connect(series, SIGNAL(visibleChanged()), this, SLOT(handleVisibleChanged()));
44 setZValue(ChartPresenter::BarSeriesZValue);
44 setZValue(ChartPresenter::BarSeriesZValue);
45 handleDataStructureChanged();
45 handleDataStructureChanged();
46 }
46 }
47
47
48 BarChartItem::~BarChartItem()
48 BarChartItem::~BarChartItem()
49 {
49 {
50 }
50 }
51
51
52 void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
52 void BarChartItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
53 {
53 {
54 Q_UNUSED(painter);
54 Q_UNUSED(painter);
55 Q_UNUSED(option);
55 Q_UNUSED(option);
56 Q_UNUSED(widget);
56 Q_UNUSED(widget);
57 }
57 }
58
58
59 QRectF BarChartItem::boundingRect() const
59 QRectF BarChartItem::boundingRect() const
60 {
60 {
61 return m_rect;
61 return m_rect;
62 }
62 }
63
63
64 QVector<QRectF> BarChartItem::calculateLayout()
64 QVector<QRectF> BarChartItem::calculateLayout()
65 {
65 {
66 QVector<QRectF> layout;
66 QVector<QRectF> layout;
67
67
68 // Use temporary qreals for accuracy
68 // Use temporary qreals for accuracy
69 qreal categoryCount = m_series->d_func()->categoryCount();
69 qreal categoryCount = m_series->d_func()->categoryCount();
70 qreal setCount = m_series->count();
70 qreal setCount = m_series->count();
71 bool barsVisible = m_series->isVisible();
71 bool barsVisible = m_series->isVisible();
72
72
73 // Domain:
73 // Domain:
74 qreal width = geometry().width();
74 qreal width = geometry().width();
75 qreal height = geometry().height();
75 qreal height = geometry().height();
76 qreal rangeY = m_domainMaxY - m_domainMinY;
76 qreal rangeY = m_domainMaxY - m_domainMinY;
77 qreal rangeX = m_domainMaxX - m_domainMinX;
77 qreal rangeX = m_domainMaxX - m_domainMinX;
78 qreal scaleY = (height / rangeY);
78 qreal scaleY = (height / rangeY);
79 qreal scaleX = (width / rangeX);
79 qreal scaleX = (width / rangeX);
80 qreal barWidth = scaleX * m_series->d_func()->barWidth();
80 qreal barWidth = scaleX * m_series->d_func()->barWidth();
81
81
82 int itemIndex(0);
82 int itemIndex(0);
83 for (int category = 0; category < categoryCount; category++) {
83 for (int category = 0; category < categoryCount; category++) {
84 qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y();
84 qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y();
85 for (int set = 0; set < setCount; set++) {
85 for (int set = 0; set < setCount; set++) {
86 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
86 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
87 qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
87 qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
88 qreal barHeight = barSet->m_values.at(category).y() * scaleY;
88 qreal barHeight = barSet->m_values.at(category).y() * scaleY;
89
89
90 Bar* bar = m_bars.at(itemIndex);
90 Bar* bar = m_bars.at(itemIndex);
91 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
91 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
92
92
93 layout.append(rect);
93 layout.append(rect);
94 bar->setPen(barSet->m_pen);
94 bar->setPen(barSet->m_pen);
95 bar->setBrush(barSet->m_brush);
95 bar->setBrush(barSet->m_brush);
96 bar->setVisible(barsVisible);
96 bar->setVisible(barsVisible);
97
97
98 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
98 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
99
99
100 if (!qFuzzyIsNull(barSet->m_values.at(category).y())) {
100 if (!qFuzzyIsNull(barSet->m_values.at(category).y())) {
101 label->setText(QString::number(barSet->m_values.at(category).y()));
101 label->setText(QString::number(barSet->m_values.at(category).y()));
102 } else {
102 } else {
103 label->setText(QString(""));
103 label->setText(QString(""));
104 }
104 }
105
105
106 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
106 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
107 ,yPos - barHeight/2 - label->boundingRect().height()/2);
107 ,yPos - barHeight/2 - label->boundingRect().height()/2);
108 label->setFont(barSet->m_labelFont);
108 label->setFont(barSet->m_labelFont);
109 label->setBrush(barSet->m_labelBrush);
109 label->setBrush(barSet->m_labelBrush);
110
110
111 itemIndex++;
111 itemIndex++;
112 }
112 }
113 }
113 }
114
114
115 return layout;
115 return layout;
116 }
116 }
117
117
118 void BarChartItem::applyLayout(const QVector<QRectF> &layout)
118 void BarChartItem::applyLayout(const QVector<QRectF> &layout)
119 {
119 {
120 if (animator()) {
120 if (animator()) {
121 animator()->updateLayout(this, m_layout, layout);
121 animator()->updateLayout(this, m_layout, layout);
122 } else {
122 } else {
123 setLayout(layout);
123 setLayout(layout);
124 update();
124 update();
125 }
125 }
126 }
126 }
127
127
128 void BarChartItem::setLayout(const QVector<QRectF> &layout)
128 void BarChartItem::setLayout(const QVector<QRectF> &layout)
129 {
129 {
130 if (layout.count() != m_bars.count())
130 if (layout.count() != m_bars.count())
131 return;
131 return;
132
132
133 m_layout = layout;
133 m_layout = layout;
134
134
135 for (int i=0; i < m_bars.count(); i++) {
135 for (int i=0; i < m_bars.count(); i++) {
136 m_bars.at(i)->setRect(layout.at(i));
136 m_bars.at(i)->setRect(layout.at(i));
137 }
137 }
138 }
138 }
139 //handlers
139 //handlers
140
140
141 void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
141 void BarChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY)
142 {
142 {
143 m_domainMinX = minX;
143 m_domainMinX = minX;
144 m_domainMaxX = maxX;
144 m_domainMaxX = maxX;
145 m_domainMinY = minY;
145 m_domainMinY = minY;
146 m_domainMaxY = maxY;
146 m_domainMaxY = maxY;
147 handleLayoutChanged();
147 handleLayoutChanged();
148 }
148 }
149
149
150 void BarChartItem::handleGeometryChanged(const QRectF &rect)
150 void BarChartItem::handleGeometryChanged(const QRectF &rect)
151 {
151 {
152 prepareGeometryChange();
152 prepareGeometryChange();
153 m_rect = rect;
153 m_rect = rect;
154 handleLayoutChanged();
154 handleLayoutChanged();
155 }
155 }
156
156
157 void BarChartItem::handleLayoutChanged()
157 void BarChartItem::handleLayoutChanged()
158 {
158 {
159 if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) {
159 if ((m_rect.width() <= 0) || (m_rect.height() <= 0)) {
160 // rect size zero.
160 // rect size zero.
161 return;
161 return;
162 }
162 }
163 QVector<QRectF> layout = calculateLayout();
163 QVector<QRectF> layout = calculateLayout();
164 applyLayout(layout);
164 applyLayout(layout);
165 }
165 }
166
166
167
167
168
168
169 void BarChartItem::handleLabelsVisibleChanged(bool visible)
169 void BarChartItem::handleLabelsVisibleChanged(bool visible)
170 {
170 {
171 foreach (QGraphicsSimpleTextItem* label, m_labels) {
171 foreach (QGraphicsSimpleTextItem* label, m_labels) {
172 label->setVisible(visible);
172 label->setVisible(visible);
173 }
173 }
174 update();
174 update();
175 }
175 }
176
176
177 void BarChartItem::handleDataStructureChanged()
177 void BarChartItem::handleDataStructureChanged()
178 {
178 {
179 foreach(QGraphicsItem *item, childItems()) {
179 foreach(QGraphicsItem *item, childItems()) {
180 delete item;
180 delete item;
181 }
181 }
182
182
183 m_bars.clear();
183 m_bars.clear();
184 m_labels.clear();
184 m_labels.clear();
185 m_layout.clear();
185 m_layout.clear();
186
186
187 bool labelsVisible = m_series->isLabelsVisible();
187 bool labelsVisible = m_series->isLabelsVisible();
188
188
189 // Create new graphic items for bars
189 // Create new graphic items for bars
190 for (int c = 0; c < m_series->d_func()->categoryCount(); c++) {
190 for (int c = 0; c < m_series->d_func()->categoryCount(); c++) {
191 for (int s = 0; s < m_series->count(); s++) {
191 for (int s = 0; s < m_series->count(); s++) {
192 QBarSet *set = m_series->d_func()->barsetAt(s);
192 QBarSet *set = m_series->d_func()->barsetAt(s);
193
193
194 // Bars
194 // Bars
195 Bar *bar = new Bar(set,c,this);
195 Bar *bar = new Bar(set,c,this);
196 m_bars.append(bar);
196 m_bars.append(bar);
197 connect(bar, SIGNAL(clicked(int, QBarSet*)), m_series, SIGNAL(clicked(int, QBarSet*)));
197 connect(bar, SIGNAL(clicked(int, QBarSet*)), m_series, SIGNAL(clicked(int, QBarSet*)));
198 connect(bar, SIGNAL(hovered(bool, QBarSet*)), m_series, SIGNAL(hovered(bool, QBarSet*)));
198 connect(bar, SIGNAL(hovered(bool, QBarSet*)), m_series, SIGNAL(hovered(bool, QBarSet*)));
199 connect(bar, SIGNAL(clicked(int, QBarSet*)), set, SIGNAL(clicked(int)));
199 connect(bar, SIGNAL(clicked(int, QBarSet*)), set, SIGNAL(clicked(int)));
200 connect(bar, SIGNAL(hovered(bool, QBarSet*)), set, SIGNAL(hovered(bool)));
200 connect(bar, SIGNAL(hovered(bool, QBarSet*)), set, SIGNAL(hovered(bool)));
201 m_layout.append(QRectF(0, 0, 0, 0));
201 m_layout.append(QRectF(0, 0, 0, 0));
202
202
203 // Labels
203 // Labels
204 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this);
204 QGraphicsSimpleTextItem *label = new QGraphicsSimpleTextItem(this);
205 label->setVisible(labelsVisible);
205 label->setVisible(labelsVisible);
206 m_labels.append(label);
206 m_labels.append(label);
207 }
207 }
208 }
208 }
209
209
210 // TODO: Is this the right place to call it?
210 // TODO: Is this the right place to call it?
211 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
211 presenter()->chartTheme()->decorate(m_series, presenter()->dataSet()->seriesIndex(m_series));
212 handleLayoutChanged();
212 handleLayoutChanged();
213 }
213 }
214
214
215 void BarChartItem::handleVisibleChanged()
215 void BarChartItem::handleVisibleChanged()
216 {
216 {
217 bool visible = m_series->isVisible();
217 bool visible = m_series->isVisible();
218 handleLabelsVisibleChanged(visible);
218 handleLabelsVisibleChanged(visible);
219 foreach(QGraphicsItem *item, childItems()) {
219 foreach(QGraphicsItem *item, childItems()) {
220 item->setVisible(visible);
220 item->setVisible(visible);
221 }
221 }
222 }
222 }
223
223
224 #include "moc_barchartitem_p.cpp"
224 #include "moc_barchartitem_p.cpp"
225
225
226 QTCOMMERCIALCHART_END_NAMESPACE
226 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,89 +1,89
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30
30
31 #ifndef BARCHARTITEM_H
31 #ifndef BARCHARTITEM_H
32 #define BARCHARTITEM_H
32 #define BARCHARTITEM_H
33
33
34 #include "chartitem_p.h"
34 #include "chartitem_p.h"
35 #include "qbarseries.h"
35 #include "qbarseries.h"
36 #include <QPen>
36 #include <QPen>
37 #include <QBrush>
37 #include <QBrush>
38
38
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40
40
41 class Bar;
41 class Bar;
42 class QAxisCategories;
42 class QAxisCategories;
43 class QChart;
43 class QChart;
44
44
45 class BarChartItem : public ChartItem
45 class BarChartItem : public ChartItem
46 {
46 {
47 Q_OBJECT
47 Q_OBJECT
48 public:
48 public:
49 BarChartItem(QBarSeries *series, ChartPresenter *presenter);
49 BarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter);
50 virtual ~BarChartItem();
50 virtual ~BarChartItem();
51
51
52 public:
52 public:
53 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
53 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
54 QRectF boundingRect() const;
54 QRectF boundingRect() const;
55
55
56 virtual QVector<QRectF> calculateLayout();
56 virtual QVector<QRectF> calculateLayout();
57 virtual void applyLayout(const QVector<QRectF> &layout);
57 virtual void applyLayout(const QVector<QRectF> &layout);
58 void setLayout(const QVector<QRectF> &layout);
58 void setLayout(const QVector<QRectF> &layout);
59 void updateLayout(const QVector<QRectF> &layout);
59 void updateLayout(const QVector<QRectF> &layout);
60
60
61 QRectF geometry() const { return m_rect;}
61 QRectF geometry() const { return m_rect;}
62
62
63 public Q_SLOTS:
63 public Q_SLOTS:
64 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
64 void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY);
65 void handleGeometryChanged(const QRectF &size);
65 void handleGeometryChanged(const QRectF &size);
66 void handleLayoutChanged();
66 void handleLayoutChanged();
67 void handleLabelsVisibleChanged(bool visible);
67 void handleLabelsVisibleChanged(bool visible);
68 void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items
68 void handleDataStructureChanged(); // structure of of series has changed, recreate graphic items
69 void handleVisibleChanged();
69 void handleVisibleChanged();
70
70
71 protected:
71 protected:
72
72
73 qreal m_domainMinX;
73 qreal m_domainMinX;
74 qreal m_domainMaxX;
74 qreal m_domainMaxX;
75 qreal m_domainMinY;
75 qreal m_domainMinY;
76 qreal m_domainMaxY;
76 qreal m_domainMaxY;
77
77
78 QRectF m_rect;
78 QRectF m_rect;
79 QVector<QRectF> m_layout;
79 QVector<QRectF> m_layout;
80
80
81 // Not owned.
81 // Not owned.
82 QBarSeries *m_series;
82 QAbstractBarSeries *m_series;
83 QList<Bar *> m_bars;
83 QList<Bar *> m_bars;
84 QList<QGraphicsSimpleTextItem *> m_labels;
84 QList<QGraphicsSimpleTextItem *> m_labels;
85 };
85 };
86
86
87 QTCOMMERCIALCHART_END_NAMESPACE
87 QTCOMMERCIALCHART_END_NAMESPACE
88
88
89 #endif // BARCHARTITEM_H
89 #endif // BARCHARTITEM_H
@@ -1,92 +1,92
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 "groupedbarchartitem_p.h"
21 #include "groupedbarchartitem_p.h"
22 #include "bar_p.h"
22 #include "bar_p.h"
23 #include "qbarset_p.h"
23 #include "qbarset_p.h"
24 #include "qbarseries_p.h"
24 #include "qbarseries_p.h"
25 #include "qbarset.h"
25 #include "qbarset.h"
26 #include "qbarset_p.h"
26 #include "qbarset_p.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 GroupedBarChartItem::GroupedBarChartItem(QBarSeries *series, ChartPresenter *presenter) :
30 GroupedBarChartItem::GroupedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
31 BarChartItem(series, presenter)
31 BarChartItem(series, presenter)
32 {
32 {
33 }
33 }
34
34
35 QVector<QRectF> GroupedBarChartItem::calculateLayout()
35 QVector<QRectF> GroupedBarChartItem::calculateLayout()
36 {
36 {
37 QVector<QRectF> layout;
37 QVector<QRectF> layout;
38
38
39 // Use temporary qreals for accuracy
39 // Use temporary qreals for accuracy
40 qreal categoryCount = m_series->d_func()->categoryCount();
40 qreal categoryCount = m_series->d_func()->categoryCount();
41 qreal setCount = m_series->count();
41 qreal setCount = m_series->count();
42 bool barsVisible = m_series->isVisible();
42 bool barsVisible = m_series->isVisible();
43
43
44 // Domain:
44 // Domain:
45 qreal width = geometry().width();
45 qreal width = geometry().width();
46 qreal height = geometry().height();
46 qreal height = geometry().height();
47 qreal rangeY = m_domainMaxY - m_domainMinY;
47 qreal rangeY = m_domainMaxY - m_domainMinY;
48 qreal rangeX = m_domainMaxX - m_domainMinX;
48 qreal rangeX = m_domainMaxX - m_domainMinX;
49 qreal scaleY = (height / rangeY);
49 qreal scaleY = (height / rangeY);
50 qreal scaleX = (width / rangeX);
50 qreal scaleX = (width / rangeX);
51 qreal barWidth = (scaleX / setCount) * m_series->d_func()->barWidth();
51 qreal barWidth = (scaleX / setCount) * m_series->d_func()->barWidth();
52
52
53 int itemIndex(0);
53 int itemIndex(0);
54 for (int category = 0; category < categoryCount; category++) {
54 for (int category = 0; category < categoryCount; category++) {
55 qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y();
55 qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y();
56 for (int set = 0; set < setCount; set++) {
56 for (int set = 0; set < setCount; set++) {
57 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
57 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
58
58
59 qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left();
59 qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left();
60 xPos -= setCount*barWidth/2;
60 xPos -= setCount*barWidth/2;
61 xPos += set*barWidth;
61 xPos += set*barWidth;
62 qreal barHeight = barSet->m_values.at(category).y() * scaleY;
62 qreal barHeight = barSet->m_values.at(category).y() * scaleY;
63 Bar* bar = m_bars.at(itemIndex);
63 Bar* bar = m_bars.at(itemIndex);
64
64
65 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
65 QRectF rect(xPos, yPos - barHeight, barWidth, barHeight);
66 layout.append(rect);
66 layout.append(rect);
67 bar->setPen(barSet->m_pen);
67 bar->setPen(barSet->m_pen);
68 bar->setBrush(barSet->m_brush);
68 bar->setBrush(barSet->m_brush);
69 bar->setVisible(barsVisible);
69 bar->setVisible(barsVisible);
70
70
71 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
71 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
72
72
73 if (!qFuzzyIsNull(barSet->m_values.at(category).y())) {
73 if (!qFuzzyIsNull(barSet->m_values.at(category).y())) {
74 label->setText(QString::number(barSet->m_values.at(category).y()));
74 label->setText(QString::number(barSet->m_values.at(category).y()));
75 } else {
75 } else {
76 label->setText(QString(""));
76 label->setText(QString(""));
77 }
77 }
78
78
79 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
79 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
80 ,yPos - barHeight/2 - label->boundingRect().height()/2);
80 ,yPos - barHeight/2 - label->boundingRect().height()/2);
81 label->setFont(barSet->m_labelFont);
81 label->setFont(barSet->m_labelFont);
82 label->setBrush(barSet->m_labelBrush);
82 label->setBrush(barSet->m_labelBrush);
83
83
84 itemIndex++;
84 itemIndex++;
85 }
85 }
86 }
86 }
87 return layout;
87 return layout;
88 }
88 }
89
89
90 #include "moc_groupedbarchartitem_p.cpp"
90 #include "moc_groupedbarchartitem_p.cpp"
91
91
92 QTCOMMERCIALCHART_END_NAMESPACE
92 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,52 +1,52
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30
30
31 #ifndef GROUPEDBARCHARTITEM_H
31 #ifndef GROUPEDBARCHARTITEM_H
32 #define GROUPEDBARCHARTITEM_H
32 #define GROUPEDBARCHARTITEM_H
33
33
34 #include "barchartitem_p.h"
34 #include "barchartitem_p.h"
35 #include "qstackedbarseries.h"
35 #include "qstackedbarseries.h"
36 #include <QGraphicsItem>
36 #include <QGraphicsItem>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class GroupedBarChartItem : public BarChartItem
40 class GroupedBarChartItem : public BarChartItem
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43 public:
43 public:
44 GroupedBarChartItem(QBarSeries *series, ChartPresenter *presenter);
44 GroupedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter);
45
45
46 private:
46 private:
47 virtual QVector<QRectF> calculateLayout();
47 virtual QVector<QRectF> calculateLayout();
48 };
48 };
49
49
50 QTCOMMERCIALCHART_END_NAMESPACE
50 QTCOMMERCIALCHART_END_NAMESPACE
51
51
52 #endif // GROUPEDBARCHARTITEM_H
52 #endif // GROUPEDBARCHARTITEM_H
@@ -1,107 +1,107
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 "percentbarchartitem_p.h"
21 #include "percentbarchartitem_p.h"
22 #include "bar_p.h"
22 #include "bar_p.h"
23 #include "qbarseries_p.h"
23 #include "qbarseries_p.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25 #include "chartanimator_p.h"
25 #include "chartanimator_p.h"
26 #include "qbarset_p.h"
26 #include "qbarset_p.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 PercentBarChartItem::PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter) :
30 PercentBarChartItem::PercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
31 BarChartItem(series, presenter)
31 BarChartItem(series, presenter)
32 {
32 {
33 }
33 }
34
34
35 QVector<QRectF> PercentBarChartItem::calculateLayout()
35 QVector<QRectF> PercentBarChartItem::calculateLayout()
36 {
36 {
37 QVector<QRectF> layout;
37 QVector<QRectF> layout;
38
38
39 // Use temporary qreals for accuracy
39 // Use temporary qreals for accuracy
40 qreal categoryCount = m_series->d_func()->categoryCount();
40 qreal categoryCount = m_series->d_func()->categoryCount();
41 qreal setCount = m_series->count();
41 qreal setCount = m_series->count();
42 bool barsVisible = m_series->isVisible();
42 bool barsVisible = m_series->isVisible();
43
43
44 // Domain:
44 // Domain:
45 qreal width = geometry().width();
45 qreal width = geometry().width();
46 qreal height = geometry().height();
46 qreal height = geometry().height();
47 qreal rangeY = m_domainMaxY - m_domainMinY;
47 qreal rangeY = m_domainMaxY - m_domainMinY;
48 qreal rangeX = m_domainMaxX - m_domainMinX;
48 qreal rangeX = m_domainMaxX - m_domainMinX;
49 qreal scaleY = (height / rangeY);
49 qreal scaleY = (height / rangeY);
50 qreal scaleX = (width / rangeX);
50 qreal scaleX = (width / rangeX);
51 qreal barWidth = scaleX * m_series->d_func()->barWidth();
51 qreal barWidth = scaleX * m_series->d_func()->barWidth();
52
52
53 int itemIndex(0);
53 int itemIndex(0);
54 for (int category = 0; category < categoryCount; category++) {
54 for (int category = 0; category < categoryCount; category++) {
55 qreal colSum = m_series->d_func()->categorySum(category);
55 qreal colSum = m_series->d_func()->categorySum(category);
56 qreal percentage = (100 / colSum);
56 qreal percentage = (100 / colSum);
57 qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y();
57 qreal yPos = height + scaleY * m_domainMinY + geometry().topLeft().y();
58 for (int set=0; set < setCount; set++) {
58 for (int set=0; set < setCount; set++) {
59 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
59 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
60
60
61 qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
61 qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
62
62
63 qreal barHeight = barSet->m_values.at(category).y() * percentage * scaleY;
63 qreal barHeight = barSet->m_values.at(category).y() * percentage * scaleY;
64 Bar* bar = m_bars.at(itemIndex);
64 Bar* bar = m_bars.at(itemIndex);
65 bar->setPen(barSet->m_pen);
65 bar->setPen(barSet->m_pen);
66 bar->setBrush(barSet->m_brush);
66 bar->setBrush(barSet->m_brush);
67 bar->setVisible(barsVisible);
67 bar->setVisible(barsVisible);
68
68
69 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
69 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
70 layout.append(rect);
70 layout.append(rect);
71
71
72 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
72 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
73
73
74 if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) {
74 if (!qFuzzyIsNull(m_series->d_func()->valueAt(set,category))) {
75 int p = m_series->d_func()->percentageAt(set,category) * 100;
75 int p = m_series->d_func()->percentageAt(set,category) * 100;
76 QString vString(QString::number(p));
76 QString vString(QString::number(p));
77 vString.truncate(3);
77 vString.truncate(3);
78 vString.append("%");
78 vString.append("%");
79 label->setText(vString);
79 label->setText(vString);
80 } else {
80 } else {
81 label->setText(QString(""));
81 label->setText(QString(""));
82 }
82 }
83
83
84 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
84 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
85 ,yPos - barHeight/2 - label->boundingRect().height()/2);
85 ,yPos - barHeight/2 - label->boundingRect().height()/2);
86 label->setFont(barSet->m_labelFont);
86 label->setFont(barSet->m_labelFont);
87 label->setBrush(barSet->m_labelBrush);
87 label->setBrush(barSet->m_labelBrush);
88
88
89 itemIndex++;
89 itemIndex++;
90 yPos -= barHeight;
90 yPos -= barHeight;
91 }
91 }
92 }
92 }
93 return layout;
93 return layout;
94 }
94 }
95
95
96 void PercentBarChartItem::applyLayout(const QVector<QRectF> &layout)
96 void PercentBarChartItem::applyLayout(const QVector<QRectF> &layout)
97 {
97 {
98 if (animator()) {
98 if (animator()) {
99 animator()->updateLayout(this, m_layout, layout);
99 animator()->updateLayout(this, m_layout, layout);
100 } else {
100 } else {
101 setLayout(layout);
101 setLayout(layout);
102 update();
102 update();
103 }
103 }
104 }
104 }
105 #include "moc_percentbarchartitem_p.cpp"
105 #include "moc_percentbarchartitem_p.cpp"
106
106
107 QTCOMMERCIALCHART_END_NAMESPACE
107 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,54 +1,54
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30
30
31 #ifndef PERCENTBARCHARTITEM_H
31 #ifndef PERCENTBARCHARTITEM_H
32 #define PERCENTBARCHARTITEM_H
32 #define PERCENTBARCHARTITEM_H
33
33
34 #include "barchartitem_p.h"
34 #include "barchartitem_p.h"
35 #include <QGraphicsItem>
35 #include <QGraphicsItem>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 class QBarSeries;
39 class QAbstractBarSeries;
40
40
41 class PercentBarChartItem : public BarChartItem
41 class PercentBarChartItem : public BarChartItem
42 {
42 {
43 Q_OBJECT
43 Q_OBJECT
44 public:
44 public:
45 PercentBarChartItem(QBarSeries *series, ChartPresenter *presenter);
45 PercentBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter);
46
46
47 private:
47 private:
48 virtual QVector<QRectF> calculateLayout();
48 virtual QVector<QRectF> calculateLayout();
49 virtual void applyLayout(const QVector<QRectF> &layout);
49 virtual void applyLayout(const QVector<QRectF> &layout);
50 };
50 };
51
51
52 QTCOMMERCIALCHART_END_NAMESPACE
52 QTCOMMERCIALCHART_END_NAMESPACE
53
53
54 #endif // PERCENTBARCHARTITEM_H
54 #endif // PERCENTBARCHARTITEM_H
@@ -1,556 +1,556
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 "qbarmodelmapper.h"
21 #include "qbarmodelmapper.h"
22 #include "qbarmodelmapper_p.h"
22 #include "qbarmodelmapper_p.h"
23 #include "qbarseries.h"
23 #include "qbarseries.h"
24 #include "qbarset.h"
24 #include "qbarset.h"
25 #include "qchart.h"
25 #include "qchart.h"
26 #include <QAbstractItemModel>
26 #include <QAbstractItemModel>
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 QBarModelMapper::QBarModelMapper(QObject *parent) :
30 QBarModelMapper::QBarModelMapper(QObject *parent) :
31 QObject(parent),
31 QObject(parent),
32 d_ptr(new QBarModelMapperPrivate(this))
32 d_ptr(new QBarModelMapperPrivate(this))
33 {
33 {
34 }
34 }
35
35
36 QAbstractItemModel* QBarModelMapper::model() const
36 QAbstractItemModel* QBarModelMapper::model() const
37 {
37 {
38 Q_D(const QBarModelMapper);
38 Q_D(const QBarModelMapper);
39 return d->m_model;
39 return d->m_model;
40 }
40 }
41
41
42 void QBarModelMapper::setModel(QAbstractItemModel *model)
42 void QBarModelMapper::setModel(QAbstractItemModel *model)
43 {
43 {
44 if (model == 0)
44 if (model == 0)
45 return;
45 return;
46
46
47 Q_D(QBarModelMapper);
47 Q_D(QBarModelMapper);
48 if (d->m_model) {
48 if (d->m_model) {
49 disconnect(d->m_model, 0, d, 0);
49 disconnect(d->m_model, 0, d, 0);
50 }
50 }
51
51
52 d->m_model = model;
52 d->m_model = model;
53 d->initializeBarFromModel();
53 d->initializeBarFromModel();
54 // connect signals from the model
54 // connect signals from the model
55 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
55 connect(d->m_model, SIGNAL(dataChanged(QModelIndex,QModelIndex)), d, SLOT(modelUpdated(QModelIndex,QModelIndex)));
56 connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int)));
56 connect(d->m_model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)), d, SLOT(modelHeaderDataUpdated(Qt::Orientation,int,int)));
57 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
57 connect(d->m_model, SIGNAL(rowsInserted(QModelIndex,int,int)), d, SLOT(modelRowsAdded(QModelIndex,int,int)));
58 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
58 connect(d->m_model, SIGNAL(rowsRemoved(QModelIndex,int,int)), d, SLOT(modelRowsRemoved(QModelIndex,int,int)));
59 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
59 connect(d->m_model, SIGNAL(columnsInserted(QModelIndex,int,int)), d, SLOT(modelColumnsAdded(QModelIndex,int,int)));
60 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
60 connect(d->m_model, SIGNAL(columnsRemoved(QModelIndex,int,int)), d, SLOT(modelColumnsRemoved(QModelIndex,int,int)));
61 }
61 }
62
62
63 QBarSeries* QBarModelMapper::series() const
63 QAbstractBarSeries* QBarModelMapper::series() const
64 {
64 {
65 Q_D(const QBarModelMapper);
65 Q_D(const QBarModelMapper);
66 return d->m_series;
66 return d->m_series;
67 }
67 }
68
68
69 void QBarModelMapper::setSeries(QBarSeries *series)
69 void QBarModelMapper::setSeries(QAbstractBarSeries *series)
70 {
70 {
71 Q_D(QBarModelMapper);
71 Q_D(QBarModelMapper);
72 if (d->m_series) {
72 if (d->m_series) {
73 disconnect(d->m_series, 0, d, 0);
73 disconnect(d->m_series, 0, d, 0);
74 }
74 }
75
75
76 if (series == 0)
76 if (series == 0)
77 return;
77 return;
78
78
79 d->m_series = series;
79 d->m_series = series;
80 d->initializeBarFromModel();
80 d->initializeBarFromModel();
81 // connect the signals from the series
81 // connect the signals from the series
82 connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>)));
82 connect(d->m_series, SIGNAL(barsetsAdded(QList<QBarSet*>)), d, SLOT(barSetsAdded(QList<QBarSet*>)));
83 connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>)));
83 connect(d->m_series, SIGNAL(barsetsRemoved(QList<QBarSet*>)), d, SLOT(barSetsRemoved(QList<QBarSet*>)));
84 }
84 }
85
85
86 /*!
86 /*!
87 Returns which row/column of the model contains the first values of the QBarSets in the series.
87 Returns which row/column of the model contains the first values of the QBarSets in the series.
88 The default value is 0.
88 The default value is 0.
89 */
89 */
90 int QBarModelMapper::first() const
90 int QBarModelMapper::first() const
91 {
91 {
92 Q_D(const QBarModelMapper);
92 Q_D(const QBarModelMapper);
93 return d->m_first;
93 return d->m_first;
94 }
94 }
95
95
96 /*!
96 /*!
97 Sets which row of the model contains the \a first values of the QBarSets in the series.
97 Sets which row of the model contains the \a first values of the QBarSets in the series.
98 The default value is 0.
98 The default value is 0.
99 */
99 */
100 void QBarModelMapper::setFirst(int first)
100 void QBarModelMapper::setFirst(int first)
101 {
101 {
102 Q_D(QBarModelMapper);
102 Q_D(QBarModelMapper);
103 d->m_first = qMax(first, 0);
103 d->m_first = qMax(first, 0);
104 d->initializeBarFromModel();
104 d->initializeBarFromModel();
105 }
105 }
106
106
107 /*!
107 /*!
108 Returns the number of rows/columns of the model that are mapped as the data for QBarSeries
108 Returns the number of rows/columns of the model that are mapped as the data for QBarSeries
109 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
109 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
110 */
110 */
111 int QBarModelMapper::count() const
111 int QBarModelMapper::count() const
112 {
112 {
113 Q_D(const QBarModelMapper);
113 Q_D(const QBarModelMapper);
114 return d->m_count;
114 return d->m_count;
115 }
115 }
116
116
117 /*!
117 /*!
118 Sets the \a count of rows/columns of the model that are mapped as the data for QBarSeries
118 Sets the \a count of rows/columns of the model that are mapped as the data for QBarSeries
119 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
119 Minimal and default value is: -1 (count limited by the number of rows/columns in the model)
120 */
120 */
121 void QBarModelMapper::setCount(int count)
121 void QBarModelMapper::setCount(int count)
122 {
122 {
123 Q_D(QBarModelMapper);
123 Q_D(QBarModelMapper);
124 d->m_count = qMax(count, -1);
124 d->m_count = qMax(count, -1);
125 d->initializeBarFromModel();
125 d->initializeBarFromModel();
126 }
126 }
127
127
128 /*!
128 /*!
129 Returns the orientation that is used when QBarModelMapper accesses the model.
129 Returns the orientation that is used when QBarModelMapper accesses the model.
130 This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal)
130 This mean whether the consecutive values of the bar set are read from row (Qt::Horizontal)
131 or from columns (Qt::Vertical)
131 or from columns (Qt::Vertical)
132 */
132 */
133 Qt::Orientation QBarModelMapper::orientation() const
133 Qt::Orientation QBarModelMapper::orientation() const
134 {
134 {
135 Q_D(const QBarModelMapper);
135 Q_D(const QBarModelMapper);
136 return d->m_orientation;
136 return d->m_orientation;
137 }
137 }
138
138
139 /*!
139 /*!
140 Returns the \a orientation that is used when QBarModelMapper accesses the model.
140 Returns the \a orientation that is used when QBarModelMapper accesses the model.
141 This mean whether the consecutive values of the pie are read from row (Qt::Horizontal)
141 This mean whether the consecutive values of the pie are read from row (Qt::Horizontal)
142 or from columns (Qt::Vertical)
142 or from columns (Qt::Vertical)
143 */
143 */
144 void QBarModelMapper::setOrientation(Qt::Orientation orientation)
144 void QBarModelMapper::setOrientation(Qt::Orientation orientation)
145 {
145 {
146 Q_D(QBarModelMapper);
146 Q_D(QBarModelMapper);
147 d->m_orientation = orientation;
147 d->m_orientation = orientation;
148 d->initializeBarFromModel();
148 d->initializeBarFromModel();
149 }
149 }
150
150
151 /*!
151 /*!
152 Returns which section of the model is used as the data source for the first bar set
152 Returns which section of the model is used as the data source for the first bar set
153 */
153 */
154 int QBarModelMapper::firstBarSetSection() const
154 int QBarModelMapper::firstBarSetSection() const
155 {
155 {
156 Q_D(const QBarModelMapper);
156 Q_D(const QBarModelMapper);
157 return d->m_firstBarSetSection;
157 return d->m_firstBarSetSection;
158 }
158 }
159
159
160 /*!
160 /*!
161 Sets the model section that is used as the data source for the first bar set
161 Sets the model section that is used as the data source for the first bar set
162 Parameter \a firstBarSetSection specifies the section of the model.
162 Parameter \a firstBarSetSection specifies the section of the model.
163 */
163 */
164 void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection)
164 void QBarModelMapper::setFirstBarSetSection(int firstBarSetSection)
165 {
165 {
166 Q_D(QBarModelMapper);
166 Q_D(QBarModelMapper);
167 d->m_firstBarSetSection = qMax(-1, firstBarSetSection);
167 d->m_firstBarSetSection = qMax(-1, firstBarSetSection);
168 d->initializeBarFromModel();
168 d->initializeBarFromModel();
169 }
169 }
170
170
171 /*!
171 /*!
172 Returns which section of the model is used as the data source for the last bar set
172 Returns which section of the model is used as the data source for the last bar set
173 */
173 */
174 int QBarModelMapper::lastBarSetSection() const
174 int QBarModelMapper::lastBarSetSection() const
175 {
175 {
176 Q_D(const QBarModelMapper);
176 Q_D(const QBarModelMapper);
177 return d->m_lastBarSetSection;
177 return d->m_lastBarSetSection;
178 }
178 }
179
179
180 /*!
180 /*!
181 Sets the model section that is used as the data source for the last bar set
181 Sets the model section that is used as the data source for the last bar set
182 Parameter \a lastBarSetSection specifies the section of the model.
182 Parameter \a lastBarSetSection specifies the section of the model.
183 */
183 */
184 void QBarModelMapper::setLastBarSetSection(int lastBarSetSection)
184 void QBarModelMapper::setLastBarSetSection(int lastBarSetSection)
185 {
185 {
186 Q_D(QBarModelMapper);
186 Q_D(QBarModelMapper);
187 d->m_lastBarSetSection = qMax(-1, lastBarSetSection);
187 d->m_lastBarSetSection = qMax(-1, lastBarSetSection);
188 d->initializeBarFromModel();
188 d->initializeBarFromModel();
189 }
189 }
190
190
191 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
191 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
192
192
193 QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
193 QBarModelMapperPrivate::QBarModelMapperPrivate(QBarModelMapper *q) :
194 m_series(0),
194 m_series(0),
195 m_model(0),
195 m_model(0),
196 m_first(0),
196 m_first(0),
197 m_count(-1),
197 m_count(-1),
198 m_orientation(Qt::Vertical),
198 m_orientation(Qt::Vertical),
199 m_firstBarSetSection(-1),
199 m_firstBarSetSection(-1),
200 m_lastBarSetSection(-1),
200 m_lastBarSetSection(-1),
201 m_seriesSignalsBlock(false),
201 m_seriesSignalsBlock(false),
202 m_modelSignalsBlock(false),
202 m_modelSignalsBlock(false),
203 q_ptr(q)
203 q_ptr(q)
204 {
204 {
205 }
205 }
206
206
207 void QBarModelMapperPrivate::blockModelSignals(bool block)
207 void QBarModelMapperPrivate::blockModelSignals(bool block)
208 {
208 {
209 m_modelSignalsBlock = block;
209 m_modelSignalsBlock = block;
210 }
210 }
211
211
212 void QBarModelMapperPrivate::blockSeriesSignals(bool block)
212 void QBarModelMapperPrivate::blockSeriesSignals(bool block)
213 {
213 {
214 m_seriesSignalsBlock = block;
214 m_seriesSignalsBlock = block;
215 }
215 }
216
216
217 QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index)
217 QBarSet* QBarModelMapperPrivate::barSet(QModelIndex index)
218 {
218 {
219 if (!index.isValid())
219 if (!index.isValid())
220 return 0;
220 return 0;
221
221
222 if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) {
222 if (m_orientation == Qt::Vertical && index.column() >= m_firstBarSetSection && index.column() <= m_lastBarSetSection) {
223 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
223 if (index.row() >= m_first && (m_count == - 1 || index.row() < m_first + m_count)) {
224 // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
224 // if (m_model->index(index.row(), m_valuesSection).isValid() && m_model->index(index.row(), m_labelsSection).isValid())
225 return m_series->barSets().at(index.column() - m_firstBarSetSection);
225 return m_series->barSets().at(index.column() - m_firstBarSetSection);
226 // else
226 // else
227 // return 0;
227 // return 0;
228 }
228 }
229 } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) {
229 } else if (m_orientation == Qt::Horizontal && index.row() >= m_firstBarSetSection && index.row() <= m_lastBarSetSection) {
230 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
230 if (index.column() >= m_first && (m_count == - 1 || index.column() < m_first + m_count))
231 return m_series->barSets().at(index.row() - m_firstBarSetSection);
231 return m_series->barSets().at(index.row() - m_firstBarSetSection);
232 }
232 }
233 return 0; // This part of model has not been mapped to any slice
233 return 0; // This part of model has not been mapped to any slice
234 }
234 }
235
235
236 QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
236 QModelIndex QBarModelMapperPrivate::barModelIndex(int barSection, int posInBar)
237 {
237 {
238 if (m_count != -1 && posInBar >= m_count)
238 if (m_count != -1 && posInBar >= m_count)
239 return QModelIndex(); // invalid
239 return QModelIndex(); // invalid
240
240
241 if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection)
241 if (barSection < m_firstBarSetSection || barSection > m_lastBarSetSection)
242 return QModelIndex(); // invalid
242 return QModelIndex(); // invalid
243
243
244 if (m_orientation == Qt::Vertical)
244 if (m_orientation == Qt::Vertical)
245 return m_model->index(posInBar + m_first, barSection);
245 return m_model->index(posInBar + m_first, barSection);
246 else
246 else
247 return m_model->index(barSection, posInBar + m_first);
247 return m_model->index(barSection, posInBar + m_first);
248 }
248 }
249
249
250 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
250 void QBarModelMapperPrivate::modelUpdated(QModelIndex topLeft, QModelIndex bottomRight)
251 {
251 {
252 Q_UNUSED(topLeft)
252 Q_UNUSED(topLeft)
253 Q_UNUSED(bottomRight)
253 Q_UNUSED(bottomRight)
254
254
255 if (m_model == 0 || m_series == 0)
255 if (m_model == 0 || m_series == 0)
256 return;
256 return;
257
257
258 if (m_modelSignalsBlock)
258 if (m_modelSignalsBlock)
259 return;
259 return;
260
260
261 blockSeriesSignals();
261 blockSeriesSignals();
262 QModelIndex index;
262 QModelIndex index;
263 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
263 for (int row = topLeft.row(); row <= bottomRight.row(); row++) {
264 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
264 for (int column = topLeft.column(); column <= bottomRight.column(); column++) {
265 index = topLeft.sibling(row, column);
265 index = topLeft.sibling(row, column);
266 QBarSet* bar = barSet(index);
266 QBarSet* bar = barSet(index);
267 if (bar) {
267 if (bar) {
268 if (m_orientation == Qt::Vertical)
268 if (m_orientation == Qt::Vertical)
269 bar->replace(row - m_first, m_model->data(index).toReal());
269 bar->replace(row - m_first, m_model->data(index).toReal());
270 else
270 else
271 bar->replace(column - m_first, m_model->data(index).toReal());
271 bar->replace(column - m_first, m_model->data(index).toReal());
272 }
272 }
273 }
273 }
274 }
274 }
275 blockSeriesSignals(false);
275 blockSeriesSignals(false);
276 }
276 }
277
277
278 void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last)
278 void QBarModelMapperPrivate::modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last)
279 {
279 {
280 if (m_model == 0 || m_series == 0)
280 if (m_model == 0 || m_series == 0)
281 return;
281 return;
282
282
283 if (m_modelSignalsBlock)
283 if (m_modelSignalsBlock)
284 return;
284 return;
285
285
286 blockSeriesSignals();
286 blockSeriesSignals();
287 if (orientation != m_orientation) {
287 if (orientation != m_orientation) {
288 for (int section = first; section <= last; section++) {
288 for (int section = first; section <= last; section++) {
289 if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) {
289 if (section >= m_firstBarSetSection && section <= m_lastBarSetSection) {
290 QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection);
290 QBarSet* bar = m_series->barSets().at(section - m_firstBarSetSection);
291 if (bar)
291 if (bar)
292 bar->setLabel(m_model->headerData(section, orientation).toString());
292 bar->setLabel(m_model->headerData(section, orientation).toString());
293 }
293 }
294 }
294 }
295 }
295 }
296 blockSeriesSignals(false);
296 blockSeriesSignals(false);
297 }
297 }
298
298
299 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
299 void QBarModelMapperPrivate::modelRowsAdded(QModelIndex parent, int start, int end)
300 {
300 {
301 Q_UNUSED(parent);
301 Q_UNUSED(parent);
302 Q_UNUSED(end)
302 Q_UNUSED(end)
303 if (m_modelSignalsBlock)
303 if (m_modelSignalsBlock)
304 return;
304 return;
305
305
306 blockSeriesSignals();
306 blockSeriesSignals();
307 if (m_orientation == Qt::Vertical)
307 if (m_orientation == Qt::Vertical)
308 // insertData(start, end);
308 // insertData(start, end);
309 initializeBarFromModel();
309 initializeBarFromModel();
310 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
310 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
311 initializeBarFromModel();
311 initializeBarFromModel();
312 blockSeriesSignals(false);
312 blockSeriesSignals(false);
313 }
313 }
314
314
315 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
315 void QBarModelMapperPrivate::modelRowsRemoved(QModelIndex parent, int start, int end)
316 {
316 {
317 Q_UNUSED(parent);
317 Q_UNUSED(parent);
318 Q_UNUSED(end)
318 Q_UNUSED(end)
319 if (m_modelSignalsBlock)
319 if (m_modelSignalsBlock)
320 return;
320 return;
321
321
322 blockSeriesSignals();
322 blockSeriesSignals();
323 if (m_orientation == Qt::Vertical)
323 if (m_orientation == Qt::Vertical)
324 // removeData(start, end);
324 // removeData(start, end);
325 initializeBarFromModel();
325 initializeBarFromModel();
326 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
326 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
327 initializeBarFromModel();
327 initializeBarFromModel();
328 blockSeriesSignals(false);
328 blockSeriesSignals(false);
329 }
329 }
330
330
331 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
331 void QBarModelMapperPrivate::modelColumnsAdded(QModelIndex parent, int start, int end)
332 {
332 {
333 Q_UNUSED(parent);
333 Q_UNUSED(parent);
334 Q_UNUSED(end)
334 Q_UNUSED(end)
335 if (m_modelSignalsBlock)
335 if (m_modelSignalsBlock)
336 return;
336 return;
337
337
338 blockSeriesSignals();
338 blockSeriesSignals();
339 if (m_orientation == Qt::Horizontal)
339 if (m_orientation == Qt::Horizontal)
340 // insertData(start, end);
340 // insertData(start, end);
341 initializeBarFromModel();
341 initializeBarFromModel();
342 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
342 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
343 initializeBarFromModel();
343 initializeBarFromModel();
344 blockSeriesSignals(false);
344 blockSeriesSignals(false);
345 }
345 }
346
346
347 void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
347 void QBarModelMapperPrivate::modelColumnsRemoved(QModelIndex parent, int start, int end)
348 {
348 {
349 Q_UNUSED(parent);
349 Q_UNUSED(parent);
350 Q_UNUSED(end)
350 Q_UNUSED(end)
351 if (m_modelSignalsBlock)
351 if (m_modelSignalsBlock)
352 return;
352 return;
353
353
354 blockSeriesSignals();
354 blockSeriesSignals();
355 if (m_orientation == Qt::Horizontal)
355 if (m_orientation == Qt::Horizontal)
356 // removeData(start, end);
356 // removeData(start, end);
357 initializeBarFromModel();
357 initializeBarFromModel();
358 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
358 else if (start <= m_firstBarSetSection || start <= m_lastBarSetSection) // if the changes affect the map - reinitialize
359 initializeBarFromModel();
359 initializeBarFromModel();
360 blockSeriesSignals(false);
360 blockSeriesSignals(false);
361 }
361 }
362
362
363 void QBarModelMapperPrivate::insertData(int start, int end)
363 void QBarModelMapperPrivate::insertData(int start, int end)
364 {
364 {
365 Q_UNUSED(end)
365 Q_UNUSED(end)
366 Q_UNUSED(start)
366 Q_UNUSED(start)
367 Q_UNUSED(end)
367 Q_UNUSED(end)
368 // To be implemented
368 // To be implemented
369 }
369 }
370
370
371 void QBarModelMapperPrivate::removeData(int start, int end)
371 void QBarModelMapperPrivate::removeData(int start, int end)
372 {
372 {
373 Q_UNUSED(end)
373 Q_UNUSED(end)
374 Q_UNUSED(start)
374 Q_UNUSED(start)
375 Q_UNUSED(end)
375 Q_UNUSED(end)
376 // To be implemented
376 // To be implemented
377 }
377 }
378
378
379 void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets)
379 void QBarModelMapperPrivate::barSetsAdded(QList<QBarSet*> sets)
380 {
380 {
381 if (m_seriesSignalsBlock)
381 if (m_seriesSignalsBlock)
382 return;
382 return;
383
383
384 if (sets.count() == 0)
384 if (sets.count() == 0)
385 return;
385 return;
386
386
387 int firstIndex = m_series->barSets().indexOf(sets.at(0));
387 int firstIndex = m_series->barSets().indexOf(sets.at(0));
388 if (firstIndex == -1)
388 if (firstIndex == -1)
389 return;
389 return;
390
390
391 int maxCount = 0;
391 int maxCount = 0;
392 for(int i = 0; i < sets.count(); i++)
392 for(int i = 0; i < sets.count(); i++)
393 if (sets.at(i)->count() > m_count)
393 if (sets.at(i)->count() > m_count)
394 maxCount = sets.at(i)->count();
394 maxCount = sets.at(i)->count();
395
395
396 if (m_count != -1 && m_count < maxCount)
396 if (m_count != -1 && m_count < maxCount)
397 m_count = maxCount;
397 m_count = maxCount;
398
398
399 m_lastBarSetSection += sets.count();
399 m_lastBarSetSection += sets.count();
400
400
401 blockModelSignals();
401 blockModelSignals();
402 int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first;
402 int modelCapacity = m_orientation == Qt::Vertical ? m_model->rowCount() - m_first : m_model->columnCount() - m_first;
403 if (maxCount > modelCapacity) {
403 if (maxCount > modelCapacity) {
404 if (m_orientation == Qt::Vertical)
404 if (m_orientation == Qt::Vertical)
405 m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity);
405 m_model->insertRows(m_model->rowCount(), maxCount - modelCapacity);
406 else
406 else
407 m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity);
407 m_model->insertColumns(m_model->columnCount(), maxCount - modelCapacity);
408 }
408 }
409
409
410 if (m_orientation == Qt::Vertical)
410 if (m_orientation == Qt::Vertical)
411 m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count());
411 m_model->insertColumns(firstIndex + m_firstBarSetSection, sets.count());
412 else
412 else
413 m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count());
413 m_model->insertRows(firstIndex + m_firstBarSetSection, sets.count());
414
414
415
415
416 for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) {
416 for(int i = firstIndex + m_firstBarSetSection; i < firstIndex + m_firstBarSetSection + sets.count(); i++) {
417 m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label());
417 m_model->setHeaderData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, sets.at(i - firstIndex - m_firstBarSetSection)->label());
418 for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++)
418 for (int j = 0; j < sets.at(i - firstIndex - m_firstBarSetSection)->count(); j++)
419 m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j));
419 m_model->setData(barModelIndex(i, j), sets.at(i - firstIndex - m_firstBarSetSection)->at(j));
420 }
420 }
421 blockModelSignals(false);
421 blockModelSignals(false);
422 initializeBarFromModel();
422 initializeBarFromModel();
423 }
423 }
424
424
425 void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets)
425 void QBarModelMapperPrivate::barSetsRemoved(QList<QBarSet*> sets)
426 {
426 {
427 if (m_seriesSignalsBlock)
427 if (m_seriesSignalsBlock)
428 return;
428 return;
429
429
430 if (sets.count() == 0)
430 if (sets.count() == 0)
431 return;
431 return;
432
432
433 int firstIndex = m_barSets.indexOf(sets.at(0));
433 int firstIndex = m_barSets.indexOf(sets.at(0));
434 if (firstIndex == -1)
434 if (firstIndex == -1)
435 return;
435 return;
436
436
437 m_lastBarSetSection -= sets.count();
437 m_lastBarSetSection -= sets.count();
438
438
439 for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--)
439 for (int i = firstIndex + sets.count() - 1; i >= firstIndex; i--)
440 m_barSets.removeAt(i);
440 m_barSets.removeAt(i);
441
441
442 blockModelSignals();
442 blockModelSignals();
443 if (m_orientation == Qt::Vertical)
443 if (m_orientation == Qt::Vertical)
444 m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count());
444 m_model->removeColumns(firstIndex + m_firstBarSetSection, sets.count());
445 else
445 else
446 m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count());
446 m_model->removeRows(firstIndex + m_firstBarSetSection, sets.count());
447 blockModelSignals(false);
447 blockModelSignals(false);
448 initializeBarFromModel();
448 initializeBarFromModel();
449 }
449 }
450
450
451 void QBarModelMapperPrivate::valuesAdded(int index, int count)
451 void QBarModelMapperPrivate::valuesAdded(int index, int count)
452 {
452 {
453 if (m_seriesSignalsBlock)
453 if (m_seriesSignalsBlock)
454 return;
454 return;
455
455
456 if (m_count != -1)
456 if (m_count != -1)
457 m_count += count;
457 m_count += count;
458
458
459 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
459 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
460
460
461 blockModelSignals();
461 blockModelSignals();
462 if (m_orientation == Qt::Vertical)
462 if (m_orientation == Qt::Vertical)
463 m_model->insertRows(index + m_first, count);
463 m_model->insertRows(index + m_first, count);
464 else
464 else
465 m_model->insertColumns(index + m_first, count);
465 m_model->insertColumns(index + m_first, count);
466
466
467 for (int j = index; j < index + count; j++)
467 for (int j = index; j < index + count; j++)
468 m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j));
468 m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, j), m_barSets.at(barSetIndex)->at(j));
469
469
470 blockModelSignals(false);
470 blockModelSignals(false);
471 initializeBarFromModel();
471 initializeBarFromModel();
472 }
472 }
473
473
474 void QBarModelMapperPrivate::valuesRemoved(int index, int count)
474 void QBarModelMapperPrivate::valuesRemoved(int index, int count)
475 {
475 {
476 if (m_seriesSignalsBlock)
476 if (m_seriesSignalsBlock)
477 return;
477 return;
478
478
479 if (m_count != -1)
479 if (m_count != -1)
480 m_count -= count;
480 m_count -= count;
481
481
482 blockModelSignals();
482 blockModelSignals();
483 if (m_orientation == Qt::Vertical)
483 if (m_orientation == Qt::Vertical)
484 m_model->removeRows(index + m_first, count);
484 m_model->removeRows(index + m_first, count);
485 else
485 else
486 m_model->removeColumns(index + m_first, count);
486 m_model->removeColumns(index + m_first, count);
487
487
488 blockModelSignals(false);
488 blockModelSignals(false);
489 initializeBarFromModel();
489 initializeBarFromModel();
490 }
490 }
491
491
492 void QBarModelMapperPrivate::barLabelChanged()
492 void QBarModelMapperPrivate::barLabelChanged()
493 {
493 {
494 if (m_seriesSignalsBlock)
494 if (m_seriesSignalsBlock)
495 return;
495 return;
496
496
497 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
497 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
498
498
499 blockModelSignals();
499 blockModelSignals();
500 m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label());
500 m_model->setHeaderData(barSetIndex + m_firstBarSetSection, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical, m_barSets.at(barSetIndex)->label());
501 blockModelSignals(false);
501 blockModelSignals(false);
502 initializeBarFromModel();
502 initializeBarFromModel();
503 }
503 }
504
504
505 void QBarModelMapperPrivate::barValueChanged(int index)
505 void QBarModelMapperPrivate::barValueChanged(int index)
506 {
506 {
507 if (m_seriesSignalsBlock)
507 if (m_seriesSignalsBlock)
508 return;
508 return;
509
509
510 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
510 int barSetIndex = m_barSets.indexOf(qobject_cast<QBarSet *>(QObject::sender()));
511
511
512 blockModelSignals();
512 blockModelSignals();
513 m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index));
513 m_model->setData(barModelIndex(barSetIndex + m_firstBarSetSection, index), m_barSets.at(barSetIndex)->at(index));
514 blockModelSignals(false);
514 blockModelSignals(false);
515 initializeBarFromModel();
515 initializeBarFromModel();
516 }
516 }
517
517
518 void QBarModelMapperPrivate::initializeBarFromModel()
518 void QBarModelMapperPrivate::initializeBarFromModel()
519 {
519 {
520 if (m_model == 0 || m_series == 0)
520 if (m_model == 0 || m_series == 0)
521 return;
521 return;
522
522
523 blockSeriesSignals();
523 blockSeriesSignals();
524 // clear current content
524 // clear current content
525 m_series->clear();
525 m_series->clear();
526 m_barSets.clear();
526 m_barSets.clear();
527
527
528 // create the initial bar sets
528 // create the initial bar sets
529 for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
529 for (int i = m_firstBarSetSection; i <= m_lastBarSetSection; i++) {
530 int posInBar = 0;
530 int posInBar = 0;
531 QModelIndex barIndex = barModelIndex(i, posInBar);
531 QModelIndex barIndex = barModelIndex(i, posInBar);
532 // check if there is such model index
532 // check if there is such model index
533 if (barIndex.isValid()) {
533 if (barIndex.isValid()) {
534 QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString());
534 QBarSet *barSet = new QBarSet(m_model->headerData(i, m_orientation == Qt::Vertical ? Qt::Horizontal : Qt::Vertical).toString());
535 while (barIndex.isValid()) {
535 while (barIndex.isValid()) {
536 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
536 barSet->append(m_model->data(barIndex, Qt::DisplayRole).toDouble());
537 posInBar++;
537 posInBar++;
538 barIndex = barModelIndex(i, posInBar);
538 barIndex = barModelIndex(i, posInBar);
539 }
539 }
540 connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int)));
540 connect(barSet, SIGNAL(valuesAdded(int, int)), this, SLOT(valuesAdded(int, int)));
541 connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int)));
541 connect(barSet, SIGNAL(valuesRemoved(int, int)), this, SLOT(valuesRemoved(int, int)));
542 connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int)));
542 connect(barSet, SIGNAL(valueChanged(int)), this, SLOT(barValueChanged(int)));
543 connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged()));
543 connect(barSet, SIGNAL(labelChanged()), this, SLOT(barLabelChanged()));
544 m_series->append(barSet);
544 m_series->append(barSet);
545 m_barSets.append(barSet);
545 m_barSets.append(barSet);
546 } else {
546 } else {
547 break;
547 break;
548 }
548 }
549 }
549 }
550 blockSeriesSignals(false);
550 blockSeriesSignals(false);
551 }
551 }
552
552
553 #include "moc_qbarmodelmapper.cpp"
553 #include "moc_qbarmodelmapper.cpp"
554 #include "moc_qbarmodelmapper_p.cpp"
554 #include "moc_qbarmodelmapper_p.cpp"
555
555
556 QTCOMMERCIALCHART_END_NAMESPACE
556 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,70 +1,70
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QBARMODELMAPPER_H
21 #ifndef QBARMODELMAPPER_H
22 #define QBARMODELMAPPER_H
22 #define QBARMODELMAPPER_H
23
23
24 #include "qchartglobal.h"
24 #include "qchartglobal.h"
25 #include <QObject>
25 #include <QObject>
26
26
27 class QAbstractItemModel;
27 class QAbstractItemModel;
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30
30
31 class QBarModelMapperPrivate;
31 class QBarModelMapperPrivate;
32 class QBarSeries;
32 class QAbstractBarSeries;
33 class QChart;
33 class QChart;
34
34
35 class QTCOMMERCIALCHART_EXPORT QBarModelMapper : public QObject
35 class QTCOMMERCIALCHART_EXPORT QBarModelMapper : public QObject
36 {
36 {
37 Q_OBJECT
37 Q_OBJECT
38
38
39 protected:
39 protected:
40 explicit QBarModelMapper(QObject *parent = 0);
40 explicit QBarModelMapper(QObject *parent = 0);
41
41
42 QAbstractItemModel* model() const;
42 QAbstractItemModel* model() const;
43 void setModel(QAbstractItemModel *model);
43 void setModel(QAbstractItemModel *model);
44
44
45 QBarSeries* series() const;
45 QAbstractBarSeries* series() const;
46 void setSeries(QBarSeries *series);
46 void setSeries(QAbstractBarSeries *series);
47
47
48 int first() const;
48 int first() const;
49 void setFirst(int first);
49 void setFirst(int first);
50
50
51 int count() const;
51 int count() const;
52 void setCount(int count);
52 void setCount(int count);
53
53
54 int firstBarSetSection() const;
54 int firstBarSetSection() const;
55 void setFirstBarSetSection(int firstBarSetSection);
55 void setFirstBarSetSection(int firstBarSetSection);
56
56
57 int lastBarSetSection() const;
57 int lastBarSetSection() const;
58 void setLastBarSetSection(int lastBarSetSection);
58 void setLastBarSetSection(int lastBarSetSection);
59
59
60 Qt::Orientation orientation() const;
60 Qt::Orientation orientation() const;
61 void setOrientation(Qt::Orientation orientation);
61 void setOrientation(Qt::Orientation orientation);
62
62
63 protected:
63 protected:
64 QBarModelMapperPrivate * const d_ptr;
64 QBarModelMapperPrivate * const d_ptr;
65 Q_DECLARE_PRIVATE(QBarModelMapper)
65 Q_DECLARE_PRIVATE(QBarModelMapper)
66 };
66 };
67
67
68 QTCOMMERCIALCHART_END_NAMESPACE
68 QTCOMMERCIALCHART_END_NAMESPACE
69
69
70 #endif // QBARMODELMAPPER_H
70 #endif // QBARMODELMAPPER_H
@@ -1,95 +1,95
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QBARMODELMAPPER_P_H
30 #ifndef QBARMODELMAPPER_P_H
31 #define QBARMODELMAPPER_P_H
31 #define QBARMODELMAPPER_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QObject>
34 #include <QObject>
35 #include "qbarmodelmapper.h"
35 #include "qbarmodelmapper.h"
36
36
37 class QModelIndex;
37 class QModelIndex;
38
38
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40
40
41 class QBarSet;
41 class QBarSet;
42
42
43 class QBarModelMapperPrivate : public QObject
43 class QBarModelMapperPrivate : public QObject
44 {
44 {
45 Q_OBJECT
45 Q_OBJECT
46 public:
46 public:
47 explicit QBarModelMapperPrivate(QBarModelMapper *q);
47 explicit QBarModelMapperPrivate(QBarModelMapper *q);
48
48
49 public Q_SLOTS:
49 public Q_SLOTS:
50 // for the model
50 // for the model
51 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
51 void modelUpdated(QModelIndex topLeft, QModelIndex bottomRight);
52 void modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last);
52 void modelHeaderDataUpdated(Qt::Orientation orientation, int first, int last);
53 void modelRowsAdded(QModelIndex parent, int start, int end);
53 void modelRowsAdded(QModelIndex parent, int start, int end);
54 void modelRowsRemoved(QModelIndex parent, int start, int end);
54 void modelRowsRemoved(QModelIndex parent, int start, int end);
55 void modelColumnsAdded(QModelIndex parent, int start, int end);
55 void modelColumnsAdded(QModelIndex parent, int start, int end);
56 void modelColumnsRemoved(QModelIndex parent, int start, int end);
56 void modelColumnsRemoved(QModelIndex parent, int start, int end);
57
57
58 // for the series
58 // for the series
59 void barSetsAdded(QList<QBarSet*> sets);
59 void barSetsAdded(QList<QBarSet*> sets);
60 void barSetsRemoved(QList<QBarSet*> sets);
60 void barSetsRemoved(QList<QBarSet*> sets);
61 void valuesAdded(int index, int count);
61 void valuesAdded(int index, int count);
62 void valuesRemoved(int index, int count);
62 void valuesRemoved(int index, int count);
63 void barLabelChanged();
63 void barLabelChanged();
64 void barValueChanged(int index);
64 void barValueChanged(int index);
65
65
66 void initializeBarFromModel();
66 void initializeBarFromModel();
67
67
68 private:
68 private:
69 QBarSet* barSet(QModelIndex index);
69 QBarSet* barSet(QModelIndex index);
70 QModelIndex barModelIndex(int barSection, int posInBar);
70 QModelIndex barModelIndex(int barSection, int posInBar);
71 void insertData(int start, int end);
71 void insertData(int start, int end);
72 void removeData(int start, int end);
72 void removeData(int start, int end);
73 void blockModelSignals(bool block = true);
73 void blockModelSignals(bool block = true);
74 void blockSeriesSignals(bool block = true);
74 void blockSeriesSignals(bool block = true);
75
75
76 private:
76 private:
77 QBarSeries *m_series;
77 QAbstractBarSeries *m_series;
78 QList<QBarSet*> m_barSets;
78 QList<QBarSet*> m_barSets;
79 QAbstractItemModel *m_model;
79 QAbstractItemModel *m_model;
80 int m_first;
80 int m_first;
81 int m_count;
81 int m_count;
82 Qt::Orientation m_orientation;
82 Qt::Orientation m_orientation;
83 int m_firstBarSetSection;
83 int m_firstBarSetSection;
84 int m_lastBarSetSection;
84 int m_lastBarSetSection;
85 bool m_seriesSignalsBlock;
85 bool m_seriesSignalsBlock;
86 bool m_modelSignalsBlock;
86 bool m_modelSignalsBlock;
87
87
88 private:
88 private:
89 QBarModelMapper *q_ptr;
89 QBarModelMapper *q_ptr;
90 Q_DECLARE_PUBLIC(QBarModelMapper)
90 Q_DECLARE_PUBLIC(QBarModelMapper)
91 };
91 };
92
92
93 QTCOMMERCIALCHART_END_NAMESPACE
93 QTCOMMERCIALCHART_END_NAMESPACE
94
94
95 #endif // QBARMODELMAPPER_P_H
95 #endif // QBARMODELMAPPER_P_H
@@ -1,732 +1,732
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 #include "qvaluesaxis.h"
30 #include "qvaluesaxis.h"
31 #include "qcategoriesaxis.h"
31 #include "qcategoriesaxis.h"
32
32
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34
34
35 /*!
35 /*!
36 \class QBarSeries
36 \class QBarSeries
37 \brief Series for creating a bar chart
37 \brief Series for creating a bar chart
38 \mainclass
38 \mainclass
39
39
40 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
40 QBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars to
41 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
41 the position defined by data. Single bar is defined by QPointF, where x value is the x-coordinate of the bar
42 and y-value is the height of the bar. The category names are ignored with this series and x-axis
42 and y-value is the height of the bar. The category names are ignored with this series and x-axis
43 shows the x-values.
43 shows the x-values.
44
44
45 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
45 See the \l {BarChart Example} {bar chart example} to learn how to create a simple bar chart.
46 \image examples_barchart.png
46 \image examples_barchart.png
47
47
48 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
48 \sa QBarSet, QStackedBarSeries, QPercentBarSeries
49 */
49 */
50 /*!
50 /*!
51 \qmlclass BarSeries QBarSeries
51 \qmlclass BarSeries QBarSeries
52 \inherits AbstractSeries
52 \inherits AbstractSeries
53
53
54 The following QML shows how to create a simple bar chart:
54 The following QML shows how to create a simple bar chart:
55 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
55 \snippet ../demos/qmlchart/qml/qmlchart/View6.qml 1
56
56
57 \beginfloatleft
57 \beginfloatleft
58 \image demos_qmlchart6.png
58 \image demos_qmlchart6.png
59 \endfloat
59 \endfloat
60 \clearfloat
60 \clearfloat
61 */
61 */
62
62
63 /*!
63 /*!
64 \property QBarSeries::barWidth
64 \property QBarSeries::barWidth
65 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
65 The width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
66 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
66 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
67 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
67 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
68 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
68 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
69 \sa QGroupedBarSeries
69 \sa QGroupedBarSeries
70 */
70 */
71 /*!
71 /*!
72 \qmlproperty real BarSeries::barWidth
72 \qmlproperty real BarSeries::barWidth
73 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
73 The width of the bars of the series. The unit of width is the unit of x-axis. The minimum width for bars
74 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
74 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
75 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
75 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
76 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
76 Note that with QGroupedBarSeries this value means the width of one group of bars instead of just one bar.
77 */
77 */
78
78
79 /*!
79 /*!
80 \property QBarSeries::count
80 \property QBarSeries::count
81 Holds the number of sets in series.
81 Holds the number of sets in series.
82 */
82 */
83 /*!
83 /*!
84 \qmlproperty int BarSeries::count
84 \qmlproperty int BarSeries::count
85 Holds the number of sets in series.
85 Holds the number of sets in series.
86 */
86 */
87
87
88 /*!
88 /*!
89 \property QBarSeries::labelsVisible
89 \property QBarSeries::labelsVisible
90 Defines the visibility of the labels in series
90 Defines the visibility of the labels in series
91 */
91 */
92 /*!
92 /*!
93 \qmlproperty bool BarSeries::labelsVisible
93 \qmlproperty bool BarSeries::labelsVisible
94 Defines the visibility of the labels in series
94 Defines the visibility of the labels in series
95 */
95 */
96
96
97 /*!
97 /*!
98 \fn void QBarSeries::clicked(int index, QBarSet *barset)
98 \fn void QBarSeries::clicked(int index, QBarSet *barset)
99 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
99 The signal is emitted if the user clicks with a mouse on top of QBarSet \a barset.
100 Clicked bar inside set is indexed by \a index
100 Clicked bar inside set is indexed by \a index
101 */
101 */
102 /*!
102 /*!
103 \qmlsignal BarSeries::onClicked(int index, BarSet barset)
103 \qmlsignal BarSeries::onClicked(int index, BarSet barset)
104 The signal is emitted if the user clicks with a mouse on top of BarSet.
104 The signal is emitted if the user clicks with a mouse on top of BarSet.
105 Clicked bar inside set is indexed by \a index
105 Clicked bar inside set is indexed by \a index
106 */
106 */
107
107
108 /*!
108 /*!
109 \fn void QBarSeries::hovered(bool status, QBarSet* barset)
109 \fn void QBarSeries::hovered(bool status, QBarSet* barset)
110
110
111 The signal is emitted if mouse is hovered on top of series.
111 The signal is emitted if mouse is hovered on top of series.
112 Parameter \a barset is the pointer of barset, where hover happened.
112 Parameter \a barset is the pointer of barset, where hover happened.
113 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
113 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
114 */
114 */
115 /*!
115 /*!
116 \qmlsignal BarSeries::onHovered(bool status, BarSet barset)
116 \qmlsignal BarSeries::onHovered(bool status, BarSet barset)
117
117
118 The signal is emitted if mouse is hovered on top of series.
118 The signal is emitted if mouse is hovered on top of series.
119 Parameter \a barset is the pointer of barset, where hover happened.
119 Parameter \a barset is the pointer of barset, where hover happened.
120 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
120 Parameter \a status is true, if mouse entered on top of series, false if mouse left from top of series.
121 */
121 */
122
122
123 /*!
123 /*!
124 \fn void QBarSeries::countChanged()
124 \fn void QBarSeries::countChanged()
125 This signal is emitted when barset count has been changed, for example by append or remove.
125 This signal is emitted when barset count has been changed, for example by append or remove.
126 */
126 */
127 /*!
127 /*!
128 \qmlsignal BarSeries::onCountChanged()
128 \qmlsignal BarSeries::onCountChanged()
129 This signal is emitted when barset count has been changed, for example by append or remove.
129 This signal is emitted when barset count has been changed, for example by append or remove.
130 */
130 */
131
131
132 /*!
132 /*!
133 \fn void QBarSeries::labelsVisibleChanged()
133 \fn void QBarSeries::labelsVisibleChanged()
134 This signal is emitted when labels visibility have changed.
134 This signal is emitted when labels visibility have changed.
135 \sa isLabelsVisible(), setLabelsVisible()
135 \sa isLabelsVisible(), setLabelsVisible()
136 */
136 */
137
137
138 /*!
138 /*!
139 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
139 \fn void QBarSeries::barsetsAdded(QList<QBarSet*> sets)
140 This signal is emitted when \a sets have been added to the series.
140 This signal is emitted when \a sets have been added to the series.
141 \sa append(), insert()
141 \sa append(), insert()
142 */
142 */
143 /*!
143 /*!
144 \qmlsignal BarSeries::onAdded(BarSet barset)
144 \qmlsignal BarSeries::onAdded(BarSet barset)
145 Emitted when \a barset has been added to the series.
145 Emitted when \a barset has been added to the series.
146 */
146 */
147
147
148 /*!
148 /*!
149 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
149 \fn void QBarSeries::barsetsRemoved(QList<QBarSet*> sets)
150 This signal is emitted when \a sets have been removed from the series.
150 This signal is emitted when \a sets have been removed from the series.
151 \sa remove()
151 \sa remove()
152 */
152 */
153 /*!
153 /*!
154 \qmlsignal BarSeries::onRemoved(BarSet barset)
154 \qmlsignal BarSeries::onRemoved(BarSet barset)
155 Emitted when \a barset has been removed from the series.
155 Emitted when \a barset has been removed from the series.
156 */
156 */
157
157
158 /*!
158 /*!
159 \qmlmethod BarSet BarSeries::at(int index)
159 \qmlmethod BarSet BarSeries::at(int index)
160 Returns bar set at \a index. Returns null if the index is not valid.
160 Returns bar set at \a index. Returns null if the index is not valid.
161 */
161 */
162
162
163 /*!
163 /*!
164 \qmlmethod BarSet BarSeries::append(string label, VariantList values)
164 \qmlmethod BarSet BarSeries::append(string label, VariantList values)
165 Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
165 Adds a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
166 For example:
166 For example:
167 \code
167 \code
168 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
168 myBarSeries.append("set 1", [0, 0.2, 0.2, 0.5, 0.4, 1.5, 0.9]);
169 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
169 myBarSeries.append("set 2", [Qt.point(0, 1), Qt.point(2, 2.5), Qt.point(3.5, 2.2)]);
170 \endcode
170 \endcode
171 */
171 */
172
172
173 /*!
173 /*!
174 \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values)
174 \qmlmethod BarSet BarSeries::insert(int index, string label, VariantList values)
175 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
175 Inserts a new bar set with \a label and \a values to \a index. Values can be a list of reals or a list of XYPoints.
176 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
176 If index is zero or smaller, the new barset is prepended. If the index is count or bigger, the new barset is
177 appended.
177 appended.
178 \sa BarSeries::append()
178 \sa BarSeries::append()
179 */
179 */
180
180
181 /*!
181 /*!
182 \qmlmethod bool BarSeries::remove(BarSet barset)
182 \qmlmethod bool BarSeries::remove(BarSet barset)
183 Removes the barset from the series. Returns true if successfull, false otherwise.
183 Removes the barset from the series. Returns true if successfull, false otherwise.
184 */
184 */
185
185
186 /*!
186 /*!
187 \qmlmethod BarSeries::clear()
187 \qmlmethod BarSeries::clear()
188 Removes all barsets from the series.
188 Removes all barsets from the series.
189 */
189 */
190
190
191 /*!
191 /*!
192 Constructs empty QBarSeries.
192 Constructs empty QBarSeries.
193 QBarSeries is QObject which is a child of a \a parent.
193 QBarSeries is QObject which is a child of a \a parent.
194 */
194 */
195 QBarSeries::QBarSeries(QObject *parent) :
195 QAbstractBarSeries::QAbstractBarSeries(QObject *parent) :
196 QAbstractSeries(*new QBarSeriesPrivate(this),parent)
196 QAbstractSeries(*new QAbstractBarSeriesPrivate(this),parent)
197 {
197 {
198 }
198 }
199
199
200 /*!
200 /*!
201 Destructs barseries and owned barsets.
201 Destructs barseries and owned barsets.
202 */
202 */
203 QBarSeries::~QBarSeries()
203 QAbstractBarSeries::~QAbstractBarSeries()
204 {
204 {
205 Q_D(QBarSeries);
205 Q_D(QAbstractBarSeries);
206 if(d->m_dataset){
206 if(d->m_dataset){
207 d->m_dataset->removeSeries(this);
207 d->m_dataset->removeSeries(this);
208 }
208 }
209 }
209 }
210
210
211 /*!
211 /*!
212 \internal
212 \internal
213 */
213 */
214 QBarSeries::QBarSeries(QBarSeriesPrivate &d, QObject *parent) :
214 QAbstractBarSeries::QAbstractBarSeries(QAbstractBarSeriesPrivate &d, QObject *parent) :
215 QAbstractSeries(d,parent)
215 QAbstractSeries(d,parent)
216 {
216 {
217 }
217 }
218
218
219 /*!
219 /*!
220 Returns the type of series. Derived classes override this.
220 Returns the type of series. Derived classes override this.
221 */
221 */
222 QAbstractSeries::SeriesType QBarSeries::type() const
222 QAbstractSeries::SeriesType QAbstractBarSeries::type() const
223 {
223 {
224 return QAbstractSeries::SeriesTypeBar;
224 return QAbstractSeries::SeriesTypeBar;
225 }
225 }
226
226
227 /*!
227 /*!
228 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
228 Sets the width of the bars of the series. The unit of \a width is the unit of x-axis. The minimum width for bars
229 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
229 is zero and negative values are treated as zero. Setting the width to zero means that width of the bar on screen
230 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
230 is one pixel no matter what the scale of x-axis is. Bars wider than zero are scaled with x-axis.
231 Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar.
231 Note that with \link QGroupedBarSeries \endlink this value means the width of one group of bars instead of just one bar.
232 */
232 */
233 void QBarSeries::setBarWidth(qreal width)
233 void QAbstractBarSeries::setBarWidth(qreal width)
234 {
234 {
235 Q_D(QBarSeries);
235 Q_D(QAbstractBarSeries);
236 d->setBarWidth(width);
236 d->setBarWidth(width);
237 }
237 }
238
238
239 /*!
239 /*!
240 Returns the width of the bars of the series.
240 Returns the width of the bars of the series.
241 \sa setBarWidth()
241 \sa setBarWidth()
242 */
242 */
243 qreal QBarSeries::barWidth() const
243 qreal QAbstractBarSeries::barWidth() const
244 {
244 {
245 Q_D(const QBarSeries);
245 Q_D(const QAbstractBarSeries);
246 return d->barWidth();
246 return d->barWidth();
247 }
247 }
248
248
249 /*!
249 /*!
250 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.
250 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.
251 Returns true, if appending succeeded.
251 Returns true, if appending succeeded.
252 */
252 */
253 bool QBarSeries::append(QBarSet *set)
253 bool QAbstractBarSeries::append(QBarSet *set)
254 {
254 {
255 Q_D(QBarSeries);
255 Q_D(QAbstractBarSeries);
256 bool success = d->append(set);
256 bool success = d->append(set);
257 if (success) {
257 if (success) {
258 QList<QBarSet*> sets;
258 QList<QBarSet*> sets;
259 sets.append(set);
259 sets.append(set);
260 emit barsetsAdded(sets);
260 emit barsetsAdded(sets);
261 emit countChanged();
261 emit countChanged();
262 }
262 }
263 return success;
263 return success;
264 }
264 }
265
265
266 /*!
266 /*!
267 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
267 Removes a set of bars from series. Releases ownership of \a set. Doesn't delete \a set.
268 Returns true, if set was removed.
268 Returns true, if set was removed.
269 */
269 */
270 bool QBarSeries::remove(QBarSet *set)
270 bool QAbstractBarSeries::remove(QBarSet *set)
271 {
271 {
272 Q_D(QBarSeries);
272 Q_D(QAbstractBarSeries);
273 bool success = d->remove(set);
273 bool success = d->remove(set);
274 if (success) {
274 if (success) {
275 QList<QBarSet*> sets;
275 QList<QBarSet*> sets;
276 sets.append(set);
276 sets.append(set);
277 emit barsetsRemoved(sets);
277 emit barsetsRemoved(sets);
278 emit countChanged();
278 emit countChanged();
279 }
279 }
280 return success;
280 return success;
281 }
281 }
282
282
283 /*!
283 /*!
284 Adds a list of barsets to series. Takes ownership of \a sets.
284 Adds a list of barsets to series. Takes ownership of \a sets.
285 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
285 Returns true, if all sets were appended succesfully. If any of the sets is null or is already appended to series,
286 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
286 nothing is appended and function returns false. If any of the sets is in list more than once, nothing is appended
287 and function returns false.
287 and function returns false.
288 */
288 */
289 bool QBarSeries::append(QList<QBarSet* > sets)
289 bool QAbstractBarSeries::append(QList<QBarSet* > sets)
290 {
290 {
291 Q_D(QBarSeries);
291 Q_D(QAbstractBarSeries);
292 bool success = d->append(sets);
292 bool success = d->append(sets);
293 if (success) {
293 if (success) {
294 emit barsetsAdded(sets);
294 emit barsetsAdded(sets);
295 emit countChanged();
295 emit countChanged();
296 }
296 }
297 return success;
297 return success;
298 }
298 }
299
299
300 /*!
300 /*!
301 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.
301 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.
302 Returns true, if inserting succeeded.
302 Returns true, if inserting succeeded.
303
303
304 */
304 */
305 bool QBarSeries::insert(int index, QBarSet *set)
305 bool QAbstractBarSeries::insert(int index, QBarSet *set)
306 {
306 {
307 Q_D(QBarSeries);
307 Q_D(QAbstractBarSeries);
308 bool success = d->insert(index, set);
308 bool success = d->insert(index, set);
309 if (success) {
309 if (success) {
310 QList<QBarSet*> sets;
310 QList<QBarSet*> sets;
311 sets.append(set);
311 sets.append(set);
312 emit barsetsAdded(sets);
312 emit barsetsAdded(sets);
313 emit countChanged();
313 emit countChanged();
314 }
314 }
315 return success;
315 return success;
316 }
316 }
317
317
318 /*!
318 /*!
319 Removes all of the bar sets from the series
319 Removes all of the bar sets from the series
320 */
320 */
321 void QBarSeries::clear()
321 void QAbstractBarSeries::clear()
322 {
322 {
323 Q_D(QBarSeries);
323 Q_D(QAbstractBarSeries);
324 QList<QBarSet *> sets = barSets();
324 QList<QBarSet *> sets = barSets();
325 bool success = d->remove(sets);
325 bool success = d->remove(sets);
326 if (success) {
326 if (success) {
327 emit barsetsRemoved(sets);
327 emit barsetsRemoved(sets);
328 emit countChanged();
328 emit countChanged();
329 }
329 }
330 }
330 }
331
331
332 /*!
332 /*!
333 Returns number of sets in series.
333 Returns number of sets in series.
334 */
334 */
335 int QBarSeries::count() const
335 int QAbstractBarSeries::count() const
336 {
336 {
337 Q_D(const QBarSeries);
337 Q_D(const QAbstractBarSeries);
338 return d->m_barSets.count();
338 return d->m_barSets.count();
339 }
339 }
340
340
341 /*!
341 /*!
342 Returns a list of sets in series. Keeps ownership of sets.
342 Returns a list of sets in series. Keeps ownership of sets.
343 */
343 */
344 QList<QBarSet*> QBarSeries::barSets() const
344 QList<QBarSet*> QAbstractBarSeries::barSets() const
345 {
345 {
346 Q_D(const QBarSeries);
346 Q_D(const QAbstractBarSeries);
347 return d->m_barSets;
347 return d->m_barSets;
348 }
348 }
349
349
350 /*!
350 /*!
351 Sets the visibility of labels in series to \a visible
351 Sets the visibility of labels in series to \a visible
352 */
352 */
353 void QBarSeries::setLabelsVisible(bool visible)
353 void QAbstractBarSeries::setLabelsVisible(bool visible)
354 {
354 {
355 Q_D(QBarSeries);
355 Q_D(QAbstractBarSeries);
356 if (d->m_labelsVisible != visible) {
356 if (d->m_labelsVisible != visible) {
357 d->setLabelsVisible(visible);
357 d->setLabelsVisible(visible);
358 emit labelsVisibleChanged();
358 emit labelsVisibleChanged();
359 }
359 }
360 }
360 }
361
361
362 /*!
362 /*!
363 Returns the visibility of labels
363 Returns the visibility of labels
364 */
364 */
365 bool QBarSeries::isLabelsVisible() const
365 bool QAbstractBarSeries::isLabelsVisible() const
366 {
366 {
367 Q_D(const QBarSeries);
367 Q_D(const QAbstractBarSeries);
368 return d->m_labelsVisible;
368 return d->m_labelsVisible;
369 }
369 }
370
370
371 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
371 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
372
372
373 QBarSeriesPrivate::QBarSeriesPrivate(QBarSeries *q) :
373 QAbstractBarSeriesPrivate::QAbstractBarSeriesPrivate(QAbstractBarSeries *q) :
374 QAbstractSeriesPrivate(q),
374 QAbstractSeriesPrivate(q),
375 m_barWidth(0.5), // Default value is 50% of category width
375 m_barWidth(0.5), // Default value is 50% of category width
376 m_labelsVisible(false),
376 m_labelsVisible(false),
377 m_visible(true)
377 m_visible(true)
378 {
378 {
379 }
379 }
380
380
381 int QBarSeriesPrivate::categoryCount() const
381 int QAbstractBarSeriesPrivate::categoryCount() const
382 {
382 {
383 // No categories defined. return count of longest set.
383 // No categories defined. return count of longest set.
384 int count = 0;
384 int count = 0;
385 for (int i=0; i<m_barSets.count(); i++) {
385 for (int i=0; i<m_barSets.count(); i++) {
386 if (m_barSets.at(i)->count() > count) {
386 if (m_barSets.at(i)->count() > count) {
387 count = m_barSets.at(i)->count();
387 count = m_barSets.at(i)->count();
388 }
388 }
389 }
389 }
390
390
391 return count;
391 return count;
392 }
392 }
393
393
394 void QBarSeriesPrivate::setBarWidth(qreal width)
394 void QAbstractBarSeriesPrivate::setBarWidth(qreal width)
395 {
395 {
396 if (width < 0.0) {
396 if (width < 0.0) {
397 width = 0.0;
397 width = 0.0;
398 }
398 }
399 m_barWidth = width;
399 m_barWidth = width;
400 emit updatedBars();
400 emit updatedBars();
401 }
401 }
402
402
403 qreal QBarSeriesPrivate::barWidth() const
403 qreal QAbstractBarSeriesPrivate::barWidth() const
404 {
404 {
405 return m_barWidth;
405 return m_barWidth;
406 }
406 }
407
407
408 QBarSet* QBarSeriesPrivate::barsetAt(int index)
408 QBarSet* QAbstractBarSeriesPrivate::barsetAt(int index)
409 {
409 {
410 return m_barSets.at(index);
410 return m_barSets.at(index);
411 }
411 }
412
412
413 void QBarSeriesPrivate::setVisible(bool visible)
413 void QAbstractBarSeriesPrivate::setVisible(bool visible)
414 {
414 {
415 m_visible = visible;
415 m_visible = visible;
416 emit updatedBars();
416 emit updatedBars();
417 }
417 }
418
418
419 void QBarSeriesPrivate::setLabelsVisible(bool visible)
419 void QAbstractBarSeriesPrivate::setLabelsVisible(bool visible)
420 {
420 {
421 m_labelsVisible = visible;
421 m_labelsVisible = visible;
422 emit labelsVisibleChanged(visible);
422 emit labelsVisibleChanged(visible);
423 }
423 }
424
424
425 qreal QBarSeriesPrivate::min()
425 qreal QAbstractBarSeriesPrivate::min()
426 {
426 {
427 if (m_barSets.count() <= 0) {
427 if (m_barSets.count() <= 0) {
428 return 0;
428 return 0;
429 }
429 }
430 qreal min = INT_MAX;
430 qreal min = INT_MAX;
431
431
432 for (int i = 0; i < m_barSets.count(); i++) {
432 for (int i = 0; i < m_barSets.count(); i++) {
433 int categoryCount = m_barSets.at(i)->count();
433 int categoryCount = m_barSets.at(i)->count();
434 for (int j = 0; j < categoryCount; j++) {
434 for (int j = 0; j < categoryCount; j++) {
435 qreal temp = m_barSets.at(i)->at(j);
435 qreal temp = m_barSets.at(i)->at(j);
436 if (temp < min)
436 if (temp < min)
437 min = temp;
437 min = temp;
438 }
438 }
439 }
439 }
440 return min;
440 return min;
441 }
441 }
442
442
443 qreal QBarSeriesPrivate::max()
443 qreal QAbstractBarSeriesPrivate::max()
444 {
444 {
445 if (m_barSets.count() <= 0) {
445 if (m_barSets.count() <= 0) {
446 return 0;
446 return 0;
447 }
447 }
448 qreal max = INT_MIN;
448 qreal max = INT_MIN;
449
449
450 for (int i = 0; i < m_barSets.count(); i++) {
450 for (int i = 0; i < m_barSets.count(); i++) {
451 int categoryCount = m_barSets.at(i)->count();
451 int categoryCount = m_barSets.at(i)->count();
452 for (int j = 0; j < categoryCount; j++) {
452 for (int j = 0; j < categoryCount; j++) {
453 qreal temp = m_barSets.at(i)->at(j);
453 qreal temp = m_barSets.at(i)->at(j);
454 if (temp > max)
454 if (temp > max)
455 max = temp;
455 max = temp;
456 }
456 }
457 }
457 }
458
458
459 return max;
459 return max;
460 }
460 }
461
461
462 qreal QBarSeriesPrivate::valueAt(int set, int category)
462 qreal QAbstractBarSeriesPrivate::valueAt(int set, int category)
463 {
463 {
464 if ((set < 0) || (set >= m_barSets.count())) {
464 if ((set < 0) || (set >= m_barSets.count())) {
465 // No set, no value.
465 // No set, no value.
466 return 0;
466 return 0;
467 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
467 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
468 // No category, no value.
468 // No category, no value.
469 return 0;
469 return 0;
470 }
470 }
471
471
472 return m_barSets.at(set)->at(category);
472 return m_barSets.at(set)->at(category);
473 }
473 }
474
474
475 qreal QBarSeriesPrivate::percentageAt(int set, int category)
475 qreal QAbstractBarSeriesPrivate::percentageAt(int set, int category)
476 {
476 {
477 if ((set < 0) || (set >= m_barSets.count())) {
477 if ((set < 0) || (set >= m_barSets.count())) {
478 // No set, no value.
478 // No set, no value.
479 return 0;
479 return 0;
480 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
480 } else if ((category < 0) || (category >= m_barSets.at(set)->count())) {
481 // No category, no value.
481 // No category, no value.
482 return 0;
482 return 0;
483 }
483 }
484
484
485 qreal value = m_barSets.at(set)->at(category);
485 qreal value = m_barSets.at(set)->at(category);
486 qreal sum = categorySum(category);
486 qreal sum = categorySum(category);
487 if ( qFuzzyIsNull(sum) ) {
487 if ( qFuzzyIsNull(sum) ) {
488 return 0;
488 return 0;
489 }
489 }
490
490
491 return value / sum;
491 return value / sum;
492 }
492 }
493
493
494 qreal QBarSeriesPrivate::categorySum(int category)
494 qreal QAbstractBarSeriesPrivate::categorySum(int category)
495 {
495 {
496 qreal sum(0);
496 qreal sum(0);
497 int count = m_barSets.count(); // Count sets
497 int count = m_barSets.count(); // Count sets
498 for (int set = 0; set < count; set++) {
498 for (int set = 0; set < count; set++) {
499 if (category < m_barSets.at(set)->count())
499 if (category < m_barSets.at(set)->count())
500 sum += m_barSets.at(set)->at(category);
500 sum += m_barSets.at(set)->at(category);
501 }
501 }
502 return sum;
502 return sum;
503 }
503 }
504
504
505 qreal QBarSeriesPrivate::absoluteCategorySum(int category)
505 qreal QAbstractBarSeriesPrivate::absoluteCategorySum(int category)
506 {
506 {
507 qreal sum(0);
507 qreal sum(0);
508 int count = m_barSets.count(); // Count sets
508 int count = m_barSets.count(); // Count sets
509 for (int set = 0; set < count; set++) {
509 for (int set = 0; set < count; set++) {
510 if (category < m_barSets.at(set)->count())
510 if (category < m_barSets.at(set)->count())
511 sum += qAbs(m_barSets.at(set)->at(category));
511 sum += qAbs(m_barSets.at(set)->at(category));
512 }
512 }
513 return sum;
513 return sum;
514 }
514 }
515
515
516 qreal QBarSeriesPrivate::maxCategorySum()
516 qreal QAbstractBarSeriesPrivate::maxCategorySum()
517 {
517 {
518 qreal max = INT_MIN;
518 qreal max = INT_MIN;
519 int count = categoryCount();
519 int count = categoryCount();
520 for (int i = 0; i < count; i++) {
520 for (int i = 0; i < count; i++) {
521 qreal sum = categorySum(i);
521 qreal sum = categorySum(i);
522 if (sum > max)
522 if (sum > max)
523 max = sum;
523 max = sum;
524 }
524 }
525 return max;
525 return max;
526 }
526 }
527
527
528 qreal QBarSeriesPrivate::minX()
528 qreal QAbstractBarSeriesPrivate::minX()
529 {
529 {
530 if (m_barSets.count() <= 0) {
530 if (m_barSets.count() <= 0) {
531 return 0;
531 return 0;
532 }
532 }
533 qreal min = INT_MAX;
533 qreal min = INT_MAX;
534
534
535 for (int i = 0; i < m_barSets.count(); i++) {
535 for (int i = 0; i < m_barSets.count(); i++) {
536 int categoryCount = m_barSets.at(i)->count();
536 int categoryCount = m_barSets.at(i)->count();
537 for (int j = 0; j < categoryCount; j++) {
537 for (int j = 0; j < categoryCount; j++) {
538 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
538 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
539 if (temp < min)
539 if (temp < min)
540 min = temp;
540 min = temp;
541 }
541 }
542 }
542 }
543 return min;
543 return min;
544 }
544 }
545
545
546 qreal QBarSeriesPrivate::maxX()
546 qreal QAbstractBarSeriesPrivate::maxX()
547 {
547 {
548 if (m_barSets.count() <= 0) {
548 if (m_barSets.count() <= 0) {
549 return 0;
549 return 0;
550 }
550 }
551 qreal max = INT_MIN;
551 qreal max = INT_MIN;
552
552
553 for (int i = 0; i < m_barSets.count(); i++) {
553 for (int i = 0; i < m_barSets.count(); i++) {
554 int categoryCount = m_barSets.at(i)->count();
554 int categoryCount = m_barSets.at(i)->count();
555 for (int j = 0; j < categoryCount; j++) {
555 for (int j = 0; j < categoryCount; j++) {
556 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
556 qreal temp = m_barSets.at(i)->d_ptr.data()->m_values.at(j).x();
557 if (temp > max)
557 if (temp > max)
558 max = temp;
558 max = temp;
559 }
559 }
560 }
560 }
561
561
562 return max;
562 return max;
563 }
563 }
564
564
565
565
566 void QBarSeriesPrivate::scaleDomain(Domain& domain)
566 void QAbstractBarSeriesPrivate::scaleDomain(Domain& domain)
567 {
567 {
568 qreal minX(domain.minX());
568 qreal minX(domain.minX());
569 qreal minY(domain.minY());
569 qreal minY(domain.minY());
570 qreal maxX(domain.maxX());
570 qreal maxX(domain.maxX());
571 qreal maxY(domain.maxY());
571 qreal maxY(domain.maxY());
572 int tickXCount(domain.tickXCount());
572 int tickXCount(domain.tickXCount());
573 int tickYCount(domain.tickYCount());
573 int tickYCount(domain.tickYCount());
574
574
575 qreal seriesMinX = this->minX();
575 qreal seriesMinX = this->minX();
576 qreal seriesMaxX = this->maxX();
576 qreal seriesMaxX = this->maxX();
577 qreal y = max();
577 qreal y = max();
578 minX = qMin(minX, seriesMinX - 0.5);
578 minX = qMin(minX, seriesMinX - 0.5);
579 minY = qMin(minY, y);
579 minY = qMin(minY, y);
580 maxX = qMax(maxX, seriesMaxX + 0.5);
580 maxX = qMax(maxX, seriesMaxX + 0.5);
581 maxY = qMax(maxY, y);
581 maxY = qMax(maxY, y);
582 tickXCount = categoryCount()+1;
582 tickXCount = categoryCount()+1;
583
583
584 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
584 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
585 }
585 }
586
586
587 Chart* QBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
587 Chart* QAbstractBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
588 {
588 {
589 Q_Q(QBarSeries);
589 Q_Q(QAbstractBarSeries);
590
590
591 BarChartItem* bar = new BarChartItem(q,presenter);
591 BarChartItem* bar = new BarChartItem(q,presenter);
592 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
592 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
593 presenter->animator()->addAnimation(bar);
593 presenter->animator()->addAnimation(bar);
594 }
594 }
595 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
595 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
596 return bar;
596 return bar;
597
597
598 }
598 }
599
599
600 QList<LegendMarker*> QBarSeriesPrivate::createLegendMarker(QLegend* legend)
600 QList<LegendMarker*> QAbstractBarSeriesPrivate::createLegendMarker(QLegend* legend)
601 {
601 {
602 Q_Q(QBarSeries);
602 Q_Q(QAbstractBarSeries);
603 QList<LegendMarker*> markers;
603 QList<LegendMarker*> markers;
604 foreach(QBarSet* set, q->barSets()) {
604 foreach(QBarSet* set, q->barSets()) {
605 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
605 BarLegendMarker* marker = new BarLegendMarker(q,set,legend);
606 markers << marker;
606 markers << marker;
607 }
607 }
608
608
609 return markers;
609 return markers;
610 }
610 }
611
611
612 QAbstractAxis* QBarSeriesPrivate::createAxisX(QObject* parent)
612 QAbstractAxis* QAbstractBarSeriesPrivate::createAxisX(QObject* parent)
613 {
613 {
614 return new QCategoriesAxis(parent);
614 return new QCategoriesAxis(parent);
615 }
615 }
616
616
617 QAbstractAxis* QBarSeriesPrivate::createAxisY(QObject* parent)
617 QAbstractAxis* QAbstractBarSeriesPrivate::createAxisY(QObject* parent)
618 {
618 {
619 return new QValuesAxis(parent);
619 return new QValuesAxis(parent);
620 }
620 }
621
621
622 bool QBarSeriesPrivate::append(QBarSet *set)
622 bool QAbstractBarSeriesPrivate::append(QBarSet *set)
623 {
623 {
624 Q_Q(QBarSeries);
624 Q_Q(QAbstractBarSeries);
625 if ((m_barSets.contains(set)) || (set == 0)) {
625 if ((m_barSets.contains(set)) || (set == 0)) {
626 // Fail if set is already in list or set is null.
626 // Fail if set is already in list or set is null.
627 return false;
627 return false;
628 }
628 }
629 m_barSets.append(set);
629 m_barSets.append(set);
630 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
630 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
631 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
631 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
632 emit restructuredBars(); // this notifies barchartitem
632 emit restructuredBars(); // this notifies barchartitem
633 if (m_dataset) {
633 if (m_dataset) {
634 m_dataset->updateSeries(q); // this notifies legend
634 m_dataset->updateSeries(q); // this notifies legend
635 }
635 }
636 return true;
636 return true;
637 }
637 }
638
638
639 bool QBarSeriesPrivate::remove(QBarSet *set)
639 bool QAbstractBarSeriesPrivate::remove(QBarSet *set)
640 {
640 {
641 Q_Q(QBarSeries);
641 Q_Q(QAbstractBarSeries);
642 if (!m_barSets.contains(set)) {
642 if (!m_barSets.contains(set)) {
643 // Fail if set is not in list
643 // Fail if set is not in list
644 return false;
644 return false;
645 }
645 }
646 m_barSets.removeOne(set);
646 m_barSets.removeOne(set);
647 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
647 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
648 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
648 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
649 emit restructuredBars(); // this notifies barchartitem
649 emit restructuredBars(); // this notifies barchartitem
650 if (m_dataset) {
650 if (m_dataset) {
651 m_dataset->updateSeries(q); // this notifies legend
651 m_dataset->updateSeries(q); // this notifies legend
652 }
652 }
653 return true;
653 return true;
654 }
654 }
655
655
656 bool QBarSeriesPrivate::append(QList<QBarSet* > sets)
656 bool QAbstractBarSeriesPrivate::append(QList<QBarSet* > sets)
657 {
657 {
658 Q_Q(QBarSeries);
658 Q_Q(QAbstractBarSeries);
659 foreach (QBarSet* set, sets) {
659 foreach (QBarSet* set, sets) {
660 if ((set == 0) || (m_barSets.contains(set))) {
660 if ((set == 0) || (m_barSets.contains(set))) {
661 // Fail if any of the sets is null or is already appended.
661 // Fail if any of the sets is null or is already appended.
662 return false;
662 return false;
663 }
663 }
664 if (sets.count(set) != 1) {
664 if (sets.count(set) != 1) {
665 // Also fail if same set is more than once in given list.
665 // Also fail if same set is more than once in given list.
666 return false;
666 return false;
667 }
667 }
668 }
668 }
669
669
670 foreach (QBarSet* set, sets) {
670 foreach (QBarSet* set, sets) {
671 m_barSets.append(set);
671 m_barSets.append(set);
672 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
672 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
673 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
673 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
674 }
674 }
675 emit restructuredBars(); // this notifies barchartitem
675 emit restructuredBars(); // this notifies barchartitem
676 if (m_dataset) {
676 if (m_dataset) {
677 m_dataset->updateSeries(q); // this notifies legend
677 m_dataset->updateSeries(q); // this notifies legend
678 }
678 }
679 return true;
679 return true;
680 }
680 }
681
681
682 bool QBarSeriesPrivate::remove(QList<QBarSet* > sets)
682 bool QAbstractBarSeriesPrivate::remove(QList<QBarSet* > sets)
683 {
683 {
684 Q_Q(QBarSeries);
684 Q_Q(QAbstractBarSeries);
685 if (sets.count() == 0) {
685 if (sets.count() == 0) {
686 return false;
686 return false;
687 }
687 }
688 foreach (QBarSet* set, sets) {
688 foreach (QBarSet* set, sets) {
689 if ((set == 0) || (!m_barSets.contains(set))) {
689 if ((set == 0) || (!m_barSets.contains(set))) {
690 // Fail if any of the sets is null or is not in series
690 // Fail if any of the sets is null or is not in series
691 return false;
691 return false;
692 }
692 }
693 if (sets.count(set) != 1) {
693 if (sets.count(set) != 1) {
694 // Also fail if same set is more than once in given list.
694 // Also fail if same set is more than once in given list.
695 return false;
695 return false;
696 }
696 }
697 }
697 }
698
698
699 foreach (QBarSet* set, sets) {
699 foreach (QBarSet* set, sets) {
700 m_barSets.removeOne(set);
700 m_barSets.removeOne(set);
701 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
701 QObject::disconnect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
702 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
702 QObject::disconnect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
703 }
703 }
704
704
705 emit restructuredBars(); // this notifies barchartitem
705 emit restructuredBars(); // this notifies barchartitem
706 if (m_dataset) {
706 if (m_dataset) {
707 m_dataset->updateSeries(q); // this notifies legend
707 m_dataset->updateSeries(q); // this notifies legend
708 }
708 }
709 return true;
709 return true;
710 }
710 }
711
711
712 bool QBarSeriesPrivate::insert(int index, QBarSet *set)
712 bool QAbstractBarSeriesPrivate::insert(int index, QBarSet *set)
713 {
713 {
714 Q_Q(QBarSeries);
714 Q_Q(QAbstractBarSeries);
715 if ((m_barSets.contains(set)) || (set == 0)) {
715 if ((m_barSets.contains(set)) || (set == 0)) {
716 // Fail if set is already in list or set is null.
716 // Fail if set is already in list or set is null.
717 return false;
717 return false;
718 }
718 }
719 m_barSets.insert(index, set);
719 m_barSets.insert(index, set);
720 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
720 QObject::connect(set->d_ptr.data(), SIGNAL(updatedBars()), this, SIGNAL(updatedBars()));
721 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
721 QObject::connect(set->d_ptr.data(), SIGNAL(restructuredBars()), this, SIGNAL(restructuredBars()));
722 emit restructuredBars(); // this notifies barchartitem
722 emit restructuredBars(); // this notifies barchartitem
723 if (m_dataset) {
723 if (m_dataset) {
724 m_dataset->updateSeries(q); // this notifies legend
724 m_dataset->updateSeries(q); // this notifies legend
725 }
725 }
726 return true;
726 return true;
727 }
727 }
728
728
729 #include "moc_qbarseries.cpp"
729 #include "moc_qbarseries.cpp"
730 #include "moc_qbarseries_p.cpp"
730 #include "moc_qbarseries_p.cpp"
731
731
732 QTCOMMERCIALCHART_END_NAMESPACE
732 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,82 +1,82
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef BARSERIES_H
21 #ifndef BARSERIES_H
22 #define BARSERIES_H
22 #define BARSERIES_H
23
23
24 #include <qabstractseries.h>
24 #include <qabstractseries.h>
25 #include <QStringList>
25 #include <QStringList>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QBarSet;
29 class QBarSet;
30 class QBarSeriesPrivate;
30 class QAbstractBarSeriesPrivate;
31
31
32 // Container for series
32 // Container for series
33 class QTCOMMERCIALCHART_EXPORT QBarSeries : public QAbstractSeries
33 class QTCOMMERCIALCHART_EXPORT QAbstractBarSeries : public QAbstractSeries
34 {
34 {
35 Q_OBJECT
35 Q_OBJECT
36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
36 Q_PROPERTY(qreal barWidth READ barWidth WRITE setBarWidth)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
37 Q_PROPERTY(int count READ count NOTIFY countChanged)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
38 Q_PROPERTY(bool labelsVisible READ isLabelsVisible WRITE setLabelsVisible NOTIFY labelsVisibleChanged)
39
39
40 public:
40 public:
41 explicit QBarSeries(QObject *parent = 0);
41 explicit QAbstractBarSeries(QObject *parent = 0);
42 virtual ~QBarSeries();
42 virtual ~QAbstractBarSeries();
43
43
44 QAbstractSeries::SeriesType type() const;
44 QAbstractSeries::SeriesType type() const;
45
45
46 void setBarWidth(qreal width);
46 void setBarWidth(qreal width);
47 qreal barWidth() const;
47 qreal barWidth() const;
48
48
49 bool append(QBarSet *set);
49 bool append(QBarSet *set);
50 bool remove(QBarSet *set);
50 bool remove(QBarSet *set);
51 bool append(QList<QBarSet* > sets);
51 bool append(QList<QBarSet* > sets);
52 bool insert(int index, QBarSet *set);
52 bool insert(int index, QBarSet *set);
53 int count() const;
53 int count() const;
54 QList<QBarSet*> barSets() const;
54 QList<QBarSet*> barSets() const;
55 void clear();
55 void clear();
56
56
57 void setLabelsVisible(bool visible = true);
57 void setLabelsVisible(bool visible = true);
58 bool isLabelsVisible() const;
58 bool isLabelsVisible() const;
59
59
60 protected:
60 protected:
61 explicit QBarSeries(QBarSeriesPrivate &d,QObject *parent = 0);
61 explicit QAbstractBarSeries(QAbstractBarSeriesPrivate &d,QObject *parent = 0);
62
62
63 Q_SIGNALS:
63 Q_SIGNALS:
64 void clicked(int index, QBarSet *barset);
64 void clicked(int index, QBarSet *barset);
65 void hovered(bool status, QBarSet *barset);
65 void hovered(bool status, QBarSet *barset);
66 void countChanged();
66 void countChanged();
67 void labelsVisibleChanged();
67 void labelsVisibleChanged();
68
68
69 void barsetsAdded(QList<QBarSet*> sets);
69 void barsetsAdded(QList<QBarSet*> sets);
70 void barsetsRemoved(QList<QBarSet*> sets);
70 void barsetsRemoved(QList<QBarSet*> sets);
71
71
72 protected:
72 protected:
73 Q_DECLARE_PRIVATE(QBarSeries)
73 Q_DECLARE_PRIVATE(QAbstractBarSeries)
74 friend class BarChartItem;
74 friend class BarChartItem;
75 friend class PercentBarChartItem;
75 friend class PercentBarChartItem;
76 friend class StackedBarChartItem;
76 friend class StackedBarChartItem;
77 friend class GroupedBarChartItem;
77 friend class GroupedBarChartItem;
78 };
78 };
79
79
80 QTCOMMERCIALCHART_END_NAMESPACE
80 QTCOMMERCIALCHART_END_NAMESPACE
81
81
82 #endif // BARSERIES_H
82 #endif // BARSERIES_H
@@ -1,97 +1,97
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QBARSERIES_P_H
30 #ifndef QBARSERIES_P_H
31 #define QBARSERIES_P_H
31 #define QBARSERIES_P_H
32
32
33 #include "qbarseries.h"
33 #include "qbarseries.h"
34 #include "qabstractseries_p.h"
34 #include "qabstractseries_p.h"
35 #include <QStringList>
35 #include <QStringList>
36 #include <QAbstractSeries>
36 #include <QAbstractSeries>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class QBarModelMapper;
40 class QBarModelMapper;
41
41
42 class QBarSeriesPrivate : public QAbstractSeriesPrivate
42 class QAbstractBarSeriesPrivate : public QAbstractSeriesPrivate
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45 public:
45 public:
46 QBarSeriesPrivate(QBarSeries *parent);
46 QAbstractBarSeriesPrivate(QAbstractBarSeries *parent);
47 int categoryCount() const;
47 int categoryCount() const;
48
48
49 void setBarWidth(qreal width);
49 void setBarWidth(qreal width);
50 qreal barWidth() const;
50 qreal barWidth() const;
51
51
52 void setVisible(bool visible);
52 void setVisible(bool visible);
53 void setLabelsVisible(bool visible);
53 void setLabelsVisible(bool visible);
54
54
55 void scaleDomain(Domain& domain);
55 void scaleDomain(Domain& domain);
56 Chart* createGraphics(ChartPresenter* presenter);
56 Chart* createGraphics(ChartPresenter* presenter);
57 QList<LegendMarker*> createLegendMarker(QLegend* legend);
57 QList<LegendMarker*> createLegendMarker(QLegend* legend);
58
58
59 QAbstractAxis* createAxisX(QObject* parent = 0);
59 QAbstractAxis* createAxisX(QObject* parent = 0);
60 QAbstractAxis* createAxisY(QObject* parent = 0);
60 QAbstractAxis* createAxisY(QObject* parent = 0);
61
61
62 bool append(QBarSet *set);
62 bool append(QBarSet *set);
63 bool remove(QBarSet *set);
63 bool remove(QBarSet *set);
64 bool append(QList<QBarSet* > sets);
64 bool append(QList<QBarSet* > sets);
65 bool remove(QList<QBarSet* > sets);
65 bool remove(QList<QBarSet* > sets);
66 bool insert(int index, QBarSet *set);
66 bool insert(int index, QBarSet *set);
67
67
68 QBarSet* barsetAt(int index);
68 QBarSet* barsetAt(int index);
69 qreal min();
69 qreal min();
70 qreal max();
70 qreal max();
71 qreal valueAt(int set, int category);
71 qreal valueAt(int set, int category);
72 qreal percentageAt(int set, int category);
72 qreal percentageAt(int set, int category);
73 qreal categorySum(int category);
73 qreal categorySum(int category);
74 qreal absoluteCategorySum(int category);
74 qreal absoluteCategorySum(int category);
75 qreal maxCategorySum();
75 qreal maxCategorySum();
76 qreal minX();
76 qreal minX();
77 qreal maxX();
77 qreal maxX();
78
78
79 Q_SIGNALS:
79 Q_SIGNALS:
80 void clicked(int index, QBarSet *barset);
80 void clicked(int index, QBarSet *barset);
81 void updatedBars();
81 void updatedBars();
82 void restructuredBars();
82 void restructuredBars();
83 void labelsVisibleChanged(bool visible);
83 void labelsVisibleChanged(bool visible);
84
84
85 protected:
85 protected:
86 QList<QBarSet *> m_barSets;
86 QList<QBarSet *> m_barSets;
87 qreal m_barWidth;
87 qreal m_barWidth;
88 bool m_labelsVisible;
88 bool m_labelsVisible;
89 bool m_visible;
89 bool m_visible;
90
90
91 private:
91 private:
92 Q_DECLARE_PUBLIC(QBarSeries)
92 Q_DECLARE_PUBLIC(QAbstractBarSeries)
93 };
93 };
94
94
95 QTCOMMERCIALCHART_END_NAMESPACE
95 QTCOMMERCIALCHART_END_NAMESPACE
96
96
97 #endif // QBARSERIESPRIVATE_P_H
97 #endif // QBARSERIESPRIVATE_P_H
@@ -1,115 +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 #ifndef QBARSET_H
21 #ifndef QBARSET_H
22 #define QBARSET_H
22 #define QBARSET_H
23
23
24 #include <qchartglobal.h>
24 #include <qchartglobal.h>
25 #include <QPen>
25 #include <QPen>
26 #include <QBrush>
26 #include <QBrush>
27 #include <QFont>
27 #include <QFont>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 class QBarSetPrivate;
30 class QBarSetPrivate;
31
31
32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
32 class QTCOMMERCIALCHART_EXPORT QBarSet : public QObject
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
35 Q_PROPERTY(QString label READ label WRITE setLabel NOTIFY labelChanged)
36 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
36 Q_PROPERTY(QPen pen READ pen WRITE setPen NOTIFY penChanged)
37 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
37 Q_PROPERTY(QBrush brush READ brush WRITE setBrush NOTIFY brushChanged)
38 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
38 Q_PROPERTY(QBrush labelBrush READ labelBrush WRITE setLabelBrush NOTIFY labelBrushChanged)
39 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
39 Q_PROPERTY(QFont labelFont READ labelFont WRITE setLabelFont NOTIFY labelFontChanged)
40 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
40 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
41 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
41 Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor NOTIFY borderColorChanged)
42 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
42 Q_PROPERTY(QColor labelColor READ labelColor WRITE setLabelColor NOTIFY labelColorChanged)
43
43
44 public:
44 public:
45 explicit QBarSet(const QString label, QObject *parent = 0);
45 explicit QBarSet(const QString label, QObject *parent = 0);
46 virtual ~QBarSet();
46 virtual ~QBarSet();
47
47
48 void setLabel(const QString label);
48 void setLabel(const QString label);
49 QString label() const;
49 QString label() const;
50
50
51 void append(const qreal value);
51 void append(const qreal value);
52 void append(const QList<qreal> &values);
52 void append(const QList<qreal> &values);
53
53
54 QBarSet& operator << (const qreal &value);
54 QBarSet& operator << (const qreal &value);
55
55
56 void insert(const int index, const qreal value);
56 void insert(const int index, const qreal value);
57 void remove(const int index, const int count = 1);
57 void remove(const int index, const int count = 1);
58 void replace(const int index, const qreal value);
58 void replace(const int index, const qreal value);
59 qreal at(const int index) const;
59 qreal at(const int index) const;
60 qreal operator [] (const int index) const;
60 qreal operator [] (const int index) const;
61 int count() const;
61 int count() const;
62 qreal sum() const;
62 qreal sum() const;
63
63
64 void setPen(const QPen &pen);
64 void setPen(const QPen &pen);
65 QPen pen() const;
65 QPen pen() const;
66
66
67 void setBrush(const QBrush &brush);
67 void setBrush(const QBrush &brush);
68 QBrush brush() const;
68 QBrush brush() const;
69
69
70 void setLabelBrush(const QBrush &brush);
70 void setLabelBrush(const QBrush &brush);
71 QBrush labelBrush() const;
71 QBrush labelBrush() const;
72
72
73 void setLabelFont(const QFont &font);
73 void setLabelFont(const QFont &font);
74 QFont labelFont() const;
74 QFont labelFont() const;
75
75
76 QColor color();
76 QColor color();
77 void setColor(QColor color);
77 void setColor(QColor color);
78
78
79 QColor borderColor();
79 QColor borderColor();
80 void setBorderColor(QColor color);
80 void setBorderColor(QColor color);
81
81
82 QColor labelColor();
82 QColor labelColor();
83 void setLabelColor(QColor color);
83 void setLabelColor(QColor color);
84
84
85 Q_SIGNALS:
85 Q_SIGNALS:
86 void clicked(int index);
86 void clicked(int index);
87 void hovered(bool status);
87 void hovered(bool status);
88 void penChanged();
88 void penChanged();
89 void brushChanged();
89 void brushChanged();
90 void labelChanged();
90 void labelChanged();
91 void labelBrushChanged();
91 void labelBrushChanged();
92 void labelFontChanged();
92 void labelFontChanged();
93 void colorChanged(QColor color);
93 void colorChanged(QColor color);
94 void borderColorChanged(QColor color);
94 void borderColorChanged(QColor color);
95 void labelColorChanged(QColor color);
95 void labelColorChanged(QColor color);
96
96
97 void valuesAdded(int index, int count);
97 void valuesAdded(int index, int count);
98 void valuesRemoved(int index, int count);
98 void valuesRemoved(int index, int count);
99 void valueChanged(int index);
99 void valueChanged(int index);
100
100
101 private:
101 private:
102 QScopedPointer<QBarSetPrivate> d_ptr;
102 QScopedPointer<QBarSetPrivate> d_ptr;
103 Q_DISABLE_COPY(QBarSet)
103 Q_DISABLE_COPY(QBarSet)
104 friend class QBarSeries;
104 friend class QBarSeries;
105 friend class BarLegendMarker;
105 friend class BarLegendMarker;
106 friend class BarChartItem;
106 friend class BarChartItem;
107 friend class QBarSeriesPrivate;
107 friend class QAbstractBarSeriesPrivate;
108 friend class StackedBarChartItem;
108 friend class StackedBarChartItem;
109 friend class PercentBarChartItem;
109 friend class PercentBarChartItem;
110 friend class GroupedBarChartItem;
110 friend class GroupedBarChartItem;
111 };
111 };
112
112
113 QTCOMMERCIALCHART_END_NAMESPACE
113 QTCOMMERCIALCHART_END_NAMESPACE
114
114
115 #endif // QBARSET_H
115 #endif // QBARSET_H
@@ -1,119 +1,119
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 #include "qcategoriesaxis.h"
27 #include "qcategoriesaxis.h"
28 #include "qvaluesaxis.h"
28 #include "qvaluesaxis.h"
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \class QGroupedBarSeries
33 \class QGroupedBarSeries
34 \brief Series for creating grouped bar chart
34 \brief Series for creating grouped bar chart
35 \mainclass
35 \mainclass
36
36
37 QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 QGroupedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data
38 as groups, where bars in same category are grouped next to each other. QGroupedBarSeries groups the data
39 from sets to categories, which are defined by a QStringList.
39 from sets to categories, which are defined by a QStringList.
40
40
41 See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart.
41 See the \l {GroupedbarChart Example} {grouped bar chart example} to learn how to create a grouped bar chart.
42 \image examples_groupedbarchart.png
42 \image examples_groupedbarchart.png
43
43
44 \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries
44 \sa QBarSet, QPercentBarSeries, QBarSeries, QStackedBarSeries
45 */
45 */
46 /*!
46 /*!
47 \qmlclass GroupedBarSeries QGroupedBarSeries
47 \qmlclass GroupedBarSeries QGroupedBarSeries
48 \inherits BarSeries
48 \inherits BarSeries
49
49
50 The following QML shows how to create a simple grouped bar chart:
50 The following QML shows how to create a simple grouped bar chart:
51 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
51 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
52 \beginfloatleft
52 \beginfloatleft
53 \image demos_qmlchart7.png
53 \image demos_qmlchart7.png
54 \endfloat
54 \endfloat
55 \clearfloat
55 \clearfloat
56 */
56 */
57
57
58 /*!
58 /*!
59 Constructs empty QGroupedBarSeries.
59 Constructs empty QGroupedBarSeries.
60 QGroupedBarSeries is QObject which is a child of a \a parent.
60 QGroupedBarSeries is QObject which is a child of a \a parent.
61 */
61 */
62 QGroupedBarSeries::QGroupedBarSeries(QObject *parent)
62 QGroupedBarSeries::QGroupedBarSeries(QObject *parent)
63 : QBarSeries(*new QGroupedBarSeriesPrivate(this), parent)
63 : QAbstractBarSeries(*new QGroupedBarSeriesPrivate(this), parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns QChartSeries::SeriesTypeGroupedBar.
68 Returns QChartSeries::SeriesTypeGroupedBar.
69 */
69 */
70 QAbstractSeries::SeriesType QGroupedBarSeries::type() const
70 QAbstractSeries::SeriesType QGroupedBarSeries::type() const
71 {
71 {
72 return QAbstractSeries::SeriesTypeGroupedBar;
72 return QAbstractSeries::SeriesTypeGroupedBar;
73 }
73 }
74
74
75 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76
76
77 QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QBarSeriesPrivate(q)
77 QGroupedBarSeriesPrivate::QGroupedBarSeriesPrivate(QGroupedBarSeries *q) : QAbstractBarSeriesPrivate(q)
78 {
78 {
79
79
80 }
80 }
81
81
82 void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain)
82 void QGroupedBarSeriesPrivate::scaleDomain(Domain& domain)
83 {
83 {
84 qreal minX(domain.minX());
84 qreal minX(domain.minX());
85 qreal minY(domain.minY());
85 qreal minY(domain.minY());
86 qreal maxX(domain.maxX());
86 qreal maxX(domain.maxX());
87 qreal maxY(domain.maxY());
87 qreal maxY(domain.maxY());
88 int tickXCount(domain.tickXCount());
88 int tickXCount(domain.tickXCount());
89 int tickYCount(domain.tickYCount());
89 int tickYCount(domain.tickYCount());
90
90
91 qreal x = categoryCount();
91 qreal x = categoryCount();
92 qreal y = max();
92 qreal y = max();
93 minX = qMin(minX, -0.5);
93 minX = qMin(minX, -0.5);
94 minY = qMin(minY, y);
94 minY = qMin(minY, y);
95 maxX = qMax(maxX, x - 0.5);
95 maxX = qMax(maxX, x - 0.5);
96 maxY = qMax(maxY, y);
96 maxY = qMax(maxY, y);
97 tickXCount = x+1;
97 tickXCount = x+1;
98
98
99 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
99 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
100 }
100 }
101
101
102
102
103 Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
103 Chart* QGroupedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
104 {
104 {
105 Q_Q(QGroupedBarSeries);
105 Q_Q(QGroupedBarSeries);
106
106
107 GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter);
107 GroupedBarChartItem* bar = new GroupedBarChartItem(q,presenter);
108 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
108 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
109 presenter->animator()->addAnimation(bar);
109 presenter->animator()->addAnimation(bar);
110 }
110 }
111 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
111 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
112 return bar;
112 return bar;
113 }
113 }
114
114
115
115
116 #include "moc_qgroupedbarseries.cpp"
116 #include "moc_qgroupedbarseries.cpp"
117
117
118 QTCOMMERCIALCHART_END_NAMESPACE
118 QTCOMMERCIALCHART_END_NAMESPACE
119
119
@@ -1,45 +1,45
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef GROUPEDBARSERIES_H
21 #ifndef GROUPEDBARSERIES_H
22 #define GROUPEDBARSERIES_H
22 #define GROUPEDBARSERIES_H
23
23
24 #include <QStringList>
24 #include <QStringList>
25 #include <qbarseries.h>
25 #include <qbarseries.h>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QGroupedBarSeriesPrivate;
29 class QGroupedBarSeriesPrivate;
30
30
31 class QTCOMMERCIALCHART_EXPORT QGroupedBarSeries : public QBarSeries
31 class QTCOMMERCIALCHART_EXPORT QGroupedBarSeries : public QAbstractBarSeries
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 public:
34 public:
35 explicit QGroupedBarSeries(QObject *parent = 0);
35 explicit QGroupedBarSeries(QObject *parent = 0);
36 QAbstractSeries::SeriesType type() const;
36 QAbstractSeries::SeriesType type() const;
37
37
38 private:
38 private:
39 Q_DECLARE_PRIVATE(QGroupedBarSeries)
39 Q_DECLARE_PRIVATE(QGroupedBarSeries)
40 Q_DISABLE_COPY(QGroupedBarSeries)
40 Q_DISABLE_COPY(QGroupedBarSeries)
41 };
41 };
42
42
43 QTCOMMERCIALCHART_END_NAMESPACE
43 QTCOMMERCIALCHART_END_NAMESPACE
44
44
45 #endif // GROUPEDBARSERIES_H
45 #endif // GROUPEDBARSERIES_H
@@ -1,52 +1,52
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QGROUPEDBARSERIES_P_H
30 #ifndef QGROUPEDBARSERIES_P_H
31 #define QGROUPEDBARSERIES_P_H
31 #define QGROUPEDBARSERIES_P_H
32
32
33 #include "qbarseries_p.h"
33 #include "qbarseries_p.h"
34 #include "domain_p.h"
34 #include "domain_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38
38
39 class QGroupedBarSeriesPrivate: public QBarSeriesPrivate
39 class QGroupedBarSeriesPrivate: public QAbstractBarSeriesPrivate
40 {
40 {
41 public:
41 public:
42 QGroupedBarSeriesPrivate(QGroupedBarSeries* q);
42 QGroupedBarSeriesPrivate(QGroupedBarSeries* q);
43 Chart* createGraphics(ChartPresenter* presenter);
43 Chart* createGraphics(ChartPresenter* presenter);
44 void scaleDomain(Domain& domain);
44 void scaleDomain(Domain& domain);
45
45
46 private:
46 private:
47 Q_DECLARE_PUBLIC(QGroupedBarSeries)
47 Q_DECLARE_PUBLIC(QGroupedBarSeries)
48 };
48 };
49
49
50 QTCOMMERCIALCHART_END_NAMESPACE
50 QTCOMMERCIALCHART_END_NAMESPACE
51
51
52 #endif // QGROUPEDBARSERIES_P_H
52 #endif // QGROUPEDBARSERIES_P_H
@@ -1,249 +1,249
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 "qhbarmodelmapper.h"
21 #include "qhbarmodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QHBarModelMapper
26 \class QHBarModelMapper
27 \brief Horizontal model mapper for bar series
27 \brief Horizontal model mapper for bar series
28 \mainclass
28 \mainclass
29
29
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
31 Horizontal model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object.
31 Horizontal model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object.
32 Model mapper maintains equal size of all the BarSets.
32 Model mapper maintains equal size of all the BarSets.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
34 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
34 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
35 */
35 */
36 /*!
36 /*!
37 \qmlclass HBarModelMapper QHBarModelMapper
37 \qmlclass HBarModelMapper QHBarModelMapper
38
38
39 HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source
39 HBarModelMapper allows you to use your own QAbstractItemModel derived model with data in rows as a data source
40 for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data.
40 for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data.
41 HBarModelMapper keeps the series and the model in sync.
41 HBarModelMapper keeps the series and the model in sync.
42
42
43 The following QML example would create a bar series with three bar sets (assuming the model has
43 The following QML example would create a bar series with three bar sets (assuming the model has
44 at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined by
44 at least four rows). Each bar set would contain data starting from column 1. The name of a set would be defined by
45 the vertical header (of the row).
45 the vertical header (of the row).
46 \code
46 \code
47 BarSeries {
47 BarSeries {
48 HBarModelMapper {
48 HBarModelMapper {
49 model: myCustomModel // QAbstractItemModel derived implementation
49 model: myCustomModel // QAbstractItemModel derived implementation
50 firstBarSetRow: 1
50 firstBarSetRow: 1
51 lastBarSetRow: 3
51 lastBarSetRow: 3
52 firstColumn: 1
52 firstColumn: 1
53 }
53 }
54 }
54 }
55 \endcode
55 \endcode
56 */
56 */
57
57
58 /*!
58 /*!
59 \property QHBarModelMapper::series
59 \property QHBarModelMapper::series
60 \brief Defines the QPieSeries object that is used by the mapper.
60 \brief Defines the QPieSeries object that is used by the mapper.
61
61
62 All the data in the series is discarded when it is set to the mapper.
62 All the data in the series is discarded when it is set to the mapper.
63 When new series is specified the old series is disconnected (it preserves its data)
63 When new series is specified the old series is disconnected (it preserves its data)
64 */
64 */
65 /*!
65 /*!
66 \qmlproperty BarSeries HBarModelMapper::series
66 \qmlproperty BarSeries HBarModelMapper::series
67 Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is
67 Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is
68 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
68 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
69 */
69 */
70
70
71 /*!
71 /*!
72 \property QHBarModelMapper::model
72 \property QHBarModelMapper::model
73 \brief Defines the model that is used by the mapper.
73 \brief Defines the model that is used by the mapper.
74 */
74 */
75 /*!
75 /*!
76 \qmlproperty SomeModel HBarModelMapper::model
76 \qmlproperty SomeModel HBarModelMapper::model
77 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
77 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
78 QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns
78 QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns
79 and modifying the data of the cells.
79 and modifying the data of the cells.
80 */
80 */
81
81
82 /*!
82 /*!
83 \property QHBarModelMapper::firstBarSetRow
83 \property QHBarModelMapper::firstBarSetRow
84 \brief Defines which column of the model is used as the data source for the first bar set
84 \brief Defines which column of the model is used as the data source for the first bar set
85 Default value is: -1 (invalid mapping)
85 Default value is: -1 (invalid mapping)
86 */
86 */
87 /*!
87 /*!
88 \qmlproperty int HBarModelMapper::firstBarSetRow
88 \qmlproperty int HBarModelMapper::firstBarSetRow
89 Defines which column of the model is used as the data source for the first bar set. The default value is -1
89 Defines which column of the model is used as the data source for the first bar set. The default value is -1
90 (invalid mapping).
90 (invalid mapping).
91 */
91 */
92
92
93 /*!
93 /*!
94 \property QHBarModelMapper::lastBarSetRow
94 \property QHBarModelMapper::lastBarSetRow
95 \brief Defines which column of the model is used as the data source for the last bar set
95 \brief Defines which column of the model is used as the data source for the last bar set
96 Default value is: -1 (invalid mapping)
96 Default value is: -1 (invalid mapping)
97 */
97 */
98 /*!
98 /*!
99 \qmlproperty int HBarModelMapper::lastBarSetRow
99 \qmlproperty int HBarModelMapper::lastBarSetRow
100 Defines which column of the model is used as the data source for the last bar set. The default value is -1
100 Defines which column of the model is used as the data source for the last bar set. The default value is -1
101 (invalid mapping).
101 (invalid mapping).
102 */
102 */
103
103
104 /*!
104 /*!
105 \property QHBarModelMapper::firstColumn
105 \property QHBarModelMapper::firstColumn
106 \brief Defines which column of the model contains the first values of the QBarSets in the series.
106 \brief Defines which column of the model contains the first values of the QBarSets in the series.
107 Minimal and default value is: 0
107 Minimal and default value is: 0
108 */
108 */
109 /*!
109 /*!
110 \qmlproperty int HBarModelMapper::firstColumn
110 \qmlproperty int HBarModelMapper::firstColumn
111 Defines which column of the model contains the first values of the QBarSets in the series.
111 Defines which column of the model contains the first values of the QBarSets in the series.
112 The default value is 0.
112 The default value is 0.
113 */
113 */
114
114
115 /*!
115 /*!
116 \property QHBarModelMapper::columnCount
116 \property QHBarModelMapper::columnCount
117 \brief Defines the number of columns of the model that are mapped as the data for QBarSeries
117 \brief Defines the number of columns of the model that are mapped as the data for QBarSeries
118 Minimal and default value is: -1 (count limited by the number of columns in the model)
118 Minimal and default value is: -1 (count limited by the number of columns in the model)
119 */
119 */
120 /*!
120 /*!
121 \qmlproperty int HBarModelMapper::columnCount
121 \qmlproperty int HBarModelMapper::columnCount
122 Defines the number of columns of the model that are mapped as the data for QBarSeries. The default value is
122 Defines the number of columns of the model that are mapped as the data for QBarSeries. The default value is
123 -1 (count limited by the number of columns in the model)
123 -1 (count limited by the number of columns in the model)
124 */
124 */
125
125
126 /*!
126 /*!
127 \fn void QHBarModelMapper::seriesReplaced()
127 \fn void QHBarModelMapper::seriesReplaced()
128
128
129 Emitted when the series to which mapper is connected to has changed.
129 Emitted when the series to which mapper is connected to has changed.
130 */
130 */
131
131
132 /*!
132 /*!
133 \fn void QHBarModelMapper::modelReplaced()
133 \fn void QHBarModelMapper::modelReplaced()
134
134
135 Emitted when the model to which mapper is connected to has changed.
135 Emitted when the model to which mapper is connected to has changed.
136 */
136 */
137
137
138 /*!
138 /*!
139 \fn void QHBarModelMapper::firstBarSetRowChanged()
139 \fn void QHBarModelMapper::firstBarSetRowChanged()
140
140
141 Emitted when the firstBarSetRow has changed.
141 Emitted when the firstBarSetRow has changed.
142 */
142 */
143
143
144 /*!
144 /*!
145 \fn void QHBarModelMapper::lastBarSetRowChanged()
145 \fn void QHBarModelMapper::lastBarSetRowChanged()
146
146
147 Emitted when the lastBarSetRow has changed.
147 Emitted when the lastBarSetRow has changed.
148 */
148 */
149
149
150 /*!
150 /*!
151 \fn void QHBarModelMapper::firstColumnChanged()
151 \fn void QHBarModelMapper::firstColumnChanged()
152 Emitted when the firstColumn has changed.
152 Emitted when the firstColumn has changed.
153 */
153 */
154
154
155 /*!
155 /*!
156 \fn void QHBarModelMapper::columnCountChanged()
156 \fn void QHBarModelMapper::columnCountChanged()
157 Emitted when the columnCount has changed.
157 Emitted when the columnCount has changed.
158 */
158 */
159
159
160 /*!
160 /*!
161 Constructs a mapper object which is a child of \a parent.
161 Constructs a mapper object which is a child of \a parent.
162 */
162 */
163 QHBarModelMapper::QHBarModelMapper(QObject *parent) :
163 QHBarModelMapper::QHBarModelMapper(QObject *parent) :
164 QBarModelMapper(parent)
164 QBarModelMapper(parent)
165 {
165 {
166 QBarModelMapper::setOrientation(Qt::Horizontal);
166 QBarModelMapper::setOrientation(Qt::Horizontal);
167 }
167 }
168
168
169 QAbstractItemModel* QHBarModelMapper::model() const
169 QAbstractItemModel* QHBarModelMapper::model() const
170 {
170 {
171 return QBarModelMapper::model();
171 return QBarModelMapper::model();
172 }
172 }
173
173
174 void QHBarModelMapper::setModel(QAbstractItemModel *model)
174 void QHBarModelMapper::setModel(QAbstractItemModel *model)
175 {
175 {
176 if (model != QBarModelMapper::model()) {
176 if (model != QBarModelMapper::model()) {
177 QBarModelMapper::setModel(model);
177 QBarModelMapper::setModel(model);
178 emit modelReplaced();
178 emit modelReplaced();
179 }
179 }
180 }
180 }
181
181
182 QBarSeries* QHBarModelMapper::series() const
182 QAbstractBarSeries* QHBarModelMapper::series() const
183 {
183 {
184 return QBarModelMapper::series();
184 return QBarModelMapper::series();
185 }
185 }
186
186
187 void QHBarModelMapper::setSeries(QBarSeries *series)
187 void QHBarModelMapper::setSeries(QAbstractBarSeries *series)
188 {
188 {
189 if (series != QBarModelMapper::series()) {
189 if (series != QBarModelMapper::series()) {
190 QBarModelMapper::setSeries(series);
190 QBarModelMapper::setSeries(series);
191 emit seriesReplaced();
191 emit seriesReplaced();
192 }
192 }
193 }
193 }
194
194
195 int QHBarModelMapper::firstBarSetRow() const
195 int QHBarModelMapper::firstBarSetRow() const
196 {
196 {
197 return QBarModelMapper::firstBarSetSection();
197 return QBarModelMapper::firstBarSetSection();
198 }
198 }
199
199
200 void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow)
200 void QHBarModelMapper::setFirstBarSetRow(int firstBarSetRow)
201 {
201 {
202 if (firstBarSetRow != firstBarSetSection()) {
202 if (firstBarSetRow != firstBarSetSection()) {
203 QBarModelMapper::setFirstBarSetSection(firstBarSetRow);
203 QBarModelMapper::setFirstBarSetSection(firstBarSetRow);
204 emit firstBarSetRowChanged();
204 emit firstBarSetRowChanged();
205 }
205 }
206 }
206 }
207
207
208 int QHBarModelMapper::lastBarSetRow() const
208 int QHBarModelMapper::lastBarSetRow() const
209 {
209 {
210 return QBarModelMapper::lastBarSetSection();
210 return QBarModelMapper::lastBarSetSection();
211 }
211 }
212
212
213 void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow)
213 void QHBarModelMapper::setLastBarSetRow(int lastBarSetRow)
214 {
214 {
215 if (lastBarSetRow != lastBarSetSection()) {
215 if (lastBarSetRow != lastBarSetSection()) {
216 QBarModelMapper::setLastBarSetSection(lastBarSetRow);
216 QBarModelMapper::setLastBarSetSection(lastBarSetRow);
217 emit lastBarSetRowChanged();
217 emit lastBarSetRowChanged();
218 }
218 }
219 }
219 }
220
220
221 int QHBarModelMapper::firstColumn() const
221 int QHBarModelMapper::firstColumn() const
222 {
222 {
223 return QBarModelMapper::first();
223 return QBarModelMapper::first();
224 }
224 }
225
225
226 void QHBarModelMapper::setFirstColumn(int firstColumn)
226 void QHBarModelMapper::setFirstColumn(int firstColumn)
227 {
227 {
228 if (firstColumn != first()) {
228 if (firstColumn != first()) {
229 QBarModelMapper::setFirst(firstColumn);
229 QBarModelMapper::setFirst(firstColumn);
230 emit firstColumnChanged();
230 emit firstColumnChanged();
231 }
231 }
232 }
232 }
233
233
234 int QHBarModelMapper::columnCount() const
234 int QHBarModelMapper::columnCount() const
235 {
235 {
236 return QBarModelMapper::count();
236 return QBarModelMapper::count();
237 }
237 }
238
238
239 void QHBarModelMapper::setColumnCount(int columnCount)
239 void QHBarModelMapper::setColumnCount(int columnCount)
240 {
240 {
241 if (columnCount != count()) {
241 if (columnCount != count()) {
242 QBarModelMapper::setCount(columnCount);
242 QBarModelMapper::setCount(columnCount);
243 emit firstColumnChanged();
243 emit firstColumnChanged();
244 }
244 }
245 }
245 }
246
246
247 #include "moc_qhbarmodelmapper.cpp"
247 #include "moc_qhbarmodelmapper.cpp"
248
248
249 QTCOMMERCIALCHART_END_NAMESPACE
249 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,70 +1,70
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QHBARMODELMAPPER_H
21 #ifndef QHBARMODELMAPPER_H
22 #define QHBARMODELMAPPER_H
22 #define QHBARMODELMAPPER_H
23
23
24 #include <QBarModelMapper>
24 #include <QBarModelMapper>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper
28 class QTCOMMERCIALCHART_EXPORT QHBarModelMapper : public QBarModelMapper
29 {
29 {
30 Q_OBJECT
30 Q_OBJECT
31 Q_PROPERTY(QBarSeries *series READ series WRITE setSeries NOTIFY seriesReplaced)
31 Q_PROPERTY(QAbstractBarSeries *series READ series WRITE setSeries NOTIFY seriesReplaced)
32 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced)
32 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced)
33 Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow NOTIFY firstBarSetRowChanged)
33 Q_PROPERTY(int firstBarSetRow READ firstBarSetRow WRITE setFirstBarSetRow NOTIFY firstBarSetRowChanged)
34 Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow NOTIFY lastBarSetRowChanged)
34 Q_PROPERTY(int lastBarSetRow READ lastBarSetRow WRITE setLastBarSetRow NOTIFY lastBarSetRowChanged)
35 Q_PROPERTY(int firstColumn READ firstColumn WRITE setFirstColumn NOTIFY firstColumnChanged)
35 Q_PROPERTY(int firstColumn READ firstColumn WRITE setFirstColumn NOTIFY firstColumnChanged)
36 Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount NOTIFY columnCountChanged)
36 Q_PROPERTY(int columnCount READ columnCount WRITE setColumnCount NOTIFY columnCountChanged)
37
37
38 public:
38 public:
39 explicit QHBarModelMapper(QObject *parent = 0);
39 explicit QHBarModelMapper(QObject *parent = 0);
40
40
41 QAbstractItemModel* model() const;
41 QAbstractItemModel* model() const;
42 void setModel(QAbstractItemModel *model);
42 void setModel(QAbstractItemModel *model);
43
43
44 QBarSeries* series() const;
44 QAbstractBarSeries* series() const;
45 void setSeries(QBarSeries *series);
45 void setSeries(QAbstractBarSeries *series);
46
46
47 int firstBarSetRow() const;
47 int firstBarSetRow() const;
48 void setFirstBarSetRow(int firstBarSetRow);
48 void setFirstBarSetRow(int firstBarSetRow);
49
49
50 int lastBarSetRow() const;
50 int lastBarSetRow() const;
51 void setLastBarSetRow(int lastBarSetRow);
51 void setLastBarSetRow(int lastBarSetRow);
52
52
53 int firstColumn() const;
53 int firstColumn() const;
54 void setFirstColumn(int firstColumn);
54 void setFirstColumn(int firstColumn);
55
55
56 int columnCount() const;
56 int columnCount() const;
57 void setColumnCount(int columnCount);
57 void setColumnCount(int columnCount);
58
58
59 Q_SIGNALS:
59 Q_SIGNALS:
60 void seriesReplaced();
60 void seriesReplaced();
61 void modelReplaced();
61 void modelReplaced();
62 void firstBarSetRowChanged();
62 void firstBarSetRowChanged();
63 void lastBarSetRowChanged();
63 void lastBarSetRowChanged();
64 void firstColumnChanged();
64 void firstColumnChanged();
65 void columnCountChanged();
65 void columnCountChanged();
66 };
66 };
67
67
68 QTCOMMERCIALCHART_END_NAMESPACE
68 QTCOMMERCIALCHART_END_NAMESPACE
69
69
70 #endif // QHBARMODELMAPPER_H
70 #endif // QHBARMODELMAPPER_H
@@ -1,117 +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 "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 #include "qcategoriesaxis.h"
27 #include "qcategoriesaxis.h"
28 #include "qvaluesaxis.h"
28 #include "qvaluesaxis.h"
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \class QPercentBarSeries
33 \class QPercentBarSeries
34 \brief Series for creating percent bar chart
34 \brief Series for creating percent bar chart
35 \mainclass
35 \mainclass
36
36
37 QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 QPercentBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 as stacks, where each bar is shown as percentage of all bars in that category.
38 as stacks, where each bar is shown as percentage of all bars in that category.
39 QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList.
39 QPercentBarSeries groups the data from sets to categories, which are defined by a QStringList.
40
40
41 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
41 See the \l {PercentbarChart Example} {percent bar chart example} to learn how to create a percent bar chart.
42 \image examples_percentbarchart.png
42 \image examples_percentbarchart.png
43
43
44 \sa QBarSet, QStackedBarSeries, QBarSeries
44 \sa QBarSet, QStackedBarSeries, QBarSeries
45 */
45 */
46 /*!
46 /*!
47 \qmlclass PercentBarSeries QPercentBarSeries
47 \qmlclass PercentBarSeries QPercentBarSeries
48 \inherits BarSeries
48 \inherits BarSeries
49
49
50 The following QML shows how to create a simple percent bar chart:
50 The following QML shows how to create a simple percent bar chart:
51 \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1
51 \snippet ../demos/qmlchart/qml/qmlchart/View9.qml 1
52 \beginfloatleft
52 \beginfloatleft
53 \image demos_qmlchart9.png
53 \image demos_qmlchart9.png
54 \endfloat
54 \endfloat
55 \clearfloat
55 \clearfloat
56 */
56 */
57
57
58 /*!
58 /*!
59 Constructs empty QPercentBarSeries.
59 Constructs empty QPercentBarSeries.
60 QPercentBarSeries is QObject which is a child of a \a parent.
60 QPercentBarSeries is QObject which is a child of a \a parent.
61 */
61 */
62 QPercentBarSeries::QPercentBarSeries(QObject *parent)
62 QPercentBarSeries::QPercentBarSeries(QObject *parent)
63 : QBarSeries(*new QPercentBarSeriesPrivate(this), parent)
63 : QAbstractBarSeries(*new QPercentBarSeriesPrivate(this), parent)
64 {
64 {
65 }
65 }
66
66
67 /*!
67 /*!
68 Returns QChartSeries::SeriesTypePercentBar.
68 Returns QChartSeries::SeriesTypePercentBar.
69 */
69 */
70 QAbstractSeries::SeriesType QPercentBarSeries::type() const
70 QAbstractSeries::SeriesType QPercentBarSeries::type() const
71 {
71 {
72 return QAbstractSeries::SeriesTypePercentBar;
72 return QAbstractSeries::SeriesTypePercentBar;
73 }
73 }
74
74
75 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
75 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76
76
77 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QBarSeriesPrivate(q)
77 QPercentBarSeriesPrivate::QPercentBarSeriesPrivate(QPercentBarSeries *q) : QAbstractBarSeriesPrivate(q)
78 {
78 {
79
79
80 }
80 }
81
81
82 void QPercentBarSeriesPrivate::scaleDomain(Domain& domain)
82 void QPercentBarSeriesPrivate::scaleDomain(Domain& domain)
83 {
83 {
84 qreal minX(domain.minX());
84 qreal minX(domain.minX());
85 qreal minY(domain.minY());
85 qreal minY(domain.minY());
86 qreal maxX(domain.maxX());
86 qreal maxX(domain.maxX());
87 qreal maxY(domain.maxY());
87 qreal maxY(domain.maxY());
88 int tickXCount(domain.tickXCount());
88 int tickXCount(domain.tickXCount());
89 int tickYCount(domain.tickYCount());
89 int tickYCount(domain.tickYCount());
90
90
91 qreal x = categoryCount();
91 qreal x = categoryCount();
92 minX = qMin(minX, -0.5);
92 minX = qMin(minX, -0.5);
93 maxX = qMax(maxX, x - 0.5);
93 maxX = qMax(maxX, x - 0.5);
94 minY = 0;
94 minY = 0;
95 maxY = 100;
95 maxY = 100;
96 tickXCount = x+1;
96 tickXCount = x+1;
97
97
98 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
98 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
99 }
99 }
100
100
101
101
102 Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
102 Chart* QPercentBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
103 {
103 {
104 Q_Q(QPercentBarSeries);
104 Q_Q(QPercentBarSeries);
105
105
106 PercentBarChartItem* bar = new PercentBarChartItem(q,presenter);
106 PercentBarChartItem* bar = new PercentBarChartItem(q,presenter);
107 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
107 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
108 presenter->animator()->addAnimation(bar);
108 presenter->animator()->addAnimation(bar);
109 }
109 }
110 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
110 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
111 return bar;
111 return bar;
112 }
112 }
113
113
114 #include "moc_qpercentbarseries.cpp"
114 #include "moc_qpercentbarseries.cpp"
115
115
116 QTCOMMERCIALCHART_END_NAMESPACE
116 QTCOMMERCIALCHART_END_NAMESPACE
117
117
@@ -1,45 +1,45
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef PERCENTBARSERIES_H
21 #ifndef PERCENTBARSERIES_H
22 #define PERCENTBARSERIES_H
22 #define PERCENTBARSERIES_H
23
23
24 #include <QStringList>
24 #include <QStringList>
25 #include <qbarseries.h>
25 #include <qbarseries.h>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QPercentBarSeriesPrivate;
29 class QPercentBarSeriesPrivate;
30
30
31 class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QBarSeries
31 class QTCOMMERCIALCHART_EXPORT QPercentBarSeries : public QAbstractBarSeries
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 public:
34 public:
35 explicit QPercentBarSeries(QObject *parent = 0);
35 explicit QPercentBarSeries(QObject *parent = 0);
36 QAbstractSeries::SeriesType type() const;
36 QAbstractSeries::SeriesType type() const;
37
37
38 private:
38 private:
39 Q_DECLARE_PRIVATE(QPercentBarSeries)
39 Q_DECLARE_PRIVATE(QPercentBarSeries)
40 Q_DISABLE_COPY(QPercentBarSeries)
40 Q_DISABLE_COPY(QPercentBarSeries)
41 };
41 };
42
42
43 QTCOMMERCIALCHART_END_NAMESPACE
43 QTCOMMERCIALCHART_END_NAMESPACE
44
44
45 #endif // PERCENTBARSERIES_H
45 #endif // PERCENTBARSERIES_H
@@ -1,51 +1,51
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QPERCENTBARSERIES_P_H
30 #ifndef QPERCENTBARSERIES_P_H
31 #define QPERCENTBARSERIES_P_H
31 #define QPERCENTBARSERIES_P_H
32
32
33 #include "qbarseries_p.h"
33 #include "qbarseries_p.h"
34 #include "domain_p.h"
34 #include "domain_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38
38
39 class QPercentBarSeriesPrivate: public QBarSeriesPrivate
39 class QPercentBarSeriesPrivate: public QAbstractBarSeriesPrivate
40 {
40 {
41 public:
41 public:
42 QPercentBarSeriesPrivate(QPercentBarSeries* q);
42 QPercentBarSeriesPrivate(QPercentBarSeries* q);
43 void scaleDomain(Domain& domain);
43 void scaleDomain(Domain& domain);
44 Chart* createGraphics(ChartPresenter* presenter);
44 Chart* createGraphics(ChartPresenter* presenter);
45 private:
45 private:
46 Q_DECLARE_PUBLIC(QPercentBarSeries)
46 Q_DECLARE_PUBLIC(QPercentBarSeries)
47 };
47 };
48
48
49 QTCOMMERCIALCHART_END_NAMESPACE
49 QTCOMMERCIALCHART_END_NAMESPACE
50
50
51 #endif
51 #endif
@@ -1,120 +1,120
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 #include "qcategoriesaxis.h"
27 #include "qcategoriesaxis.h"
28 #include "qvaluesaxis.h"
28 #include "qvaluesaxis.h"
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
31
32 /*!
32 /*!
33 \class QStackedBarSeries
33 \class QStackedBarSeries
34 \brief Series for creating stacked bar chart
34 \brief Series for creating stacked bar chart
35 \mainclass
35 \mainclass
36
36
37 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
37 QStackedBarSeries represents a series of data shown as bars. The purpose of this class is to draw bars
38 as stacks, where bars in same category are stacked on top of each other.
38 as stacks, where bars in same category are stacked on top of each other.
39 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
39 QStackedBarSeries groups the data from sets to categories, which are defined by QStringList.
40
40
41 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
41 See the \l {StackedbarChart Example} {stacked bar chart example} to learn how to create a stacked bar chart.
42 \image examples_stackedbarchart.png
42 \image examples_stackedbarchart.png
43
43
44 \sa QBarSet, QPercentBarSeries, QBarSeries
44 \sa QBarSet, QPercentBarSeries, QBarSeries
45 */
45 */
46
46
47 /*!
47 /*!
48 \qmlclass StackedBarSeries QStackedBarSeries
48 \qmlclass StackedBarSeries QStackedBarSeries
49 \inherits BarSeries
49 \inherits BarSeries
50
50
51 The following QML shows how to create a simple stacked bar chart:
51 The following QML shows how to create a simple stacked bar chart:
52 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
52 \snippet ../demos/qmlchart/qml/qmlchart/View8.qml 1
53 \beginfloatleft
53 \beginfloatleft
54 \image demos_qmlchart8.png
54 \image demos_qmlchart8.png
55 \endfloat
55 \endfloat
56 \clearfloat
56 \clearfloat
57 */
57 */
58
58
59 /*!
59 /*!
60 Constructs empty QStackedBarSeries.
60 Constructs empty QStackedBarSeries.
61 QStackedBarSeries is QObject which is a child of a \a parent.
61 QStackedBarSeries is QObject which is a child of a \a parent.
62 */
62 */
63 QStackedBarSeries::QStackedBarSeries(QObject *parent)
63 QStackedBarSeries::QStackedBarSeries(QObject *parent)
64 : QBarSeries(*new QStackedBarSeriesPrivate(this), parent)
64 : QAbstractBarSeries(*new QStackedBarSeriesPrivate(this), parent)
65 {
65 {
66 }
66 }
67
67
68 /*!
68 /*!
69 Returns QChartSeries::SeriesTypeStackedBar.
69 Returns QChartSeries::SeriesTypeStackedBar.
70 */
70 */
71 QAbstractSeries::SeriesType QStackedBarSeries::type() const
71 QAbstractSeries::SeriesType QStackedBarSeries::type() const
72 {
72 {
73 return QAbstractSeries::SeriesTypeStackedBar;
73 return QAbstractSeries::SeriesTypeStackedBar;
74 }
74 }
75
75
76 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
76 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
77
77
78 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QBarSeriesPrivate(q)
78 QStackedBarSeriesPrivate::QStackedBarSeriesPrivate(QStackedBarSeries *q) : QAbstractBarSeriesPrivate(q)
79 {
79 {
80
80
81 }
81 }
82
82
83 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
83 void QStackedBarSeriesPrivate::scaleDomain(Domain& domain)
84 {
84 {
85 qreal minX(domain.minX());
85 qreal minX(domain.minX());
86 qreal minY(domain.minY());
86 qreal minY(domain.minY());
87 qreal maxX(domain.maxX());
87 qreal maxX(domain.maxX());
88 qreal maxY(domain.maxY());
88 qreal maxY(domain.maxY());
89 int tickXCount(domain.tickXCount());
89 int tickXCount(domain.tickXCount());
90 int tickYCount(domain.tickYCount());
90 int tickYCount(domain.tickYCount());
91
91
92 qreal x = categoryCount();
92 qreal x = categoryCount();
93 qreal y = maxCategorySum();
93 qreal y = maxCategorySum();
94 minX = qMin(minX, -0.5);
94 minX = qMin(minX, -0.5);
95 minY = qMin(minY, y);
95 minY = qMin(minY, y);
96 maxX = qMax(maxX, x - 0.5);
96 maxX = qMax(maxX, x - 0.5);
97 maxY = qMax(maxY, y);
97 maxY = qMax(maxY, y);
98 tickXCount = x+1;
98 tickXCount = x+1;
99
99
100 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
100 domain.setRange(minX,maxX,minY,maxY,tickXCount,tickYCount);
101 }
101 }
102
102
103
103
104 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
104 Chart* QStackedBarSeriesPrivate::createGraphics(ChartPresenter* presenter)
105 {
105 {
106 Q_Q(QStackedBarSeries);
106 Q_Q(QStackedBarSeries);
107
107
108 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
108 StackedBarChartItem* bar = new StackedBarChartItem(q,presenter);
109 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
109 if(presenter->animationOptions().testFlag(QChart::SeriesAnimations)) {
110 presenter->animator()->addAnimation(bar);
110 presenter->animator()->addAnimation(bar);
111 }
111 }
112 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
112 presenter->chartTheme()->decorate(q, presenter->dataSet()->seriesIndex(q));
113 return bar;
113 return bar;
114 }
114 }
115
115
116
116
117 #include "moc_qstackedbarseries.cpp"
117 #include "moc_qstackedbarseries.cpp"
118
118
119 QTCOMMERCIALCHART_END_NAMESPACE
119 QTCOMMERCIALCHART_END_NAMESPACE
120
120
@@ -1,45 +1,45
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef STACKEDBARSERIES_H
21 #ifndef STACKEDBARSERIES_H
22 #define STACKEDBARSERIES_H
22 #define STACKEDBARSERIES_H
23
23
24 #include <QStringList>
24 #include <QStringList>
25 #include <qbarseries.h>
25 #include <qbarseries.h>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 class QStackedBarSeriesPrivate;
29 class QStackedBarSeriesPrivate;
30
30
31 class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QBarSeries
31 class QTCOMMERCIALCHART_EXPORT QStackedBarSeries : public QAbstractBarSeries
32 {
32 {
33 Q_OBJECT
33 Q_OBJECT
34 public:
34 public:
35 explicit QStackedBarSeries(QObject *parent = 0);
35 explicit QStackedBarSeries(QObject *parent = 0);
36 QAbstractSeries::SeriesType type() const;
36 QAbstractSeries::SeriesType type() const;
37
37
38 private:
38 private:
39 Q_DECLARE_PRIVATE(QStackedBarSeries)
39 Q_DECLARE_PRIVATE(QStackedBarSeries)
40 Q_DISABLE_COPY(QStackedBarSeries)
40 Q_DISABLE_COPY(QStackedBarSeries)
41 };
41 };
42
42
43 QTCOMMERCIALCHART_END_NAMESPACE
43 QTCOMMERCIALCHART_END_NAMESPACE
44
44
45 #endif // STACKEDBARSERIES_H
45 #endif // STACKEDBARSERIES_H
@@ -1,52 +1,52
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef QSTACKEDBARSERIES_P_H
30 #ifndef QSTACKEDBARSERIES_P_H
31 #define QSTACKEDBARSERIES_P_H
31 #define QSTACKEDBARSERIES_P_H
32
32
33 #include "qbarseries_p.h"
33 #include "qbarseries_p.h"
34 #include "domain_p.h"
34 #include "domain_p.h"
35
35
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37
37
38
38
39 class QStackedBarSeriesPrivate: public QBarSeriesPrivate
39 class QStackedBarSeriesPrivate: public QAbstractBarSeriesPrivate
40 {
40 {
41 public:
41 public:
42 QStackedBarSeriesPrivate(QStackedBarSeries* q);
42 QStackedBarSeriesPrivate(QStackedBarSeries* q);
43 Chart* createGraphics(ChartPresenter* presenter);
43 Chart* createGraphics(ChartPresenter* presenter);
44 void scaleDomain(Domain& domain);
44 void scaleDomain(Domain& domain);
45
45
46 private:
46 private:
47 Q_DECLARE_PUBLIC(QStackedBarSeries)
47 Q_DECLARE_PUBLIC(QStackedBarSeries)
48 };
48 };
49
49
50 QTCOMMERCIALCHART_END_NAMESPACE
50 QTCOMMERCIALCHART_END_NAMESPACE
51
51
52 #endif
52 #endif
@@ -1,248 +1,248
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 "qvbarmodelmapper.h"
21 #include "qvbarmodelmapper.h"
22
22
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
23 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24
24
25 /*!
25 /*!
26 \class QVBarModelMapper
26 \class QVBarModelMapper
27 \brief Vertical model mapper for bar series
27 \brief Vertical model mapper for bar series
28 \mainclass
28 \mainclass
29
29
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
30 Model mappers allow you to use QAbstractItemModel derived models as a data source for a chart series.
31 Vertical model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object.
31 Vertical model mapper is used to create a connection between QBarSeries and QAbstractItemModel derived model object.
32 Model mapper maintains equal size of all the BarSets.
32 Model mapper maintains equal size of all the BarSets.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
33 Adding/removing value from the BarSet causes the the same change in the rest of the BarSets added to the same series.
34 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
34 NOTE: used model has to support adding/removing rows/columns and modifying the data of the cells.
35 */
35 */
36 /*!
36 /*!
37 \qmlclass VBarModelMapper
37 \qmlclass VBarModelMapper
38 \mainclass
38 \mainclass
39
39
40 VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
40 VBarModelMapper allows you to use your own QAbstractItemModel derived model with data in columns as a data source
41 for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data.
41 for any bar series. It is possible to use both QAbstractItemModel and bar series data API to manipulate data.
42 VBarModelMapper keeps the series and the model in sync.
42 VBarModelMapper keeps the series and the model in sync.
43
43
44 The following QML example would create a bar series with three bar sets (assuming the
44 The following QML example would create a bar series with three bar sets (assuming the
45 model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be
45 model has at least four columns). Each bar set would contain data starting from row 1. The name of a set would be
46 defined by the horizontal header (of the column).
46 defined by the horizontal header (of the column).
47 \code
47 \code
48 GroupedBarSeries {
48 GroupedBarSeries {
49 VBarModelMapper {
49 VBarModelMapper {
50 model: myCustomModel // QAbstractItemModel derived implementation
50 model: myCustomModel // QAbstractItemModel derived implementation
51 firstBarSetColumn: 1
51 firstBarSetColumn: 1
52 lastBarSetColumn: 3
52 lastBarSetColumn: 3
53 firstRow: 1
53 firstRow: 1
54 }
54 }
55 }
55 }
56 \endcode
56 \endcode
57 */
57 */
58
58
59 /*!
59 /*!
60 \property QVBarModelMapper::series
60 \property QVBarModelMapper::series
61 \brief Defines the QPieSeries object that is used by the mapper.
61 \brief Defines the QPieSeries object that is used by the mapper.
62
62
63 All the data in the series is discarded when it is set to the mapper.
63 All the data in the series is discarded when it is set to the mapper.
64 When new series is specified the old series is disconnected (it preserves its data)
64 When new series is specified the old series is disconnected (it preserves its data)
65 */
65 */
66 /*!
66 /*!
67 \qmlproperty BarSeries VBarModelMapper::series
67 \qmlproperty BarSeries VBarModelMapper::series
68 Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is
68 Defines the BarSeries based object that is used by the mapper. All the data in the series is discarded when it is
69 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
69 set to the mapper. When new series is specified the old series is disconnected (it preserves its data).
70 */
70 */
71
71
72 /*!
72 /*!
73 \property QVBarModelMapper::model
73 \property QVBarModelMapper::model
74 \brief Defines the model that is used by the mapper.
74 \brief Defines the model that is used by the mapper.
75 */
75 */
76 /*!
76 /*!
77 \qmlproperty SomeModel VBarModelMapper::model
77 \qmlproperty SomeModel VBarModelMapper::model
78 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
78 The QAbstractItemModel based model that is used by the mapper. You need to implement the model and expose it to
79 QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns
79 QML as shown in \l {QML Custom Model} demo application. NOTE: the model has to support adding/removing rows/columns
80 and modifying the data of the cells.
80 and modifying the data of the cells.
81 */
81 */
82
82
83 /*!
83 /*!
84 \property QVBarModelMapper::firstBarSetColumn
84 \property QVBarModelMapper::firstBarSetColumn
85 \brief Defines which column of the model is used as the data source for the first bar set
85 \brief Defines which column of the model is used as the data source for the first bar set
86 Default value is: -1 (invalid mapping)
86 Default value is: -1 (invalid mapping)
87 */
87 */
88 /*!
88 /*!
89 \qmlproperty int VBarModelMapper::firstBarSetColumn
89 \qmlproperty int VBarModelMapper::firstBarSetColumn
90 Defines which column of the model is used as the data source for the first bar set. Default value
90 Defines which column of the model is used as the data source for the first bar set. Default value
91 is: -1 (invalid mapping).
91 is: -1 (invalid mapping).
92 */
92 */
93
93
94 /*!
94 /*!
95 \property QVBarModelMapper::lastBarSetColumn
95 \property QVBarModelMapper::lastBarSetColumn
96 \brief Defines which column of the model is used as the data source for the last bar set
96 \brief Defines which column of the model is used as the data source for the last bar set
97 Default value is: -1 (invalid mapping)
97 Default value is: -1 (invalid mapping)
98 */
98 */
99 /*!
99 /*!
100 \qmlproperty int VBarModelMapper::lastBarSetColumn
100 \qmlproperty int VBarModelMapper::lastBarSetColumn
101 Defines which column of the model is used as the data source for the last bar set. Default
101 Defines which column of the model is used as the data source for the last bar set. Default
102 value is: -1 (invalid mapping).
102 value is: -1 (invalid mapping).
103 */
103 */
104
104
105 /*!
105 /*!
106 \property QVBarModelMapper::firstRow
106 \property QVBarModelMapper::firstRow
107 \brief Defines which row of the model contains the first values of the QBarSets in the series.
107 \brief Defines which row of the model contains the first values of the QBarSets in the series.
108 Minimal and default value is: 0
108 Minimal and default value is: 0
109 */
109 */
110 /*!
110 /*!
111 \qmlproperty int VBarModelMapper::firstRow
111 \qmlproperty int VBarModelMapper::firstRow
112 Defines which row of the model contains the first values of the QBarSets in the series.
112 Defines which row of the model contains the first values of the QBarSets in the series.
113 The default value is 0.
113 The default value is 0.
114 */
114 */
115
115
116 /*!
116 /*!
117 \property QVBarModelMapper::rowCount
117 \property QVBarModelMapper::rowCount
118 \brief Defines the number of rows of the model that are mapped as the data for QBarSeries
118 \brief Defines the number of rows of the model that are mapped as the data for QBarSeries
119 Minimal and default value is: -1 (count limited by the number of rows in the model)
119 Minimal and default value is: -1 (count limited by the number of rows in the model)
120 */
120 */
121 /*!
121 /*!
122 \qmlproperty int VBarModelMapper::rowCount
122 \qmlproperty int VBarModelMapper::rowCount
123 Defines the number of rows of the model that are mapped as the data for QBarSeries. The default value is
123 Defines the number of rows of the model that are mapped as the data for QBarSeries. The default value is
124 -1 (count limited by the number of rows in the model)
124 -1 (count limited by the number of rows in the model)
125 */
125 */
126
126
127 /*!
127 /*!
128 \fn void QVBarModelMapper::seriesReplaced()
128 \fn void QVBarModelMapper::seriesReplaced()
129
129
130 Emitted when the series to which mapper is connected to has changed.
130 Emitted when the series to which mapper is connected to has changed.
131 */
131 */
132
132
133 /*!
133 /*!
134 \fn void QVBarModelMapper::modelReplaced()
134 \fn void QVBarModelMapper::modelReplaced()
135
135
136 Emitted when the model to which mapper is connected to has changed.
136 Emitted when the model to which mapper is connected to has changed.
137 */
137 */
138
138
139 /*!
139 /*!
140 \fn void QVBarModelMapper::firstBarSetColumnChanged()
140 \fn void QVBarModelMapper::firstBarSetColumnChanged()
141 Emitted when the firstBarSetColumn has changed.
141 Emitted when the firstBarSetColumn has changed.
142 */
142 */
143
143
144 /*!
144 /*!
145 \fn void QVBarModelMapper::lastBarSetColumnChanged()
145 \fn void QVBarModelMapper::lastBarSetColumnChanged()
146 Emitted when the lastBarSetColumn has changed.
146 Emitted when the lastBarSetColumn has changed.
147 */
147 */
148
148
149 /*!
149 /*!
150 \fn void QVBarModelMapper::firstRowChanged()
150 \fn void QVBarModelMapper::firstRowChanged()
151 Emitted when the firstRow has changed.
151 Emitted when the firstRow has changed.
152 */
152 */
153
153
154 /*!
154 /*!
155 \fn void QVBarModelMapper::rowCountChanged()
155 \fn void QVBarModelMapper::rowCountChanged()
156 Emitted when the rowCount has changed.
156 Emitted when the rowCount has changed.
157 */
157 */
158
158
159 /*!
159 /*!
160 Constructs a mapper object which is a child of \a parent.
160 Constructs a mapper object which is a child of \a parent.
161 */
161 */
162 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
162 QVBarModelMapper::QVBarModelMapper(QObject *parent) :
163 QBarModelMapper(parent)
163 QBarModelMapper(parent)
164 {
164 {
165 QBarModelMapper::setOrientation(Qt::Vertical);
165 QBarModelMapper::setOrientation(Qt::Vertical);
166 }
166 }
167
167
168 QAbstractItemModel* QVBarModelMapper::model() const
168 QAbstractItemModel* QVBarModelMapper::model() const
169 {
169 {
170 return QBarModelMapper::model();
170 return QBarModelMapper::model();
171 }
171 }
172
172
173 void QVBarModelMapper::setModel(QAbstractItemModel *model)
173 void QVBarModelMapper::setModel(QAbstractItemModel *model)
174 {
174 {
175 if (model != QBarModelMapper::model()) {
175 if (model != QBarModelMapper::model()) {
176 QBarModelMapper::setModel(model);
176 QBarModelMapper::setModel(model);
177 emit modelReplaced();
177 emit modelReplaced();
178 }
178 }
179 }
179 }
180
180
181 QBarSeries* QVBarModelMapper::series() const
181 QAbstractBarSeries* QVBarModelMapper::series() const
182 {
182 {
183 return QBarModelMapper::series();
183 return QBarModelMapper::series();
184 }
184 }
185
185
186 void QVBarModelMapper::setSeries(QBarSeries *series)
186 void QVBarModelMapper::setSeries(QAbstractBarSeries *series)
187 {
187 {
188 if (series != QBarModelMapper::series()) {
188 if (series != QBarModelMapper::series()) {
189 QBarModelMapper::setSeries(series);
189 QBarModelMapper::setSeries(series);
190 emit seriesReplaced();
190 emit seriesReplaced();
191 }
191 }
192 }
192 }
193
193
194 int QVBarModelMapper::firstBarSetColumn() const
194 int QVBarModelMapper::firstBarSetColumn() const
195 {
195 {
196 return QBarModelMapper::firstBarSetSection();
196 return QBarModelMapper::firstBarSetSection();
197 }
197 }
198
198
199 void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn)
199 void QVBarModelMapper::setFirstBarSetColumn(int firstBarSetColumn)
200 {
200 {
201 if (firstBarSetColumn != firstBarSetSection()) {
201 if (firstBarSetColumn != firstBarSetSection()) {
202 QBarModelMapper::setFirstBarSetSection(firstBarSetColumn);
202 QBarModelMapper::setFirstBarSetSection(firstBarSetColumn);
203 emit firstBarSetColumnChanged();
203 emit firstBarSetColumnChanged();
204 }
204 }
205 }
205 }
206
206
207 int QVBarModelMapper::lastBarSetColumn() const
207 int QVBarModelMapper::lastBarSetColumn() const
208 {
208 {
209 return QBarModelMapper::lastBarSetSection();
209 return QBarModelMapper::lastBarSetSection();
210 }
210 }
211
211
212 void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn)
212 void QVBarModelMapper::setLastBarSetColumn(int lastBarSetColumn)
213 {
213 {
214 if (lastBarSetColumn != lastBarSetSection()) {
214 if (lastBarSetColumn != lastBarSetSection()) {
215 QBarModelMapper::setLastBarSetSection(lastBarSetColumn);
215 QBarModelMapper::setLastBarSetSection(lastBarSetColumn);
216 emit lastBarSetColumnChanged();
216 emit lastBarSetColumnChanged();
217 }
217 }
218 }
218 }
219
219
220 int QVBarModelMapper::firstRow() const
220 int QVBarModelMapper::firstRow() const
221 {
221 {
222 return QBarModelMapper::first();
222 return QBarModelMapper::first();
223 }
223 }
224
224
225 void QVBarModelMapper::setFirstRow(int firstRow)
225 void QVBarModelMapper::setFirstRow(int firstRow)
226 {
226 {
227 if (firstRow != first()) {
227 if (firstRow != first()) {
228 QBarModelMapper::setFirst(firstRow);
228 QBarModelMapper::setFirst(firstRow);
229 emit firstRowChanged();
229 emit firstRowChanged();
230 }
230 }
231 }
231 }
232
232
233 int QVBarModelMapper::rowCount() const
233 int QVBarModelMapper::rowCount() const
234 {
234 {
235 return QBarModelMapper::count();
235 return QBarModelMapper::count();
236 }
236 }
237
237
238 void QVBarModelMapper::setRowCount(int rowCount)
238 void QVBarModelMapper::setRowCount(int rowCount)
239 {
239 {
240 if (rowCount != count()) {
240 if (rowCount != count()) {
241 QBarModelMapper::setCount(rowCount);
241 QBarModelMapper::setCount(rowCount);
242 emit firstRowChanged();
242 emit firstRowChanged();
243 }
243 }
244 }
244 }
245
245
246 #include "moc_qvbarmodelmapper.cpp"
246 #include "moc_qvbarmodelmapper.cpp"
247
247
248 QTCOMMERCIALCHART_END_NAMESPACE
248 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,70 +1,70
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef QVBARMODELMAPPER_H
21 #ifndef QVBARMODELMAPPER_H
22 #define QVBARMODELMAPPER_H
22 #define QVBARMODELMAPPER_H
23
23
24 #include <QBarModelMapper>
24 #include <QBarModelMapper>
25
25
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27
27
28 class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper
28 class QTCOMMERCIALCHART_EXPORT QVBarModelMapper : public QBarModelMapper
29 {
29 {
30 Q_OBJECT
30 Q_OBJECT
31 Q_PROPERTY(QBarSeries *series READ series WRITE setSeries NOTIFY seriesReplaced)
31 Q_PROPERTY(QAbstractBarSeries *series READ series WRITE setSeries NOTIFY seriesReplaced)
32 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced)
32 Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelReplaced)
33 Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn NOTIFY firstBarSetColumnChanged)
33 Q_PROPERTY(int firstBarSetColumn READ firstBarSetColumn WRITE setFirstBarSetColumn NOTIFY firstBarSetColumnChanged)
34 Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn NOTIFY lastBarSetColumnChanged)
34 Q_PROPERTY(int lastBarSetColumn READ lastBarSetColumn WRITE setLastBarSetColumn NOTIFY lastBarSetColumnChanged)
35 Q_PROPERTY(int firstRow READ firstRow WRITE setFirstRow NOTIFY firstRowChanged)
35 Q_PROPERTY(int firstRow READ firstRow WRITE setFirstRow NOTIFY firstRowChanged)
36 Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged)
36 Q_PROPERTY(int rowCount READ rowCount WRITE setRowCount NOTIFY rowCountChanged)
37
37
38 public:
38 public:
39 explicit QVBarModelMapper(QObject *parent = 0);
39 explicit QVBarModelMapper(QObject *parent = 0);
40
40
41 QAbstractItemModel* model() const;
41 QAbstractItemModel* model() const;
42 void setModel(QAbstractItemModel *model);
42 void setModel(QAbstractItemModel *model);
43
43
44 QBarSeries* series() const;
44 QAbstractBarSeries* series() const;
45 void setSeries(QBarSeries *series);
45 void setSeries(QAbstractBarSeries *series);
46
46
47 int firstBarSetColumn() const;
47 int firstBarSetColumn() const;
48 void setFirstBarSetColumn(int firstBarSetColumn);
48 void setFirstBarSetColumn(int firstBarSetColumn);
49
49
50 int lastBarSetColumn() const;
50 int lastBarSetColumn() const;
51 void setLastBarSetColumn(int lastBarSetColumn);
51 void setLastBarSetColumn(int lastBarSetColumn);
52
52
53 int firstRow() const;
53 int firstRow() const;
54 void setFirstRow(int firstRow);
54 void setFirstRow(int firstRow);
55
55
56 int rowCount() const;
56 int rowCount() const;
57 void setRowCount(int rowCount);
57 void setRowCount(int rowCount);
58
58
59 Q_SIGNALS:
59 Q_SIGNALS:
60 void seriesReplaced();
60 void seriesReplaced();
61 void modelReplaced();
61 void modelReplaced();
62 void firstBarSetColumnChanged();
62 void firstBarSetColumnChanged();
63 void lastBarSetColumnChanged();
63 void lastBarSetColumnChanged();
64 void firstRowChanged();
64 void firstRowChanged();
65 void rowCountChanged();
65 void rowCountChanged();
66 };
66 };
67
67
68 QTCOMMERCIALCHART_END_NAMESPACE
68 QTCOMMERCIALCHART_END_NAMESPACE
69
69
70 #endif // QVBARMODELMAPPER_H
70 #endif // QVBARMODELMAPPER_H
@@ -1,101 +1,101
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 "stackedbarchartitem_p.h"
21 #include "stackedbarchartitem_p.h"
22 #include "bar_p.h"
22 #include "bar_p.h"
23 #include "qbarset_p.h"
23 #include "qbarset_p.h"
24 #include "qbarseries_p.h"
24 #include "qbarseries_p.h"
25 #include "qbarset.h"
25 #include "qbarset.h"
26 #include "chartanimator_p.h"
26 #include "chartanimator_p.h"
27
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29
29
30 StackedBarChartItem::StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter) :
30 StackedBarChartItem::StackedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter) :
31 BarChartItem(series, presenter)
31 BarChartItem(series, presenter)
32 {
32 {
33 }
33 }
34
34
35 QVector<QRectF> StackedBarChartItem::calculateLayout()
35 QVector<QRectF> StackedBarChartItem::calculateLayout()
36 {
36 {
37 QVector<QRectF> layout;
37 QVector<QRectF> layout;
38 // Use temporary qreals for accuracy
38 // Use temporary qreals for accuracy
39 qreal categoryCount = m_series->d_func()->categoryCount();
39 qreal categoryCount = m_series->d_func()->categoryCount();
40 qreal setCount = m_series->count();
40 qreal setCount = m_series->count();
41 bool barsVisible = m_series->isVisible();
41 bool barsVisible = m_series->isVisible();
42
42
43 // Domain:
43 // Domain:
44 qreal width = geometry().width();
44 qreal width = geometry().width();
45 qreal height = geometry().height();
45 qreal height = geometry().height();
46 qreal rangeY = m_domainMaxY - m_domainMinY;
46 qreal rangeY = m_domainMaxY - m_domainMinY;
47 qreal rangeX = m_domainMaxX - m_domainMinX;
47 qreal rangeX = m_domainMaxX - m_domainMinX;
48 qreal scaleY = (height / rangeY);
48 qreal scaleY = (height / rangeY);
49 qreal scaleX = (width / rangeX);
49 qreal scaleX = (width / rangeX);
50 qreal barWidth = scaleX * m_series->d_func()->barWidth();
50 qreal barWidth = scaleX * m_series->d_func()->barWidth();
51
51
52 int itemIndex(0);
52 int itemIndex(0);
53 for (int category = 0; category < categoryCount; category++) {
53 for (int category = 0; category < categoryCount; category++) {
54 qreal yPos = height + rangeY * m_domainMinY + geometry().topLeft().y();
54 qreal yPos = height + rangeY * m_domainMinY + geometry().topLeft().y();
55 for (int set=0; set < setCount; set++) {
55 for (int set=0; set < setCount; set++) {
56 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
56 QBarSetPrivate* barSet = m_series->d_func()->barsetAt(set)->d_ptr.data();
57
57
58 qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
58 qreal xPos = (barSet->m_values.at(category).x() - m_domainMinX) * scaleX + m_rect.left() - barWidth/2;
59
59
60 qreal barHeight = barSet->m_values.at(category).y() * scaleY;
60 qreal barHeight = barSet->m_values.at(category).y() * scaleY;
61 Bar* bar = m_bars.at(itemIndex);
61 Bar* bar = m_bars.at(itemIndex);
62 bar->setPen(barSet->m_pen);
62 bar->setPen(barSet->m_pen);
63 bar->setBrush(barSet->m_brush);
63 bar->setBrush(barSet->m_brush);
64 bar->setVisible(barsVisible);
64 bar->setVisible(barsVisible);
65
65
66 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
66 QRectF rect(xPos, yPos-barHeight, barWidth, barHeight);
67 layout.append(rect);
67 layout.append(rect);
68
68
69 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
69 QGraphicsSimpleTextItem* label = m_labels.at(itemIndex);
70
70
71 if (!qFuzzyIsNull(barSet->m_values.at(category).y())) {
71 if (!qFuzzyIsNull(barSet->m_values.at(category).y())) {
72 label->setText(QString::number(barSet->m_values.at(category).y()));
72 label->setText(QString::number(barSet->m_values.at(category).y()));
73 } else {
73 } else {
74 label->setText(QString(""));
74 label->setText(QString(""));
75 }
75 }
76
76
77 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
77 label->setPos(xPos + (rect.width()/2 - label->boundingRect().width()/2)
78 ,yPos - barHeight/2 - label->boundingRect().height()/2);
78 ,yPos - barHeight/2 - label->boundingRect().height()/2);
79 label->setFont(barSet->m_labelFont);
79 label->setFont(barSet->m_labelFont);
80 label->setBrush(barSet->m_labelBrush);
80 label->setBrush(barSet->m_labelBrush);
81 itemIndex++;
81 itemIndex++;
82 yPos -= barHeight;
82 yPos -= barHeight;
83 }
83 }
84 }
84 }
85
85
86 return layout;
86 return layout;
87 }
87 }
88
88
89 void StackedBarChartItem::applyLayout(const QVector<QRectF> &layout)
89 void StackedBarChartItem::applyLayout(const QVector<QRectF> &layout)
90 {
90 {
91 if (animator()) {
91 if (animator()) {
92 animator()->updateLayout(this, m_layout, layout);
92 animator()->updateLayout(this, m_layout, layout);
93 } else {
93 } else {
94 setLayout(layout);
94 setLayout(layout);
95 update();
95 update();
96 }
96 }
97 }
97 }
98
98
99 #include "moc_stackedbarchartitem_p.cpp"
99 #include "moc_stackedbarchartitem_p.cpp"
100
100
101 QTCOMMERCIALCHART_END_NAMESPACE
101 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,53 +1,53
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30
30
31 #ifndef STACKEDBARCHARTITEM_H
31 #ifndef STACKEDBARCHARTITEM_H
32 #define STACKEDBARCHARTITEM_H
32 #define STACKEDBARCHARTITEM_H
33
33
34 #include "barchartitem_p.h"
34 #include "barchartitem_p.h"
35 #include "qstackedbarseries.h"
35 #include "qstackedbarseries.h"
36 #include <QGraphicsItem>
36 #include <QGraphicsItem>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class StackedBarChartItem : public BarChartItem
40 class StackedBarChartItem : public BarChartItem
41 {
41 {
42 Q_OBJECT
42 Q_OBJECT
43 public:
43 public:
44 StackedBarChartItem(QBarSeries *series, ChartPresenter *presenter);
44 StackedBarChartItem(QAbstractBarSeries *series, ChartPresenter *presenter);
45
45
46 private:
46 private:
47 virtual QVector<QRectF> calculateLayout();
47 virtual QVector<QRectF> calculateLayout();
48 virtual void applyLayout(const QVector<QRectF> &layout);
48 virtual void applyLayout(const QVector<QRectF> &layout);
49 };
49 };
50
50
51 QTCOMMERCIALCHART_END_NAMESPACE
51 QTCOMMERCIALCHART_END_NAMESPACE
52
52
53 #endif // STACKEDBARCHARTITEM_H
53 #endif // STACKEDBARCHARTITEM_H
@@ -1,389 +1,389
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 "charttheme_p.h"
21 #include "charttheme_p.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qchart_p.h"
23 #include "qchart_p.h"
24 #include "qchartview.h"
24 #include "qchartview.h"
25 #include "qlegend.h"
25 #include "qlegend.h"
26 #include "qabstractaxis.h"
26 #include "qabstractaxis.h"
27 #include <QTime>
27 #include <QTime>
28
28
29 //series
29 //series
30 #include "qbarset.h"
30 #include "qbarset.h"
31 #include "qbarseries.h"
31 #include "qbarseries.h"
32 #include "qstackedbarseries.h"
32 #include "qstackedbarseries.h"
33 #include "qpercentbarseries.h"
33 #include "qpercentbarseries.h"
34 #include "qlineseries.h"
34 #include "qlineseries.h"
35 #include "qareaseries.h"
35 #include "qareaseries.h"
36 #include "qscatterseries.h"
36 #include "qscatterseries.h"
37 #include "qpieseries.h"
37 #include "qpieseries.h"
38 #include "qpieslice.h"
38 #include "qpieslice.h"
39 #include "qpieslice_p.h"
39 #include "qpieslice_p.h"
40 #include "qsplineseries.h"
40 #include "qsplineseries.h"
41
41
42 //items
42 //items
43 #include "chartaxis_p.h"
43 #include "chartaxis_p.h"
44 #include "barchartitem_p.h"
44 #include "barchartitem_p.h"
45 #include "stackedbarchartitem_p.h"
45 #include "stackedbarchartitem_p.h"
46 #include "percentbarchartitem_p.h"
46 #include "percentbarchartitem_p.h"
47 #include "linechartitem_p.h"
47 #include "linechartitem_p.h"
48 #include "areachartitem_p.h"
48 #include "areachartitem_p.h"
49 #include "scatterchartitem_p.h"
49 #include "scatterchartitem_p.h"
50 #include "piechartitem_p.h"
50 #include "piechartitem_p.h"
51 #include "splinechartitem_p.h"
51 #include "splinechartitem_p.h"
52
52
53 //themes
53 //themes
54 #include "chartthemesystem_p.h"
54 #include "chartthemesystem_p.h"
55 #include "chartthemelight_p.h"
55 #include "chartthemelight_p.h"
56 #include "chartthemebluecerulean_p.h"
56 #include "chartthemebluecerulean_p.h"
57 #include "chartthemedark_p.h"
57 #include "chartthemedark_p.h"
58 #include "chartthemebrownsand_p.h"
58 #include "chartthemebrownsand_p.h"
59 #include "chartthemebluencs_p.h"
59 #include "chartthemebluencs_p.h"
60 #include "chartthemehighcontrast_p.h"
60 #include "chartthemehighcontrast_p.h"
61 #include "chartthemeblueicy_p.h"
61 #include "chartthemeblueicy_p.h"
62
62
63 QTCOMMERCIALCHART_BEGIN_NAMESPACE
63 QTCOMMERCIALCHART_BEGIN_NAMESPACE
64
64
65 ChartTheme::ChartTheme(QChart::ChartTheme id) :
65 ChartTheme::ChartTheme(QChart::ChartTheme id) :
66 m_masterFont(QFont("arial", 14)),
66 m_masterFont(QFont("arial", 14)),
67 m_labelFont(QFont("arial", 10)),
67 m_labelFont(QFont("arial", 10)),
68 m_labelBrush(QColor(QRgb(0x000000))),
68 m_labelBrush(QColor(QRgb(0x000000))),
69 m_axisLinePen(QPen(QRgb(0x000000))),
69 m_axisLinePen(QPen(QRgb(0x000000))),
70 m_backgroundShadesPen(Qt::NoPen),
70 m_backgroundShadesPen(Qt::NoPen),
71 m_backgroundShadesBrush(Qt::NoBrush),
71 m_backgroundShadesBrush(Qt::NoBrush),
72 m_backgroundShades(BackgroundShadesNone),
72 m_backgroundShades(BackgroundShadesNone),
73 m_backgroundDropShadowEnabled(false),
73 m_backgroundDropShadowEnabled(false),
74 m_gridLinePen(QPen(QRgb(0x000000))),
74 m_gridLinePen(QPen(QRgb(0x000000))),
75 m_force(false)
75 m_force(false)
76 {
76 {
77 m_id = id;
77 m_id = id;
78 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
78 qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
79 }
79 }
80
80
81
81
82 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
82 ChartTheme* ChartTheme::createTheme(QChart::ChartTheme theme)
83 {
83 {
84 switch(theme) {
84 switch(theme) {
85 case QChart::ChartThemeLight:
85 case QChart::ChartThemeLight:
86 return new ChartThemeLight();
86 return new ChartThemeLight();
87 case QChart::ChartThemeBlueCerulean:
87 case QChart::ChartThemeBlueCerulean:
88 return new ChartThemeBlueCerulean();
88 return new ChartThemeBlueCerulean();
89 case QChart::ChartThemeDark:
89 case QChart::ChartThemeDark:
90 return new ChartThemeDark();
90 return new ChartThemeDark();
91 case QChart::ChartThemeBrownSand:
91 case QChart::ChartThemeBrownSand:
92 return new ChartThemeBrownSand();
92 return new ChartThemeBrownSand();
93 case QChart::ChartThemeBlueNcs:
93 case QChart::ChartThemeBlueNcs:
94 return new ChartThemeBlueNcs();
94 return new ChartThemeBlueNcs();
95 case QChart::ChartThemeHighContrast:
95 case QChart::ChartThemeHighContrast:
96 return new ChartThemeHighContrast();
96 return new ChartThemeHighContrast();
97 case QChart::ChartThemeBlueIcy:
97 case QChart::ChartThemeBlueIcy:
98 return new ChartThemeBlueIcy();
98 return new ChartThemeBlueIcy();
99 default:
99 default:
100 return new ChartThemeSystem();
100 return new ChartThemeSystem();
101 }
101 }
102 }
102 }
103
103
104 void ChartTheme::decorate(QChart *chart)
104 void ChartTheme::decorate(QChart *chart)
105 {
105 {
106 QBrush brush;
106 QBrush brush;
107
107
108 if(brush == chart->backgroundBrush() || m_force)
108 if(brush == chart->backgroundBrush() || m_force)
109 chart->setBackgroundBrush(m_chartBackgroundGradient);
109 chart->setBackgroundBrush(m_chartBackgroundGradient);
110 chart->setTitleFont(m_masterFont);
110 chart->setTitleFont(m_masterFont);
111 chart->setTitleBrush(m_labelBrush);
111 chart->setTitleBrush(m_labelBrush);
112 chart->setDropShadowEnabled(m_backgroundDropShadowEnabled);
112 chart->setDropShadowEnabled(m_backgroundDropShadowEnabled);
113 }
113 }
114
114
115 void ChartTheme::decorate(QLegend *legend)
115 void ChartTheme::decorate(QLegend *legend)
116 {
116 {
117 QPen pen;
117 QPen pen;
118 QBrush brush;
118 QBrush brush;
119 QFont font;
119 QFont font;
120
120
121 if (pen == legend->pen() || m_force)
121 if (pen == legend->pen() || m_force)
122 legend->setPen(m_axisLinePen);
122 legend->setPen(m_axisLinePen);
123
123
124 if (brush == legend->brush() || m_force)
124 if (brush == legend->brush() || m_force)
125 legend->setBrush(m_chartBackgroundGradient);
125 legend->setBrush(m_chartBackgroundGradient);
126
126
127 if (font == legend->font() || m_force)
127 if (font == legend->font() || m_force)
128 legend->setFont(m_labelFont);
128 legend->setFont(m_labelFont);
129
129
130 if (brush == legend->labelBrush() || m_force)
130 if (brush == legend->labelBrush() || m_force)
131 legend->setLabelBrush(m_labelBrush);
131 legend->setLabelBrush(m_labelBrush);
132 }
132 }
133
133
134 void ChartTheme::decorate(QAreaSeries *series, int index)
134 void ChartTheme::decorate(QAreaSeries *series, int index)
135 {
135 {
136 QPen pen;
136 QPen pen;
137 QBrush brush;
137 QBrush brush;
138
138
139 if (pen == series->pen() || m_force){
139 if (pen == series->pen() || m_force){
140 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
140 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
141 pen.setWidthF(2);
141 pen.setWidthF(2);
142 series->setPen(pen);
142 series->setPen(pen);
143 }
143 }
144
144
145 if (brush == series->brush() || m_force) {
145 if (brush == series->brush() || m_force) {
146 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
146 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
147 series->setBrush(brush);
147 series->setBrush(brush);
148 }
148 }
149 }
149 }
150
150
151
151
152 void ChartTheme::decorate(QLineSeries *series,int index)
152 void ChartTheme::decorate(QLineSeries *series,int index)
153 {
153 {
154 QPen pen;
154 QPen pen;
155 if(pen == series->pen() || m_force ){
155 if(pen == series->pen() || m_force ){
156 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
156 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
157 pen.setWidthF(2);
157 pen.setWidthF(2);
158 series->setPen(pen);
158 series->setPen(pen);
159 }
159 }
160 }
160 }
161
161
162 void ChartTheme::decorate(QBarSeries *series, int index)
162 void ChartTheme::decorate(QAbstractBarSeries *series, int index)
163 {
163 {
164 QBrush brush;
164 QBrush brush;
165 QPen pen;
165 QPen pen;
166 QList<QBarSet *> sets = series->barSets();
166 QList<QBarSet *> sets = series->barSets();
167
167
168 qreal takeAtPos = 0.5;
168 qreal takeAtPos = 0.5;
169 qreal step = 0.2;
169 qreal step = 0.2;
170 if (sets.count() > 1 ) {
170 if (sets.count() > 1 ) {
171 step = 1.0 / (qreal) sets.count();
171 step = 1.0 / (qreal) sets.count();
172 if (sets.count() % m_seriesGradients.count())
172 if (sets.count() % m_seriesGradients.count())
173 step *= m_seriesGradients.count();
173 step *= m_seriesGradients.count();
174 else
174 else
175 step *= (m_seriesGradients.count() - 1);
175 step *= (m_seriesGradients.count() - 1);
176 }
176 }
177
177
178 for (int i(0); i < sets.count(); i++) {
178 for (int i(0); i < sets.count(); i++) {
179 int colorIndex = (index + i) % m_seriesGradients.count();
179 int colorIndex = (index + i) % m_seriesGradients.count();
180 if (i > 0 && i % m_seriesGradients.count() == 0) {
180 if (i > 0 && i % m_seriesGradients.count() == 0) {
181 // There is no dedicated base color for each sets, generate more colors
181 // There is no dedicated base color for each sets, generate more colors
182 takeAtPos += step;
182 takeAtPos += step;
183 if (takeAtPos == 1.0)
183 if (takeAtPos == 1.0)
184 takeAtPos += step;
184 takeAtPos += step;
185 takeAtPos -= (int) takeAtPos;
185 takeAtPos -= (int) takeAtPos;
186 }
186 }
187 if (brush == sets.at(i)->brush() || m_force )
187 if (brush == sets.at(i)->brush() || m_force )
188 sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos));
188 sets.at(i)->setBrush(colorAt(m_seriesGradients.at(colorIndex), takeAtPos));
189
189
190 // Pick label color from the opposite end of the gradient.
190 // Pick label color from the opposite end of the gradient.
191 // 0.3 as a boundary seems to work well.
191 // 0.3 as a boundary seems to work well.
192 if (takeAtPos < 0.3)
192 if (takeAtPos < 0.3)
193 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
193 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 1));
194 else
194 else
195 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0));
195 sets.at(i)->setLabelBrush(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0));
196
196
197 if (pen == sets.at(i)->pen() || m_force) {
197 if (pen == sets.at(i)->pen() || m_force) {
198 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
198 QColor c = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
199 sets.at(i)->setPen(c);
199 sets.at(i)->setPen(c);
200 }
200 }
201 }
201 }
202 }
202 }
203
203
204 void ChartTheme::decorate(QScatterSeries *series, int index)
204 void ChartTheme::decorate(QScatterSeries *series, int index)
205 {
205 {
206 QPen pen;
206 QPen pen;
207 QBrush brush;
207 QBrush brush;
208
208
209 if (pen == series->pen() || m_force) {
209 if (pen == series->pen() || m_force) {
210 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
210 pen.setColor(colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0));
211 pen.setWidthF(2);
211 pen.setWidthF(2);
212 series->setPen(pen);
212 series->setPen(pen);
213 }
213 }
214
214
215 if (brush == series->brush() || m_force) {
215 if (brush == series->brush() || m_force) {
216 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
216 QBrush brush(m_seriesColors.at(index % m_seriesColors.size()));
217 series->setBrush(brush);
217 series->setBrush(brush);
218 }
218 }
219 }
219 }
220
220
221 void ChartTheme::decorate(QPieSeries *series, int index)
221 void ChartTheme::decorate(QPieSeries *series, int index)
222 {
222 {
223
223
224 for (int i(0); i < series->slices().count(); i++) {
224 for (int i(0); i < series->slices().count(); i++) {
225
225
226 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
226 QColor penColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), 0.0);
227
227
228 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
228 // Get color for a slice from a gradient linearly, beginning from the start of the gradient
229 qreal pos = (qreal) (i + 1) / (qreal) series->count();
229 qreal pos = (qreal) (i + 1) / (qreal) series->count();
230 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
230 QColor brushColor = colorAt(m_seriesGradients.at(index % m_seriesGradients.size()), pos);
231
231
232 QPieSlice *s = series->slices().at(i);
232 QPieSlice *s = series->slices().at(i);
233 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
233 QPieSlicePrivate *d = QPieSlicePrivate::fromSlice(s);
234
234
235 if (d->m_data.m_slicePen.isThemed() || m_force)
235 if (d->m_data.m_slicePen.isThemed() || m_force)
236 d->setPen(penColor, true);
236 d->setPen(penColor, true);
237
237
238 if (d->m_data.m_sliceBrush.isThemed() || m_force)
238 if (d->m_data.m_sliceBrush.isThemed() || m_force)
239 d->setBrush(brushColor, true);
239 d->setBrush(brushColor, true);
240
240
241 if (d->m_data.m_labelBrush.isThemed() || m_force)
241 if (d->m_data.m_labelBrush.isThemed() || m_force)
242 d->setLabelBrush(m_labelBrush.color(), true);
242 d->setLabelBrush(m_labelBrush.color(), true);
243
243
244 if (d->m_data.m_labelFont.isThemed() || m_force)
244 if (d->m_data.m_labelFont.isThemed() || m_force)
245 d->setLabelFont(m_labelFont, true);
245 d->setLabelFont(m_labelFont, true);
246 }
246 }
247 }
247 }
248
248
249 void ChartTheme::decorate(QSplineSeries *series, int index)
249 void ChartTheme::decorate(QSplineSeries *series, int index)
250 {
250 {
251 QPen pen;
251 QPen pen;
252 if(pen == series->pen() || m_force){
252 if(pen == series->pen() || m_force){
253 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
253 pen.setColor(m_seriesColors.at(index%m_seriesColors.size()));
254 pen.setWidthF(2);
254 pen.setWidthF(2);
255 series->setPen(pen);
255 series->setPen(pen);
256 }
256 }
257 }
257 }
258
258
259 void ChartTheme::decorate(QAbstractAxis *axis,bool axisX)
259 void ChartTheme::decorate(QAbstractAxis *axis,bool axisX)
260 {
260 {
261 QPen pen;
261 QPen pen;
262 QBrush brush;
262 QBrush brush;
263 QFont font;
263 QFont font;
264
264
265 if (axis->isAxisVisible()) {
265 if (axis->isAxisVisible()) {
266
266
267 if(brush == axis->labelsBrush() || m_force){
267 if(brush == axis->labelsBrush() || m_force){
268 axis->setLabelsBrush(m_labelBrush);
268 axis->setLabelsBrush(m_labelBrush);
269 }
269 }
270 if(pen == axis->labelsPen() || m_force){
270 if(pen == axis->labelsPen() || m_force){
271 axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
271 axis->setLabelsPen(Qt::NoPen); // NoPen for performance reasons
272 }
272 }
273
273
274
274
275 if (axis->shadesVisible() || m_force) {
275 if (axis->shadesVisible() || m_force) {
276
276
277 if(brush == axis->shadesBrush() || m_force){
277 if(brush == axis->shadesBrush() || m_force){
278 axis->setShadesBrush(m_backgroundShadesBrush);
278 axis->setShadesBrush(m_backgroundShadesBrush);
279 }
279 }
280
280
281 if(pen == axis->shadesPen() || m_force){
281 if(pen == axis->shadesPen() || m_force){
282 axis->setShadesPen(m_backgroundShadesPen);
282 axis->setShadesPen(m_backgroundShadesPen);
283 }
283 }
284
284
285 if( m_force && (m_backgroundShades == BackgroundShadesBoth
285 if( m_force && (m_backgroundShades == BackgroundShadesBoth
286 || (m_backgroundShades == BackgroundShadesVertical && axisX)
286 || (m_backgroundShades == BackgroundShadesVertical && axisX)
287 || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){
287 || (m_backgroundShades == BackgroundShadesHorizontal && !axisX))){
288 axis->setShadesVisible(true);
288 axis->setShadesVisible(true);
289
289
290 }
290 }
291 }
291 }
292
292
293 if(pen == axis->axisPen() || m_force){
293 if(pen == axis->axisPen() || m_force){
294 axis->setAxisPen(m_axisLinePen);
294 axis->setAxisPen(m_axisLinePen);
295 }
295 }
296
296
297 if(pen == axis->gridLinePen() || m_force){
297 if(pen == axis->gridLinePen() || m_force){
298 axis->setGridLinePen(m_gridLinePen);
298 axis->setGridLinePen(m_gridLinePen);
299 }
299 }
300
300
301 if(font == axis->labelsFont() || m_force){
301 if(font == axis->labelsFont() || m_force){
302 axis->setLabelsFont(m_labelFont);
302 axis->setLabelsFont(m_labelFont);
303 }
303 }
304 }
304 }
305 }
305 }
306
306
307 void ChartTheme::generateSeriesGradients()
307 void ChartTheme::generateSeriesGradients()
308 {
308 {
309 // Generate gradients in HSV color space
309 // Generate gradients in HSV color space
310 foreach (const QColor& color, m_seriesColors) {
310 foreach (const QColor& color, m_seriesColors) {
311 QLinearGradient g;
311 QLinearGradient g;
312 qreal h = color.hsvHueF();
312 qreal h = color.hsvHueF();
313 qreal s = color.hsvSaturationF();
313 qreal s = color.hsvSaturationF();
314
314
315 // TODO: tune the algorithm to give nice results with most base colors defined in
315 // TODO: tune the algorithm to give nice results with most base colors defined in
316 // most themes. The rest of the gradients we can define manually in theme specific
316 // most themes. The rest of the gradients we can define manually in theme specific
317 // implementation.
317 // implementation.
318 QColor start = color;
318 QColor start = color;
319 start.setHsvF(h, 0.0, 1.0);
319 start.setHsvF(h, 0.0, 1.0);
320 g.setColorAt(0.0, start);
320 g.setColorAt(0.0, start);
321
321
322 g.setColorAt(0.5, color);
322 g.setColorAt(0.5, color);
323
323
324 QColor end = color;
324 QColor end = color;
325 end.setHsvF(h, s, 0.25);
325 end.setHsvF(h, s, 0.25);
326 g.setColorAt(1.0, end);
326 g.setColorAt(1.0, end);
327
327
328 m_seriesGradients << g;
328 m_seriesGradients << g;
329 }
329 }
330 }
330 }
331
331
332
332
333 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
333 QColor ChartTheme::colorAt(const QColor &start, const QColor &end, qreal pos)
334 {
334 {
335 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
335 Q_ASSERT(pos >= 0.0 && pos <= 1.0);
336 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
336 qreal r = start.redF() + ((end.redF() - start.redF()) * pos);
337 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
337 qreal g = start.greenF() + ((end.greenF() - start.greenF()) * pos);
338 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
338 qreal b = start.blueF() + ((end.blueF() - start.blueF()) * pos);
339 QColor c;
339 QColor c;
340 c.setRgbF(r, g, b);
340 c.setRgbF(r, g, b);
341 return c;
341 return c;
342 }
342 }
343
343
344 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
344 QColor ChartTheme::colorAt(const QGradient &gradient, qreal pos)
345 {
345 {
346 Q_ASSERT(pos >= 0 && pos <= 1.0);
346 Q_ASSERT(pos >= 0 && pos <= 1.0);
347
347
348 QGradientStops stops = gradient.stops();
348 QGradientStops stops = gradient.stops();
349 int count = stops.count();
349 int count = stops.count();
350
350
351 // find previous stop relative to position
351 // find previous stop relative to position
352 QGradientStop prev = stops.first();
352 QGradientStop prev = stops.first();
353 for (int i = 0; i < count; i++) {
353 for (int i = 0; i < count; i++) {
354 QGradientStop stop = stops.at(i);
354 QGradientStop stop = stops.at(i);
355 if (pos > stop.first)
355 if (pos > stop.first)
356 prev = stop;
356 prev = stop;
357
357
358 // given position is actually a stop position?
358 // given position is actually a stop position?
359 if (pos == stop.first) {
359 if (pos == stop.first) {
360 //qDebug() << "stop color" << pos;
360 //qDebug() << "stop color" << pos;
361 return stop.second;
361 return stop.second;
362 }
362 }
363 }
363 }
364
364
365 // find next stop relative to position
365 // find next stop relative to position
366 QGradientStop next = stops.last();
366 QGradientStop next = stops.last();
367 for (int i = count - 1; i >= 0; i--) {
367 for (int i = count - 1; i >= 0; i--) {
368 QGradientStop stop = stops.at(i);
368 QGradientStop stop = stops.at(i);
369 if (pos < stop.first)
369 if (pos < stop.first)
370 next = stop;
370 next = stop;
371 }
371 }
372
372
373 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
373 //qDebug() << "prev" << prev.first << "pos" << pos << "next" << next.first;
374
374
375 qreal range = next.first - prev.first;
375 qreal range = next.first - prev.first;
376 qreal posDelta = pos - prev.first;
376 qreal posDelta = pos - prev.first;
377 qreal relativePos = posDelta / range;
377 qreal relativePos = posDelta / range;
378
378
379 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
379 //qDebug() << "range" << range << "posDelta" << posDelta << "relativePos" << relativePos;
380
380
381 return colorAt(prev.second, next.second, relativePos);
381 return colorAt(prev.second, next.second, relativePos);
382 }
382 }
383
383
384 void ChartTheme::setForced(bool enabled)
384 void ChartTheme::setForced(bool enabled)
385 {
385 {
386 m_force=enabled;
386 m_force=enabled;
387 }
387 }
388
388
389 QTCOMMERCIALCHART_END_NAMESPACE
389 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,110 +1,110
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef CHARTTHEME_H
30 #ifndef CHARTTHEME_H
31 #define CHARTTHEME_H
31 #define CHARTTHEME_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include "qchart.h"
34 #include "qchart.h"
35 #include <QColor>
35 #include <QColor>
36 #include <QGradientStops>
36 #include <QGradientStops>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class ChartItem;
40 class ChartItem;
41 class LineChartItem;
41 class LineChartItem;
42 class QLineSeries;
42 class QLineSeries;
43 class BarChartItem;
43 class BarChartItem;
44 class QBarSeries;
44 class QAbstractBarSeries;
45 class StackedBarChartItem;
45 class StackedBarChartItem;
46 class QStackedBarSeries;
46 class QStackedBarSeries;
47 class QPercentBarSeries;
47 class QPercentBarSeries;
48 class PercentBarChartItem;
48 class PercentBarChartItem;
49 class QScatterSeries;
49 class QScatterSeries;
50 class ScatterChartItem;
50 class ScatterChartItem;
51 class PieChartItem;
51 class PieChartItem;
52 class QPieSeries;
52 class QPieSeries;
53 class SplineChartItem;
53 class SplineChartItem;
54 class QSplineSeries;
54 class QSplineSeries;
55 class AreaChartItem;
55 class AreaChartItem;
56 class QAreaSeries;
56 class QAreaSeries;
57
57
58 class ChartTheme
58 class ChartTheme
59 {
59 {
60 public:
60 public:
61 enum BackgroundShadesMode {
61 enum BackgroundShadesMode {
62 BackgroundShadesNone = 0,
62 BackgroundShadesNone = 0,
63 BackgroundShadesVertical,
63 BackgroundShadesVertical,
64 BackgroundShadesHorizontal,
64 BackgroundShadesHorizontal,
65 BackgroundShadesBoth
65 BackgroundShadesBoth
66 };
66 };
67
67
68 protected:
68 protected:
69 explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight);
69 explicit ChartTheme(QChart::ChartTheme id = QChart::ChartThemeLight);
70 public:
70 public:
71 static ChartTheme *createTheme(QChart::ChartTheme theme);
71 static ChartTheme *createTheme(QChart::ChartTheme theme);
72 QChart::ChartTheme id() const {return m_id;}
72 QChart::ChartTheme id() const {return m_id;}
73 void decorate(QChart *chart);
73 void decorate(QChart *chart);
74 void decorate(QLegend *legend);
74 void decorate(QLegend *legend);
75 void decorate(QBarSeries *series, int index);
75 void decorate(QAbstractBarSeries *series, int index);
76 void decorate(QLineSeries *series, int index);
76 void decorate(QLineSeries *series, int index);
77 void decorate(QAreaSeries *series, int index);
77 void decorate(QAreaSeries *series, int index);
78 void decorate(QScatterSeries *series, int index);
78 void decorate(QScatterSeries *series, int index);
79 void decorate(QPieSeries *series, int index);
79 void decorate(QPieSeries *series, int index);
80 void decorate(QSplineSeries *series, int index);
80 void decorate(QSplineSeries *series, int index);
81 void decorate(QAbstractAxis *axis, bool axisX);
81 void decorate(QAbstractAxis *axis, bool axisX);
82 void setForced(bool enabled);
82 void setForced(bool enabled);
83 bool isForced() { return m_force; }
83 bool isForced() { return m_force; }
84
84
85 public: // utils
85 public: // utils
86 void generateSeriesGradients();
86 void generateSeriesGradients();
87 static QColor colorAt(const QColor &start, const QColor &end, qreal pos);
87 static QColor colorAt(const QColor &start, const QColor &end, qreal pos);
88 static QColor colorAt(const QGradient &gradient, qreal pos);
88 static QColor colorAt(const QGradient &gradient, qreal pos);
89
89
90 protected:
90 protected:
91 QChart::ChartTheme m_id;
91 QChart::ChartTheme m_id;
92 QList<QColor> m_seriesColors;
92 QList<QColor> m_seriesColors;
93 QList<QGradient> m_seriesGradients;
93 QList<QGradient> m_seriesGradients;
94 QLinearGradient m_chartBackgroundGradient;
94 QLinearGradient m_chartBackgroundGradient;
95
95
96 QFont m_masterFont;
96 QFont m_masterFont;
97 QFont m_labelFont;
97 QFont m_labelFont;
98 QBrush m_labelBrush;
98 QBrush m_labelBrush;
99 QPen m_axisLinePen;
99 QPen m_axisLinePen;
100 QPen m_backgroundShadesPen;
100 QPen m_backgroundShadesPen;
101 QBrush m_backgroundShadesBrush;
101 QBrush m_backgroundShadesBrush;
102 BackgroundShadesMode m_backgroundShades;
102 BackgroundShadesMode m_backgroundShades;
103 bool m_backgroundDropShadowEnabled;
103 bool m_backgroundDropShadowEnabled;
104 QPen m_gridLinePen;
104 QPen m_gridLinePen;
105 bool m_force;
105 bool m_force;
106 };
106 };
107
107
108 QTCOMMERCIALCHART_END_NAMESPACE
108 QTCOMMERCIALCHART_END_NAMESPACE
109
109
110 #endif // CHARTTHEME_H
110 #endif // CHARTTHEME_H
@@ -1,237 +1,237
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 "legendmarker_p.h"
21 #include "legendmarker_p.h"
22 #include "qxyseries.h"
22 #include "qxyseries.h"
23 #include "qxyseries_p.h"
23 #include "qxyseries_p.h"
24 #include "qlegend.h"
24 #include "qlegend.h"
25 #include "qbarseries.h"
25 #include "qbarseries.h"
26 #include "qpieseries.h"
26 #include "qpieseries.h"
27 #include "qpieslice.h"
27 #include "qpieslice.h"
28 #include "qbarset.h"
28 #include "qbarset.h"
29 #include "qbarset_p.h"
29 #include "qbarset_p.h"
30 #include "qareaseries.h"
30 #include "qareaseries.h"
31 #include "qareaseries_p.h"
31 #include "qareaseries_p.h"
32 #include <QPainter>
32 #include <QPainter>
33 #include <QGraphicsSceneEvent>
33 #include <QGraphicsSceneEvent>
34 #include <QGraphicsSimpleTextItem>
34 #include <QGraphicsSimpleTextItem>
35 #include <QDebug>
35 #include <QDebug>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) :
39 LegendMarker::LegendMarker(QAbstractSeries *series, QLegend *legend) :
40 QGraphicsObject(legend),
40 QGraphicsObject(legend),
41 m_series(series),
41 m_series(series),
42 m_markerRect(0,0,10.0,10.0),
42 m_markerRect(0,0,10.0,10.0),
43 m_boundingRect(0,0,0,0),
43 m_boundingRect(0,0,0,0),
44 m_legend(legend),
44 m_legend(legend),
45 m_textItem(new QGraphicsSimpleTextItem(this)),
45 m_textItem(new QGraphicsSimpleTextItem(this)),
46 m_rectItem(new QGraphicsRectItem(this)),
46 m_rectItem(new QGraphicsRectItem(this)),
47 m_margin(2),
47 m_margin(2),
48 m_space(4)
48 m_space(4)
49 {
49 {
50 //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
50 //setAcceptedMouseButtons(Qt::LeftButton|Qt::RightButton);
51 m_rectItem->setRect(m_markerRect);
51 m_rectItem->setRect(m_markerRect);
52 }
52 }
53
53
54 void LegendMarker::setPen(const QPen &pen)
54 void LegendMarker::setPen(const QPen &pen)
55 {
55 {
56 m_rectItem->setPen(pen);
56 m_rectItem->setPen(pen);
57 m_textItem->setPen(pen);
57 m_textItem->setPen(pen);
58 }
58 }
59
59
60 QPen LegendMarker::pen() const
60 QPen LegendMarker::pen() const
61 {
61 {
62 return m_rectItem->pen();
62 return m_rectItem->pen();
63 }
63 }
64
64
65 void LegendMarker::setBrush(const QBrush &brush)
65 void LegendMarker::setBrush(const QBrush &brush)
66 {
66 {
67 m_rectItem->setBrush(brush);
67 m_rectItem->setBrush(brush);
68 }
68 }
69
69
70 QBrush LegendMarker::brush() const
70 QBrush LegendMarker::brush() const
71 {
71 {
72 return m_rectItem->brush();
72 return m_rectItem->brush();
73 }
73 }
74
74
75 void LegendMarker::setFont(const QFont &font)
75 void LegendMarker::setFont(const QFont &font)
76 {
76 {
77 m_textItem->setFont(font);
77 m_textItem->setFont(font);
78 QFontMetrics fn(font);
78 QFontMetrics fn(font);
79 m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
79 m_markerRect = QRectF(0,0,fn.height()/2,fn.height()/2);
80 updateGeometry();
80 updateGeometry();
81 }
81 }
82
82
83 QFont LegendMarker::font() const
83 QFont LegendMarker::font() const
84 {
84 {
85 return m_textItem->font();
85 return m_textItem->font();
86 }
86 }
87
87
88 void LegendMarker::setLabel(const QString label)
88 void LegendMarker::setLabel(const QString label)
89 {
89 {
90 m_textItem->setText(label);
90 m_textItem->setText(label);
91 }
91 }
92
92
93 QString LegendMarker::label() const
93 QString LegendMarker::label() const
94 {
94 {
95 return m_textItem->text();
95 return m_textItem->text();
96 }
96 }
97
97
98 QRectF LegendMarker::boundingRect() const
98 QRectF LegendMarker::boundingRect() const
99 {
99 {
100 return m_boundingRect;
100 return m_boundingRect;
101 }
101 }
102
102
103 void LegendMarker::setLabelBrush(const QBrush &brush)
103 void LegendMarker::setLabelBrush(const QBrush &brush)
104 {
104 {
105 m_textItem->setBrush(brush);
105 m_textItem->setBrush(brush);
106 }
106 }
107
107
108 QBrush LegendMarker::labelBrush() const
108 QBrush LegendMarker::labelBrush() const
109 {
109 {
110 return m_textItem->brush();
110 return m_textItem->brush();
111 }
111 }
112
112
113
113
114 void LegendMarker::setGeometry(const QRectF& rect)
114 void LegendMarker::setGeometry(const QRectF& rect)
115 {
115 {
116 const QRectF& textRect = m_textItem->boundingRect();
116 const QRectF& textRect = m_textItem->boundingRect();
117
117
118 m_textItem->setPos(m_markerRect.width() + m_space + m_margin,rect.height()/2 - textRect.height()/2);
118 m_textItem->setPos(m_markerRect.width() + m_space + m_margin,rect.height()/2 - textRect.height()/2);
119 m_rectItem->setRect(m_markerRect);
119 m_rectItem->setRect(m_markerRect);
120 m_rectItem->setPos(m_margin,rect.height()/2 - m_markerRect.height()/2);
120 m_rectItem->setPos(m_margin,rect.height()/2 - m_markerRect.height()/2);
121
121
122 prepareGeometryChange();
122 prepareGeometryChange();
123 m_boundingRect = rect;
123 m_boundingRect = rect;
124 }
124 }
125
125
126 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
126 void LegendMarker::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
127 {
127 {
128 Q_UNUSED(option)
128 Q_UNUSED(option)
129 Q_UNUSED(widget)
129 Q_UNUSED(widget)
130 Q_UNUSED(painter)
130 Q_UNUSED(painter)
131 }
131 }
132
132
133
133
134 QSizeF LegendMarker::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
134 QSizeF LegendMarker::sizeHint(Qt::SizeHint which, const QSizeF& constraint) const
135 {
135 {
136 Q_UNUSED(constraint)
136 Q_UNUSED(constraint)
137
137
138 QFontMetrics fn(m_textItem->font());
138 QFontMetrics fn(m_textItem->font());
139 QSizeF sh;
139 QSizeF sh;
140
140
141 switch (which) {
141 switch (which) {
142 case Qt::MinimumSize:
142 case Qt::MinimumSize:
143 sh = QSizeF(fn.boundingRect("...").width(),fn.height());
143 sh = QSizeF(fn.boundingRect("...").width(),fn.height());
144 break;
144 break;
145 case Qt::PreferredSize:
145 case Qt::PreferredSize:
146 sh = QSizeF(fn.boundingRect(m_textItem->text()).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
146 sh = QSizeF(fn.boundingRect(m_textItem->text()).width() + 2*m_margin + m_space +m_markerRect.width(),qMax(m_markerRect.height()+2*m_margin,fn.height()+2*m_margin));
147 break;
147 break;
148 default:
148 default:
149 break;
149 break;
150 }
150 }
151
151
152 return sh;
152 return sh;
153 }
153 }
154
154
155 void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
155 void LegendMarker::mousePressEvent(QGraphicsSceneMouseEvent *event)
156 {
156 {
157 QGraphicsObject::mousePressEvent(event);
157 QGraphicsObject::mousePressEvent(event);
158 qDebug()<<"Not implemented"; //TODO: selected signal removed for now
158 qDebug()<<"Not implemented"; //TODO: selected signal removed for now
159 }
159 }
160
160
161 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
161 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
162
162
163 AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend),
163 AreaLegendMarker::AreaLegendMarker(QAreaSeries *series,QLegend *legend) : LegendMarker(series,legend),
164 m_series(series)
164 m_series(series)
165 {
165 {
166 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
166 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
167 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
167 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
168 QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated()));
168 QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated()));
169 updated();
169 updated();
170 }
170 }
171
171
172 void AreaLegendMarker::updated()
172 void AreaLegendMarker::updated()
173 {
173 {
174 setBrush(m_series->brush());
174 setBrush(m_series->brush());
175 setLabel(m_series->name());
175 setLabel(m_series->name());
176 }
176 }
177
177
178 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
178 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
179
179
180 BarLegendMarker::BarLegendMarker(QBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend),
180 BarLegendMarker::BarLegendMarker(QAbstractBarSeries *barseries,QBarSet *barset, QLegend *legend) : LegendMarker(barseries,legend),
181 m_barset(barset)
181 m_barset(barset)
182 {
182 {
183 //QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected()));
183 //QObject::connect(this, SIGNAL(selected()),barset->d_ptr.data(), SIGNAL(selected()));
184 QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated()));
184 QObject::connect(barset->d_ptr.data(), SIGNAL(updatedBars()), this, SLOT(updated()));
185 updated();
185 updated();
186 }
186 }
187
187
188 void BarLegendMarker::updated()
188 void BarLegendMarker::updated()
189 {
189 {
190 setBrush(m_barset->brush());
190 setBrush(m_barset->brush());
191 setLabel(m_barset->label());
191 setLabel(m_barset->label());
192 }
192 }
193
193
194 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
194 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
195
195
196 PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend),
196 PieLegendMarker::PieLegendMarker(QPieSeries* series,QPieSlice *pieslice, QLegend *legend) : LegendMarker(series,legend),
197 m_pieslice(pieslice)
197 m_pieslice(pieslice)
198 {
198 {
199 QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated()));
199 QObject::connect(pieslice, SIGNAL(labelChanged()), this, SLOT(updated()));
200 QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated()));
200 QObject::connect(pieslice, SIGNAL(brushChanged()), this, SLOT(updated()));
201 updated();
201 updated();
202 }
202 }
203
203
204 void PieLegendMarker::updated()
204 void PieLegendMarker::updated()
205 {
205 {
206 setBrush(m_pieslice->brush());
206 setBrush(m_pieslice->brush());
207 setLabel(m_pieslice->label());
207 setLabel(m_pieslice->label());
208 }
208 }
209
209
210 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
210 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
211
211
212 XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend),
212 XYLegendMarker::XYLegendMarker(QXYSeries *series, QLegend *legend) : LegendMarker(series,legend),
213 m_series(series)
213 m_series(series)
214 {
214 {
215 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
215 //QObject::connect(this, SIGNAL(selected()), series, SIGNAL(selected()));
216 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
216 QObject::connect(series->d_func(),SIGNAL(updated()), this, SLOT(updated()));
217 QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated()));
217 QObject::connect(series, SIGNAL(nameChanged()), this, SLOT(updated()));
218 updated();
218 updated();
219 }
219 }
220
220
221 void XYLegendMarker::updated()
221 void XYLegendMarker::updated()
222 {
222 {
223 setLabel(m_series->name());
223 setLabel(m_series->name());
224
224
225 if(m_series->type()== QAbstractSeries::SeriesTypeScatter)
225 if(m_series->type()== QAbstractSeries::SeriesTypeScatter)
226 {
226 {
227 setBrush(m_series->brush());
227 setBrush(m_series->brush());
228
228
229 }
229 }
230 else {
230 else {
231 setBrush(QBrush(m_series->pen().color()));
231 setBrush(QBrush(m_series->pen().color()));
232 }
232 }
233 }
233 }
234
234
235 #include "moc_legendmarker_p.cpp"
235 #include "moc_legendmarker_p.cpp"
236
236
237 QTCOMMERCIALCHART_END_NAMESPACE
237 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,144 +1,144
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 // W A R N I N G
21 // W A R N I N G
22 // -------------
22 // -------------
23 //
23 //
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
24 // This file is not part of the QtCommercial Chart API. It exists purely as an
25 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
26 // version without notice, or even be removed.
26 // version without notice, or even be removed.
27 //
27 //
28 // We mean it.
28 // We mean it.
29
29
30 #ifndef LEGENDMARKER_P_H
30 #ifndef LEGENDMARKER_P_H
31 #define LEGENDMARKER_P_H
31 #define LEGENDMARKER_P_H
32
32
33 #include "qchartglobal.h"
33 #include "qchartglobal.h"
34 #include <QGraphicsObject>
34 #include <QGraphicsObject>
35 #include <QBrush>
35 #include <QBrush>
36 #include <QPen>
36 #include <QPen>
37 #include <QGraphicsSimpleTextItem>
37 #include <QGraphicsSimpleTextItem>
38 #include <QGraphicsLayoutItem>
38 #include <QGraphicsLayoutItem>
39
39
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
40 QTCOMMERCIALCHART_BEGIN_NAMESPACE
41
41
42 class QAbstractSeries;
42 class QAbstractSeries;
43 class QAreaSeries;
43 class QAreaSeries;
44 class QXYSeries;
44 class QXYSeries;
45 class QBarSet;
45 class QBarSet;
46 class QBarSeries;
46 class QAbstractBarSeries;
47 class QPieSlice;
47 class QPieSlice;
48 class QLegend;
48 class QLegend;
49 class QPieSeries;
49 class QPieSeries;
50
50
51 class LegendMarker : public QGraphicsObject, public QGraphicsLayoutItem
51 class LegendMarker : public QGraphicsObject, public QGraphicsLayoutItem
52 {
52 {
53 Q_OBJECT
53 Q_OBJECT
54 Q_INTERFACES(QGraphicsLayoutItem)
54 Q_INTERFACES(QGraphicsLayoutItem)
55 public:
55 public:
56 explicit LegendMarker(QAbstractSeries *m_series, QLegend *parent);
56 explicit LegendMarker(QAbstractSeries *m_series, QLegend *parent);
57
57
58 void setPen(const QPen &pen);
58 void setPen(const QPen &pen);
59 QPen pen() const;
59 QPen pen() const;
60
60
61 void setBrush(const QBrush &brush);
61 void setBrush(const QBrush &brush);
62 QBrush brush() const;
62 QBrush brush() const;
63
63
64 void setFont(const QFont &font);
64 void setFont(const QFont &font);
65 QFont font() const;
65 QFont font() const;
66
66
67 void setLabel(const QString label);
67 void setLabel(const QString label);
68 QString label() const;
68 QString label() const;
69
69
70 void setLabelBrush(const QBrush &brush);
70 void setLabelBrush(const QBrush &brush);
71 QBrush labelBrush() const;
71 QBrush labelBrush() const;
72
72
73 QAbstractSeries *series() const { return m_series;}
73 QAbstractSeries *series() const { return m_series;}
74
74
75 void setGeometry(const QRectF& rect);
75 void setGeometry(const QRectF& rect);
76
76
77 QRectF boundingRect() const;
77 QRectF boundingRect() const;
78
78
79 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
79 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
80
80
81 QSizeF sizeHint (Qt::SizeHint which, const QSizeF& constraint) const;
81 QSizeF sizeHint (Qt::SizeHint which, const QSizeF& constraint) const;
82
82
83 protected:
83 protected:
84 // From QGraphicsObject
84 // From QGraphicsObject
85 void mousePressEvent(QGraphicsSceneMouseEvent *event);
85 void mousePressEvent(QGraphicsSceneMouseEvent *event);
86
86
87 public Q_SLOTS:
87 public Q_SLOTS:
88 virtual void updated() = 0;
88 virtual void updated() = 0;
89
89
90 protected:
90 protected:
91 QAbstractSeries *m_series;
91 QAbstractSeries *m_series;
92 QRectF m_markerRect;
92 QRectF m_markerRect;
93 QRectF m_boundingRect;
93 QRectF m_boundingRect;
94 QLegend* m_legend;
94 QLegend* m_legend;
95 QGraphicsSimpleTextItem *m_textItem;
95 QGraphicsSimpleTextItem *m_textItem;
96 QGraphicsRectItem *m_rectItem;
96 QGraphicsRectItem *m_rectItem;
97 qreal m_margin;
97 qreal m_margin;
98 qreal m_space;
98 qreal m_space;
99
99
100 };
100 };
101
101
102 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
102 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
103 class XYLegendMarker : public LegendMarker
103 class XYLegendMarker : public LegendMarker
104 {
104 {
105 public:
105 public:
106 XYLegendMarker(QXYSeries *series, QLegend *legend);
106 XYLegendMarker(QXYSeries *series, QLegend *legend);
107 protected:
107 protected:
108 void updated();
108 void updated();
109 private:
109 private:
110 QXYSeries *m_series;
110 QXYSeries *m_series;
111 };
111 };
112 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
112 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
113 class AreaLegendMarker : public LegendMarker
113 class AreaLegendMarker : public LegendMarker
114 {
114 {
115 public:
115 public:
116 AreaLegendMarker(QAreaSeries *series, QLegend *legend);
116 AreaLegendMarker(QAreaSeries *series, QLegend *legend);
117 protected:
117 protected:
118 void updated();
118 void updated();
119 private:
119 private:
120 QAreaSeries *m_series;
120 QAreaSeries *m_series;
121 };
121 };
122 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
122 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
123 class BarLegendMarker : public LegendMarker
123 class BarLegendMarker : public LegendMarker
124 {
124 {
125 public:
125 public:
126 BarLegendMarker(QBarSeries *barseries, QBarSet *barset,QLegend *legend);
126 BarLegendMarker(QAbstractBarSeries *barseries, QBarSet *barset,QLegend *legend);
127 protected:
127 protected:
128 void updated();
128 void updated();
129 private:
129 private:
130 QBarSet *m_barset;
130 QBarSet *m_barset;
131 };
131 };
132 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
132 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
133 class PieLegendMarker : public LegendMarker
133 class PieLegendMarker : public LegendMarker
134 {
134 {
135 public:
135 public:
136 PieLegendMarker(QPieSeries *pieSeries, QPieSlice *pieslice, QLegend *legend);
136 PieLegendMarker(QPieSeries *pieSeries, QPieSlice *pieslice, QLegend *legend);
137 protected:
137 protected:
138 void updated();
138 void updated();
139 private:
139 private:
140 QPieSlice *m_pieslice;
140 QPieSlice *m_pieslice;
141 };
141 };
142
142
143 QTCOMMERCIALCHART_END_NAMESPACE
143 QTCOMMERCIALCHART_END_NAMESPACE
144 #endif // LEGENDMARKER_P_H
144 #endif // LEGENDMARKER_P_H
@@ -1,634 +1,634
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 <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qabstractaxis.h>
22 #include <qabstractaxis.h>
23 #include <qvaluesaxis.h>
23 #include <qvaluesaxis.h>
24 #include <qcategoriesaxis.h>
24 #include <qcategoriesaxis.h>
25 #include <qlineseries.h>
25 #include <qlineseries.h>
26 #include <qareaseries.h>
26 #include <qareaseries.h>
27 #include <qscatterseries.h>
27 #include <qscatterseries.h>
28 #include <qsplineseries.h>
28 #include <qsplineseries.h>
29 #include <qpieseries.h>
29 #include <qpieseries.h>
30 #include <qbarseries.h>
30 #include <qbarseries.h>
31 #include <qpercentbarseries.h>
31 #include <qpercentbarseries.h>
32 #include <qstackedbarseries.h>
32 #include <qstackedbarseries.h>
33 #include <private/chartdataset_p.h>
33 #include <private/chartdataset_p.h>
34 #include <private/domain_p.h>
34 #include <private/domain_p.h>
35 #include <tst_definitions.h>
35 #include <tst_definitions.h>
36
36
37 QTCOMMERCIALCHART_USE_NAMESPACE
37 QTCOMMERCIALCHART_USE_NAMESPACE
38
38
39 Q_DECLARE_METATYPE(Domain *)
39 Q_DECLARE_METATYPE(Domain *)
40 Q_DECLARE_METATYPE(QAbstractAxis *)
40 Q_DECLARE_METATYPE(QAbstractAxis *)
41 Q_DECLARE_METATYPE(QAbstractSeries *)
41 Q_DECLARE_METATYPE(QAbstractSeries *)
42 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
42 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
43 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
43 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
44 Q_DECLARE_METATYPE(QLineSeries *)
44 Q_DECLARE_METATYPE(QLineSeries *)
45
45
46 class tst_ChartDataSet: public QObject {
46 class tst_ChartDataSet: public QObject {
47
47
48 Q_OBJECT
48 Q_OBJECT
49
49
50 public Q_SLOTS:
50 public Q_SLOTS:
51 void initTestCase();
51 void initTestCase();
52 void cleanupTestCase();
52 void cleanupTestCase();
53 void init();
53 void init();
54 void cleanup();
54 void cleanup();
55
55
56 private Q_SLOTS:
56 private Q_SLOTS:
57 void chartdataset_data();
57 void chartdataset_data();
58 void chartdataset();
58 void chartdataset();
59 void addSeries_data();
59 void addSeries_data();
60 void addSeries();
60 void addSeries();
61 void setAxisX_data();
61 void setAxisX_data();
62 void setAxisX();
62 void setAxisX();
63 void setAxisY_data();
63 void setAxisY_data();
64 void setAxisY();
64 void setAxisY();
65 void removeSeries_data();
65 void removeSeries_data();
66 void removeSeries();
66 void removeSeries();
67 void removeAllSeries_data();
67 void removeAllSeries_data();
68 void removeAllSeries();
68 void removeAllSeries();
69 void seriesCount_data();
69 void seriesCount_data();
70 void seriesCount();
70 void seriesCount();
71 void seriesIndex_data();
71 void seriesIndex_data();
72 void seriesIndex();
72 void seriesIndex();
73 void domain_data();
73 void domain_data();
74 void domain();
74 void domain();
75 void zoomInDomain_data();
75 void zoomInDomain_data();
76 void zoomInDomain();
76 void zoomInDomain();
77 /*
77 /*
78 void zoomOutDomain_data();
78 void zoomOutDomain_data();
79 void zoomOutDomain();
79 void zoomOutDomain();
80 void scrollDomain_data();
80 void scrollDomain_data();
81 void scrollDomain();
81 void scrollDomain();
82 */
82 */
83 private:
83 private:
84 ChartDataSet* m_dataset;
84 ChartDataSet* m_dataset;
85 };
85 };
86
86
87 void tst_ChartDataSet::initTestCase()
87 void tst_ChartDataSet::initTestCase()
88 {
88 {
89 qRegisterMetaType<Domain*>();
89 qRegisterMetaType<Domain*>();
90 qRegisterMetaType<QAbstractAxis*>();
90 qRegisterMetaType<QAbstractAxis*>();
91 qRegisterMetaType<QAbstractSeries*>();
91 qRegisterMetaType<QAbstractSeries*>();
92 }
92 }
93
93
94 void tst_ChartDataSet::cleanupTestCase()
94 void tst_ChartDataSet::cleanupTestCase()
95 {
95 {
96 }
96 }
97
97
98 void tst_ChartDataSet::init()
98 void tst_ChartDataSet::init()
99 {
99 {
100 m_dataset = new ChartDataSet();
100 m_dataset = new ChartDataSet();
101 }
101 }
102
102
103
103
104 void tst_ChartDataSet::cleanup()
104 void tst_ChartDataSet::cleanup()
105 {
105 {
106 QList<QAbstractSeries*> series = m_dataset->series();
106 QList<QAbstractSeries*> series = m_dataset->series();
107 foreach(QAbstractSeries* serie, series)
107 foreach(QAbstractSeries* serie, series)
108 {
108 {
109 m_dataset->removeSeries(serie);
109 m_dataset->removeSeries(serie);
110 }
110 }
111 }
111 }
112
112
113 void tst_ChartDataSet::chartdataset_data()
113 void tst_ChartDataSet::chartdataset_data()
114 {
114 {
115 }
115 }
116
116
117 void tst_ChartDataSet::chartdataset()
117 void tst_ChartDataSet::chartdataset()
118 {
118 {
119 QVERIFY(m_dataset->axisX(0) == 0);
119 QVERIFY(m_dataset->axisX(0) == 0);
120 QVERIFY(m_dataset->axisY(0) == 0);
120 QVERIFY(m_dataset->axisY(0) == 0);
121 QLineSeries* series = new QLineSeries(this);
121 QLineSeries* series = new QLineSeries(this);
122 QCOMPARE(m_dataset->seriesIndex(series),-1);
122 QCOMPARE(m_dataset->seriesIndex(series),-1);
123 QVERIFY(m_dataset->domain(series) == 0);
123 QVERIFY(m_dataset->domain(series) == 0);
124 QVERIFY(m_dataset->axisX(series) == 0);
124 QVERIFY(m_dataset->axisX(series) == 0);
125 QVERIFY(m_dataset->axisY(series) == 0);
125 QVERIFY(m_dataset->axisY(series) == 0);
126 m_dataset->createDefaultAxes();
126 m_dataset->createDefaultAxes();
127 }
127 }
128
128
129
129
130 void tst_ChartDataSet::addSeries_data()
130 void tst_ChartDataSet::addSeries_data()
131 {
131 {
132 QTest::addColumn<QAbstractSeries*>("series");
132 QTest::addColumn<QAbstractSeries*>("series");
133
133
134 QAbstractSeries* line = new QLineSeries(this);
134 QAbstractSeries* line = new QLineSeries(this);
135 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
135 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
136 QAbstractSeries* scatter = new QScatterSeries(this);
136 QAbstractSeries* scatter = new QScatterSeries(this);
137 QAbstractSeries* spline = new QSplineSeries(this);
137 QAbstractSeries* spline = new QSplineSeries(this);
138 QAbstractSeries* pie = new QPieSeries(this);
138 QAbstractSeries* pie = new QPieSeries(this);
139 QAbstractSeries* bar = new QBarSeries(this);
139 QAbstractSeries* bar = new QAbstractBarSeries(this);
140 QAbstractSeries* percent = new QPercentBarSeries(this);
140 QAbstractSeries* percent = new QPercentBarSeries(this);
141 QAbstractSeries* stacked = new QStackedBarSeries(this);
141 QAbstractSeries* stacked = new QStackedBarSeries(this);
142
142
143 QTest::newRow("line") << line;
143 QTest::newRow("line") << line;
144 QTest::newRow("area") << area;
144 QTest::newRow("area") << area;
145 QTest::newRow("scatter") << scatter;
145 QTest::newRow("scatter") << scatter;
146 QTest::newRow("spline") << spline;
146 QTest::newRow("spline") << spline;
147 QTest::newRow("pie") << pie;
147 QTest::newRow("pie") << pie;
148 QTest::newRow("bar") << bar;
148 QTest::newRow("bar") << bar;
149 QTest::newRow("percent") << percent;
149 QTest::newRow("percent") << percent;
150 QTest::newRow("stacked") << stacked;
150 QTest::newRow("stacked") << stacked;
151 }
151 }
152
152
153 void tst_ChartDataSet::addSeries()
153 void tst_ChartDataSet::addSeries()
154 {
154 {
155
155
156 QFETCH(QAbstractSeries*, series);
156 QFETCH(QAbstractSeries*, series);
157
157
158 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
158 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
159 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
159 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
160 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
160 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
161 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
161 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
162
162
163 m_dataset->addSeries(series);
163 m_dataset->addSeries(series);
164 m_dataset->createDefaultAxes();
164 m_dataset->createDefaultAxes();
165 if(series->type()==QAbstractSeries::SeriesTypePie){
165 if(series->type()==QAbstractSeries::SeriesTypePie){
166 TRY_COMPARE(spy0.count(), 0);
166 TRY_COMPARE(spy0.count(), 0);
167 }else{
167 }else{
168 TRY_COMPARE(spy0.count(), 2);
168 TRY_COMPARE(spy0.count(), 2);
169 }
169 }
170 TRY_COMPARE(spy1.count(), 0);
170 TRY_COMPARE(spy1.count(), 0);
171 TRY_COMPARE(spy2.count(), 1);
171 TRY_COMPARE(spy2.count(), 1);
172 TRY_COMPARE(spy3.count(), 0);
172 TRY_COMPARE(spy3.count(), 0);
173 }
173 }
174
174
175
175
176 void tst_ChartDataSet::setAxisX_data()
176 void tst_ChartDataSet::setAxisX_data()
177 {
177 {
178
178
179 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
179 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
180 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
180 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
181 QTest::addColumn<int>("axisCount");
181 QTest::addColumn<int>("axisCount");
182
182
183 QAbstractSeries* line = new QLineSeries(this);
183 QAbstractSeries* line = new QLineSeries(this);
184 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
184 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
185 QAbstractSeries* scatter = new QScatterSeries(this);
185 QAbstractSeries* scatter = new QScatterSeries(this);
186 QAbstractSeries* spline = new QSplineSeries(this);
186 QAbstractSeries* spline = new QSplineSeries(this);
187 QAbstractSeries* pie = new QPieSeries(this);
187 QAbstractSeries* pie = new QPieSeries(this);
188 QAbstractSeries* bar = new QBarSeries(this);
188 QAbstractSeries* bar = new QAbstractBarSeries(this);
189 QAbstractSeries* percent = new QPercentBarSeries(this);
189 QAbstractSeries* percent = new QPercentBarSeries(this);
190 QAbstractSeries* stacked = new QStackedBarSeries(this);
190 QAbstractSeries* stacked = new QStackedBarSeries(this);
191
191
192 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
192 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
193 << (QList<QAbstractSeries*>() << line << spline << scatter)
193 << (QList<QAbstractSeries*>() << line << spline << scatter)
194 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3;
194 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3;
195
195
196 QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area)
196 QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area)
197 << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1;
197 << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1;
198
198
199 QList<QAbstractAxis*> axes0;
199 QList<QAbstractAxis*> axes0;
200 axes0 << new QValuesAxis(this) << new QValuesAxis(this);
200 axes0 << new QValuesAxis(this) << new QValuesAxis(this);
201 axes0 << axes0.last();
201 axes0 << axes0.last();
202 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1")
202 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1")
203 << (QList<QAbstractSeries*>() << line << spline << scatter)
203 << (QList<QAbstractSeries*>() << line << spline << scatter)
204 << axes0 << 2;
204 << axes0 << 2;
205 //TODO: add more test cases
205 //TODO: add more test cases
206 }
206 }
207
207
208 void tst_ChartDataSet::setAxisX()
208 void tst_ChartDataSet::setAxisX()
209 {
209 {
210 QFETCH(QList<QAbstractSeries*>, seriesList);
210 QFETCH(QList<QAbstractSeries*>, seriesList);
211 QFETCH(QList<QAbstractAxis*>, axisList);
211 QFETCH(QList<QAbstractAxis*>, axisList);
212 QFETCH(int, axisCount);
212 QFETCH(int, axisCount);
213
213
214 Q_ASSERT(seriesList.count() == axisList.count());
214 Q_ASSERT(seriesList.count() == axisList.count());
215
215
216 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
216 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
217 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
217 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
218 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
218 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
219 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
219 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
220
220
221 foreach(QAbstractSeries* series, seriesList){
221 foreach(QAbstractSeries* series, seriesList){
222 m_dataset->addSeries(series);
222 m_dataset->addSeries(series);
223 }
223 }
224
224
225 TRY_COMPARE(spy0.count(), 0);
225 TRY_COMPARE(spy0.count(), 0);
226 TRY_COMPARE(spy1.count(), 0);
226 TRY_COMPARE(spy1.count(), 0);
227 TRY_COMPARE(spy2.count(), seriesList.count());
227 TRY_COMPARE(spy2.count(), seriesList.count());
228 TRY_COMPARE(spy3.count(), 0);
228 TRY_COMPARE(spy3.count(), 0);
229
229
230 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
230 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
231 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
231 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
232 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
232 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
233 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
233 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
234
234
235 for(int i=0 ; i < seriesList.count(); i++){
235 for(int i=0 ; i < seriesList.count(); i++){
236 m_dataset->setAxisX(seriesList.at(i),axisList.at(i));
236 m_dataset->setAxisX(seriesList.at(i),axisList.at(i));
237 }
237 }
238
238
239 TRY_COMPARE(spy4.count(), axisCount);
239 TRY_COMPARE(spy4.count(), axisCount);
240 TRY_COMPARE(spy5.count(), 0);
240 TRY_COMPARE(spy5.count(), 0);
241 TRY_COMPARE(spy6.count(), 0);
241 TRY_COMPARE(spy6.count(), 0);
242 TRY_COMPARE(spy7.count(), 0);
242 TRY_COMPARE(spy7.count(), 0);
243
243
244 for(int i=0 ; i < seriesList.count(); i++){
244 for(int i=0 ; i < seriesList.count(); i++){
245 QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i));
245 QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i));
246 }
246 }
247 }
247 }
248
248
249 void tst_ChartDataSet::setAxisY_data()
249 void tst_ChartDataSet::setAxisY_data()
250 {
250 {
251 setAxisX_data();
251 setAxisX_data();
252 }
252 }
253
253
254 void tst_ChartDataSet::setAxisY()
254 void tst_ChartDataSet::setAxisY()
255 {
255 {
256 QFETCH(QList<QAbstractSeries*>, seriesList);
256 QFETCH(QList<QAbstractSeries*>, seriesList);
257 QFETCH(QList<QAbstractAxis*>, axisList);
257 QFETCH(QList<QAbstractAxis*>, axisList);
258 QFETCH(int, axisCount);
258 QFETCH(int, axisCount);
259
259
260 Q_ASSERT(seriesList.count() == axisList.count());
260 Q_ASSERT(seriesList.count() == axisList.count());
261
261
262 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
262 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
263 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
263 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
264 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
264 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
265 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
265 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
266
266
267 foreach(QAbstractSeries* series, seriesList){
267 foreach(QAbstractSeries* series, seriesList){
268 m_dataset->addSeries(series);
268 m_dataset->addSeries(series);
269 }
269 }
270
270
271 TRY_COMPARE(spy0.count(), 0);
271 TRY_COMPARE(spy0.count(), 0);
272 TRY_COMPARE(spy1.count(), 0);
272 TRY_COMPARE(spy1.count(), 0);
273 TRY_COMPARE(spy2.count(), seriesList.count());
273 TRY_COMPARE(spy2.count(), seriesList.count());
274 TRY_COMPARE(spy3.count(), 0);
274 TRY_COMPARE(spy3.count(), 0);
275
275
276 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
276 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
277 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
277 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
278 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
278 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
279 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
279 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
280
280
281 for(int i=0 ; i < seriesList.count(); i++){
281 for(int i=0 ; i < seriesList.count(); i++){
282 m_dataset->setAxisY(seriesList.at(i),axisList.at(i));
282 m_dataset->setAxisY(seriesList.at(i),axisList.at(i));
283 }
283 }
284
284
285 TRY_COMPARE(spy4.count(), axisCount);
285 TRY_COMPARE(spy4.count(), axisCount);
286 TRY_COMPARE(spy5.count(), 0);
286 TRY_COMPARE(spy5.count(), 0);
287 TRY_COMPARE(spy6.count(), 0);
287 TRY_COMPARE(spy6.count(), 0);
288 TRY_COMPARE(spy7.count(), 0);
288 TRY_COMPARE(spy7.count(), 0);
289
289
290 for(int i=0 ; i < seriesList.count(); i++){
290 for(int i=0 ; i < seriesList.count(); i++){
291 QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i));
291 QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i));
292 }
292 }
293 }
293 }
294
294
295 void tst_ChartDataSet::removeSeries_data()
295 void tst_ChartDataSet::removeSeries_data()
296 {
296 {
297 addSeries_data();
297 addSeries_data();
298 }
298 }
299
299
300 void tst_ChartDataSet::removeSeries()
300 void tst_ChartDataSet::removeSeries()
301 {
301 {
302 QFETCH(QAbstractSeries*, series);
302 QFETCH(QAbstractSeries*, series);
303
303
304 m_dataset->addSeries(series);
304 m_dataset->addSeries(series);
305 m_dataset->createDefaultAxes();
305 m_dataset->createDefaultAxes();
306
306
307 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
307 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
308 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
308 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
309 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
309 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
310 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
310 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
311
311
312 m_dataset->removeSeries(series);
312 m_dataset->removeSeries(series);
313
313
314 TRY_COMPARE(spy0.count(), 0);
314 TRY_COMPARE(spy0.count(), 0);
315 if (series->type() == QAbstractSeries::SeriesTypePie) {
315 if (series->type() == QAbstractSeries::SeriesTypePie) {
316 TRY_COMPARE(spy1.count(), 0);
316 TRY_COMPARE(spy1.count(), 0);
317 }
317 }
318 else {
318 else {
319 TRY_COMPARE(spy1.count(), 2);
319 TRY_COMPARE(spy1.count(), 2);
320 }
320 }
321 TRY_COMPARE(spy2.count(), 0);
321 TRY_COMPARE(spy2.count(), 0);
322 TRY_COMPARE(spy3.count(), 1);
322 TRY_COMPARE(spy3.count(), 1);
323 }
323 }
324
324
325 void tst_ChartDataSet::removeAllSeries_data()
325 void tst_ChartDataSet::removeAllSeries_data()
326 {
326 {
327 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
327 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
328 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
328 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
329 QTest::addColumn<int>("axisCount");
329 QTest::addColumn<int>("axisCount");
330
330
331 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
331 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
332 << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this)
332 << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this)
333 << new QScatterSeries(this))
333 << new QScatterSeries(this))
334 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this)
334 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this)
335 << new QValuesAxis(this)) << 3;
335 << new QValuesAxis(this)) << 3;
336 //TODO:
336 //TODO:
337 }
337 }
338
338
339 void tst_ChartDataSet::removeAllSeries()
339 void tst_ChartDataSet::removeAllSeries()
340 {
340 {
341 QFETCH(QList<QAbstractSeries*>, seriesList);
341 QFETCH(QList<QAbstractSeries*>, seriesList);
342 QFETCH(QList<QAbstractAxis*>, axisList);
342 QFETCH(QList<QAbstractAxis*>, axisList);
343 QFETCH(int, axisCount);
343 QFETCH(int, axisCount);
344
344
345 foreach(QAbstractSeries* series, seriesList) {
345 foreach(QAbstractSeries* series, seriesList) {
346 m_dataset->addSeries(series);
346 m_dataset->addSeries(series);
347 }
347 }
348
348
349 for (int i = 0; i < seriesList.count(); i++) {
349 for (int i = 0; i < seriesList.count(); i++) {
350 m_dataset->setAxisX(seriesList.at(i), axisList.at(i));
350 m_dataset->setAxisX(seriesList.at(i), axisList.at(i));
351 }
351 }
352
352
353 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
353 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
354 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
354 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
355 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
355 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
356 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
356 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
357
357
358 m_dataset->removeAllSeries();
358 m_dataset->removeAllSeries();
359
359
360 TRY_COMPARE(spy0.count(), 0);
360 TRY_COMPARE(spy0.count(), 0);
361 TRY_COMPARE(spy1.count(), axisCount);
361 TRY_COMPARE(spy1.count(), axisCount);
362 TRY_COMPARE(spy2.count(), 0);
362 TRY_COMPARE(spy2.count(), 0);
363 TRY_COMPARE(spy3.count(), seriesList.count());
363 TRY_COMPARE(spy3.count(), seriesList.count());
364 }
364 }
365
365
366
366
367 void tst_ChartDataSet::seriesCount_data()
367 void tst_ChartDataSet::seriesCount_data()
368 {
368 {
369 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
369 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
370 QTest::addColumn<int>("seriesCount");
370 QTest::addColumn<int>("seriesCount");
371
371
372 QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3;
372 QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3;
373 QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2;
373 QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2;
374 }
374 }
375
375
376 void tst_ChartDataSet::seriesCount()
376 void tst_ChartDataSet::seriesCount()
377 {
377 {
378 QFETCH(QList<QAbstractSeries*>, seriesList);
378 QFETCH(QList<QAbstractSeries*>, seriesList);
379 QFETCH(int, seriesCount);
379 QFETCH(int, seriesCount);
380
380
381 foreach(QAbstractSeries* series, seriesList){
381 foreach(QAbstractSeries* series, seriesList){
382 m_dataset->addSeries(series);
382 m_dataset->addSeries(series);
383 }
383 }
384
384
385 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
385 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
386 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
386 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
387 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
387 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
388 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
388 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
389
389
390 QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount);
390 QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount);
391 TRY_COMPARE(spy0.count(), 0);
391 TRY_COMPARE(spy0.count(), 0);
392 TRY_COMPARE(spy1.count(), 0);
392 TRY_COMPARE(spy1.count(), 0);
393 TRY_COMPARE(spy2.count(), 0);
393 TRY_COMPARE(spy2.count(), 0);
394 TRY_COMPARE(spy3.count(), 0);
394 TRY_COMPARE(spy3.count(), 0);
395 }
395 }
396
396
397 void tst_ChartDataSet::seriesIndex_data()
397 void tst_ChartDataSet::seriesIndex_data()
398 {
398 {
399 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
399 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
400
400
401 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
401 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
402 QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) );
402 QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) );
403 }
403 }
404
404
405 void tst_ChartDataSet::seriesIndex()
405 void tst_ChartDataSet::seriesIndex()
406 {
406 {
407
407
408 QFETCH(QList<QAbstractSeries*>, seriesList);
408 QFETCH(QList<QAbstractSeries*>, seriesList);
409
409
410 foreach(QAbstractSeries* series, seriesList) {
410 foreach(QAbstractSeries* series, seriesList) {
411 m_dataset->addSeries(series);
411 m_dataset->addSeries(series);
412 }
412 }
413
413
414 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
414 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
415 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
415 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
416 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)));
416 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)));
417 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
417 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
418
418
419 for (int i = 0; i < seriesList.count(); i++) {
419 for (int i = 0; i < seriesList.count(); i++) {
420 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
420 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
421 }
421 }
422
422
423 TRY_COMPARE(spy0.count(), 0);
423 TRY_COMPARE(spy0.count(), 0);
424 TRY_COMPARE(spy1.count(), 0);
424 TRY_COMPARE(spy1.count(), 0);
425 TRY_COMPARE(spy2.count(), 0);
425 TRY_COMPARE(spy2.count(), 0);
426 TRY_COMPARE(spy3.count(), 0);
426 TRY_COMPARE(spy3.count(), 0);
427
427
428 foreach(QAbstractSeries* series, seriesList) {
428 foreach(QAbstractSeries* series, seriesList) {
429 m_dataset->removeSeries(series);
429 m_dataset->removeSeries(series);
430 }
430 }
431
431
432 for (int i = 0; i < seriesList.count(); i++) {
432 for (int i = 0; i < seriesList.count(); i++) {
433 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
433 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
434 }
434 }
435
435
436 foreach(QAbstractSeries* series, seriesList) {
436 foreach(QAbstractSeries* series, seriesList) {
437 m_dataset->addSeries(series);
437 m_dataset->addSeries(series);
438 }
438 }
439
439
440 for (int i = 0; i < seriesList.count(); i++) {
440 for (int i = 0; i < seriesList.count(); i++) {
441 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
441 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
442 }
442 }
443
443
444 m_dataset->removeSeries(seriesList.at(1));
444 m_dataset->removeSeries(seriesList.at(1));
445
445
446 for (int i = 0; i < seriesList.count(); i++) {
446 for (int i = 0; i < seriesList.count(); i++) {
447 if (i != 1)
447 if (i != 1)
448 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
448 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
449 else
449 else
450 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
450 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
451 }
451 }
452
452
453 m_dataset->addSeries(seriesList.at(1));
453 m_dataset->addSeries(seriesList.at(1));
454
454
455 for (int i = 0; i < seriesList.count(); i++) {
455 for (int i = 0; i < seriesList.count(); i++) {
456 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
456 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
457 }
457 }
458
458
459 m_dataset->removeSeries(seriesList.at(2));
459 m_dataset->removeSeries(seriesList.at(2));
460
460
461 for (int i = 0; i < seriesList.count(); i++) {
461 for (int i = 0; i < seriesList.count(); i++) {
462 if (i != 2)
462 if (i != 2)
463 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
463 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
464 else
464 else
465 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
465 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
466 }
466 }
467
467
468 m_dataset->removeSeries(seriesList.at(0));
468 m_dataset->removeSeries(seriesList.at(0));
469
469
470 for (int i = 0; i < seriesList.count(); i++) {
470 for (int i = 0; i < seriesList.count(); i++) {
471 if (i != 2 && i != 0)
471 if (i != 2 && i != 0)
472 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
472 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
473 else
473 else
474 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
474 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
475 }
475 }
476
476
477 m_dataset->addSeries(seriesList.at(2));
477 m_dataset->addSeries(seriesList.at(2));
478 m_dataset->addSeries(seriesList.at(0));
478 m_dataset->addSeries(seriesList.at(0));
479
479
480 for (int i = 0; i < seriesList.count(); i++) {
480 for (int i = 0; i < seriesList.count(); i++) {
481 if (i == 2)
481 if (i == 2)
482 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0);
482 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0);
483 else if (i == 0)
483 else if (i == 0)
484 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2);
484 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2);
485 else
485 else
486 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
486 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
487 }
487 }
488
488
489 }
489 }
490
490
491 void tst_ChartDataSet::domain_data()
491 void tst_ChartDataSet::domain_data()
492 {
492 {
493 addSeries_data();
493 addSeries_data();
494 }
494 }
495
495
496 void tst_ChartDataSet::domain()
496 void tst_ChartDataSet::domain()
497 {
497 {
498 QFETCH(QAbstractSeries*, series);
498 QFETCH(QAbstractSeries*, series);
499
499
500 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
500 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
501 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
501 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
502 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
502 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
503 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
503 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
504
504
505 m_dataset->addSeries(series);
505 m_dataset->addSeries(series);
506 QVERIFY(m_dataset->domain(series));
506 QVERIFY(m_dataset->domain(series));
507
507
508
508
509 TRY_COMPARE(spy0.count(), 0);
509 TRY_COMPARE(spy0.count(), 0);
510 TRY_COMPARE(spy1.count(), 0);
510 TRY_COMPARE(spy1.count(), 0);
511 TRY_COMPARE(spy2.count(), 1);
511 TRY_COMPARE(spy2.count(), 1);
512
512
513 QList<QVariant> arguments = spy2.takeFirst();
513 QList<QVariant> arguments = spy2.takeFirst();
514 Domain *domain = (Domain *) arguments.at(1).value<Domain *>();
514 Domain *domain = (Domain *) arguments.at(1).value<Domain *>();
515 QVERIFY(m_dataset->domain(series) == domain);
515 QVERIFY(m_dataset->domain(series) == domain);
516
516
517 TRY_COMPARE(spy3.count(), 0);
517 TRY_COMPARE(spy3.count(), 0);
518
518
519 }
519 }
520
520
521 void tst_ChartDataSet::zoomInDomain_data()
521 void tst_ChartDataSet::zoomInDomain_data()
522 {
522 {
523 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
523 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
524 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
524 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
525 }
525 }
526
526
527 void tst_ChartDataSet::zoomInDomain()
527 void tst_ChartDataSet::zoomInDomain()
528 {
528 {
529 QFETCH(QList<QAbstractSeries*>, seriesList);
529 QFETCH(QList<QAbstractSeries*>, seriesList);
530
530
531 foreach(QAbstractSeries* series, seriesList) {
531 foreach(QAbstractSeries* series, seriesList) {
532 m_dataset->addSeries(series);
532 m_dataset->addSeries(series);
533 }
533 }
534
534
535 /*
535 /*
536 QValuesAxis* axis = new QValuesAxis();
536 QValuesAxis* axis = new QValuesAxis();
537
537
538 for (int i = 0; i < seriesList.count(); i++) {
538 for (int i = 0; i < seriesList.count(); i++) {
539 m_dataset->setAxisX(seriesList.at(i), axis);
539 m_dataset->setAxisX(seriesList.at(i), axis);
540 }
540 }
541 */
541 */
542 m_dataset->createDefaultAxes();
542 m_dataset->createDefaultAxes();
543
543
544 QList<QSignalSpy*> spyList;
544 QList<QSignalSpy*> spyList;
545
545
546 foreach(QAbstractSeries* series, seriesList) {
546 foreach(QAbstractSeries* series, seriesList) {
547 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
547 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
548 }
548 }
549
549
550 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
550 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
551
551
552 foreach(QSignalSpy* spy, spyList) {
552 foreach(QSignalSpy* spy, spyList) {
553 TRY_COMPARE(spy->count(), 1);
553 TRY_COMPARE(spy->count(), 1);
554 }
554 }
555
555
556 qDeleteAll(spyList);
556 qDeleteAll(spyList);
557 }
557 }
558
558
559 /*
559 /*
560 void tst_ChartDataSet::zoomOutDomain_data()
560 void tst_ChartDataSet::zoomOutDomain_data()
561 {
561 {
562 addSeries_data();
562 addSeries_data();
563 }
563 }
564
564
565 void tst_ChartDataSet::zoomOutDomain()
565 void tst_ChartDataSet::zoomOutDomain()
566 {
566 {
567 QFETCH(QLineSeries*, series0);
567 QFETCH(QLineSeries*, series0);
568 QFETCH(QAxis*, axis0);
568 QFETCH(QAxis*, axis0);
569 QFETCH(QLineSeries*, series1);
569 QFETCH(QLineSeries*, series1);
570 QFETCH(QAxis*, axis1);
570 QFETCH(QAxis*, axis1);
571 QFETCH(QLineSeries*, series2);
571 QFETCH(QLineSeries*, series2);
572 QFETCH(QAxis*, axis2);
572 QFETCH(QAxis*, axis2);
573 QFETCH(int, axisCount);
573 QFETCH(int, axisCount);
574
574
575 Q_UNUSED(axisCount);
575 Q_UNUSED(axisCount);
576
576
577 m_dataset->addSeries(series0, axis0);
577 m_dataset->addSeries(series0, axis0);
578 m_dataset->addSeries(series1, axis1);
578 m_dataset->addSeries(series1, axis1);
579 m_dataset->addSeries(series2, axis2);
579 m_dataset->addSeries(series2, axis2);
580
580
581 Domain* domain0 = m_dataset->domain(series0);
581 Domain* domain0 = m_dataset->domain(series0);
582 Domain* domain1 = m_dataset->domain(series1);
582 Domain* domain1 = m_dataset->domain(series1);
583 Domain* domain2 = m_dataset->domain(series2);
583 Domain* domain2 = m_dataset->domain(series2);
584
584
585 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
585 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
586 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
586 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
587 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
587 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
588
588
589 m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000));
589 m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000));
590
590
591 TRY_COMPARE(spy0.count(), 1);
591 TRY_COMPARE(spy0.count(), 1);
592 TRY_COMPARE(spy1.count(), 1);
592 TRY_COMPARE(spy1.count(), 1);
593 TRY_COMPARE(spy2.count(), 1);
593 TRY_COMPARE(spy2.count(), 1);
594 }
594 }
595
595
596 void tst_ChartDataSet::scrollDomain_data()
596 void tst_ChartDataSet::scrollDomain_data()
597 {
597 {
598 addSeries_data();
598 addSeries_data();
599 }
599 }
600
600
601 void tst_ChartDataSet::scrollDomain()
601 void tst_ChartDataSet::scrollDomain()
602 {
602 {
603 QFETCH(QLineSeries*, series0);
603 QFETCH(QLineSeries*, series0);
604 QFETCH(QAxis*, axis0);
604 QFETCH(QAxis*, axis0);
605 QFETCH(QLineSeries*, series1);
605 QFETCH(QLineSeries*, series1);
606 QFETCH(QAxis*, axis1);
606 QFETCH(QAxis*, axis1);
607 QFETCH(QLineSeries*, series2);
607 QFETCH(QLineSeries*, series2);
608 QFETCH(QAxis*, axis2);
608 QFETCH(QAxis*, axis2);
609 QFETCH(int, axisCount);
609 QFETCH(int, axisCount);
610
610
611 Q_UNUSED(axisCount);
611 Q_UNUSED(axisCount);
612
612
613 m_dataset->addSeries(series0, axis0);
613 m_dataset->addSeries(series0, axis0);
614 m_dataset->addSeries(series1, axis1);
614 m_dataset->addSeries(series1, axis1);
615 m_dataset->addSeries(series2, axis2);
615 m_dataset->addSeries(series2, axis2);
616
616
617 Domain* domain0 = m_dataset->domain(series0);
617 Domain* domain0 = m_dataset->domain(series0);
618 Domain* domain1 = m_dataset->domain(series1);
618 Domain* domain1 = m_dataset->domain(series1);
619 Domain* domain2 = m_dataset->domain(series2);
619 Domain* domain2 = m_dataset->domain(series2);
620
620
621 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
621 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
622 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
622 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
623 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
623 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
624
624
625 m_dataset->scrollDomain(10,10,QSize(1000,1000));
625 m_dataset->scrollDomain(10,10,QSize(1000,1000));
626
626
627 TRY_COMPARE(spy0.count(), 1);
627 TRY_COMPARE(spy0.count(), 1);
628 TRY_COMPARE(spy1.count(), 1);
628 TRY_COMPARE(spy1.count(), 1);
629 TRY_COMPARE(spy2.count(), 1);
629 TRY_COMPARE(spy2.count(), 1);
630 }
630 }
631 */
631 */
632 QTEST_MAIN(tst_ChartDataSet)
632 QTEST_MAIN(tst_ChartDataSet)
633 #include "tst_chartdataset.moc"
633 #include "tst_chartdataset.moc"
634
634
@@ -1,577 +1,577
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 <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qbarseries.h>
22 #include <qbarseries.h>
23 #include <qbarset.h>
23 #include <qbarset.h>
24 #include <qchartview.h>
24 #include <qchartview.h>
25 #include <qchart.h>
25 #include <qchart.h>
26 #include "tst_definitions.h"
26 #include "tst_definitions.h"
27
27
28 QTCOMMERCIALCHART_USE_NAMESPACE
28 QTCOMMERCIALCHART_USE_NAMESPACE
29
29
30 Q_DECLARE_METATYPE(QBarSet*)
30 Q_DECLARE_METATYPE(QBarSet*)
31
31
32 class tst_QBarSeries : public QObject
32 class tst_QBarSeries : public QObject
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35
35
36 public slots:
36 public slots:
37 void initTestCase();
37 void initTestCase();
38 void cleanupTestCase();
38 void cleanupTestCase();
39 void init();
39 void init();
40 void cleanup();
40 void cleanup();
41
41
42 private slots:
42 private slots:
43 void qbarseries_data();
43 void qbarseries_data();
44 void qbarseries();
44 void qbarseries();
45 void type_data();
45 void type_data();
46 void type();
46 void type();
47 void append_data();
47 void append_data();
48 void append();
48 void append();
49 void remove_data();
49 void remove_data();
50 void remove();
50 void remove();
51 void appendList_data();
51 void appendList_data();
52 void appendList();
52 void appendList();
53 void count_data();
53 void count_data();
54 void count();
54 void count();
55 void barSets_data();
55 void barSets_data();
56 void barSets();
56 void barSets();
57 void setLabelsVisible_data();
57 void setLabelsVisible_data();
58 void setLabelsVisible();
58 void setLabelsVisible();
59 void mouseclicked_data();
59 void mouseclicked_data();
60 void mouseclicked();
60 void mouseclicked();
61 void mousehovered_data();
61 void mousehovered_data();
62 void mousehovered();
62 void mousehovered();
63 void clearWithAnimations();
63 void clearWithAnimations();
64
64
65 private:
65 private:
66 QBarSeries* m_barseries;
66 QAbstractBarSeries* m_barseries;
67 QBarSeries* m_barseries_with_sets;
67 QAbstractBarSeries* m_barseries_with_sets;
68
68
69 QList<QBarSet*> m_testSets;
69 QList<QBarSet*> m_testSets;
70
70
71 };
71 };
72
72
73 void tst_QBarSeries::initTestCase()
73 void tst_QBarSeries::initTestCase()
74 {
74 {
75 qRegisterMetaType<QBarSet*>("QBarSet*");
75 qRegisterMetaType<QBarSet*>("QBarSet*");
76 }
76 }
77
77
78 void tst_QBarSeries::cleanupTestCase()
78 void tst_QBarSeries::cleanupTestCase()
79 {
79 {
80 }
80 }
81
81
82 void tst_QBarSeries::init()
82 void tst_QBarSeries::init()
83 {
83 {
84 m_barseries = new QBarSeries();
84 m_barseries = new QAbstractBarSeries();
85 m_barseries_with_sets = new QBarSeries();
85 m_barseries_with_sets = new QAbstractBarSeries();
86
86
87 for (int i=0; i<5; i++) {
87 for (int i=0; i<5; i++) {
88 m_testSets.append(new QBarSet("testset"));
88 m_testSets.append(new QBarSet("testset"));
89 m_barseries_with_sets->append(m_testSets.at(i));
89 m_barseries_with_sets->append(m_testSets.at(i));
90 }
90 }
91 }
91 }
92
92
93 void tst_QBarSeries::cleanup()
93 void tst_QBarSeries::cleanup()
94 {
94 {
95 foreach(QBarSet* s, m_testSets) {
95 foreach(QBarSet* s, m_testSets) {
96 m_barseries_with_sets->remove(s);
96 m_barseries_with_sets->remove(s);
97 delete s;
97 delete s;
98 }
98 }
99 m_testSets.clear();
99 m_testSets.clear();
100
100
101 delete m_barseries;
101 delete m_barseries;
102 m_barseries = 0;
102 m_barseries = 0;
103 delete m_barseries_with_sets;
103 delete m_barseries_with_sets;
104 m_barseries_with_sets = 0;
104 m_barseries_with_sets = 0;
105 }
105 }
106
106
107 void tst_QBarSeries::qbarseries_data()
107 void tst_QBarSeries::qbarseries_data()
108 {
108 {
109 }
109 }
110
110
111 void tst_QBarSeries::qbarseries()
111 void tst_QBarSeries::qbarseries()
112 {
112 {
113 QBarSeries *barseries = new QBarSeries();
113 QAbstractBarSeries *barseries = new QAbstractBarSeries();
114 QVERIFY(barseries != 0);
114 QVERIFY(barseries != 0);
115 }
115 }
116
116
117 void tst_QBarSeries::type_data()
117 void tst_QBarSeries::type_data()
118 {
118 {
119
119
120 }
120 }
121
121
122 void tst_QBarSeries::type()
122 void tst_QBarSeries::type()
123 {
123 {
124 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar);
124 QVERIFY(m_barseries->type() == QAbstractSeries::SeriesTypeBar);
125 }
125 }
126
126
127 void tst_QBarSeries::append_data()
127 void tst_QBarSeries::append_data()
128 {
128 {
129 }
129 }
130
130
131 void tst_QBarSeries::append()
131 void tst_QBarSeries::append()
132 {
132 {
133 QVERIFY(m_barseries->count() == 0);
133 QVERIFY(m_barseries->count() == 0);
134
134
135 bool ret = false;
135 bool ret = false;
136
136
137 // Try adding barset
137 // Try adding barset
138 QBarSet *barset = new QBarSet("testset");
138 QBarSet *barset = new QBarSet("testset");
139 ret = m_barseries->append(barset);
139 ret = m_barseries->append(barset);
140
140
141 QVERIFY(ret == true);
141 QVERIFY(ret == true);
142 QVERIFY(m_barseries->count() == 1);
142 QVERIFY(m_barseries->count() == 1);
143
143
144 // Try adding another set
144 // Try adding another set
145 QBarSet *barset2 = new QBarSet("testset2");
145 QBarSet *barset2 = new QBarSet("testset2");
146 ret = m_barseries->append(barset2);
146 ret = m_barseries->append(barset2);
147
147
148 QVERIFY(ret == true);
148 QVERIFY(ret == true);
149 QVERIFY(m_barseries->count() == 2);
149 QVERIFY(m_barseries->count() == 2);
150
150
151 // Try adding same set again
151 // Try adding same set again
152 ret = m_barseries->append(barset2);
152 ret = m_barseries->append(barset2);
153 QVERIFY(ret == false);
153 QVERIFY(ret == false);
154 QVERIFY(m_barseries->count() == 2);
154 QVERIFY(m_barseries->count() == 2);
155
155
156 // Try adding null set
156 // Try adding null set
157 ret = m_barseries->append(0);
157 ret = m_barseries->append(0);
158 QVERIFY(ret == false);
158 QVERIFY(ret == false);
159 QVERIFY(m_barseries->count() == 2);
159 QVERIFY(m_barseries->count() == 2);
160
160
161 }
161 }
162
162
163 void tst_QBarSeries::remove_data()
163 void tst_QBarSeries::remove_data()
164 {
164 {
165 }
165 }
166
166
167 void tst_QBarSeries::remove()
167 void tst_QBarSeries::remove()
168 {
168 {
169 int count = m_testSets.count();
169 int count = m_testSets.count();
170 QVERIFY(m_barseries_with_sets->count() == count);
170 QVERIFY(m_barseries_with_sets->count() == count);
171
171
172 // Try to remove null pointer (should not remove, should not crash)
172 // Try to remove null pointer (should not remove, should not crash)
173 bool ret = false;
173 bool ret = false;
174 ret = m_barseries_with_sets->remove(0);
174 ret = m_barseries_with_sets->remove(0);
175 QVERIFY(ret == false);
175 QVERIFY(ret == false);
176 QVERIFY(m_barseries_with_sets->count() == count);
176 QVERIFY(m_barseries_with_sets->count() == count);
177
177
178 // Try to remove invalid pointer (should not remove, should not crash)
178 // Try to remove invalid pointer (should not remove, should not crash)
179 ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) );
179 ret = m_barseries_with_sets->remove((QBarSet*) (m_testSets.at(0) + 1) );
180 QVERIFY(ret == false);
180 QVERIFY(ret == false);
181 QVERIFY(m_barseries_with_sets->count() == count);
181 QVERIFY(m_barseries_with_sets->count() == count);
182
182
183 // remove some sets
183 // remove some sets
184 ret = m_barseries_with_sets->remove(m_testSets.at(2));
184 ret = m_barseries_with_sets->remove(m_testSets.at(2));
185 QVERIFY(ret == true);
185 QVERIFY(ret == true);
186 ret = m_barseries_with_sets->remove(m_testSets.at(3));
186 ret = m_barseries_with_sets->remove(m_testSets.at(3));
187 QVERIFY(ret == true);
187 QVERIFY(ret == true);
188 ret = m_barseries_with_sets->remove(m_testSets.at(4));
188 ret = m_barseries_with_sets->remove(m_testSets.at(4));
189 QVERIFY(ret == true);
189 QVERIFY(ret == true);
190
190
191 QVERIFY(m_barseries_with_sets->count() == 2);
191 QVERIFY(m_barseries_with_sets->count() == 2);
192
192
193 QList<QBarSet*> verifysets = m_barseries_with_sets->barSets();
193 QList<QBarSet*> verifysets = m_barseries_with_sets->barSets();
194
194
195 QVERIFY(verifysets.at(0) == m_testSets.at(0));
195 QVERIFY(verifysets.at(0) == m_testSets.at(0));
196 QVERIFY(verifysets.at(1) == m_testSets.at(1));
196 QVERIFY(verifysets.at(1) == m_testSets.at(1));
197
197
198 // Try removing all sets again (should be ok, even if some sets have already been removed)
198 // Try removing all sets again (should be ok, even if some sets have already been removed)
199 ret = false;
199 ret = false;
200 for (int i=0; i<count; i++) {
200 for (int i=0; i<count; i++) {
201 ret |= m_barseries_with_sets->remove(m_testSets.at(i));
201 ret |= m_barseries_with_sets->remove(m_testSets.at(i));
202 }
202 }
203
203
204 QVERIFY(ret == true);
204 QVERIFY(ret == true);
205 QVERIFY(m_barseries_with_sets->count() == 0);
205 QVERIFY(m_barseries_with_sets->count() == 0);
206 }
206 }
207
207
208 void tst_QBarSeries::appendList_data()
208 void tst_QBarSeries::appendList_data()
209 {
209 {
210
210
211 }
211 }
212
212
213 void tst_QBarSeries::appendList()
213 void tst_QBarSeries::appendList()
214 {
214 {
215 int count = 5;
215 int count = 5;
216 QVERIFY(m_barseries->count() == 0);
216 QVERIFY(m_barseries->count() == 0);
217
217
218 QList<QBarSet*> sets;
218 QList<QBarSet*> sets;
219 for (int i=0; i<count; i++) {
219 for (int i=0; i<count; i++) {
220 sets.append(new QBarSet("testset"));
220 sets.append(new QBarSet("testset"));
221 }
221 }
222
222
223 // Append new sets (should succeed, count should match the count of sets)
223 // Append new sets (should succeed, count should match the count of sets)
224 bool ret = false;
224 bool ret = false;
225 ret = m_barseries->append(sets);
225 ret = m_barseries->append(sets);
226 QVERIFY(ret == true);
226 QVERIFY(ret == true);
227 QVERIFY(m_barseries->count() == count);
227 QVERIFY(m_barseries->count() == count);
228
228
229 // Append same sets again (should fail, count should remain same)
229 // Append same sets again (should fail, count should remain same)
230 ret = m_barseries->append(sets);
230 ret = m_barseries->append(sets);
231 QVERIFY(ret == false);
231 QVERIFY(ret == false);
232 QVERIFY(m_barseries->count() == count);
232 QVERIFY(m_barseries->count() == count);
233
233
234 // Try append empty list (should succeed, but count should remain same)
234 // Try append empty list (should succeed, but count should remain same)
235 QList<QBarSet*> invalidList;
235 QList<QBarSet*> invalidList;
236 ret = m_barseries->append(invalidList);
236 ret = m_barseries->append(invalidList);
237 QVERIFY(ret == true);
237 QVERIFY(ret == true);
238 QVERIFY(m_barseries->count() == count);
238 QVERIFY(m_barseries->count() == count);
239
239
240 // Try append list with one new and one existing set (should fail, count remains same)
240 // Try append list with one new and one existing set (should fail, count remains same)
241 invalidList.append(new QBarSet("ok set"));
241 invalidList.append(new QBarSet("ok set"));
242 invalidList.append(sets.at(0));
242 invalidList.append(sets.at(0));
243 ret = m_barseries->append(invalidList);
243 ret = m_barseries->append(invalidList);
244 QVERIFY(ret == false);
244 QVERIFY(ret == false);
245 QVERIFY(m_barseries->count() == count);
245 QVERIFY(m_barseries->count() == count);
246
246
247 // Try append list with null pointers (should fail, count remains same)
247 // Try append list with null pointers (should fail, count remains same)
248 QList<QBarSet*> invalidList2;
248 QList<QBarSet*> invalidList2;
249 invalidList2.append(0);
249 invalidList2.append(0);
250 invalidList2.append(0);
250 invalidList2.append(0);
251 invalidList2.append(0);
251 invalidList2.append(0);
252 ret = m_barseries->append(invalidList2);
252 ret = m_barseries->append(invalidList2);
253 QVERIFY(ret == false);
253 QVERIFY(ret == false);
254 QVERIFY(m_barseries->count() == count);
254 QVERIFY(m_barseries->count() == count);
255 }
255 }
256
256
257 void tst_QBarSeries::count_data()
257 void tst_QBarSeries::count_data()
258 {
258 {
259
259
260 }
260 }
261
261
262 void tst_QBarSeries::count()
262 void tst_QBarSeries::count()
263 {
263 {
264 QVERIFY(m_barseries->count() == 0);
264 QVERIFY(m_barseries->count() == 0);
265 QVERIFY(m_barseries_with_sets->count() == m_testSets.count());
265 QVERIFY(m_barseries_with_sets->count() == m_testSets.count());
266 }
266 }
267
267
268 void tst_QBarSeries::barSets_data()
268 void tst_QBarSeries::barSets_data()
269 {
269 {
270
270
271 }
271 }
272
272
273 void tst_QBarSeries::barSets()
273 void tst_QBarSeries::barSets()
274 {
274 {
275 QVERIFY(m_barseries->barSets().count() == 0);
275 QVERIFY(m_barseries->barSets().count() == 0);
276
276
277 QList<QBarSet*> sets = m_barseries_with_sets->barSets();
277 QList<QBarSet*> sets = m_barseries_with_sets->barSets();
278 QVERIFY(sets.count() == m_testSets.count());
278 QVERIFY(sets.count() == m_testSets.count());
279
279
280 for (int i=0; i<m_testSets.count(); i++) {
280 for (int i=0; i<m_testSets.count(); i++) {
281 QVERIFY(sets.at(i) == m_testSets.at(i));
281 QVERIFY(sets.at(i) == m_testSets.at(i));
282 }
282 }
283 }
283 }
284
284
285 void tst_QBarSeries::setLabelsVisible_data()
285 void tst_QBarSeries::setLabelsVisible_data()
286 {
286 {
287
287
288 }
288 }
289
289
290 void tst_QBarSeries::setLabelsVisible()
290 void tst_QBarSeries::setLabelsVisible()
291 {
291 {
292 // labels should be invisible by default
292 // labels should be invisible by default
293 QVERIFY(m_barseries->isLabelsVisible() == false);
293 QVERIFY(m_barseries->isLabelsVisible() == false);
294 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
294 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
295
295
296 // turn labels to visible
296 // turn labels to visible
297 m_barseries_with_sets->setLabelsVisible(true);
297 m_barseries_with_sets->setLabelsVisible(true);
298 // TODO: test the signal
298 // TODO: test the signal
299 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
299 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
300
300
301 // turn labels to invisible
301 // turn labels to invisible
302 m_barseries_with_sets->setLabelsVisible(false);
302 m_barseries_with_sets->setLabelsVisible(false);
303 // TODO: test the signal
303 // TODO: test the signal
304 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
304 QVERIFY(m_barseries_with_sets->isLabelsVisible() == false);
305
305
306 // without parameter, should turn labels to visible
306 // without parameter, should turn labels to visible
307 m_barseries_with_sets->setLabelsVisible();
307 m_barseries_with_sets->setLabelsVisible();
308 // TODO: test the signal
308 // TODO: test the signal
309 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
309 QVERIFY(m_barseries_with_sets->isLabelsVisible() == true);
310 }
310 }
311
311
312 void tst_QBarSeries::mouseclicked_data()
312 void tst_QBarSeries::mouseclicked_data()
313 {
313 {
314
314
315 }
315 }
316
316
317 void tst_QBarSeries::mouseclicked()
317 void tst_QBarSeries::mouseclicked()
318 {
318 {
319 QBarSeries* series = new QBarSeries();
319 QAbstractBarSeries* series = new QAbstractBarSeries();
320
320
321 QBarSet* set1 = new QBarSet(QString("set 1"));
321 QBarSet* set1 = new QBarSet(QString("set 1"));
322 // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
322 // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
323 *set1 << 10 << 10 << 10;
323 *set1 << 10 << 10 << 10;
324 series->append(set1);
324 series->append(set1);
325
325
326 QBarSet* set2 = new QBarSet(QString("set 2"));
326 QBarSet* set2 = new QBarSet(QString("set 2"));
327 // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
327 // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
328 *set2 << 10 << 10 << 10;
328 *set2 << 10 << 10 << 10;
329 series->append(set2);
329 series->append(set2);
330
330
331 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
331 QSignalSpy seriesSpy(series,SIGNAL(clicked(int,QBarSet*)));
332 QSignalSpy setSpy1(set1, SIGNAL(clicked(int)));
332 QSignalSpy setSpy1(set1, SIGNAL(clicked(int)));
333 QSignalSpy setSpy2(set2, SIGNAL(clicked(int)));
333 QSignalSpy setSpy2(set2, SIGNAL(clicked(int)));
334
334
335 QChartView view(new QChart());
335 QChartView view(new QChart());
336 view.resize(400,300);
336 view.resize(400,300);
337 view.chart()->addSeries(series);
337 view.chart()->addSeries(series);
338 view.show();
338 view.show();
339 QTest::qWaitForWindowShown(&view);
339 QTest::qWaitForWindowShown(&view);
340
340
341 //====================================================================================
341 //====================================================================================
342 // barset 1, bar 0
342 // barset 1, bar 0
343 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(102,142));
343 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(102,142));
344 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
344 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
345
345
346 QCOMPARE(seriesSpy.count(), 1);
346 QCOMPARE(seriesSpy.count(), 1);
347 QCOMPARE(setSpy1.count(), 1);
347 QCOMPARE(setSpy1.count(), 1);
348 QCOMPARE(setSpy2.count(), 0);
348 QCOMPARE(setSpy2.count(), 0);
349
349
350 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
350 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
351 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
351 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
352 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
352 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
353 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
353 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
354
354
355 QList<QVariant> setSpyArg = setSpy1.takeFirst();
355 QList<QVariant> setSpyArg = setSpy1.takeFirst();
356 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
356 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
357 QVERIFY(setSpyArg.at(0).toInt() == 0);
357 QVERIFY(setSpyArg.at(0).toInt() == 0);
358
358
359 //====================================================================================
359 //====================================================================================
360 // barset 1, bar 1
360 // barset 1, bar 1
361 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142));
361 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(186,142));
362 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
362 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
363
363
364 QCOMPARE(seriesSpy.count(), 1);
364 QCOMPARE(seriesSpy.count(), 1);
365 QCOMPARE(setSpy1.count(), 1);
365 QCOMPARE(setSpy1.count(), 1);
366 QCOMPARE(setSpy2.count(), 0);
366 QCOMPARE(setSpy2.count(), 0);
367
367
368 seriesSpyArg = seriesSpy.takeFirst();
368 seriesSpyArg = seriesSpy.takeFirst();
369 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
369 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
370 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
370 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
371 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
371 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
372
372
373 setSpyArg = setSpy1.takeFirst();
373 setSpyArg = setSpy1.takeFirst();
374 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
374 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
375 QVERIFY(setSpyArg.at(0).toInt() == 1);
375 QVERIFY(setSpyArg.at(0).toInt() == 1);
376
376
377 //====================================================================================
377 //====================================================================================
378 // barset 1, bar 2
378 // barset 1, bar 2
379 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142));
379 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(271,142));
380 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
380 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
381
381
382 QCOMPARE(seriesSpy.count(), 1);
382 QCOMPARE(seriesSpy.count(), 1);
383 QCOMPARE(setSpy1.count(), 1);
383 QCOMPARE(setSpy1.count(), 1);
384 QCOMPARE(setSpy2.count(), 0);
384 QCOMPARE(setSpy2.count(), 0);
385
385
386 seriesSpyArg = seriesSpy.takeFirst();
386 seriesSpyArg = seriesSpy.takeFirst();
387 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
387 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
388 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
388 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
389 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
389 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
390
390
391 setSpyArg = setSpy1.takeFirst();
391 setSpyArg = setSpy1.takeFirst();
392 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
392 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
393 QVERIFY(setSpyArg.at(0).toInt() == 2);
393 QVERIFY(setSpyArg.at(0).toInt() == 2);
394
394
395 //====================================================================================
395 //====================================================================================
396 // barset 2, bar 0
396 // barset 2, bar 0
397 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142));
397 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(127,142));
398 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
398 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
399
399
400 QCOMPARE(seriesSpy.count(), 1);
400 QCOMPARE(seriesSpy.count(), 1);
401 QCOMPARE(setSpy1.count(), 0);
401 QCOMPARE(setSpy1.count(), 0);
402 QCOMPARE(setSpy2.count(), 1);
402 QCOMPARE(setSpy2.count(), 1);
403
403
404 seriesSpyArg = seriesSpy.takeFirst();
404 seriesSpyArg = seriesSpy.takeFirst();
405 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
405 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
406 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
406 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
407 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
407 QVERIFY(seriesSpyArg.at(0).toInt() == 0);
408
408
409 setSpyArg = setSpy2.takeFirst();
409 setSpyArg = setSpy2.takeFirst();
410 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
410 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
411 QVERIFY(setSpyArg.at(0).toInt() == 0);
411 QVERIFY(setSpyArg.at(0).toInt() == 0);
412
412
413 //====================================================================================
413 //====================================================================================
414 // barset 2, bar 1
414 // barset 2, bar 1
415 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142));
415 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(212,142));
416 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
416 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
417
417
418 QCOMPARE(seriesSpy.count(), 1);
418 QCOMPARE(seriesSpy.count(), 1);
419 QCOMPARE(setSpy1.count(), 0);
419 QCOMPARE(setSpy1.count(), 0);
420 QCOMPARE(setSpy2.count(), 1);
420 QCOMPARE(setSpy2.count(), 1);
421
421
422 seriesSpyArg = seriesSpy.takeFirst();
422 seriesSpyArg = seriesSpy.takeFirst();
423 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
423 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
424 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
424 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
425 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
425 QVERIFY(seriesSpyArg.at(0).toInt() == 1);
426
426
427 setSpyArg = setSpy2.takeFirst();
427 setSpyArg = setSpy2.takeFirst();
428 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
428 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
429 QVERIFY(setSpyArg.at(0).toInt() == 1);
429 QVERIFY(setSpyArg.at(0).toInt() == 1);
430
430
431 //====================================================================================
431 //====================================================================================
432 // barset 2, bar 2
432 // barset 2, bar 2
433 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142));
433 QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(296,142));
434 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
434 QCoreApplication::processEvents(QEventLoop::AllEvents, 1000);
435
435
436 QCOMPARE(seriesSpy.count(), 1);
436 QCOMPARE(seriesSpy.count(), 1);
437 QCOMPARE(setSpy1.count(), 0);
437 QCOMPARE(setSpy1.count(), 0);
438 QCOMPARE(setSpy2.count(), 1);
438 QCOMPARE(setSpy2.count(), 1);
439
439
440 seriesSpyArg = seriesSpy.takeFirst();
440 seriesSpyArg = seriesSpy.takeFirst();
441 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
441 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
442 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
442 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Int);
443 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
443 QVERIFY(seriesSpyArg.at(0).toInt() == 2);
444
444
445 setSpyArg = setSpy2.takeFirst();
445 setSpyArg = setSpy2.takeFirst();
446 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
446 QVERIFY(setSpyArg.at(0).type() == QVariant::Int);
447 QVERIFY(setSpyArg.at(0).toInt() == 2);
447 QVERIFY(setSpyArg.at(0).toInt() == 2);
448 }
448 }
449
449
450 void tst_QBarSeries::mousehovered_data()
450 void tst_QBarSeries::mousehovered_data()
451 {
451 {
452
452
453 }
453 }
454
454
455 void tst_QBarSeries::mousehovered()
455 void tst_QBarSeries::mousehovered()
456 {
456 {
457 QBarSeries* series = new QBarSeries();
457 QAbstractBarSeries* series = new QAbstractBarSeries();
458
458
459 QBarSet* set1 = new QBarSet(QString("set 1"));
459 QBarSet* set1 = new QBarSet(QString("set 1"));
460 // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
460 // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
461 *set1 << 10 << 10 << 10;
461 *set1 << 10 << 10 << 10;
462 series->append(set1);
462 series->append(set1);
463
463
464 QBarSet* set2 = new QBarSet(QString("set 2"));
464 QBarSet* set2 = new QBarSet(QString("set 2"));
465 // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
465 // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
466 *set2 << 10 << 10 << 10;
466 *set2 << 10 << 10 << 10;
467 series->append(set2);
467 series->append(set2);
468
468
469 QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*)));
469 QSignalSpy seriesSpy(series,SIGNAL(hovered(bool,QBarSet*)));
470 QSignalSpy setSpy1(set1, SIGNAL(hovered(bool)));
470 QSignalSpy setSpy1(set1, SIGNAL(hovered(bool)));
471 QSignalSpy setSpy2(set2, SIGNAL(hovered(bool)));
471 QSignalSpy setSpy2(set2, SIGNAL(hovered(bool)));
472
472
473 QChartView view(new QChart());
473 QChartView view(new QChart());
474 view.resize(400,300);
474 view.resize(400,300);
475 view.chart()->addSeries(series);
475 view.chart()->addSeries(series);
476 view.show();
476 view.show();
477 QTest::qWaitForWindowShown(&view);
477 QTest::qWaitForWindowShown(&view);
478
478
479 //this is hack since view does not get events otherwise
479 //this is hack since view does not get events otherwise
480 view.setMouseTracking(true);
480 view.setMouseTracking(true);
481
481
482 //=======================================================================
482 //=======================================================================
483 // move mouse to left border
483 // move mouse to left border
484 QTest::mouseMove(view.viewport(), QPoint(0, 142));
484 QTest::mouseMove(view.viewport(), QPoint(0, 142));
485 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
485 QCoreApplication::processEvents(QEventLoop::AllEvents, 10000);
486 TRY_COMPARE(seriesSpy.count(), 0);
486 TRY_COMPARE(seriesSpy.count(), 0);
487 TRY_COMPARE(setSpy1.count(), 0);
487 TRY_COMPARE(setSpy1.count(), 0);
488 TRY_COMPARE(setSpy2.count(), 0);
488 TRY_COMPARE(setSpy2.count(), 0);
489
489
490 //=======================================================================
490 //=======================================================================
491 // move mouse on top of set1
491 // move mouse on top of set1
492 QTest::mouseMove(view.viewport(), QPoint(102,142));
492 QTest::mouseMove(view.viewport(), QPoint(102,142));
493 TRY_COMPARE(seriesSpy.count(), 1);
493 TRY_COMPARE(seriesSpy.count(), 1);
494 TRY_COMPARE(setSpy1.count(), 1);
494 TRY_COMPARE(setSpy1.count(), 1);
495 TRY_COMPARE(setSpy2.count(), 0);
495 TRY_COMPARE(setSpy2.count(), 0);
496
496
497 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
497 QList<QVariant> seriesSpyArg = seriesSpy.takeFirst();
498 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
498 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
499 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
499 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
500 QVERIFY(seriesSpyArg.at(0).toBool() == true);
500 QVERIFY(seriesSpyArg.at(0).toBool() == true);
501
501
502 QList<QVariant> setSpyArg = setSpy1.takeFirst();
502 QList<QVariant> setSpyArg = setSpy1.takeFirst();
503 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
503 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
504 QVERIFY(setSpyArg.at(0).toBool() == true);
504 QVERIFY(setSpyArg.at(0).toBool() == true);
505
505
506 //=======================================================================
506 //=======================================================================
507 // move mouse from top of set1 to top of set2
507 // move mouse from top of set1 to top of set2
508 QTest::mouseMove(view.viewport(), QPoint(127,142));
508 QTest::mouseMove(view.viewport(), QPoint(127,142));
509 TRY_COMPARE(seriesSpy.count(), 2);
509 TRY_COMPARE(seriesSpy.count(), 2);
510 TRY_COMPARE(setSpy1.count(), 1);
510 TRY_COMPARE(setSpy1.count(), 1);
511 TRY_COMPARE(setSpy2.count(), 1);
511 TRY_COMPARE(setSpy2.count(), 1);
512
512
513 // should leave set1
513 // should leave set1
514 seriesSpyArg = seriesSpy.takeFirst();
514 seriesSpyArg = seriesSpy.takeFirst();
515 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
515 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set1);
516 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
516 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
517 QVERIFY(seriesSpyArg.at(0).toBool() == false);
517 QVERIFY(seriesSpyArg.at(0).toBool() == false);
518
518
519 setSpyArg = setSpy1.takeFirst();
519 setSpyArg = setSpy1.takeFirst();
520 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
520 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
521 QVERIFY(setSpyArg.at(0).toBool() == false);
521 QVERIFY(setSpyArg.at(0).toBool() == false);
522
522
523 // should enter set2
523 // should enter set2
524 seriesSpyArg = seriesSpy.takeFirst();
524 seriesSpyArg = seriesSpy.takeFirst();
525 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
525 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
526 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
526 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
527 QVERIFY(seriesSpyArg.at(0).toBool() == true);
527 QVERIFY(seriesSpyArg.at(0).toBool() == true);
528
528
529 setSpyArg = setSpy2.takeFirst();
529 setSpyArg = setSpy2.takeFirst();
530 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
530 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
531 QVERIFY(setSpyArg.at(0).toBool() == true);
531 QVERIFY(setSpyArg.at(0).toBool() == true);
532
532
533 //=======================================================================
533 //=======================================================================
534 // move mouse from top of set2 to background
534 // move mouse from top of set2 to background
535 QTest::mouseMove(view.viewport(), QPoint(127,0));
535 QTest::mouseMove(view.viewport(), QPoint(127,0));
536 TRY_COMPARE(seriesSpy.count(), 1);
536 TRY_COMPARE(seriesSpy.count(), 1);
537 TRY_COMPARE(setSpy1.count(), 0);
537 TRY_COMPARE(setSpy1.count(), 0);
538 TRY_COMPARE(setSpy2.count(), 1);
538 TRY_COMPARE(setSpy2.count(), 1);
539
539
540 // should leave set2
540 // should leave set2
541 seriesSpyArg = seriesSpy.takeFirst();
541 seriesSpyArg = seriesSpy.takeFirst();
542 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
542 QCOMPARE(qvariant_cast<QBarSet*>(seriesSpyArg.at(1)), set2);
543 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
543 QVERIFY(seriesSpyArg.at(0).type() == QVariant::Bool);
544 QVERIFY(seriesSpyArg.at(0).toBool() == false);
544 QVERIFY(seriesSpyArg.at(0).toBool() == false);
545
545
546 setSpyArg = setSpy2.takeFirst();
546 setSpyArg = setSpy2.takeFirst();
547 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
547 QVERIFY(setSpyArg.at(0).type() == QVariant::Bool);
548 QVERIFY(setSpyArg.at(0).toBool() == false);
548 QVERIFY(setSpyArg.at(0).toBool() == false);
549 }
549 }
550
550
551 void tst_QBarSeries::clearWithAnimations()
551 void tst_QBarSeries::clearWithAnimations()
552 {
552 {
553 QBarSeries* series = new QBarSeries();
553 QAbstractBarSeries* series = new QAbstractBarSeries();
554
554
555 QBarSet* set1 = new QBarSet(QString("set 1"));
555 QBarSet* set1 = new QBarSet(QString("set 1"));
556 // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
556 // *set1 << QPointF(0,10) << QPointF(1,10) << QPointF(2,10);
557 *set1 << 10 << 10 << 10;
557 *set1 << 10 << 10 << 10;
558 series->append(set1);
558 series->append(set1);
559
559
560 QBarSet* set2 = new QBarSet(QString("set 2"));
560 QBarSet* set2 = new QBarSet(QString("set 2"));
561 // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
561 // *set2 << QPointF(0.3,10) << QPointF(1.3,10) << QPointF(2.3,10);
562 *set2 << 10 << 10 << 10;
562 *set2 << 10 << 10 << 10;
563 series->append(set2);
563 series->append(set2);
564
564
565 QChartView view(new QChart());
565 QChartView view(new QChart());
566 view.resize(400,300);
566 view.resize(400,300);
567 view.chart()->setAnimationOptions(QChart::SeriesAnimations);
567 view.chart()->setAnimationOptions(QChart::SeriesAnimations);
568 view.chart()->addSeries(series);
568 view.chart()->addSeries(series);
569 view.show();
569 view.show();
570
570
571 series->clear();
571 series->clear();
572 }
572 }
573
573
574 QTEST_MAIN(tst_QBarSeries)
574 QTEST_MAIN(tst_QBarSeries)
575
575
576 #include "tst_qbarseries.moc"
576 #include "tst_qbarseries.moc"
577
577
@@ -1,614 +1,614
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 <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qchartview.h>
22 #include <qchartview.h>
23 #include <qlineseries.h>
23 #include <qlineseries.h>
24 #include <qareaseries.h>
24 #include <qareaseries.h>
25 #include <qscatterseries.h>
25 #include <qscatterseries.h>
26 #include <qsplineseries.h>
26 #include <qsplineseries.h>
27 #include <qpieseries.h>
27 #include <qpieseries.h>
28 #include <qbarseries.h>
28 #include <qbarseries.h>
29 #include <qpercentbarseries.h>
29 #include <qpercentbarseries.h>
30 #include <qstackedbarseries.h>
30 #include <qstackedbarseries.h>
31 #include <qvaluesaxis.h>
31 #include <qvaluesaxis.h>
32
32
33 QTCOMMERCIALCHART_USE_NAMESPACE
33 QTCOMMERCIALCHART_USE_NAMESPACE
34
34
35 Q_DECLARE_METATYPE(QAbstractAxis *)
35 Q_DECLARE_METATYPE(QAbstractAxis *)
36 Q_DECLARE_METATYPE(QValuesAxis *)
36 Q_DECLARE_METATYPE(QValuesAxis *)
37 Q_DECLARE_METATYPE(QAbstractSeries *)
37 Q_DECLARE_METATYPE(QAbstractSeries *)
38 Q_DECLARE_METATYPE(QChart::AnimationOption)
38 Q_DECLARE_METATYPE(QChart::AnimationOption)
39 Q_DECLARE_METATYPE(QBrush)
39 Q_DECLARE_METATYPE(QBrush)
40 Q_DECLARE_METATYPE(QPen)
40 Q_DECLARE_METATYPE(QPen)
41 Q_DECLARE_METATYPE(QChart::ChartTheme)
41 Q_DECLARE_METATYPE(QChart::ChartTheme)
42
42
43 class tst_QChart : public QObject
43 class tst_QChart : public QObject
44 {
44 {
45 Q_OBJECT
45 Q_OBJECT
46
46
47 public slots:
47 public slots:
48 void initTestCase();
48 void initTestCase();
49 void cleanupTestCase();
49 void cleanupTestCase();
50 void init();
50 void init();
51 void cleanup();
51 void cleanup();
52
52
53 private slots:
53 private slots:
54 void qchart_data();
54 void qchart_data();
55 void qchart();
55 void qchart();
56
56
57 void addSeries_data();
57 void addSeries_data();
58 void addSeries();
58 void addSeries();
59 void animationOptions_data();
59 void animationOptions_data();
60 void animationOptions();
60 void animationOptions();
61 void axisX_data();
61 void axisX_data();
62 void axisX();
62 void axisX();
63 void axisY_data();
63 void axisY_data();
64 void axisY();
64 void axisY();
65 void backgroundBrush_data();
65 void backgroundBrush_data();
66 void backgroundBrush();
66 void backgroundBrush();
67 void backgroundPen_data();
67 void backgroundPen_data();
68 void backgroundPen();
68 void backgroundPen();
69 void isBackgroundVisible_data();
69 void isBackgroundVisible_data();
70 void isBackgroundVisible();
70 void isBackgroundVisible();
71 void legend_data();
71 void legend_data();
72 void legend();
72 void legend();
73 void margins_data();
73 void margins_data();
74 void margins();
74 void margins();
75 void removeAllSeries_data();
75 void removeAllSeries_data();
76 void removeAllSeries();
76 void removeAllSeries();
77 void removeSeries_data();
77 void removeSeries_data();
78 void removeSeries();
78 void removeSeries();
79 void scroll_data();
79 void scroll_data();
80 void scroll();
80 void scroll();
81 void theme_data();
81 void theme_data();
82 void theme();
82 void theme();
83 void title_data();
83 void title_data();
84 void title();
84 void title();
85 void titleBrush_data();
85 void titleBrush_data();
86 void titleBrush();
86 void titleBrush();
87 void titleFont_data();
87 void titleFont_data();
88 void titleFont();
88 void titleFont();
89 void zoomIn_data();
89 void zoomIn_data();
90 void zoomIn();
90 void zoomIn();
91 void zoomOut_data();
91 void zoomOut_data();
92 void zoomOut();
92 void zoomOut();
93
93
94 private:
94 private:
95 void createTestData();
95 void createTestData();
96
96
97 private:
97 private:
98 QChartView* m_view;
98 QChartView* m_view;
99 QChart* m_chart;
99 QChart* m_chart;
100 };
100 };
101
101
102 void tst_QChart::initTestCase()
102 void tst_QChart::initTestCase()
103 {
103 {
104
104
105 }
105 }
106
106
107 void tst_QChart::cleanupTestCase()
107 void tst_QChart::cleanupTestCase()
108 {
108 {
109
109
110 }
110 }
111
111
112 void tst_QChart::init()
112 void tst_QChart::init()
113 {
113 {
114 m_view = new QChartView(new QChart());
114 m_view = new QChartView(new QChart());
115 m_chart = m_view->chart();
115 m_chart = m_view->chart();
116 }
116 }
117
117
118 void tst_QChart::createTestData()
118 void tst_QChart::createTestData()
119 {
119 {
120 QLineSeries* series0 = new QLineSeries(this);
120 QLineSeries* series0 = new QLineSeries(this);
121 *series0 << QPointF(0, 0) << QPointF(100, 100);
121 *series0 << QPointF(0, 0) << QPointF(100, 100);
122 m_chart->addSeries(series0);
122 m_chart->addSeries(series0);
123 m_view->show();
123 m_view->show();
124 QTest::qWaitForWindowShown(m_view);
124 QTest::qWaitForWindowShown(m_view);
125 }
125 }
126
126
127 void tst_QChart::cleanup()
127 void tst_QChart::cleanup()
128 {
128 {
129 delete m_view;
129 delete m_view;
130 m_view = 0;
130 m_view = 0;
131 m_chart = 0;
131 m_chart = 0;
132 }
132 }
133
133
134 void tst_QChart::qchart_data()
134 void tst_QChart::qchart_data()
135 {
135 {
136 }
136 }
137
137
138 void tst_QChart::qchart()
138 void tst_QChart::qchart()
139 {
139 {
140 QVERIFY(m_chart);
140 QVERIFY(m_chart);
141 QVERIFY(m_chart->legend());
141 QVERIFY(m_chart->legend());
142 QVERIFY(m_chart->legend()->isVisible());
142 QVERIFY(m_chart->legend()->isVisible());
143
143
144 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
144 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
145 QVERIFY(m_chart->axisX());
145 QVERIFY(m_chart->axisX());
146 QVERIFY(m_chart->axisY());
146 QVERIFY(m_chart->axisY());
147 QVERIFY(m_chart->backgroundBrush()!=QBrush());
147 QVERIFY(m_chart->backgroundBrush()!=QBrush());
148 QVERIFY(m_chart->backgroundPen()!=QPen());
148 QVERIFY(m_chart->backgroundPen()!=QPen());
149 QCOMPARE(m_chart->isBackgroundVisible(), true);
149 QCOMPARE(m_chart->isBackgroundVisible(), true);
150
150
151 QVERIFY(m_chart->margins().top()>0);
151 QVERIFY(m_chart->margins().top()>0);
152 QVERIFY(m_chart->margins().left()>0);
152 QVERIFY(m_chart->margins().left()>0);
153 QVERIFY(m_chart->margins().right()>0);
153 QVERIFY(m_chart->margins().right()>0);
154 QVERIFY(m_chart->margins().bottom()>0);
154 QVERIFY(m_chart->margins().bottom()>0);
155
155
156 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
156 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
157 QCOMPARE(m_chart->title(), QString());
157 QCOMPARE(m_chart->title(), QString());
158
158
159 //QCOMPARE(m_chart->titleBrush(),QBrush());
159 //QCOMPARE(m_chart->titleBrush(),QBrush());
160 //QCOMPARE(m_chart->titleFont(),QFont());
160 //QCOMPARE(m_chart->titleFont(),QFont());
161
161
162 m_chart->removeAllSeries();
162 m_chart->removeAllSeries();
163 m_chart->scroll(0,0);
163 m_chart->scroll(0,0);
164
164
165 m_chart->zoomIn();
165 m_chart->zoomIn();
166 m_chart->zoomIn(QRectF());
166 m_chart->zoomIn(QRectF());
167 m_chart->zoomOut();
167 m_chart->zoomOut();
168 }
168 }
169
169
170 void tst_QChart::addSeries_data()
170 void tst_QChart::addSeries_data()
171 {
171 {
172 QTest::addColumn<QAbstractSeries *>("series");
172 QTest::addColumn<QAbstractSeries *>("series");
173 QTest::addColumn<QAbstractAxis *>("axis");
173 QTest::addColumn<QAbstractAxis *>("axis");
174
174
175 QAbstractSeries* series0 = new QLineSeries(this);
175 QAbstractSeries* series0 = new QLineSeries(this);
176 QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0));
176 QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0));
177 QAbstractSeries* series2 = new QScatterSeries(this);
177 QAbstractSeries* series2 = new QScatterSeries(this);
178 QAbstractSeries* series3 = new QSplineSeries(this);
178 QAbstractSeries* series3 = new QSplineSeries(this);
179 QAbstractSeries* series4 = new QPieSeries(this);
179 QAbstractSeries* series4 = new QPieSeries(this);
180 QAbstractSeries* series5 = new QBarSeries(this);
180 QAbstractSeries* series5 = new QAbstractBarSeries(this);
181 QAbstractSeries* series6 = new QPercentBarSeries(this);
181 QAbstractSeries* series6 = new QPercentBarSeries(this);
182 QAbstractSeries* series7 = new QStackedBarSeries(this);
182 QAbstractSeries* series7 = new QStackedBarSeries(this);
183
183
184 QValuesAxis* axis = new QValuesAxis(this);
184 QValuesAxis* axis = new QValuesAxis(this);
185
185
186 QTest::newRow("default axis: lineSeries") << series0 << (QAbstractAxis*) 0;
186 QTest::newRow("default axis: lineSeries") << series0 << (QAbstractAxis*) 0;
187 QTest::newRow("axis0: lineSeries") << series0 << axis;
187 QTest::newRow("axis0: lineSeries") << series0 << axis;
188 QTest::newRow("default axis: areaSeries") << series1 << (QAbstractAxis*) 0;
188 QTest::newRow("default axis: areaSeries") << series1 << (QAbstractAxis*) 0;
189 QTest::newRow("axis: areaSeries") << series1 << axis;
189 QTest::newRow("axis: areaSeries") << series1 << axis;
190 QTest::newRow("default axis: scatterSeries") << series2 << (QAbstractAxis*) 0;
190 QTest::newRow("default axis: scatterSeries") << series2 << (QAbstractAxis*) 0;
191 QTest::newRow("axis1: scatterSeries") << series2 << axis;
191 QTest::newRow("axis1: scatterSeries") << series2 << axis;
192 QTest::newRow("default axis: splineSeries") << series3 << (QAbstractAxis*) 0;
192 QTest::newRow("default axis: splineSeries") << series3 << (QAbstractAxis*) 0;
193 QTest::newRow("axis: splineSeries") << series3 << axis;
193 QTest::newRow("axis: splineSeries") << series3 << axis;
194 QTest::newRow("default axis: pieSeries") << series4 << (QAbstractAxis*) 0;
194 QTest::newRow("default axis: pieSeries") << series4 << (QAbstractAxis*) 0;
195 QTest::newRow("axis: pieSeries") << series4 << axis;
195 QTest::newRow("axis: pieSeries") << series4 << axis;
196 QTest::newRow("default axis: barSeries") << series5 << (QAbstractAxis*) 0;
196 QTest::newRow("default axis: barSeries") << series5 << (QAbstractAxis*) 0;
197 QTest::newRow("axis: barSeries") << series5 << axis;
197 QTest::newRow("axis: barSeries") << series5 << axis;
198 QTest::newRow("default axis: percentBarSeries") << series6 << (QAbstractAxis*) 0;
198 QTest::newRow("default axis: percentBarSeries") << series6 << (QAbstractAxis*) 0;
199 QTest::newRow("axis: barSeries") << series6 << axis;
199 QTest::newRow("axis: barSeries") << series6 << axis;
200 QTest::newRow("default axis: stackedBarSeries") << series7 << (QAbstractAxis*) 0;
200 QTest::newRow("default axis: stackedBarSeries") << series7 << (QAbstractAxis*) 0;
201 QTest::newRow("axis: barSeries") << series7 << axis;
201 QTest::newRow("axis: barSeries") << series7 << axis;
202
202
203 }
203 }
204
204
205 void tst_QChart::addSeries()
205 void tst_QChart::addSeries()
206 {
206 {
207 QFETCH(QAbstractSeries *, series);
207 QFETCH(QAbstractSeries *, series);
208 QFETCH(QAbstractAxis *, axis);
208 QFETCH(QAbstractAxis *, axis);
209 m_view->show();
209 m_view->show();
210 QTest::qWaitForWindowShown(m_view);
210 QTest::qWaitForWindowShown(m_view);
211 if(!axis) axis = m_chart->axisY();
211 if(!axis) axis = m_chart->axisY();
212 QVERIFY(!series->chart());
212 QVERIFY(!series->chart());
213 QCOMPARE(m_chart->series().count(), 0);
213 QCOMPARE(m_chart->series().count(), 0);
214 m_chart->addSeries(series);
214 m_chart->addSeries(series);
215 m_chart->setAxisY(axis,series);
215 m_chart->setAxisY(axis,series);
216 QCOMPARE(m_chart->series().count(), 1);
216 QCOMPARE(m_chart->series().count(), 1);
217 QCOMPARE(m_chart->series().first(), series);
217 QCOMPARE(m_chart->series().first(), series);
218 QVERIFY(series->chart() == m_chart);
218 QVERIFY(series->chart() == m_chart);
219 QCOMPARE(m_chart->axisY(series),axis);
219 QCOMPARE(m_chart->axisY(series),axis);
220 m_chart->removeSeries(series);
220 m_chart->removeSeries(series);
221 QVERIFY(!series->chart());
221 QVERIFY(!series->chart());
222 QCOMPARE(m_chart->series().count(), 0);
222 QCOMPARE(m_chart->series().count(), 0);
223 }
223 }
224
224
225 void tst_QChart::animationOptions_data()
225 void tst_QChart::animationOptions_data()
226 {
226 {
227 QTest::addColumn<QChart::AnimationOption>("animationOptions");
227 QTest::addColumn<QChart::AnimationOption>("animationOptions");
228 QTest::newRow("AllAnimations") << QChart::AllAnimations;
228 QTest::newRow("AllAnimations") << QChart::AllAnimations;
229 QTest::newRow("NoAnimation") << QChart::NoAnimation;
229 QTest::newRow("NoAnimation") << QChart::NoAnimation;
230 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
230 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
231 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
231 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
232 }
232 }
233
233
234 void tst_QChart::animationOptions()
234 void tst_QChart::animationOptions()
235 {
235 {
236 createTestData();
236 createTestData();
237 QFETCH(QChart::AnimationOption, animationOptions);
237 QFETCH(QChart::AnimationOption, animationOptions);
238 m_chart->setAnimationOptions(animationOptions);
238 m_chart->setAnimationOptions(animationOptions);
239 QCOMPARE(m_chart->animationOptions(), animationOptions);
239 QCOMPARE(m_chart->animationOptions(), animationOptions);
240 }
240 }
241
241
242 void tst_QChart::axisX_data()
242 void tst_QChart::axisX_data()
243 {
243 {
244
244
245 }
245 }
246
246
247 void tst_QChart::axisX()
247 void tst_QChart::axisX()
248 {
248 {
249 QVERIFY(m_chart->axisX());
249 QVERIFY(m_chart->axisX());
250 QAbstractAxis* axis = m_chart->axisX();
250 QAbstractAxis* axis = m_chart->axisX();
251 createTestData();
251 createTestData();
252 //it should be the same axis
252 //it should be the same axis
253 QCOMPARE(axis,m_chart->axisX());
253 QCOMPARE(axis,m_chart->axisX());
254 }
254 }
255
255
256 void tst_QChart::axisY_data()
256 void tst_QChart::axisY_data()
257 {
257 {
258 QTest::addColumn<QAbstractAxis*>("axis0");
258 QTest::addColumn<QAbstractAxis*>("axis0");
259 QTest::addColumn<QAbstractAxis*>("axis1");
259 QTest::addColumn<QAbstractAxis*>("axis1");
260 QTest::addColumn<QAbstractAxis*>("axis2");
260 QTest::addColumn<QAbstractAxis*>("axis2");
261 QTest::newRow("1 defualt, 2 optional") << (QAbstractAxis*)0 << new QValuesAxis() << new QValuesAxis();
261 QTest::newRow("1 defualt, 2 optional") << (QAbstractAxis*)0 << new QValuesAxis() << new QValuesAxis();
262 QTest::newRow("3 optional") << new QValuesAxis() << new QValuesAxis() << new QValuesAxis();
262 QTest::newRow("3 optional") << new QValuesAxis() << new QValuesAxis() << new QValuesAxis();
263 }
263 }
264
264
265
265
266 void tst_QChart::axisY()
266 void tst_QChart::axisY()
267 {
267 {
268 QFETCH(QAbstractAxis*, axis0);
268 QFETCH(QAbstractAxis*, axis0);
269 QFETCH(QAbstractAxis*, axis1);
269 QFETCH(QAbstractAxis*, axis1);
270 QFETCH(QAbstractAxis*, axis2);
270 QFETCH(QAbstractAxis*, axis2);
271
271
272 QAbstractAxis* defaultAxisY = m_chart->axisY();
272 QAbstractAxis* defaultAxisY = m_chart->axisY();
273
273
274 QVERIFY2(defaultAxisY, "Missing axisY.");
274 QVERIFY2(defaultAxisY, "Missing axisY.");
275
275
276 QLineSeries* series0 = new QLineSeries();
276 QLineSeries* series0 = new QLineSeries();
277 m_chart->addSeries(series0);
277 m_chart->addSeries(series0);
278 m_chart->setAxisY(axis0,series0);
278 m_chart->setAxisY(axis0,series0);
279
279
280 QLineSeries* series1 = new QLineSeries();
280 QLineSeries* series1 = new QLineSeries();
281 m_chart->addSeries(series1);
281 m_chart->addSeries(series1);
282 m_chart->setAxisY(axis1,series1);
282 m_chart->setAxisY(axis1,series1);
283
283
284 QLineSeries* series2 = new QLineSeries();
284 QLineSeries* series2 = new QLineSeries();
285 m_chart->addSeries(series2);
285 m_chart->addSeries(series2);
286 m_chart->setAxisY(axis2,series2);
286 m_chart->setAxisY(axis2,series2);
287
287
288 if (!axis0)
288 if (!axis0)
289 axis0 = defaultAxisY;
289 axis0 = defaultAxisY;
290 if (!axis1)
290 if (!axis1)
291 axis1 = defaultAxisY;
291 axis1 = defaultAxisY;
292 if (!axis2)
292 if (!axis2)
293 axis2 = defaultAxisY;
293 axis2 = defaultAxisY;
294
294
295 QVERIFY(m_chart->axisY(series0) == axis0);
295 QVERIFY(m_chart->axisY(series0) == axis0);
296 QVERIFY(m_chart->axisY(series1) == axis1);
296 QVERIFY(m_chart->axisY(series1) == axis1);
297 QVERIFY(m_chart->axisY(series2) == axis2);
297 QVERIFY(m_chart->axisY(series2) == axis2);
298 }
298 }
299
299
300 void tst_QChart::backgroundBrush_data()
300 void tst_QChart::backgroundBrush_data()
301 {
301 {
302 QTest::addColumn<QBrush>("backgroundBrush");
302 QTest::addColumn<QBrush>("backgroundBrush");
303 QTest::newRow("null") << QBrush();
303 QTest::newRow("null") << QBrush();
304 QTest::newRow("blue") << QBrush(Qt::blue);
304 QTest::newRow("blue") << QBrush(Qt::blue);
305 QTest::newRow("white") << QBrush(Qt::white);
305 QTest::newRow("white") << QBrush(Qt::white);
306 QTest::newRow("black") << QBrush(Qt::black);
306 QTest::newRow("black") << QBrush(Qt::black);
307 }
307 }
308
308
309 void tst_QChart::backgroundBrush()
309 void tst_QChart::backgroundBrush()
310 {
310 {
311 QFETCH(QBrush, backgroundBrush);
311 QFETCH(QBrush, backgroundBrush);
312 m_chart->setBackgroundBrush(backgroundBrush);
312 m_chart->setBackgroundBrush(backgroundBrush);
313 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
313 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
314 }
314 }
315
315
316 void tst_QChart::backgroundPen_data()
316 void tst_QChart::backgroundPen_data()
317 {
317 {
318 QTest::addColumn<QPen>("backgroundPen");
318 QTest::addColumn<QPen>("backgroundPen");
319 QTest::newRow("null") << QPen();
319 QTest::newRow("null") << QPen();
320 QTest::newRow("blue") << QPen(Qt::blue);
320 QTest::newRow("blue") << QPen(Qt::blue);
321 QTest::newRow("white") << QPen(Qt::white);
321 QTest::newRow("white") << QPen(Qt::white);
322 QTest::newRow("black") << QPen(Qt::black);
322 QTest::newRow("black") << QPen(Qt::black);
323 }
323 }
324
324
325
325
326 void tst_QChart::backgroundPen()
326 void tst_QChart::backgroundPen()
327 {
327 {
328 QFETCH(QPen, backgroundPen);
328 QFETCH(QPen, backgroundPen);
329 m_chart->setBackgroundPen(backgroundPen);
329 m_chart->setBackgroundPen(backgroundPen);
330 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
330 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
331 }
331 }
332
332
333 void tst_QChart::isBackgroundVisible_data()
333 void tst_QChart::isBackgroundVisible_data()
334 {
334 {
335 QTest::addColumn<bool>("isBackgroundVisible");
335 QTest::addColumn<bool>("isBackgroundVisible");
336 QTest::newRow("true") << true;
336 QTest::newRow("true") << true;
337 QTest::newRow("false") << false;
337 QTest::newRow("false") << false;
338 }
338 }
339
339
340 void tst_QChart::isBackgroundVisible()
340 void tst_QChart::isBackgroundVisible()
341 {
341 {
342 QFETCH(bool, isBackgroundVisible);
342 QFETCH(bool, isBackgroundVisible);
343 m_chart->setBackgroundVisible(isBackgroundVisible);
343 m_chart->setBackgroundVisible(isBackgroundVisible);
344 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
344 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
345 }
345 }
346
346
347 void tst_QChart::legend_data()
347 void tst_QChart::legend_data()
348 {
348 {
349
349
350 }
350 }
351
351
352 void tst_QChart::legend()
352 void tst_QChart::legend()
353 {
353 {
354 QLegend *legend = m_chart->legend();
354 QLegend *legend = m_chart->legend();
355 QVERIFY(legend);
355 QVERIFY(legend);
356
356
357 // Colors related signals
357 // Colors related signals
358 QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor)));
358 QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor)));
359 QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor)));
359 QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor)));
360 QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor)));
360 QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor)));
361
361
362 // colorChanged
362 // colorChanged
363 legend->setColor(QColor("aliceblue"));
363 legend->setColor(QColor("aliceblue"));
364 QCOMPARE(colorSpy.count(), 1);
364 QCOMPARE(colorSpy.count(), 1);
365 QBrush b = legend->brush();
365 QBrush b = legend->brush();
366 b.setColor(QColor("aqua"));
366 b.setColor(QColor("aqua"));
367 legend->setBrush(b);
367 legend->setBrush(b);
368 QCOMPARE(colorSpy.count(), 2);
368 QCOMPARE(colorSpy.count(), 2);
369
369
370 // borderColorChanged
370 // borderColorChanged
371 legend->setBorderColor(QColor("aliceblue"));
371 legend->setBorderColor(QColor("aliceblue"));
372 QCOMPARE(borderColorSpy.count(), 1);
372 QCOMPARE(borderColorSpy.count(), 1);
373 QPen p = legend->pen();
373 QPen p = legend->pen();
374 p.setColor(QColor("aqua"));
374 p.setColor(QColor("aqua"));
375 legend->setPen(p);
375 legend->setPen(p);
376 QCOMPARE(borderColorSpy.count(), 2);
376 QCOMPARE(borderColorSpy.count(), 2);
377
377
378 // labelColorChanged
378 // labelColorChanged
379 legend->setLabelColor(QColor("lightsalmon"));
379 legend->setLabelColor(QColor("lightsalmon"));
380 QCOMPARE(labelColorSpy.count(), 1);
380 QCOMPARE(labelColorSpy.count(), 1);
381 b = legend->labelBrush();
381 b = legend->labelBrush();
382 b.setColor(QColor("lightseagreen"));
382 b.setColor(QColor("lightseagreen"));
383 legend->setLabelBrush(b);
383 legend->setLabelBrush(b);
384 QCOMPARE(labelColorSpy.count(), 2);
384 QCOMPARE(labelColorSpy.count(), 2);
385
385
386 // fontChanged
386 // fontChanged
387 QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont)));
387 QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont)));
388 QFont f = legend->font();
388 QFont f = legend->font();
389 f.setBold(!f.bold());
389 f.setBold(!f.bold());
390 legend->setFont(f);
390 legend->setFont(f);
391 QCOMPARE(fontSpy.count(), 1);
391 QCOMPARE(fontSpy.count(), 1);
392 }
392 }
393
393
394 void tst_QChart::margins_data()
394 void tst_QChart::margins_data()
395 {
395 {
396
396
397 }
397 }
398
398
399 void tst_QChart::margins()
399 void tst_QChart::margins()
400 {
400 {
401 createTestData();
401 createTestData();
402 QRectF rect = m_chart->geometry();
402 QRectF rect = m_chart->geometry();
403
403
404 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
404 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
405 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
405 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
406 }
406 }
407
407
408 void tst_QChart::removeAllSeries_data()
408 void tst_QChart::removeAllSeries_data()
409 {
409 {
410
410
411 }
411 }
412
412
413 void tst_QChart::removeAllSeries()
413 void tst_QChart::removeAllSeries()
414 {
414 {
415 QLineSeries* series0 = new QLineSeries(this);
415 QLineSeries* series0 = new QLineSeries(this);
416 QLineSeries* series1 = new QLineSeries(this);
416 QLineSeries* series1 = new QLineSeries(this);
417 QLineSeries* series2 = new QLineSeries(this);
417 QLineSeries* series2 = new QLineSeries(this);
418 QSignalSpy deleteSpy1(series0, SIGNAL(destroyed()));
418 QSignalSpy deleteSpy1(series0, SIGNAL(destroyed()));
419 QSignalSpy deleteSpy2(series1, SIGNAL(destroyed()));
419 QSignalSpy deleteSpy2(series1, SIGNAL(destroyed()));
420 QSignalSpy deleteSpy3(series2, SIGNAL(destroyed()));
420 QSignalSpy deleteSpy3(series2, SIGNAL(destroyed()));
421
421
422 m_chart->addSeries(series0);
422 m_chart->addSeries(series0);
423 m_chart->addSeries(series1);
423 m_chart->addSeries(series1);
424 m_chart->addSeries(series2);
424 m_chart->addSeries(series2);
425 m_view->show();
425 m_view->show();
426 QTest::qWaitForWindowShown(m_view);
426 QTest::qWaitForWindowShown(m_view);
427
427
428 QVERIFY(m_chart->axisY(series0)!=0);
428 QVERIFY(m_chart->axisY(series0)!=0);
429 QVERIFY(m_chart->axisY(series1)!=0);
429 QVERIFY(m_chart->axisY(series1)!=0);
430 QVERIFY(m_chart->axisY(series2)!=0);
430 QVERIFY(m_chart->axisY(series2)!=0);
431
431
432 m_chart->removeAllSeries();
432 m_chart->removeAllSeries();
433 QVERIFY(m_chart->axisY(series0)==0);
433 QVERIFY(m_chart->axisY(series0)==0);
434 QVERIFY(m_chart->axisY(series1)==0);
434 QVERIFY(m_chart->axisY(series1)==0);
435 QVERIFY(m_chart->axisY(series2)==0);
435 QVERIFY(m_chart->axisY(series2)==0);
436 QCOMPARE(deleteSpy1.count(), 1);
436 QCOMPARE(deleteSpy1.count(), 1);
437 QCOMPARE(deleteSpy2.count(), 1);
437 QCOMPARE(deleteSpy2.count(), 1);
438 QCOMPARE(deleteSpy3.count(), 1);
438 QCOMPARE(deleteSpy3.count(), 1);
439 }
439 }
440
440
441 void tst_QChart::removeSeries_data()
441 void tst_QChart::removeSeries_data()
442 {
442 {
443 addSeries_data();
443 addSeries_data();
444 }
444 }
445
445
446 void tst_QChart::removeSeries()
446 void tst_QChart::removeSeries()
447 {
447 {
448 QFETCH(QAbstractSeries *, series);
448 QFETCH(QAbstractSeries *, series);
449 QFETCH(QAbstractAxis *, axis);
449 QFETCH(QAbstractAxis *, axis);
450 QSignalSpy deleteSpy(series, SIGNAL(destroyed()));
450 QSignalSpy deleteSpy(series, SIGNAL(destroyed()));
451 m_view->show();
451 m_view->show();
452 QTest::qWaitForWindowShown(m_view);
452 QTest::qWaitForWindowShown(m_view);
453 if(!axis) axis = m_chart->axisY();
453 if(!axis) axis = m_chart->axisY();
454 m_chart->addSeries(series);
454 m_chart->addSeries(series);
455 m_chart->setAxisY(axis,series);
455 m_chart->setAxisY(axis,series);
456 QCOMPARE(m_chart->axisY(series),axis);
456 QCOMPARE(m_chart->axisY(series),axis);
457 m_chart->removeSeries(series);
457 m_chart->removeSeries(series);
458 QVERIFY(m_chart->axisY(series)==0);
458 QVERIFY(m_chart->axisY(series)==0);
459 QCOMPARE(deleteSpy.count(), 0);
459 QCOMPARE(deleteSpy.count(), 0);
460 }
460 }
461
461
462 void tst_QChart::scroll_data()
462 void tst_QChart::scroll_data()
463 {
463 {
464
464
465 }
465 }
466
466
467 void tst_QChart::scroll()
467 void tst_QChart::scroll()
468 {
468 {
469 qFatal("implement me");
469 qFatal("implement me");
470 createTestData();
470 createTestData();
471 //TODO qreal min = m_chart->axisY()->min();
471 //TODO qreal min = m_chart->axisY()->min();
472 m_chart->scroll(0,0);
472 m_chart->scroll(0,0);
473 //TODO QVERIFY(m_chart->axisY()->min()<min);
473 //TODO QVERIFY(m_chart->axisY()->min()<min);
474 }
474 }
475
475
476 void tst_QChart::theme_data()
476 void tst_QChart::theme_data()
477 {
477 {
478 QTest::addColumn<QChart::ChartTheme>("theme");
478 QTest::addColumn<QChart::ChartTheme>("theme");
479 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
479 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
480 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
480 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
481 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
481 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
482 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
482 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
483 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
483 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
484 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
484 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
485 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
485 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
486 }
486 }
487
487
488 void tst_QChart::theme()
488 void tst_QChart::theme()
489 {
489 {
490 QFETCH(QChart::ChartTheme, theme);
490 QFETCH(QChart::ChartTheme, theme);
491 createTestData();
491 createTestData();
492 m_chart->setTheme(theme);
492 m_chart->setTheme(theme);
493 QVERIFY(m_chart->theme()==theme);
493 QVERIFY(m_chart->theme()==theme);
494 }
494 }
495
495
496 void tst_QChart::title_data()
496 void tst_QChart::title_data()
497 {
497 {
498 QTest::addColumn<QString>("title");
498 QTest::addColumn<QString>("title");
499 QTest::newRow("null") << QString();
499 QTest::newRow("null") << QString();
500 QTest::newRow("foo") << QString("foo");
500 QTest::newRow("foo") << QString("foo");
501 }
501 }
502
502
503 void tst_QChart::title()
503 void tst_QChart::title()
504 {
504 {
505 QFETCH(QString, title);
505 QFETCH(QString, title);
506 m_chart->setTitle(title);
506 m_chart->setTitle(title);
507 QCOMPARE(m_chart->title(), title);
507 QCOMPARE(m_chart->title(), title);
508 }
508 }
509
509
510 void tst_QChart::titleBrush_data()
510 void tst_QChart::titleBrush_data()
511 {
511 {
512 QTest::addColumn<QBrush>("titleBrush");
512 QTest::addColumn<QBrush>("titleBrush");
513 QTest::newRow("null") << QBrush();
513 QTest::newRow("null") << QBrush();
514 QTest::newRow("blue") << QBrush(Qt::blue);
514 QTest::newRow("blue") << QBrush(Qt::blue);
515 QTest::newRow("white") << QBrush(Qt::white);
515 QTest::newRow("white") << QBrush(Qt::white);
516 QTest::newRow("black") << QBrush(Qt::black);
516 QTest::newRow("black") << QBrush(Qt::black);
517 }
517 }
518
518
519 void tst_QChart::titleBrush()
519 void tst_QChart::titleBrush()
520 {
520 {
521 QFETCH(QBrush, titleBrush);
521 QFETCH(QBrush, titleBrush);
522 m_chart->setTitleBrush(titleBrush);
522 m_chart->setTitleBrush(titleBrush);
523 QCOMPARE(m_chart->titleBrush(), titleBrush);
523 QCOMPARE(m_chart->titleBrush(), titleBrush);
524 }
524 }
525
525
526 void tst_QChart::titleFont_data()
526 void tst_QChart::titleFont_data()
527 {
527 {
528 QTest::addColumn<QFont>("titleFont");
528 QTest::addColumn<QFont>("titleFont");
529 QTest::newRow("null") << QFont();
529 QTest::newRow("null") << QFont();
530 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
530 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
531 }
531 }
532
532
533 void tst_QChart::titleFont()
533 void tst_QChart::titleFont()
534 {
534 {
535 QFETCH(QFont, titleFont);
535 QFETCH(QFont, titleFont);
536 m_chart->setTitleFont(titleFont);
536 m_chart->setTitleFont(titleFont);
537 QCOMPARE(m_chart->titleFont(), titleFont);
537 QCOMPARE(m_chart->titleFont(), titleFont);
538 }
538 }
539
539
540 void tst_QChart::zoomIn_data()
540 void tst_QChart::zoomIn_data()
541 {
541 {
542 QTest::addColumn<QRectF>("rect");
542 QTest::addColumn<QRectF>("rect");
543 QTest::newRow("null") << QRectF();
543 QTest::newRow("null") << QRectF();
544 QTest::newRow("100x100") << QRectF(10,10,100,100);
544 QTest::newRow("100x100") << QRectF(10,10,100,100);
545 QTest::newRow("200x200") << QRectF(10,10,200,200);
545 QTest::newRow("200x200") << QRectF(10,10,200,200);
546 }
546 }
547
547
548
548
549 void tst_QChart::zoomIn()
549 void tst_QChart::zoomIn()
550 {
550 {
551 qFatal("implement me");
551 qFatal("implement me");
552 /*
552 /*
553 QFETCH(QRectF, rect);
553 QFETCH(QRectF, rect);
554 createTestData();
554 createTestData();
555 QRectF marigns = m_chart->margins();
555 QRectF marigns = m_chart->margins();
556 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
556 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
557 qreal minX = m_chart->axisX()->min();
557 qreal minX = m_chart->axisX()->min();
558 qreal minY = m_chart->axisY()->min();
558 qreal minY = m_chart->axisY()->min();
559 qreal maxX = m_chart->axisX()->max();
559 qreal maxX = m_chart->axisX()->max();
560 qreal maxY = m_chart->axisY()->max();
560 qreal maxY = m_chart->axisY()->max();
561 m_chart->zoomIn(rect);
561 m_chart->zoomIn(rect);
562 if(rect.isValid()){
562 if(rect.isValid()){
563 QVERIFY(minX<m_chart->axisX()->min());
563 QVERIFY(minX<m_chart->axisX()->min());
564 QVERIFY(maxX>m_chart->axisX()->max());
564 QVERIFY(maxX>m_chart->axisX()->max());
565 QVERIFY(minY<m_chart->axisY()->min());
565 QVERIFY(minY<m_chart->axisY()->min());
566 QVERIFY(maxY>m_chart->axisY()->max());
566 QVERIFY(maxY>m_chart->axisY()->max());
567 }
567 }
568 */
568 */
569 }
569 }
570
570
571 void tst_QChart::zoomOut_data()
571 void tst_QChart::zoomOut_data()
572 {
572 {
573
573
574 }
574 }
575
575
576 void tst_QChart::zoomOut()
576 void tst_QChart::zoomOut()
577 {
577 {
578 qFatal("implement me");
578 qFatal("implement me");
579 createTestData();
579 createTestData();
580 /*
580 /*
581 qreal minX = m_chart->axisX()->min();
581 qreal minX = m_chart->axisX()->min();
582 qreal minY = m_chart->axisY()->min();
582 qreal minY = m_chart->axisY()->min();
583 qreal maxX = m_chart->axisX()->max();
583 qreal maxX = m_chart->axisX()->max();
584 qreal maxY = m_chart->axisY()->max();
584 qreal maxY = m_chart->axisY()->max();
585
585
586 m_chart->zoomIn();
586 m_chart->zoomIn();
587
587
588 QVERIFY(minX < m_chart->axisX()->min());
588 QVERIFY(minX < m_chart->axisX()->min());
589 QVERIFY(maxX > m_chart->axisX()->max());
589 QVERIFY(maxX > m_chart->axisX()->max());
590 QVERIFY(minY < m_chart->axisY()->min());
590 QVERIFY(minY < m_chart->axisY()->min());
591 QVERIFY(maxY > m_chart->axisY()->max());
591 QVERIFY(maxY > m_chart->axisY()->max());
592
592
593 m_chart->zoomOut();
593 m_chart->zoomOut();
594
594
595 // min x may be a zero value
595 // min x may be a zero value
596 if (qFuzzyIsNull(minX))
596 if (qFuzzyIsNull(minX))
597 QVERIFY(qFuzzyIsNull(m_chart->axisX()->min()));
597 QVERIFY(qFuzzyIsNull(m_chart->axisX()->min()));
598 else
598 else
599 QCOMPARE(minX, m_chart->axisX()->min());
599 QCOMPARE(minX, m_chart->axisX()->min());
600
600
601 // min y may be a zero value
601 // min y may be a zero value
602 if (qFuzzyIsNull(minY))
602 if (qFuzzyIsNull(minY))
603 QVERIFY(qFuzzyIsNull(m_chart->axisY()->min()));
603 QVERIFY(qFuzzyIsNull(m_chart->axisY()->min()));
604 else
604 else
605 QCOMPARE(minY, m_chart->axisY()->min());
605 QCOMPARE(minY, m_chart->axisY()->min());
606
606
607 QVERIFY(maxX == m_chart->axisX()->max());
607 QVERIFY(maxX == m_chart->axisX()->max());
608 QVERIFY(maxY == m_chart->axisY()->max());
608 QVERIFY(maxY == m_chart->axisY()->max());
609 */
609 */
610 }
610 }
611
611
612 QTEST_MAIN(tst_QChart)
612 QTEST_MAIN(tst_QChart)
613 #include "tst_qchart.moc"
613 #include "tst_qchart.moc"
614
614
@@ -1,364 +1,364
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 "mainwidget.h"
21 #include "mainwidget.h"
22 #include "dataseriedialog.h"
22 #include "dataseriedialog.h"
23 #include "qchartview.h"
23 #include "qchartview.h"
24 #include "qpieseries.h"
24 #include "qpieseries.h"
25 #include "qscatterseries.h"
25 #include "qscatterseries.h"
26 #include "qlineseries.h"
26 #include "qlineseries.h"
27 #include <qareaseries.h>
27 #include <qareaseries.h>
28 #include <qsplineseries.h>
28 #include <qsplineseries.h>
29 #include <qbarset.h>
29 #include <qbarset.h>
30 #include <qbarseries.h>
30 #include <qbarseries.h>
31 #include <qgroupedbarseries.h>
31 #include <qgroupedbarseries.h>
32 #include <qstackedbarseries.h>
32 #include <qstackedbarseries.h>
33 #include <qpercentbarseries.h>
33 #include <qpercentbarseries.h>
34 #include <QPushButton>
34 #include <QPushButton>
35 #include <QComboBox>
35 #include <QComboBox>
36 #include <QSpinBox>
36 #include <QSpinBox>
37 #include <QCheckBox>
37 #include <QCheckBox>
38 #include <QGridLayout>
38 #include <QGridLayout>
39 #include <QHBoxLayout>
39 #include <QHBoxLayout>
40 #include <QLabel>
40 #include <QLabel>
41 #include <QSpacerItem>
41 #include <QSpacerItem>
42 #include <QMessageBox>
42 #include <QMessageBox>
43 #include <cmath>
43 #include <cmath>
44 #include <QDebug>
44 #include <QDebug>
45 #include <QStandardItemModel>
45 #include <QStandardItemModel>
46 #include <QCategoriesAxis>
46 #include <QCategoriesAxis>
47
47
48
48
49 QTCOMMERCIALCHART_USE_NAMESPACE
49 QTCOMMERCIALCHART_USE_NAMESPACE
50
50
51 MainWidget::MainWidget(QWidget *parent) :
51 MainWidget::MainWidget(QWidget *parent) :
52 QWidget(parent),
52 QWidget(parent),
53 m_addSerieDialog(0),
53 m_addSerieDialog(0),
54 m_chart(0)
54 m_chart(0)
55 {
55 {
56 m_chart = new QChart();
56 m_chart = new QChart();
57
57
58 // Grid layout for the controls for configuring the chart widget
58 // Grid layout for the controls for configuring the chart widget
59 QGridLayout *grid = new QGridLayout();
59 QGridLayout *grid = new QGridLayout();
60 QPushButton *addSeriesButton = new QPushButton("Add series");
60 QPushButton *addSeriesButton = new QPushButton("Add series");
61 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
61 connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries()));
62 grid->addWidget(addSeriesButton, 0, 1);
62 grid->addWidget(addSeriesButton, 0, 1);
63 initBackroundCombo(grid);
63 initBackroundCombo(grid);
64 initScaleControls(grid);
64 initScaleControls(grid);
65 initThemeCombo(grid);
65 initThemeCombo(grid);
66 initCheckboxes(grid);
66 initCheckboxes(grid);
67
67
68 // add row with empty label to make all the other rows static
68 // add row with empty label to make all the other rows static
69 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
69 grid->addWidget(new QLabel(""), grid->rowCount(), 0);
70 grid->setRowStretch(grid->rowCount() - 1, 1);
70 grid->setRowStretch(grid->rowCount() - 1, 1);
71
71
72 // Create chart view with the chart
72 // Create chart view with the chart
73 m_chartView = new QChartView(m_chart, this);
73 m_chartView = new QChartView(m_chart, this);
74 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
74 m_chartView->setRubberBand(QChartView::HorizonalRubberBand);
75
75
76 // Another grid layout as a main layout
76 // Another grid layout as a main layout
77 QGridLayout *mainLayout = new QGridLayout();
77 QGridLayout *mainLayout = new QGridLayout();
78 mainLayout->addLayout(grid, 0, 0);
78 mainLayout->addLayout(grid, 0, 0);
79 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
79 mainLayout->addWidget(m_chartView, 0, 1, 3, 1);
80 setLayout(mainLayout);
80 setLayout(mainLayout);
81 }
81 }
82
82
83 // Combo box for selecting the chart's background
83 // Combo box for selecting the chart's background
84 void MainWidget::initBackroundCombo(QGridLayout *grid)
84 void MainWidget::initBackroundCombo(QGridLayout *grid)
85 {
85 {
86 QComboBox *backgroundCombo = new QComboBox(this);
86 QComboBox *backgroundCombo = new QComboBox(this);
87 backgroundCombo->addItem("Color");
87 backgroundCombo->addItem("Color");
88 backgroundCombo->addItem("Gradient");
88 backgroundCombo->addItem("Gradient");
89 backgroundCombo->addItem("Image");
89 backgroundCombo->addItem("Image");
90 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
90 connect(backgroundCombo, SIGNAL(currentIndexChanged(int)),
91 this, SLOT(backgroundChanged(int)));
91 this, SLOT(backgroundChanged(int)));
92
92
93 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
93 grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0);
94 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
94 grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1);
95 }
95 }
96
96
97 // Scale related controls (auto-scale vs. manual min-max values)
97 // Scale related controls (auto-scale vs. manual min-max values)
98 void MainWidget::initScaleControls(QGridLayout *grid)
98 void MainWidget::initScaleControls(QGridLayout *grid)
99 {
99 {
100 m_autoScaleCheck = new QCheckBox("Automatic scaling");
100 m_autoScaleCheck = new QCheckBox("Automatic scaling");
101 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
101 connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int)));
102 // Allow setting also non-sense values (like -2147483648 and 2147483647)
102 // Allow setting also non-sense values (like -2147483648 and 2147483647)
103 m_xMinSpin = new QSpinBox();
103 m_xMinSpin = new QSpinBox();
104 m_xMinSpin->setMinimum(INT_MIN);
104 m_xMinSpin->setMinimum(INT_MIN);
105 m_xMinSpin->setMaximum(INT_MAX);
105 m_xMinSpin->setMaximum(INT_MAX);
106 m_xMinSpin->setValue(0);
106 m_xMinSpin->setValue(0);
107 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
107 connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int)));
108 m_xMaxSpin = new QSpinBox();
108 m_xMaxSpin = new QSpinBox();
109 m_xMaxSpin->setMinimum(INT_MIN);
109 m_xMaxSpin->setMinimum(INT_MIN);
110 m_xMaxSpin->setMaximum(INT_MAX);
110 m_xMaxSpin->setMaximum(INT_MAX);
111 m_xMaxSpin->setValue(10);
111 m_xMaxSpin->setValue(10);
112 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
112 connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int)));
113 m_yMinSpin = new QSpinBox();
113 m_yMinSpin = new QSpinBox();
114 m_yMinSpin->setMinimum(INT_MIN);
114 m_yMinSpin->setMinimum(INT_MIN);
115 m_yMinSpin->setMaximum(INT_MAX);
115 m_yMinSpin->setMaximum(INT_MAX);
116 m_yMinSpin->setValue(0);
116 m_yMinSpin->setValue(0);
117 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
117 connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int)));
118 m_yMaxSpin = new QSpinBox();
118 m_yMaxSpin = new QSpinBox();
119 m_yMaxSpin->setMinimum(INT_MIN);
119 m_yMaxSpin->setMinimum(INT_MIN);
120 m_yMaxSpin->setMaximum(INT_MAX);
120 m_yMaxSpin->setMaximum(INT_MAX);
121 m_yMaxSpin->setValue(10);
121 m_yMaxSpin->setValue(10);
122 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
122 connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int)));
123
123
124 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
124 grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0);
125 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
125 grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0);
126 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
126 grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1);
127 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
127 grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0);
128 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
128 grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1);
129 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
129 grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0);
130 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
130 grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1);
131 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
131 grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0);
132 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
132 grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1);
133
133
134 m_autoScaleCheck->setChecked(true);
134 m_autoScaleCheck->setChecked(true);
135 }
135 }
136
136
137 // Combo box for selecting theme
137 // Combo box for selecting theme
138 void MainWidget::initThemeCombo(QGridLayout *grid)
138 void MainWidget::initThemeCombo(QGridLayout *grid)
139 {
139 {
140 QComboBox *chartTheme = new QComboBox();
140 QComboBox *chartTheme = new QComboBox();
141 chartTheme->addItem("Default");
141 chartTheme->addItem("Default");
142 chartTheme->addItem("Light");
142 chartTheme->addItem("Light");
143 chartTheme->addItem("Blue Cerulean");
143 chartTheme->addItem("Blue Cerulean");
144 chartTheme->addItem("Dark");
144 chartTheme->addItem("Dark");
145 chartTheme->addItem("Brown Sand");
145 chartTheme->addItem("Brown Sand");
146 chartTheme->addItem("Blue NCS");
146 chartTheme->addItem("Blue NCS");
147 chartTheme->addItem("High Contrast");
147 chartTheme->addItem("High Contrast");
148 chartTheme->addItem("Blue Icy");
148 chartTheme->addItem("Blue Icy");
149 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
149 connect(chartTheme, SIGNAL(currentIndexChanged(int)),
150 this, SLOT(changeChartTheme(int)));
150 this, SLOT(changeChartTheme(int)));
151 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
151 grid->addWidget(new QLabel("Chart theme:"), 8, 0);
152 grid->addWidget(chartTheme, 8, 1);
152 grid->addWidget(chartTheme, 8, 1);
153 }
153 }
154
154
155 // Different check boxes for customizing chart
155 // Different check boxes for customizing chart
156 void MainWidget::initCheckboxes(QGridLayout *grid)
156 void MainWidget::initCheckboxes(QGridLayout *grid)
157 {
157 {
158 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
158 // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off
159 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
159 QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom");
160 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
160 // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool)));
161 zoomCheckBox->setChecked(true);
161 zoomCheckBox->setChecked(true);
162 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
162 grid->addWidget(zoomCheckBox, grid->rowCount(), 0);
163
163
164 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
164 QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias");
165 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
165 connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool)));
166 aliasCheckBox->setChecked(false);
166 aliasCheckBox->setChecked(false);
167 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
167 grid->addWidget(aliasCheckBox, grid->rowCount(), 0);
168 }
168 }
169
169
170 void MainWidget::antiAliasToggled(bool enabled)
170 void MainWidget::antiAliasToggled(bool enabled)
171 {
171 {
172 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
172 m_chartView->setRenderHint(QPainter::Antialiasing, enabled);
173 }
173 }
174
174
175 void MainWidget::addSeries()
175 void MainWidget::addSeries()
176 {
176 {
177 if (!m_addSerieDialog) {
177 if (!m_addSerieDialog) {
178 m_addSerieDialog = new DataSerieDialog(this);
178 m_addSerieDialog = new DataSerieDialog(this);
179 connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)),
179 connect(m_addSerieDialog, SIGNAL(accepted(QString,int,int,QString,bool)),
180 this, SLOT(addSeries(QString,int,int,QString,bool)));
180 this, SLOT(addSeries(QString,int,int,QString,bool)));
181 }
181 }
182 m_addSerieDialog->exec();
182 m_addSerieDialog->exec();
183 }
183 }
184
184
185 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
185 QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics)
186 {
186 {
187 // TODO: dataCharacteristics
187 // TODO: dataCharacteristics
188 QList<RealList> testData;
188 QList<RealList> testData;
189 for (int j(0); j < columnCount; j++) {
189 for (int j(0); j < columnCount; j++) {
190 QList <qreal> newColumn;
190 QList <qreal> newColumn;
191 for (int i(0); i < rowCount; i++) {
191 for (int i(0); i < rowCount; i++) {
192 if (dataCharacteristics == "Sin") {
192 if (dataCharacteristics == "Sin") {
193 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
193 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100));
194 } else if (dataCharacteristics == "Sin + random") {
194 } else if (dataCharacteristics == "Sin + random") {
195 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
195 newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5));
196 } else if (dataCharacteristics == "Random") {
196 } else if (dataCharacteristics == "Random") {
197 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
197 newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX);
198 } else if (dataCharacteristics == "Linear") {
198 } else if (dataCharacteristics == "Linear") {
199 //newColumn.append(i * (j + 1.0));
199 //newColumn.append(i * (j + 1.0));
200 // TODO: temporary hack to make pie work; prevent zero values:
200 // TODO: temporary hack to make pie work; prevent zero values:
201 newColumn.append(i * (j + 1.0) + 0.1);
201 newColumn.append(i * (j + 1.0) + 0.1);
202 } else { // "constant"
202 } else { // "constant"
203 newColumn.append((j + 1.0));
203 newColumn.append((j + 1.0));
204 }
204 }
205 }
205 }
206 testData.append(newColumn);
206 testData.append(newColumn);
207 }
207 }
208 return testData;
208 return testData;
209 }
209 }
210
210
211 QStringList MainWidget::generateLabels(int count)
211 QStringList MainWidget::generateLabels(int count)
212 {
212 {
213 QStringList result;
213 QStringList result;
214 for (int i(0); i < count; i++)
214 for (int i(0); i < count; i++)
215 result.append("label" + QString::number(i));
215 result.append("label" + QString::number(i));
216 return result;
216 return result;
217 }
217 }
218
218
219 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
219 void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled)
220 {
220 {
221 qDebug() << "addSeries: " << seriesName
221 qDebug() << "addSeries: " << seriesName
222 << " columnCount: " << columnCount
222 << " columnCount: " << columnCount
223 << " rowCount: " << rowCount
223 << " rowCount: " << rowCount
224 << " dataCharacteristics: " << dataCharacteristics
224 << " dataCharacteristics: " << dataCharacteristics
225 << " labels enabled: " << labelsEnabled;
225 << " labels enabled: " << labelsEnabled;
226 m_defaultSeriesName = seriesName;
226 m_defaultSeriesName = seriesName;
227
227
228 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
228 QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics);
229
229
230 // Line series and scatter series use similar data
230 // Line series and scatter series use similar data
231 if (seriesName == "Line") {
231 if (seriesName == "Line") {
232 for (int j(0); j < data.count(); j ++) {
232 for (int j(0); j < data.count(); j ++) {
233 QList<qreal> column = data.at(j);
233 QList<qreal> column = data.at(j);
234 QLineSeries *series = new QLineSeries();
234 QLineSeries *series = new QLineSeries();
235 series->setName("line" + QString::number(j));
235 series->setName("line" + QString::number(j));
236 for (int i(0); i < column.count(); i++)
236 for (int i(0); i < column.count(); i++)
237 series->append(i, column.at(i));
237 series->append(i, column.at(i));
238 m_chart->addSeries(series);
238 m_chart->addSeries(series);
239 }
239 }
240 } else if (seriesName == "Area") {
240 } else if (seriesName == "Area") {
241 // TODO: lower series for the area?
241 // TODO: lower series for the area?
242 for (int j(0); j < data.count(); j ++) {
242 for (int j(0); j < data.count(); j ++) {
243 QList<qreal> column = data.at(j);
243 QList<qreal> column = data.at(j);
244 QLineSeries *lineSeries = new QLineSeries();
244 QLineSeries *lineSeries = new QLineSeries();
245 for (int i(0); i < column.count(); i++)
245 for (int i(0); i < column.count(); i++)
246 lineSeries->append(i, column.at(i));
246 lineSeries->append(i, column.at(i));
247 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
247 QAreaSeries *areaSeries = new QAreaSeries(lineSeries);
248 areaSeries->setName("area" + QString::number(j));
248 areaSeries->setName("area" + QString::number(j));
249 m_chart->addSeries(areaSeries);
249 m_chart->addSeries(areaSeries);
250 }
250 }
251 } else if (seriesName == "Scatter") {
251 } else if (seriesName == "Scatter") {
252 for (int j(0); j < data.count(); j++) {
252 for (int j(0); j < data.count(); j++) {
253 QList<qreal> column = data.at(j);
253 QList<qreal> column = data.at(j);
254 QScatterSeries *series = new QScatterSeries();
254 QScatterSeries *series = new QScatterSeries();
255 series->setName("scatter" + QString::number(j));
255 series->setName("scatter" + QString::number(j));
256 for (int i(0); i < column.count(); i++)
256 for (int i(0); i < column.count(); i++)
257 series->append(i, column.at(i));
257 series->append(i, column.at(i));
258 m_chart->addSeries(series);
258 m_chart->addSeries(series);
259 }
259 }
260 } else if (seriesName == "Pie") {
260 } else if (seriesName == "Pie") {
261 QStringList labels = generateLabels(rowCount);
261 QStringList labels = generateLabels(rowCount);
262 for (int j(0); j < data.count(); j++) {
262 for (int j(0); j < data.count(); j++) {
263 QPieSeries *series = new QPieSeries();
263 QPieSeries *series = new QPieSeries();
264 QList<qreal> column = data.at(j);
264 QList<qreal> column = data.at(j);
265 for (int i(0); i < column.count(); i++)
265 for (int i(0); i < column.count(); i++)
266 series->append(labels.at(i), column.at(i));
266 series->append(labels.at(i), column.at(i));
267 m_chart->addSeries(series);
267 m_chart->addSeries(series);
268 }
268 }
269 } else if (seriesName == "Bar"
269 } else if (seriesName == "Bar"
270 || seriesName == "Grouped bar"
270 || seriesName == "Grouped bar"
271 || seriesName == "Stacked bar"
271 || seriesName == "Stacked bar"
272 || seriesName == "Percent bar") {
272 || seriesName == "Percent bar") {
273 QStringList category;
273 QStringList category;
274 QStringList labels = generateLabels(rowCount);
274 QStringList labels = generateLabels(rowCount);
275 foreach(QString label, labels)
275 foreach(QString label, labels)
276 category << label;
276 category << label;
277 QBarSeries* series = 0;
277 QAbstractBarSeries* series = 0;
278 if (seriesName == "Bar") {
278 if (seriesName == "Bar") {
279 series = new QBarSeries(this);
279 series = new QAbstractBarSeries(this);
280 QCategoriesAxis* axis = new QCategoriesAxis();
280 QCategoriesAxis* axis = new QCategoriesAxis();
281 axis->append(category);
281 axis->append(category);
282 m_chart->setAxisX(axis,series);
282 m_chart->setAxisX(axis,series);
283 } else if (seriesName == "Grouped bar") {
283 } else if (seriesName == "Grouped bar") {
284 series = new QGroupedBarSeries(this);
284 series = new QGroupedBarSeries(this);
285 QCategoriesAxis* axis = new QCategoriesAxis();
285 QCategoriesAxis* axis = new QCategoriesAxis();
286 axis->append(category);
286 axis->append(category);
287 m_chart->setAxisX(axis,series);
287 m_chart->setAxisX(axis,series);
288 } else if (seriesName == "Stacked bar") {
288 } else if (seriesName == "Stacked bar") {
289 series = new QStackedBarSeries(this);
289 series = new QStackedBarSeries(this);
290 QCategoriesAxis* axis = new QCategoriesAxis();
290 QCategoriesAxis* axis = new QCategoriesAxis();
291 axis->append(category);
291 axis->append(category);
292 m_chart->setAxisX(axis,series);
292 m_chart->setAxisX(axis,series);
293 } else {
293 } else {
294 series = new QPercentBarSeries(this);
294 series = new QPercentBarSeries(this);
295 QCategoriesAxis* axis = new QCategoriesAxis();
295 QCategoriesAxis* axis = new QCategoriesAxis();
296 axis->append(category);
296 axis->append(category);
297 m_chart->setAxisX(axis,series);
297 m_chart->setAxisX(axis,series);
298 }
298 }
299
299
300 for (int j(0); j < data.count(); j++) {
300 for (int j(0); j < data.count(); j++) {
301 QList<qreal> column = data.at(j);
301 QList<qreal> column = data.at(j);
302 QBarSet *set = new QBarSet("set" + QString::number(j));
302 QBarSet *set = new QBarSet("set" + QString::number(j));
303 for (int i(0); i < column.count(); i++)
303 for (int i(0); i < column.count(); i++)
304 *set << column.at(i);
304 *set << column.at(i);
305 series->append(set);
305 series->append(set);
306 }
306 }
307
307
308 m_chart->addSeries(series);
308 m_chart->addSeries(series);
309 } else if (seriesName == "Spline") {
309 } else if (seriesName == "Spline") {
310 for (int j(0); j < data.count(); j ++) {
310 for (int j(0); j < data.count(); j ++) {
311 QList<qreal> column = data.at(j);
311 QList<qreal> column = data.at(j);
312 QSplineSeries *series = new QSplineSeries();
312 QSplineSeries *series = new QSplineSeries();
313 for (int i(0); i < column.count(); i++)
313 for (int i(0); i < column.count(); i++)
314 series->append(i, column.at(i));
314 series->append(i, column.at(i));
315 m_chart->addSeries(series);
315 m_chart->addSeries(series);
316 }
316 }
317 }
317 }
318 m_chart->createDefaultAxes();
318 m_chart->createDefaultAxes();
319 }
319 }
320
320
321 void MainWidget::backgroundChanged(int itemIndex)
321 void MainWidget::backgroundChanged(int itemIndex)
322 {
322 {
323 qDebug() << "backgroundChanged: " << itemIndex;
323 qDebug() << "backgroundChanged: " << itemIndex;
324 }
324 }
325
325
326 void MainWidget::autoScaleChanged(int value)
326 void MainWidget::autoScaleChanged(int value)
327 {
327 {
328 if (value) {
328 if (value) {
329 // TODO: enable auto scaling
329 // TODO: enable auto scaling
330 } else {
330 } else {
331 // TODO: set scaling manually (and disable auto scaling)
331 // TODO: set scaling manually (and disable auto scaling)
332 }
332 }
333
333
334 m_xMinSpin->setEnabled(!value);
334 m_xMinSpin->setEnabled(!value);
335 m_xMaxSpin->setEnabled(!value);
335 m_xMaxSpin->setEnabled(!value);
336 m_yMinSpin->setEnabled(!value);
336 m_yMinSpin->setEnabled(!value);
337 m_yMaxSpin->setEnabled(!value);
337 m_yMaxSpin->setEnabled(!value);
338 }
338 }
339
339
340 void MainWidget::xMinChanged(int value)
340 void MainWidget::xMinChanged(int value)
341 {
341 {
342 qDebug() << "xMinChanged: " << value;
342 qDebug() << "xMinChanged: " << value;
343 }
343 }
344
344
345 void MainWidget::xMaxChanged(int value)
345 void MainWidget::xMaxChanged(int value)
346 {
346 {
347 qDebug() << "xMaxChanged: " << value;
347 qDebug() << "xMaxChanged: " << value;
348 }
348 }
349
349
350 void MainWidget::yMinChanged(int value)
350 void MainWidget::yMinChanged(int value)
351 {
351 {
352 qDebug() << "yMinChanged: " << value;
352 qDebug() << "yMinChanged: " << value;
353 }
353 }
354
354
355 void MainWidget::yMaxChanged(int value)
355 void MainWidget::yMaxChanged(int value)
356 {
356 {
357 qDebug() << "yMaxChanged: " << value;
357 qDebug() << "yMaxChanged: " << value;
358 }
358 }
359
359
360 void MainWidget::changeChartTheme(int themeIndex)
360 void MainWidget::changeChartTheme(int themeIndex)
361 {
361 {
362 qDebug() << "changeChartTheme: " << themeIndex;
362 qDebug() << "changeChartTheme: " << themeIndex;
363 m_chart->setTheme((QChart::ChartTheme) themeIndex);
363 m_chart->setTheme((QChart::ChartTheme) themeIndex);
364 }
364 }
General Comments 0
You need to be logged in to leave comments. Login now