##// END OF EJS Templates
Updates chartdataset unit test
Michal Klocek -
r771:9f133768a877
parent child
Show More
@@ -1,331 +1,346
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include "chartdataset_p.h"
21 #include "chartdataset_p.h"
2 #include "qchartaxis.h"
22 #include "qchartaxis.h"
3 //series
23 //series
4 #include "qlineseries.h"
24 #include "qlineseries.h"
5 #include "qareaseries.h"
25 #include "qareaseries.h"
6 #include "qbarseries.h"
26 #include "qbarseries.h"
7 #include "qstackedbarseries.h"
27 #include "qstackedbarseries.h"
8 #include "qpercentbarseries.h"
28 #include "qpercentbarseries.h"
9 #include "qpieseries.h"
29 #include "qpieseries.h"
10 #include "qscatterseries.h"
30 #include "qscatterseries.h"
11 #include "qsplineseries.h"
31 #include "qsplineseries.h"
12
32
13 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33 QTCOMMERCIALCHART_BEGIN_NAMESPACE
14
34
15 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
35 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
16 m_axisX(new QChartAxis(this)),
36 m_axisX(new QChartAxis(this)),
17 m_axisY(new QChartAxis(this)),
37 m_axisY(new QChartAxis(this)),
18 m_domainIndex(0),
38 m_domainIndex(0),
19 m_axisXInitialized(false)
39 m_axisXInitialized(false)
20 {
40 {
21 }
41 }
22
42
23 ChartDataSet::~ChartDataSet()
43 ChartDataSet::~ChartDataSet()
24 {
44 {
25 }
45 }
26
46
27 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
47 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY)
28 {
48 {
29 if(axisY==0) axisY = m_axisY;
49 if(axisY==0) axisY = m_axisY;
30
50
31 QChartAxis* axis = m_seriesAxisMap.value(series);
51 QChartAxis* axis = m_seriesAxisMap.value(series);
32
52
33 if(axis) {
53 if(axis) {
34 qWarning() << "Can not add series. Series already on the chart";
54 qWarning() << "Can not add series. Series already on the chart";
35 return;
55 return;
36 }
56 }
37
57
38 if(!series->parent()){
58 if(!series->parent()){
39 series->setParent(this); // take ownership
59 series->setParent(this); // take ownership
40 };
60 };
41
61
42 if(!axisY->parent()){
62 if(!axisY->parent()){
43 axisY->setParent(this); // take ownership
63 axisY->setParent(this); // take ownership
44 }
64 }
45
65
46 Domain* domain = m_axisDomainMap.value(axisY);
66 Domain* domain = m_axisDomainMap.value(axisY);
47
67
48 if(!domain) {
68 if(!domain) {
49 domain = new Domain();
69 domain = new Domain();
50 QObject::connect(axisY,SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
70 QObject::connect(axisY,SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
51 QObject::connect(axisX(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
71 QObject::connect(axisX(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
52 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY,SLOT(handleAxisRangeChanged(qreal,qreal,int)));
72 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY,SLOT(handleAxisRangeChanged(qreal,qreal,int)));
53 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
73 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
54 //initialize
74 //initialize
55 m_axisDomainMap.insert(axisY,domain);
75 m_axisDomainMap.insert(axisY,domain);
56 emit axisAdded(axisY,domain);
76 emit axisAdded(axisY,domain);
57 }
77 }
58
78
59 if(!m_axisXInitialized){
79 if(!m_axisXInitialized){
60 emit axisAdded(axisX(),domain);
80 emit axisAdded(axisX(),domain);
61 m_axisXInitialized=true;
81 m_axisXInitialized=true;
62 }
82 }
63
83
64 calculateDomain(series,domain);
84 calculateDomain(series,domain);
65
85
66 m_seriesAxisMap.insert(series,axisY);
86 m_seriesAxisMap.insert(series,axisY);
67 emit seriesAdded(series,domain);
87 emit seriesAdded(series,domain);
68
88
69 }
89 }
70
90
71 void ChartDataSet::removeSeries(QSeries* series)
91 void ChartDataSet::removeSeries(QSeries* series)
72 {
92 {
73
93
74 QChartAxis* axis = m_seriesAxisMap.value(series);
94 QChartAxis* axis = m_seriesAxisMap.value(series);
75
95
76 if(!axis){
96 if(!axis){
77 qWarning()<<"Can not remove series. Series not found on the chart.";
97 qWarning()<<"Can not remove series. Series not found on the chart.";
78 return;
98 return;
79 }
99 }
80 emit seriesRemoved(series);
100 emit seriesRemoved(series);
81 m_seriesAxisMap.remove(series);
101 m_seriesAxisMap.remove(series);
82
102
83 if(series->parent()==this){
103 if(series->parent()==this){
84 delete series;
104 delete series;
85 series=0;
105 series=0;
86 }
106 }
87
107
88 QList<QChartAxis*> axes = m_seriesAxisMap.values();
108 QList<QChartAxis*> axes = m_seriesAxisMap.values();
89
109
90 int i = axes.indexOf(axis);
110 int i = axes.indexOf(axis);
91
111
92 if(i==-1){
112 if(i==-1){
93 Domain* domain = m_axisDomainMap.take(axis);
113 Domain* domain = m_axisDomainMap.take(axis);
94 emit axisRemoved(axis);
114 emit axisRemoved(axis);
95 if(axis!=axisY()){
115 if(axis!=axisY()){
96 if(axis->parent()==this){
116 if(axis->parent()==this){
97 delete axis;
117 delete axis;
98 axis=0;
118 axis=0;
99 }
119 }
100 }
120 }
101 delete domain;
121 delete domain;
102 }
122 }
103
123
104 if(m_seriesAxisMap.values().size()==0)
124 if(m_seriesAxisMap.values().size()==0)
105 {
125 {
106 m_axisXInitialized=false;
126 m_axisXInitialized=false;
107 emit axisRemoved(axisX());
127 emit axisRemoved(axisX());
108 }
128 }
109 }
129 }
110
130
111 void ChartDataSet::removeAllSeries()
131 void ChartDataSet::removeAllSeries()
112 {
132 {
113
133
114 QList<QSeries*> series = m_seriesAxisMap.keys();
134 QList<QSeries*> series = m_seriesAxisMap.keys();
115
135
116 foreach(QSeries* s , series) {
136 foreach(QSeries* s , series) {
117 removeSeries(s);
137 removeSeries(s);
118 }
138 }
119
139
120 Q_ASSERT(m_seriesAxisMap.count()==0);
140 Q_ASSERT(m_seriesAxisMap.count()==0);
121 Q_ASSERT(m_axisDomainMap.count()==0);
141 Q_ASSERT(m_axisDomainMap.count()==0);
122
142
123 }
143 }
124
144
125 //to be removed with PIMPL
145 //to be removed with PIMPL
126 void ChartDataSet::calculateDomain(QSeries* series,Domain* domain)
146 void ChartDataSet::calculateDomain(QSeries* series,Domain* domain)
127 {
147 {
128 qreal minX(domain->minX());
148 qreal minX(domain->minX());
129 qreal minY(domain->minY());
149 qreal minY(domain->minY());
130 qreal maxX(domain->maxX());
150 qreal maxX(domain->maxX());
131 qreal maxY(domain->maxY());
151 qreal maxY(domain->maxY());
132 int tickXCount(domain->tickXCount());
152 int tickXCount(domain->tickXCount());
133 int tickYCount(domain->tickYCount());
153 int tickYCount(domain->tickYCount());
134
154
135
155
136 switch(series->type())
156 switch(series->type())
137 {
157 {
138 case QSeries::SeriesTypeLine:
158 case QSeries::SeriesTypeLine:
139 case QSeries::SeriesTypeSpline:
159 case QSeries::SeriesTypeSpline:
140 case QSeries::SeriesTypeScatter:
160 case QSeries::SeriesTypeScatter:
141 {
161 {
142
162
143 QXYSeries* xySeries = static_cast<QXYSeries*>(series);
163 QXYSeries* xySeries = static_cast<QXYSeries*>(series);
144
164
145 for (int i = 0; i < xySeries->count(); i++)
165 for (int i = 0; i < xySeries->count(); i++)
146 {
166 {
147 qreal x = xySeries->x(i);
167 qreal x = xySeries->x(i);
148 qreal y = xySeries->y(i);
168 qreal y = xySeries->y(i);
149 minX = qMin(minX, x);
169 minX = qMin(minX, x);
150 minY = qMin(minY, y);
170 minY = qMin(minY, y);
151 maxX = qMax(maxX, x);
171 maxX = qMax(maxX, x);
152 maxY = qMax(maxY, y);
172 maxY = qMax(maxY, y);
153 }
173 }
154 break;
174 break;
155 }
175 }
156 case QSeries::SeriesTypeArea: {
176 case QSeries::SeriesTypeArea: {
157
177
158 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
178 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
159 QLineSeries* upperSeries = areaSeries->upperSeries();
179 QLineSeries* upperSeries = areaSeries->upperSeries();
160 QLineSeries* lowerSeries = areaSeries->lowerSeries();
180 QLineSeries* lowerSeries = areaSeries->lowerSeries();
161
181
162 for (int i = 0; i < upperSeries->count(); i++)
182 for (int i = 0; i < upperSeries->count(); i++)
163 {
183 {
164 qreal x = upperSeries->x(i);
184 qreal x = upperSeries->x(i);
165 qreal y = upperSeries->y(i);
185 qreal y = upperSeries->y(i);
166 minX = qMin(minX, x);
186 minX = qMin(minX, x);
167 minY = qMin(minY, y);
187 minY = qMin(minY, y);
168 maxX = qMax(maxX, x);
188 maxX = qMax(maxX, x);
169 maxY = qMax(maxY, y);
189 maxY = qMax(maxY, y);
170 }
190 }
171 if(lowerSeries) {
191 if(lowerSeries) {
172 for (int i = 0; i < lowerSeries->count(); i++)
192 for (int i = 0; i < lowerSeries->count(); i++)
173 {
193 {
174 qreal x = lowerSeries->x(i);
194 qreal x = lowerSeries->x(i);
175 qreal y = lowerSeries->y(i);
195 qreal y = lowerSeries->y(i);
176 minX = qMin(minX, x);
196 minX = qMin(minX, x);
177 minY = qMin(minY, y);
197 minY = qMin(minY, y);
178 maxX = qMax(maxX, x);
198 maxX = qMax(maxX, x);
179 maxY = qMax(maxY, y);
199 maxY = qMax(maxY, y);
180 }}
200 }}
181 break;
201 break;
182 }
202 }
183 case QSeries::SeriesTypeBar: {
203 case QSeries::SeriesTypeBar: {
184
204
185 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
205 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
186 qreal x = barSeries->categoryCount();
206 qreal x = barSeries->categoryCount();
187 qreal y = barSeries->max();
207 qreal y = barSeries->max();
188 minX = qMin(minX, x);
208 minX = qMin(minX, x);
189 minY = qMin(minY, y);
209 minY = qMin(minY, y);
190 maxX = qMax(maxX, x);
210 maxX = qMax(maxX, x);
191 maxY = qMax(maxY, y);
211 maxY = qMax(maxY, y);
192 tickXCount = x+1;
212 tickXCount = x+1;
193 setupCategories(barSeries);
213 setupCategories(barSeries);
194 break;
214 break;
195 }
215 }
196 case QSeries::SeriesTypeStackedBar: {
216 case QSeries::SeriesTypeStackedBar: {
197
217
198 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
218 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
199 qreal x = stackedBarSeries->categoryCount();
219 qreal x = stackedBarSeries->categoryCount();
200 qreal y = stackedBarSeries->maxCategorySum();
220 qreal y = stackedBarSeries->maxCategorySum();
201 minX = qMin(minX, x);
221 minX = qMin(minX, x);
202 minY = qMin(minY, y);
222 minY = qMin(minY, y);
203 maxX = qMax(maxX, x);
223 maxX = qMax(maxX, x);
204 maxY = qMax(maxY, y);
224 maxY = qMax(maxY, y);
205 tickXCount = x+1;
225 tickXCount = x+1;
206 setupCategories(stackedBarSeries);
226 setupCategories(stackedBarSeries);
207 break;
227 break;
208 }
228 }
209 case QSeries::SeriesTypePercentBar: {
229 case QSeries::SeriesTypePercentBar: {
210
230
211 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
231 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
212 qreal x = percentBarSeries->categoryCount();
232 qreal x = percentBarSeries->categoryCount();
213 minX = qMin(minX, x);
233 minX = qMin(minX, x);
214 maxX = qMax(maxX, x);
234 maxX = qMax(maxX, x);
215 minY = 0;
235 minY = 0;
216 maxY = 100;
236 maxY = 100;
217 setupCategories(percentBarSeries);
237 setupCategories(percentBarSeries);
218 break;
238 break;
219 }
239 }
220
240
221 case QSeries::SeriesTypePie: {
241 case QSeries::SeriesTypePie: {
222 //QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
242 //QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
223 // TODO: domain stuff
243 // TODO: domain stuff
224 break;
244 break;
225 }
245 }
226
246
227
247
228 default: {
248 default: {
229 qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
249 qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
230 return;
250 return;
231 break;
251 break;
232 }
252 }
233
253
234 }
254 }
235
255
236 domain->setRangeX(minX,maxX,tickXCount);
256 domain->setRangeX(minX,maxX,tickXCount);
237 domain->setRangeY(minY,maxY,tickYCount);
257 domain->setRangeY(minY,maxY,tickYCount);
238 }
258 }
239
259
240
260
241 void ChartDataSet::setupCategories(QBarSeries* series)
261 void ChartDataSet::setupCategories(QBarSeries* series)
242 {
262 {
243 QChartAxisCategories* categories = axisX()->categories();
263 QChartAxisCategories* categories = axisX()->categories();
244 categories->clear();
264 categories->clear();
245 categories->insert(series->categories());
265 categories->insert(series->categories());
246 }
266 }
247
267
248 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
268 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
249 {
269 {
250 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
270 QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap);
251 while (i.hasNext()) {
271 while (i.hasNext()) {
252 i.next();
272 i.next();
253 i.value()->zoomIn(rect,size);
273 i.value()->zoomIn(rect,size);
254 }
274 }
255 }
275 }
256
276
257 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
277 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
258 {
278 {
259 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
279 QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap);
260 while (i.hasNext()) {
280 while (i.hasNext()) {
261 i.next();
281 i.next();
262 i.value()->zoomOut(rect,size);
282 i.value()->zoomOut(rect,size);
263 }
283 }
264 }
284 }
265
285
266 int ChartDataSet::seriesCount(QSeries::QSeriesType type)
286 int ChartDataSet::seriesCount(QSeries::QSeriesType type)
267 {
287 {
268 int count=0;
288 int count=0;
269 QMapIterator<QSeries*, QChartAxis*> i( m_seriesAxisMap);
289 QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap);
270 while (i.hasNext()) {
290 while (i.hasNext()) {
271 i.next();
291 i.next();
272 if(i.key()->type()==type) count++;
292 if(i.key()->type()==type) count++;
273 }
293 }
274 return count;
294 return count;
275 }
295 }
276
296
277 int ChartDataSet::seriesIndex(QSeries *series)
297 int ChartDataSet::seriesIndex(QSeries *series)
278 {
298 {
279 int count(-1);
299 int count=-1;
280 QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap);
300 QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap);
281 while (i.hasNext()) {
301 while (i.hasNext()) {
282 i.next();
302 i.next();
283 count++;
303 count++;
284 if (i.key() == series)
304 if (i.key() == series)
285 return count;
305 return count;
286 }
306 }
287 return count;
307 return count;
288 }
308 }
289
309
290 QChartAxis* ChartDataSet::axisY(QSeries* series) const
310 QChartAxis* ChartDataSet::axisY(QSeries* series) const
291 {
311 {
292 if(series == 0) return m_axisY;
312 if(series == 0) return m_axisY;
293 return m_seriesAxisMap.value(series);
313 return m_seriesAxisMap.value(series);
294 }
314 }
295
315
296 Domain* ChartDataSet::domain(QSeries* series) const
316 Domain* ChartDataSet::domain(QSeries* series) const
297 {
317 {
298 QChartAxis* axis = m_seriesAxisMap.value(series);
318 QChartAxis* axis = m_seriesAxisMap.value(series);
299 if(axis){
319 if(axis){
300 return m_axisDomainMap.value(axis);
320 return m_axisDomainMap.value(axis);
301 }else
321 }else
302 return 0;
322 return 0;
303 }
323 }
304
324
305 Domain* ChartDataSet::domain(QChartAxis* axis) const
325 Domain* ChartDataSet::domain(QChartAxis* axis) const
306 {
326 {
307 if(axis==axisX()) {
327 if(!axis || axis==axisX()) {
308 return m_axisDomainMap.value(axisY());
328 return m_axisDomainMap.value(axisY());
309 }
329 }
310 else {
330 else {
311 return m_axisDomainMap.value(axis);
331 return m_axisDomainMap.value(axis);
312 }
332 }
313 }
333 }
314
334
315 QChartAxis* ChartDataSet::axis(QSeries* series) const
316 {
317 return m_seriesAxisMap.value(series);
318 }
319
320 void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size)
335 void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size)
321 {
336 {
322 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
337 QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap);
323 while (i.hasNext()) {
338 while (i.hasNext()) {
324 i.next();
339 i.next();
325 i.value()->move(dx,dy,size);
340 i.value()->move(dx,dy,size);
326 }
341 }
327 }
342 }
328
343
329 #include "moc_chartdataset_p.cpp"
344 #include "moc_chartdataset_p.cpp"
330
345
331 QTCOMMERCIALCHART_END_NAMESPACE
346 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,61 +1,89
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
21 // W A R N I N G
22 // -------------
23 //
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
26 // version without notice, or even be removed.
27 //
28 // We mean it.
29
1 #ifndef CHARTDATASET_P_H_
30 #ifndef CHARTDATASET_P_H_
2 #define CHARTDATASET_P_H_
31 #define CHARTDATASET_P_H_
3
32
4 #include "qseries.h"
33 #include "qseries.h"
5 #include "domain_p.h"
34 #include "domain_p.h"
6 #include <QVector>
35 #include <QVector>
7
36
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
38
10 class QChartAxis;
39 class QChartAxis;
11 class QBarSeries;
40 class QBarSeries;
12
41
13 class ChartDataSet : public QObject
42 class ChartDataSet : public QObject
14 {
43 {
15 Q_OBJECT
44 Q_OBJECT
16 public:
45 public:
17 ChartDataSet(QObject* parent=0);
46 ChartDataSet(QObject* parent=0);
18 virtual ~ChartDataSet();
47 virtual ~ChartDataSet();
19
48
20 void addSeries(QSeries* series,QChartAxis *axisY = 0);
49 void addSeries(QSeries* series,QChartAxis *axisY = 0);
21 void removeSeries(QSeries* series);
50 void removeSeries(QSeries* series);
22 void removeAllSeries();
51 void removeAllSeries();
23
52
24 void zoomInDomain(const QRectF& rect, const QSizeF& size);
53 void zoomInDomain(const QRectF& rect, const QSizeF& size);
25 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
54 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
26 void scrollDomain(int dx,int dy,const QSizeF& size);
55 void scrollDomain(int dx,int dy,const QSizeF& size);
27
56
28 int seriesCount(QSeries::QSeriesType type);
57 int seriesCount(QSeries::QSeriesType type);
29 int seriesIndex(QSeries *series);
58 int seriesIndex(QSeries *series);
30
59
31 Domain* domain(QSeries* series) const;
60 Domain* domain(QSeries* series) const;
32 Domain* domain(QChartAxis* axis) const;
61 Domain* domain(QChartAxis* axis) const;
33 QChartAxis* axis(QSeries* series) const;
34
62
35 QChartAxis* axisX() const { return m_axisX; }
63 QChartAxis* axisX() const { return m_axisX; }
36 QChartAxis* axisY(QSeries* series = 0) const;
64 QChartAxis* axisY(QSeries* series = 0) const;
37
65
38 signals:
66 Q_SIGNALS:
39 void seriesAdded(QSeries* series,Domain* domain);
67 void seriesAdded(QSeries* series,Domain* domain);
40 void seriesRemoved(QSeries* series);
68 void seriesRemoved(QSeries* series);
41 void axisAdded(QChartAxis* axis,Domain* domain);
69 void axisAdded(QChartAxis* axis,Domain* domain);
42 void axisRemoved(QChartAxis* axis);
70 void axisRemoved(QChartAxis* axis);
43
71
44 private:
72 private:
45 QStringList createLabels(QChartAxis* axis,qreal min, qreal max);
73 QStringList createLabels(QChartAxis* axis,qreal min, qreal max);
46 void calculateDomain(QSeries* series,Domain* domain);
74 void calculateDomain(QSeries* series,Domain* domain);
47 void setupCategories(QBarSeries* series);
75 void setupCategories(QBarSeries* series);
48
76
49 private:
77 private:
50 QMap<QSeries*, QChartAxis*> m_seriesAxisMap;
78 QMap<QSeries*, QChartAxis*> m_seriesAxisMap;
51 QMap<QChartAxis*, Domain*> m_axisDomainMap;
79 QMap<QChartAxis*, Domain*> m_axisDomainMap;
52 QChartAxis* m_axisX;
80 QChartAxis* m_axisX;
53 QChartAxis* m_axisY;
81 QChartAxis* m_axisY;
54
82
55 int m_domainIndex;
83 int m_domainIndex;
56 bool m_axisXInitialized;
84 bool m_axisXInitialized;
57 };
85 };
58
86
59 QTCOMMERCIALCHART_END_NAMESPACE
87 QTCOMMERCIALCHART_END_NAMESPACE
60
88
61 #endif /* CHARTENGINE_P_H_ */
89 #endif /* CHARTENGINE_P_H_ */
@@ -1,43 +1,63
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 // W A R N I N G
21 // W A R N I N G
2 // -------------
22 // -------------
3 //
23 //
4 // 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
5 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
6 // version without notice, or even be removed.
26 // version without notice, or even be removed.
7 //
27 //
8 // We mean it.
28 // We mean it.
9
29
10 #ifndef QCHART_P_H
30 #ifndef QCHART_P_H
11 #define QCHART_P_H
31 #define QCHART_P_H
12
32
13 #include "qchartaxis.h"
33 #include "qchartaxis.h"
14 #include "qlegend.h"
34 #include "qlegend.h"
15 #include "chartpresenter_p.h"
35 #include "chartpresenter_p.h"
16 #include "chartdataset_p.h"
36 #include "chartdataset_p.h"
17 #include "chartbackground_p.h"
37 #include "chartbackground_p.h"
18
38
19 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39 QTCOMMERCIALCHART_BEGIN_NAMESPACE
20
40
21 class QChart;
41 class QChart;
22
42
23 struct QChartPrivate
43 struct QChartPrivate
24 {
44 {
25 QChartPrivate(QChart *parent);
45 QChartPrivate(QChart *parent);
26 ~QChartPrivate();
46 ~QChartPrivate();
27
47
28 void createChartBackgroundItem();
48 void createChartBackgroundItem();
29 void createChartTitleItem();
49 void createChartTitleItem();
30 void updateLayout();
50 void updateLayout();
31 void updateLegendLayout();
51 void updateLegendLayout();
32
52
33 QChart *q_ptr;
53 QChart *q_ptr;
34 ChartBackground* m_backgroundItem;
54 ChartBackground* m_backgroundItem;
35 QGraphicsSimpleTextItem* m_titleItem;
55 QGraphicsSimpleTextItem* m_titleItem;
36 QRectF m_rect;
56 QRectF m_rect;
37 QLegend* m_legend;
57 QLegend* m_legend;
38 ChartDataSet *m_dataset;
58 ChartDataSet *m_dataset;
39 ChartPresenter *m_presenter;
59 ChartPresenter *m_presenter;
40 };
60 };
41
61
42 QTCOMMERCIALCHART_END_NAMESPACE
62 QTCOMMERCIALCHART_END_NAMESPACE
43 #endif
63 #endif
@@ -1,35 +1,55
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 // W A R N I N G
21 // W A R N I N G
2 // -------------
22 // -------------
3 //
23 //
4 // 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
5 // implementation detail. This header file may change from version to
25 // implementation detail. This header file may change from version to
6 // version without notice, or even be removed.
26 // version without notice, or even be removed.
7 //
27 //
8 // We mean it.
28 // We mean it.
9
29
10 #ifndef QCHARTVIEW_P_H
30 #ifndef QCHARTVIEW_P_H
11 #define QCHARTVIEW_P_H
31 #define QCHARTVIEW_P_H
12
32
13 #include "qchartview.h"
33 #include "qchartview.h"
14
34
15 class QGraphicsScene;
35 class QGraphicsScene;
16
36
17 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
18
38
19 class QChart;
39 class QChart;
20
40
21 struct QChartViewPrivate {
41 struct QChartViewPrivate {
22
42
23 QChartViewPrivate();
43 QChartViewPrivate();
24 ~QChartViewPrivate();
44 ~QChartViewPrivate();
25
45
26 QGraphicsScene *m_scene;
46 QGraphicsScene *m_scene;
27 QChart *m_chart;
47 QChart *m_chart;
28 ChartPresenter *m_presenter;
48 ChartPresenter *m_presenter;
29 QPoint m_rubberBandOrigin;
49 QPoint m_rubberBandOrigin;
30 QRubberBand *m_rubberBand;
50 QRubberBand *m_rubberBand;
31 QChartView::RubberBands m_rubberBandFlags;
51 QChartView::RubberBands m_rubberBandFlags;
32 };
52 };
33
53
34 QTCOMMERCIALCHART_END_NAMESPACE
54 QTCOMMERCIALCHART_END_NAMESPACE
35 #endif
55 #endif
@@ -1,277 +1,490
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
14 **
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
18 **
19 ****************************************************************************/
20
1 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
2 #include <qchartaxis.h>
22 #include <qchartaxis.h>
3 #include <qlineseries.h>
23 #include <qlineseries.h>
4 #include <private/chartdataset_p.h>
24 #include <private/chartdataset_p.h>
5 #include <private/domain_p.h>
25 #include <private/domain_p.h>
6
26
7 QTCOMMERCIALCHART_USE_NAMESPACE
27 QTCOMMERCIALCHART_USE_NAMESPACE
8
28
9 Q_DECLARE_METATYPE(Domain*)
29 Q_DECLARE_METATYPE(Domain*)
10 Q_DECLARE_METATYPE(QChartAxis*)
30 Q_DECLARE_METATYPE(QChartAxis*)
11 Q_DECLARE_METATYPE(QSeries*)
31 Q_DECLARE_METATYPE(QSeries*)
12 Q_DECLARE_METATYPE(QLineSeries*)
32 Q_DECLARE_METATYPE(QLineSeries*)
13
33
14 class tst_ChartDataSet: public QObject {
34 class tst_ChartDataSet: public QObject {
15 Q_OBJECT
16
35
17 public slots:
36 Q_OBJECT
37
38 public Q_SLOTS:
18 void initTestCase();
39 void initTestCase();
19 void cleanupTestCase();
40 void cleanupTestCase();
20 void init();
41 void init();
21 void cleanup();
42 void cleanup();
22
43
23 private slots:
44 private Q_SLOTS:
24 void chartdataset_data();
45 void chartdataset_data();
25 void chartdataset();
46 void chartdataset();
26
27 void addSeries_data();
47 void addSeries_data();
28 void addSeries();
48 void addSeries();
29 void removeSeries_data();
49 void removeSeries_data();
30 void removeSeries();
50 void removeSeries();
31 void removeAllSeries_data();
51 void removeAllSeries_data();
32 void removeAllSeries();
52 void removeAllSeries();
33 void axisY_data();
53 void axisY_data();
34 void axisY();
54 void axisY();
35
55 void seriesCount_data();
56 void seriesCount();
57 void seriesIndex_data();
58 void seriesIndex();
59 void domain_data();
60 void domain();
61 void zoomInDomain_data();
62 void zoomInDomain();
63 void zoomOutDomain_data();
64 void zoomOutDomain();
65 void scrollDomain_data();
66 void scrollDomain();
36 };
67 };
37
68
38 void tst_ChartDataSet::initTestCase()
69 void tst_ChartDataSet::initTestCase()
39 {
70 {
40 qRegisterMetaType<Domain*>();
71 qRegisterMetaType<Domain*>();
41 qRegisterMetaType<QChartAxis*>();
72 qRegisterMetaType<QChartAxis*>();
42 qRegisterMetaType<QSeries*>();
73 qRegisterMetaType<QSeries*>();
43 }
74 }
44
75
45 void tst_ChartDataSet::cleanupTestCase()
76 void tst_ChartDataSet::cleanupTestCase()
46 {
77 {
47 }
78 }
48
79
49 void tst_ChartDataSet::init()
80 void tst_ChartDataSet::init()
50 {
81 {
51 }
82 }
52
83
53 void tst_ChartDataSet::cleanup()
84 void tst_ChartDataSet::cleanup()
54 {
85 {
55 }
86 }
56
87
57 void tst_ChartDataSet::chartdataset_data()
88 void tst_ChartDataSet::chartdataset_data()
58 {
89 {
59 }
90 }
60
91
61 void tst_ChartDataSet::chartdataset()
92 void tst_ChartDataSet::chartdataset()
62 {
93 {
63 ChartDataSet dataSet;
94 ChartDataSet dataSet;
64 QVERIFY2(dataSet.axisX(), "Missing axisX.");
95 QVERIFY2(dataSet.axisX(), "Missing axisX.");
65 QVERIFY2(dataSet.axisY(), "Missing axisY.");
96 QVERIFY2(dataSet.axisY(), "Missing axisY.");
66 //check if not dangling pointer
97 //check if not dangling pointer
67 dataSet.axisX()->objectName();
98 dataSet.axisX()->objectName();
68 dataSet.axisY()->objectName();
99 dataSet.axisY()->objectName();
69 }
100 }
70
101
71 void tst_ChartDataSet::addSeries_data()
102 void tst_ChartDataSet::addSeries_data()
72 {
103 {
73 QTest::addColumn<QLineSeries*>("series0");
104 QTest::addColumn<QLineSeries*>("series0");
74 QTest::addColumn<QChartAxis*>("axis0");
105 QTest::addColumn<QChartAxis*>("axis0");
75 QTest::addColumn<QLineSeries*>("series1");
106 QTest::addColumn<QLineSeries*>("series1");
76 QTest::addColumn<QChartAxis*>("axis1");
107 QTest::addColumn<QChartAxis*>("axis1");
77 QTest::addColumn<QLineSeries*>("series2");
108 QTest::addColumn<QLineSeries*>("series2");
78 QTest::addColumn<QChartAxis*>("axis2");
109 QTest::addColumn<QChartAxis*>("axis2");
79 QTest::addColumn<int>("axisCount");
110 QTest::addColumn<int>("axisCount");
80
111
81 QLineSeries* series0 = new QLineSeries(this);
112 QLineSeries* series0 = new QLineSeries(this);
82 QLineSeries* series1 = new QLineSeries(this);
113 QLineSeries* series1 = new QLineSeries(this);
83 QLineSeries* series2 = new QLineSeries(this);
114 QLineSeries* series2 = new QLineSeries(this);
84
115
85 QChartAxis* axis0 = new QChartAxis(this);
116 QChartAxis* axis0 = new QChartAxis(this);
86 QChartAxis* axis1 = new QChartAxis(this);
117 QChartAxis* axis1 = new QChartAxis(this);
87 QChartAxis* axis2 = new QChartAxis(this);
118 QChartAxis* axis2 = new QChartAxis(this);
88
119
89 QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QChartAxis*)0 << series1 << (QChartAxis*)0 << series2 << (QChartAxis*)0 << 2;
120 QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QChartAxis*)0 << series1 << (QChartAxis*)0 << series2 << (QChartAxis*)0 << 2;
90 QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (QChartAxis*)0 << series1 << axis0 << series2 << axis0 << 3;
121 QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (QChartAxis*)0 << series1 << axis0 << series2 << axis0 << 3;
91 QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1 << axis1 << series2 << axis2 << 4;
122 QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1 << axis1 << series2 << axis2 << 4;
92 }
123 }
93
124
94 void tst_ChartDataSet::addSeries()
125 void tst_ChartDataSet::addSeries()
95 {
126 {
96 QFETCH(QLineSeries*, series0);
127 QFETCH(QLineSeries*, series0);
97 QFETCH(QChartAxis*, axis0);
128 QFETCH(QChartAxis*, axis0);
98 QFETCH(QLineSeries*, series1);
129 QFETCH(QLineSeries*, series1);
99 QFETCH(QChartAxis*, axis1);
130 QFETCH(QChartAxis*, axis1);
100 QFETCH(QLineSeries*, series2);
131 QFETCH(QLineSeries*, series2);
101 QFETCH(QChartAxis*, axis2);
132 QFETCH(QChartAxis*, axis2);
102 QFETCH(int, axisCount);
133 QFETCH(int, axisCount);
103
134
104 ChartDataSet dataSet;
135 ChartDataSet dataSet;
105
136
106 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
137 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
107 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
138 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
108 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
139 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
109 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
140 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
110
141
111 dataSet.addSeries(series0,axis0);
142 dataSet.addSeries(series0,axis0);
112 dataSet.addSeries(series1,axis1);
143 dataSet.addSeries(series1,axis1);
113 dataSet.addSeries(series2,axis2);
144 dataSet.addSeries(series2,axis2);
114
145
115 QCOMPARE(spy0.count(), axisCount);
146 QCOMPARE(spy0.count(), axisCount);
116 QCOMPARE(spy1.count(), 0);
147 QCOMPARE(spy1.count(), 0);
117 QCOMPARE(spy2.count(), 3);
148 QCOMPARE(spy2.count(), 3);
118 QCOMPARE(spy3.count(), 0);
149 QCOMPARE(spy3.count(), 0);
119
150
120 }
151 }
121
152
122 void tst_ChartDataSet::removeSeries_data()
153 void tst_ChartDataSet::removeSeries_data()
123 {
154 {
124 QTest::addColumn<QLineSeries*>("series0");
155 addSeries_data();
125 QTest::addColumn<QChartAxis*>("axis0");
126 QTest::addColumn<QLineSeries*>("series1");
127 QTest::addColumn<QChartAxis*>("axis1");
128 QTest::addColumn<QLineSeries*>("series2");
129 QTest::addColumn<QChartAxis*>("axis2");
130 QTest::addColumn<int>("axisCount");
131
132 QLineSeries* series0 = new QLineSeries(this);
133 QLineSeries* series1 = new QLineSeries(this);
134 QLineSeries* series2 = new QLineSeries(this);
135
136 QChartAxis* axis0 = new QChartAxis(this);
137 QChartAxis* axis1 = new QChartAxis(this);
138 QChartAxis* axis2 = new QChartAxis(this);
139
140 QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QChartAxis*) 0
141 << series1 << (QChartAxis*) 0 << series2 << (QChartAxis*) 0 << 2;
142 QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (QChartAxis*) 0
143 << series1 << axis0 << series2 << axis0 << 3;
144 QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1
145 << axis1 << series2 << axis2 << 4;
146 }
156 }
147
157
148 void tst_ChartDataSet::removeSeries()
158 void tst_ChartDataSet::removeSeries()
149 {
159 {
150 QFETCH(QLineSeries*, series0);
160 QFETCH(QLineSeries*, series0);
151 QFETCH(QChartAxis*, axis0);
161 QFETCH(QChartAxis*, axis0);
152 QFETCH(QLineSeries*, series1);
162 QFETCH(QLineSeries*, series1);
153 QFETCH(QChartAxis*, axis1);
163 QFETCH(QChartAxis*, axis1);
154 QFETCH(QLineSeries*, series2);
164 QFETCH(QLineSeries*, series2);
155 QFETCH(QChartAxis*, axis2);
165 QFETCH(QChartAxis*, axis2);
156 QFETCH(int, axisCount);
166 QFETCH(int, axisCount);
157
167
158 ChartDataSet dataSet;
168 ChartDataSet dataSet;
159
169
160 dataSet.addSeries(series0,axis0);
170 dataSet.addSeries(series0,axis0);
161 dataSet.addSeries(series1,axis1);
171 dataSet.addSeries(series1,axis1);
162 dataSet.addSeries(series2,axis2);
172 dataSet.addSeries(series2,axis2);
163
173
164 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
174 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
165 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
175 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
166 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
176 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
167 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
177 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
168
178
169 dataSet.removeSeries(series0);
179 dataSet.removeSeries(series0);
170 dataSet.removeSeries(series1);
180 dataSet.removeSeries(series1);
171 dataSet.removeSeries(series2);
181 dataSet.removeSeries(series2);
172
182
173 QCOMPARE(spy0.count(), 0);
183 QCOMPARE(spy0.count(), 0);
174 QCOMPARE(spy1.count(), axisCount);
184 QCOMPARE(spy1.count(), axisCount);
175 QCOMPARE(spy2.count(), 0);
185 QCOMPARE(spy2.count(), 0);
176 QCOMPARE(spy3.count(), 3);
186 QCOMPARE(spy3.count(), 3);
177 }
187 }
178
188
179 void tst_ChartDataSet::removeAllSeries_data()
189 void tst_ChartDataSet::removeAllSeries_data()
180 {
190 {
181 QTest::addColumn<QLineSeries*>("series0");
191 addSeries_data();
182 QTest::addColumn<QChartAxis*>("axis0");
183 QTest::addColumn<QLineSeries*>("series1");
184 QTest::addColumn<QChartAxis*>("axis1");
185 QTest::addColumn<QLineSeries*>("series2");
186 QTest::addColumn<QChartAxis*>("axis2");
187 QTest::addColumn<int>("axisCount");
188
189 QLineSeries* series0 = new QLineSeries(this);
190 QLineSeries* series1 = new QLineSeries(this);
191 QLineSeries* series2 = new QLineSeries(this);
192
193 QChartAxis* axis0 = new QChartAxis(this);
194 QChartAxis* axis1 = new QChartAxis(this);
195 QChartAxis* axis2 = new QChartAxis(this);
196
197 QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QChartAxis*) 0
198 << series1 << (QChartAxis*) 0 << series2 << (QChartAxis*) 0 << 2;
199 QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (QChartAxis*) 0
200 << series1 << axis0 << series2 << axis0 << 3;
201 QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1
202 << axis1 << series2 << axis2 << 4;
203 }
192 }
204
193
205 void tst_ChartDataSet::removeAllSeries()
194 void tst_ChartDataSet::removeAllSeries()
206 {
195 {
207 QFETCH(QLineSeries*, series0);
196 QFETCH(QLineSeries*, series0);
208 QFETCH(QChartAxis*, axis0);
197 QFETCH(QChartAxis*, axis0);
209 QFETCH(QLineSeries*, series1);
198 QFETCH(QLineSeries*, series1);
210 QFETCH(QChartAxis*, axis1);
199 QFETCH(QChartAxis*, axis1);
211 QFETCH(QLineSeries*, series2);
200 QFETCH(QLineSeries*, series2);
212 QFETCH(QChartAxis*, axis2);
201 QFETCH(QChartAxis*, axis2);
213 QFETCH(int, axisCount);
202 QFETCH(int, axisCount);
214
203
215 ChartDataSet dataSet;
204 ChartDataSet dataSet;
216
205
217 dataSet.addSeries(series0,axis0);
206 dataSet.addSeries(series0,axis0);
218 dataSet.addSeries(series1,axis1);
207 dataSet.addSeries(series1,axis1);
219 dataSet.addSeries(series2,axis2);
208 dataSet.addSeries(series2,axis2);
220
209
221 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
210 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
222 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
211 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
223 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
212 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
224 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
213 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
225
214
226 dataSet.removeAllSeries();
215 dataSet.removeAllSeries();
227
216
228 QCOMPARE(spy0.count(), 0);
217 QCOMPARE(spy0.count(), 0);
229 QCOMPARE(spy1.count(), axisCount);
218 QCOMPARE(spy1.count(), axisCount);
230 QCOMPARE(spy2.count(), 0);
219 QCOMPARE(spy2.count(), 0);
231 QCOMPARE(spy3.count(), 3);
220 QCOMPARE(spy3.count(), 3);
232 }
221 }
233
222
234
223
235 void tst_ChartDataSet::axisY_data()
224 void tst_ChartDataSet::axisY_data()
236 {
225 {
237 QTest::addColumn<QChartAxis*>("axis0");
226 QTest::addColumn<QChartAxis*>("axis0");
238 QTest::addColumn<QChartAxis*>("axis1");
227 QTest::addColumn<QChartAxis*>("axis1");
239 QTest::addColumn<QChartAxis*>("axis2");
228 QTest::addColumn<QChartAxis*>("axis2");
240 QTest::newRow("1 defualt, 2 optional") << (QChartAxis*)0 << new QChartAxis() << new QChartAxis();
229 QTest::newRow("1 defualt, 2 optional") << (QChartAxis*)0 << new QChartAxis() << new QChartAxis();
241 QTest::newRow("3 optional") << new QChartAxis() << new QChartAxis() << new QChartAxis();
230 QTest::newRow("3 optional") << new QChartAxis() << new QChartAxis() << new QChartAxis();
242 }
231 }
243
232
244 void tst_ChartDataSet::axisY()
233 void tst_ChartDataSet::axisY()
245 {
234 {
246 QFETCH(QChartAxis*, axis0);
235 QFETCH(QChartAxis*, axis0);
247 QFETCH(QChartAxis*, axis1);
236 QFETCH(QChartAxis*, axis1);
248 QFETCH(QChartAxis*, axis2);
237 QFETCH(QChartAxis*, axis2);
249
238
250 ChartDataSet dataSet;
239 ChartDataSet dataSet;
251
240
252 QChartAxis* defaultAxisY = dataSet.axisY();
241 QChartAxis* defaultAxisY = dataSet.axisY();
253
242
254 QVERIFY2(defaultAxisY, "Missing axisY.");
243 QVERIFY2(defaultAxisY, "Missing axisY.");
255
244
256 QLineSeries* series0 = new QLineSeries();
245 QLineSeries* series0 = new QLineSeries();
257 dataSet.addSeries(series0,axis0);
246 dataSet.addSeries(series0,axis0);
258
247
259 QLineSeries* series1 = new QLineSeries();
248 QLineSeries* series1 = new QLineSeries();
260 dataSet.addSeries(series1,axis1);
249 dataSet.addSeries(series1,axis1);
261
250
262 QLineSeries* series2 = new QLineSeries();
251 QLineSeries* series2 = new QLineSeries();
263 dataSet.addSeries(series2,axis2);
252 dataSet.addSeries(series2,axis2);
264
253
265 if(!axis0) axis0=defaultAxisY ;
254 if(!axis0) axis0=defaultAxisY ;
266 if(!axis1) axis1=defaultAxisY ;
255 if(!axis1) axis1=defaultAxisY ;
267 if(!axis2) axis2=defaultAxisY ;
256 if(!axis2) axis2=defaultAxisY ;
268
257
269 QVERIFY(dataSet.axisY(series0) == axis0);
258 QVERIFY(dataSet.axisY(series0) == axis0);
270 QVERIFY(dataSet.axisY(series1) == axis1);
259 QVERIFY(dataSet.axisY(series1) == axis1);
271 QVERIFY(dataSet.axisY(series2) == axis2);
260 QVERIFY(dataSet.axisY(series2) == axis2);
272
261
273 }
262 }
274
263
264 void tst_ChartDataSet::seriesCount_data()
265 {
266 addSeries_data();
267 }
268
269 void tst_ChartDataSet::seriesCount()
270 {
271 QFETCH(QLineSeries*, series0);
272 QFETCH(QChartAxis*, axis0);
273 QFETCH(QLineSeries*, series1);
274 QFETCH(QChartAxis*, axis1);
275 QFETCH(QLineSeries*, series2);
276 QFETCH(QChartAxis*, axis2);
277 QFETCH(int, axisCount);
278 Q_UNUSED(axisCount);
279
280 ChartDataSet dataSet;
281
282 dataSet.addSeries(series0, axis0);
283 dataSet.addSeries(series1, axis1);
284 dataSet.addSeries(series2, axis2);
285
286 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
287 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
288 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
289 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
290
291 QCOMPARE(dataSet.seriesCount(series0->type()),3);
292 QCOMPARE(spy0.count(), 0);
293 QCOMPARE(spy1.count(), 0);
294 QCOMPARE(spy2.count(), 0);
295 QCOMPARE(spy3.count(), 0);
296 }
297
298 void tst_ChartDataSet::seriesIndex_data()
299 {
300 addSeries_data();
301 }
302
303 void tst_ChartDataSet::seriesIndex()
304 {
305 QFETCH(QLineSeries*, series0);
306 QFETCH(QChartAxis*, axis0);
307 QFETCH(QLineSeries*, series1);
308 QFETCH(QChartAxis*, axis1);
309 QFETCH(QLineSeries*, series2);
310 QFETCH(QChartAxis*, axis2);
311 QFETCH(int, axisCount);
312 Q_UNUSED(axisCount);
313
314 ChartDataSet dataSet;
315
316 dataSet.addSeries(series0, axis0);
317 dataSet.addSeries(series1, axis1);
318 dataSet.addSeries(series2, axis2);
319
320 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
321 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
322 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
323 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
324
325 int i0 = dataSet.seriesIndex(series0);
326 int i1 = dataSet.seriesIndex(series1);
327 int i2 = dataSet.seriesIndex(series2);
328
329 QVERIFY(i1!=i2);
330 QVERIFY(i0!=i2);
331 QVERIFY(i0!=i1);
332
333 QCOMPARE(spy0.count(), 0);
334 QCOMPARE(spy1.count(), 0);
335 QCOMPARE(spy2.count(), 0);
336 QCOMPARE(spy3.count(), 0);
337 }
338
339 void tst_ChartDataSet::domain_data()
340 {
341 addSeries_data();
342 }
343
344 void tst_ChartDataSet::domain()
345 {
346 QFETCH(QLineSeries*, series0);
347 QFETCH(QChartAxis*, axis0);
348 QFETCH(QLineSeries*, series1);
349 QFETCH(QChartAxis*, axis1);
350 QFETCH(QLineSeries*, series2);
351 QFETCH(QChartAxis*, axis2);
352 QFETCH(int, axisCount);
353 Q_UNUSED(axisCount);
354
355 ChartDataSet dataSet;
356
357 dataSet.addSeries(series0, axis0);
358 dataSet.addSeries(series1, axis1);
359 dataSet.addSeries(series2, axis2);
360
361 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*)));
362 QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
363 QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*)));
364 QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*)));
365
366 QVERIFY(dataSet.domain(axis0)==dataSet.domain(series0));
367 QVERIFY(dataSet.domain(axis1)==dataSet.domain(series1));
368 QVERIFY(dataSet.domain(axis2)==dataSet.domain(series2));
369 QCOMPARE(spy0.count(), 0);
370 QCOMPARE(spy1.count(), 0);
371 QCOMPARE(spy2.count(), 0);
372 QCOMPARE(spy3.count(), 0);
373 }
374
375 void tst_ChartDataSet::zoomInDomain_data()
376 {
377 addSeries_data();
378 }
379
380 void tst_ChartDataSet::zoomInDomain()
381 {
382 QFETCH(QLineSeries*, series0);
383 QFETCH(QChartAxis*, axis0);
384 QFETCH(QLineSeries*, series1);
385 QFETCH(QChartAxis*, axis1);
386 QFETCH(QLineSeries*, series2);
387 QFETCH(QChartAxis*, axis2);
388 QFETCH(int, axisCount);
389
390 Q_UNUSED(axisCount);
391 ChartDataSet dataSet;
392
393 dataSet.addSeries(series0, axis0);
394 dataSet.addSeries(series1, axis1);
395 dataSet.addSeries(series2, axis2);
396
397 Domain* domain0 = dataSet.domain(series0);
398 Domain* domain1 = dataSet.domain(series1);
399 Domain* domain2 = dataSet.domain(series2);
400
401 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
402 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
403 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
404
405 dataSet.zoomInDomain(QRect(0,0,100,100),QSize(1000,1000));
406
407 QCOMPARE(spy0.count(), 1);
408 QCOMPARE(spy1.count(), 1);
409 QCOMPARE(spy2.count(), 1);
410 }
411
412 void tst_ChartDataSet::zoomOutDomain_data()
413 {
414 addSeries_data();
415 }
416
417 void tst_ChartDataSet::zoomOutDomain()
418 {
419 QFETCH(QLineSeries*, series0);
420 QFETCH(QChartAxis*, axis0);
421 QFETCH(QLineSeries*, series1);
422 QFETCH(QChartAxis*, axis1);
423 QFETCH(QLineSeries*, series2);
424 QFETCH(QChartAxis*, axis2);
425 QFETCH(int, axisCount);
426
427 Q_UNUSED(axisCount);
428
429 ChartDataSet dataSet;
430
431 dataSet.addSeries(series0, axis0);
432 dataSet.addSeries(series1, axis1);
433 dataSet.addSeries(series2, axis2);
434
435 Domain* domain0 = dataSet.domain(series0);
436 Domain* domain1 = dataSet.domain(series1);
437 Domain* domain2 = dataSet.domain(series2);
438
439 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
440 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
441 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
442
443 dataSet.zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000));
444
445 QCOMPARE(spy0.count(), 1);
446 QCOMPARE(spy1.count(), 1);
447 QCOMPARE(spy2.count(), 1);
448 }
449
450 void tst_ChartDataSet::scrollDomain_data()
451 {
452 addSeries_data();
453 }
454
455 void tst_ChartDataSet::scrollDomain()
456 {
457 QFETCH(QLineSeries*, series0);
458 QFETCH(QChartAxis*, axis0);
459 QFETCH(QLineSeries*, series1);
460 QFETCH(QChartAxis*, axis1);
461 QFETCH(QLineSeries*, series2);
462 QFETCH(QChartAxis*, axis2);
463 QFETCH(int, axisCount);
464
465 Q_UNUSED(axisCount);
466
467 ChartDataSet dataSet;
468
469 dataSet.addSeries(series0, axis0);
470 dataSet.addSeries(series1, axis1);
471 dataSet.addSeries(series2, axis2);
472
473 Domain* domain0 = dataSet.domain(series0);
474 Domain* domain1 = dataSet.domain(series1);
475 Domain* domain2 = dataSet.domain(series2);
476
477 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
478 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
479 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
480
481 dataSet.scrollDomain(10,10,QSize(1000,1000));
482
483 QCOMPARE(spy0.count(), 1);
484 QCOMPARE(spy1.count(), 1);
485 QCOMPARE(spy2.count(), 1);
486 }
487
275 QTEST_MAIN(tst_ChartDataSet)
488 QTEST_MAIN(tst_ChartDataSet)
276 #include "tst_chartdataset.moc"
489 #include "tst_chartdataset.moc"
277
490
General Comments 0
You need to be logged in to leave comments. Login now