##// END OF EJS Templates
Implemented QAbstractSeries::chart()...
Jani Honkonen -
r1314:f6f67dde6408
parent child
Show More
@@ -1,296 +1,300
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 "chartdataset_p.h"
21 #include "chartdataset_p.h"
22 #include "qchart.h"
22 #include "qaxis.h"
23 #include "qaxis.h"
23 #include "qaxis_p.h"
24 #include "qaxis_p.h"
24 #include "qabstractseries_p.h"
25 #include "qabstractseries_p.h"
25 #include "qbarseries.h"
26 #include "qbarseries.h"
26 #include "qstackedbarseries.h"
27 #include "qstackedbarseries.h"
27 #include "qpercentbarseries.h"
28 #include "qpercentbarseries.h"
28 #include "qpieseries.h"
29 #include "qpieseries.h"
29
30
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31
32
32 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
33 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent),
33 m_axisX(new QAxis(this)),
34 m_axisX(new QAxis(this)),
34 m_axisY(new QAxis(this)),
35 m_axisY(new QAxis(this)),
35 m_domainIndex(0),
36 m_domainIndex(0),
36 m_axisXInitialized(false),
37 m_axisXInitialized(false),
37 m_axisYInitialized(false)
38 m_axisYInitialized(false)
38 {
39 {
39 //create main domain
40 //create main domain
40 Domain* domain = new Domain(m_axisY);
41 Domain* domain = new Domain(m_axisY);
41 m_axisDomainMap.insert(m_axisY,domain);
42 m_axisDomainMap.insert(m_axisY,domain);
42 QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
43 QObject::connect(m_axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
43 QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
44 QObject::connect(m_axisX->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
44 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
45 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),m_axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
45 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
46 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),m_axisX->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
46 }
47 }
47
48
48 ChartDataSet::~ChartDataSet()
49 ChartDataSet::~ChartDataSet()
49 {
50 {
50 removeAllSeries();
51 removeAllSeries();
51 }
52 }
52
53
53 void ChartDataSet::addSeries(QAbstractSeries* series, QAxis *axisY)
54 void ChartDataSet::addSeries(QAbstractSeries* series, QAxis *axisY)
54 {
55 {
55 if(axisY==0) axisY = m_axisY;
56 if(axisY==0) axisY = m_axisY;
56
57
57 QAxis* axis = m_seriesAxisMap.value(series);
58 QAxis* axis = m_seriesAxisMap.value(series);
58
59
59 if(axis) {
60 if(axis) {
60 qWarning() << "Can not add series. Series already on the chart";
61 qWarning() << "Can not add series. Series already on the chart";
61 return;
62 return;
62 }
63 }
63
64
64 series->setParent(this); // take ownership
65 series->setParent(this); // take ownership
65 axisY->setParent(this); // take ownership
66 axisY->setParent(this); // take ownership
66
67
67 Domain* domain = m_axisDomainMap.value(axisY);
68 Domain* domain = m_axisDomainMap.value(axisY);
68
69
69 if(!domain) {
70 if(!domain) {
70 domain = new Domain(axisY);
71 domain = new Domain(axisY);
71 QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
72 QObject::connect(axisY->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
72 QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int)));
73 QObject::connect(axisX()->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int)));
73 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
74 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
74 //initialize
75 //initialize
75 m_axisDomainMap.insert(axisY,domain);
76 m_axisDomainMap.insert(axisY,domain);
76 emit axisAdded(axisY,domain);
77 emit axisAdded(axisY,domain);
77 }
78 }
78
79
79 if(!m_axisXInitialized){
80 if(!m_axisXInitialized){
80 m_axisXInitialized=true;
81 m_axisXInitialized=true;
81 emit axisAdded(m_axisX,domain);
82 emit axisAdded(m_axisX,domain);
82 }
83 }
83
84
84 if(!m_axisYInitialized && axisY==m_axisY){
85 if(!m_axisYInitialized && axisY==m_axisY){
85 m_axisYInitialized=true;
86 m_axisYInitialized=true;
86 emit axisAdded(m_axisY,domain);
87 emit axisAdded(m_axisY,domain);
87 }
88 }
88
89
89 series->d_ptr->scaleDomain(*domain);
90 series->d_ptr->scaleDomain(*domain);
90
91
91 // Note that with SeriesTypeBar we don't set up categories, but use real values on x-asis
92 // Note that with SeriesTypeBar we don't set up categories, but use real values on x-asis
92 if(series->type() == QAbstractSeries::SeriesTypeGroupedBar
93 if(series->type() == QAbstractSeries::SeriesTypeGroupedBar
93 || series->type() == QAbstractSeries::SeriesTypeStackedBar
94 || series->type() == QAbstractSeries::SeriesTypeStackedBar
94 || series->type() == QAbstractSeries::SeriesTypePercentBar) {
95 || series->type() == QAbstractSeries::SeriesTypePercentBar) {
95 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
96 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
96 setupCategories(barSeries);
97 setupCategories(barSeries);
97 }
98 }
98
99
99 if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) {
100 if (series->type()== QAbstractSeries::SeriesTypePie && m_seriesAxisMap.count() == 0) {
100 axisX()->hide();
101 axisX()->hide();
101 this->axisY()->hide();
102 this->axisY()->hide();
102 }
103 }
103
104
104 m_seriesAxisMap.insert(series,axisY);
105 m_seriesAxisMap.insert(series,axisY);
105
106
106 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
107 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
107
108
108 int key=0;
109 int key=0;
109 while (i.hasNext()) {
110 while (i.hasNext()) {
110 i.next();
111 i.next();
111 if(i.key()!=key) {
112 if(i.key()!=key) {
112 break;
113 break;
113 }
114 }
114 key++;
115 key++;
115 }
116 }
116
117
117 m_indexSeriesMap.insert(key,series);
118 m_indexSeriesMap.insert(key,series);
118
119
120 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
119 series->d_ptr->m_dataset=this;
121 series->d_ptr->m_dataset = this;
120
122
121 emit seriesAdded(series,domain);
123 emit seriesAdded(series,domain);
122
124
123 }
125 }
124
126
125 QAxis* ChartDataSet::removeSeries(QAbstractSeries* series)
127 QAxis* ChartDataSet::removeSeries(QAbstractSeries* series)
126 {
128 {
127 QAxis* axis = m_seriesAxisMap.value(series);
129 QAxis* axis = m_seriesAxisMap.value(series);
128
130
129 if(!axis){
131 if(!axis){
130 qWarning()<<"Can not remove series. Series not found on the chart.";
132 qWarning()<<"Can not remove series. Series not found on the chart.";
131 return 0;
133 return 0;
132 }
134 }
133
135
134 emit seriesRemoved(series);
136 emit seriesRemoved(series);
135
137
136 m_seriesAxisMap.remove(series);
138 m_seriesAxisMap.remove(series);
137 int key = seriesIndex(series);
139 int key = seriesIndex(series);
138 Q_ASSERT(key!=-1);
140 Q_ASSERT(key!=-1);
139
141
140 m_indexSeriesMap.remove(key);
142 m_indexSeriesMap.remove(key);
143
141 series->setParent(0);
144 series->setParent(0);
145 series->d_ptr->m_chart = 0;
142 series->d_ptr->m_dataset=0;
146 series->d_ptr->m_dataset = 0;
143
147
144 QList<QAxis*> axes = m_seriesAxisMap.values();
148 QList<QAxis*> axes = m_seriesAxisMap.values();
145
149
146 int i = axes.indexOf(axis);
150 int i = axes.indexOf(axis);
147
151
148 if(i==-1){
152 if(i==-1){
149 Domain* domain = m_axisDomainMap.take(axis);
153 Domain* domain = m_axisDomainMap.take(axis);
150 emit axisRemoved(axis);
154 emit axisRemoved(axis);
151 if(axis!=m_axisY){
155 if(axis!=m_axisY){
152 axis->setParent(0);
156 axis->setParent(0);
153 delete domain;
157 delete domain;
154 }else{
158 }else{
155 m_axisYInitialized=false;
159 m_axisYInitialized=false;
156 m_axisDomainMap.insert(m_axisY,domain);
160 m_axisDomainMap.insert(m_axisY,domain);
157 }
161 }
158 }
162 }
159
163
160 if(m_seriesAxisMap.values().size()==0)
164 if(m_seriesAxisMap.values().size()==0)
161 {
165 {
162 m_axisXInitialized=false;
166 m_axisXInitialized=false;
163 emit axisRemoved(axisX());
167 emit axisRemoved(axisX());
164 }
168 }
165
169
166 return axis;
170 return axis;
167 }
171 }
168
172
169 void ChartDataSet::removeAllSeries()
173 void ChartDataSet::removeAllSeries()
170 {
174 {
171 QList<QAbstractSeries*> series = m_seriesAxisMap.keys();
175 QList<QAbstractSeries*> series = m_seriesAxisMap.keys();
172 QList<QAxis*> axes;
176 QList<QAxis*> axes;
173 foreach(QAbstractSeries *s , series) {
177 foreach(QAbstractSeries *s , series) {
174 QAxis* axis = removeSeries(s);
178 QAxis* axis = removeSeries(s);
175 if(axis==axisY()) continue;
179 if(axis==axisY()) continue;
176 int i = axes.indexOf(axis);
180 int i = axes.indexOf(axis);
177 if(i==-1){
181 if(i==-1){
178 axes<<axis;
182 axes<<axis;
179 }
183 }
180 }
184 }
181
185
182 Q_ASSERT(m_seriesAxisMap.count()==0);
186 Q_ASSERT(m_seriesAxisMap.count()==0);
183 Q_ASSERT(m_axisDomainMap.count()==1);
187 Q_ASSERT(m_axisDomainMap.count()==1);
184
188
185 qDeleteAll(series);
189 qDeleteAll(series);
186 qDeleteAll(axes);
190 qDeleteAll(axes);
187 }
191 }
188
192
189 void ChartDataSet::setupCategories(QBarSeries* series)
193 void ChartDataSet::setupCategories(QBarSeries* series)
190 {
194 {
191 QAxisCategories* categories = axisX()->categories();
195 QAxisCategories* categories = axisX()->categories();
192 categories->clear();
196 categories->clear();
193 categories->insert(series->categories());
197 categories->insert(series->categories());
194 }
198 }
195
199
196 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
200 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
197 {
201 {
198 QMapIterator<QAxis*, Domain*> i(m_axisDomainMap);
202 QMapIterator<QAxis*, Domain*> i(m_axisDomainMap);
199 //main domain has to be the last one;
203 //main domain has to be the last one;
200 Domain *domain = m_axisDomainMap.value(axisY());
204 Domain *domain = m_axisDomainMap.value(axisY());
201 Q_ASSERT(domain);
205 Q_ASSERT(domain);
202 while (i.hasNext()) {
206 while (i.hasNext()) {
203 i.next();
207 i.next();
204 if(i.value()==domain) continue;
208 if(i.value()==domain) continue;
205 i.value()->zoomIn(rect,size);
209 i.value()->zoomIn(rect,size);
206 }
210 }
207 domain->zoomIn(rect,size);
211 domain->zoomIn(rect,size);
208 }
212 }
209
213
210 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
214 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
211 {
215 {
212 QMapIterator<QAxis*, Domain*> i(m_axisDomainMap);
216 QMapIterator<QAxis*, Domain*> i(m_axisDomainMap);
213 //main domain has to be the last one;
217 //main domain has to be the last one;
214 Domain *domain = m_axisDomainMap.value(axisY());
218 Domain *domain = m_axisDomainMap.value(axisY());
215 Q_ASSERT(domain);
219 Q_ASSERT(domain);
216 while (i.hasNext()) {
220 while (i.hasNext()) {
217 i.next();
221 i.next();
218 if(i.value()==domain) continue;
222 if(i.value()==domain) continue;
219 i.value()->zoomOut(rect,size);
223 i.value()->zoomOut(rect,size);
220 }
224 }
221 domain->zoomOut(rect,size);
225 domain->zoomOut(rect,size);
222 }
226 }
223
227
224 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
228 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
225 {
229 {
226 int count=0;
230 int count=0;
227 QMapIterator<QAbstractSeries*, QAxis*> i(m_seriesAxisMap);
231 QMapIterator<QAbstractSeries*, QAxis*> i(m_seriesAxisMap);
228 while (i.hasNext()) {
232 while (i.hasNext()) {
229 i.next();
233 i.next();
230 if(i.key()->type()==type) count++;
234 if(i.key()->type()==type) count++;
231 }
235 }
232 return count;
236 return count;
233 }
237 }
234
238
235 int ChartDataSet::seriesIndex(QAbstractSeries *series)
239 int ChartDataSet::seriesIndex(QAbstractSeries *series)
236 {
240 {
237 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
241 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
238 while (i.hasNext()) {
242 while (i.hasNext()) {
239 i.next();
243 i.next();
240 if (i.value() == series)
244 if (i.value() == series)
241 return i.key();
245 return i.key();
242 }
246 }
243 return -1;
247 return -1;
244 }
248 }
245
249
246 QAxis* ChartDataSet::axisY(QAbstractSeries *series) const
250 QAxis* ChartDataSet::axisY(QAbstractSeries *series) const
247 {
251 {
248 if(series == 0) return m_axisY;
252 if(series == 0) return m_axisY;
249 return m_seriesAxisMap.value(series);
253 return m_seriesAxisMap.value(series);
250 }
254 }
251
255
252 Domain* ChartDataSet::domain(QAbstractSeries *series) const
256 Domain* ChartDataSet::domain(QAbstractSeries *series) const
253 {
257 {
254 QAxis* axis = m_seriesAxisMap.value(series);
258 QAxis* axis = m_seriesAxisMap.value(series);
255 if(axis){
259 if(axis){
256 return m_axisDomainMap.value(axis);
260 return m_axisDomainMap.value(axis);
257 }else
261 }else
258 return 0;
262 return 0;
259 }
263 }
260
264
261 Domain* ChartDataSet::domain(QAxis* axis) const
265 Domain* ChartDataSet::domain(QAxis* axis) const
262 {
266 {
263 if(!axis || axis==axisX()) {
267 if(!axis || axis==axisX()) {
264 return m_axisDomainMap.value(axisY());
268 return m_axisDomainMap.value(axisY());
265 }
269 }
266 else {
270 else {
267 return m_axisDomainMap.value(axis);
271 return m_axisDomainMap.value(axis);
268 }
272 }
269 }
273 }
270
274
271 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
275 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
272 {
276 {
273 QMapIterator<QAxis*, Domain*> i( m_axisDomainMap);
277 QMapIterator<QAxis*, Domain*> i( m_axisDomainMap);
274 //main domain has to be the last one;
278 //main domain has to be the last one;
275 Domain *domain = m_axisDomainMap.value(axisY());
279 Domain *domain = m_axisDomainMap.value(axisY());
276 while (i.hasNext()) {
280 while (i.hasNext()) {
277 i.next();
281 i.next();
278 if(i.value()==domain) continue;
282 if(i.value()==domain) continue;
279 i.value()->move(dx,dy,size);
283 i.value()->move(dx,dy,size);
280 }
284 }
281 domain->move(dx,dy,size);
285 domain->move(dx,dy,size);
282 }
286 }
283
287
284 QList<QAbstractSeries*> ChartDataSet::series() const
288 QList<QAbstractSeries*> ChartDataSet::series() const
285 {
289 {
286 return m_seriesAxisMap.keys();
290 return m_seriesAxisMap.keys();
287 }
291 }
288
292
289 void ChartDataSet::updateSeries(QAbstractSeries *series)
293 void ChartDataSet::updateSeries(QAbstractSeries *series)
290 {
294 {
291 emit seriesUpdated(series);
295 emit seriesUpdated(series);
292 }
296 }
293
297
294 #include "moc_chartdataset_p.cpp"
298 #include "moc_chartdataset_p.cpp"
295
299
296 QTCOMMERCIALCHART_END_NAMESPACE
300 QTCOMMERCIALCHART_END_NAMESPACE
@@ -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 CHARTDATASET_P_H
30 #ifndef CHARTDATASET_P_H
31 #define CHARTDATASET_P_H
31 #define CHARTDATASET_P_H
32
32
33 #include "qabstractseries.h"
33 #include "qabstractseries.h"
34 #include "domain_p.h"
34 #include "domain_p.h"
35 #include <QVector>
35 #include <QVector>
36
36
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
37 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38
38
39 class QAxis;
39 class QAxis;
40 class QBarSeries;
40 class QBarSeries;
41
41
42 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
42 class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject
43 {
43 {
44 Q_OBJECT
44 Q_OBJECT
45 public:
45 public:
46 ChartDataSet(QObject* parent=0);
46 ChartDataSet(QChart* parent=0);
47 virtual ~ChartDataSet();
47 virtual ~ChartDataSet();
48
48
49 void addSeries(QAbstractSeries* series,QAxis *axisY = 0);
49 void addSeries(QAbstractSeries* series,QAxis *axisY = 0);
50 QAxis* removeSeries(QAbstractSeries* series);
50 QAxis* removeSeries(QAbstractSeries* series);
51 void removeAllSeries();
51 void removeAllSeries();
52 void updateSeries(QAbstractSeries* series);
52 void updateSeries(QAbstractSeries* series);
53
53
54 void zoomInDomain(const QRectF& rect, const QSizeF& size);
54 void zoomInDomain(const QRectF& rect, const QSizeF& size);
55 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
55 void zoomOutDomain(const QRectF& rect, const QSizeF& size);
56 void scrollDomain(qreal dx,qreal dy,const QSizeF& size);
56 void scrollDomain(qreal dx,qreal dy,const QSizeF& size);
57
57
58 int seriesCount(QAbstractSeries::SeriesType type);
58 int seriesCount(QAbstractSeries::SeriesType type);
59 int seriesIndex(QAbstractSeries *series);
59 int seriesIndex(QAbstractSeries *series);
60
60
61 Domain* domain(QAbstractSeries* series) const;
61 Domain* domain(QAbstractSeries* series) const;
62 Domain* domain(QAxis* axis) const;
62 Domain* domain(QAxis* axis) const;
63
63
64 QAxis* axisX() const { return m_axisX; }
64 QAxis* axisX() const { return m_axisX; }
65 QAxis* axisY(QAbstractSeries *series = 0) const;
65 QAxis* axisY(QAbstractSeries *series = 0) const;
66
66
67 QList<QAbstractSeries*> series() const;
67 QList<QAbstractSeries*> series() const;
68
68
69 Q_SIGNALS:
69 Q_SIGNALS:
70 void seriesAdded(QAbstractSeries* series, Domain* domain);
70 void seriesAdded(QAbstractSeries* series, Domain* domain);
71 void seriesRemoved(QAbstractSeries* series);
71 void seriesRemoved(QAbstractSeries* series);
72 void seriesUpdated(QAbstractSeries* series);
72 void seriesUpdated(QAbstractSeries* series);
73 void axisAdded(QAxis* axis,Domain* domain);
73 void axisAdded(QAxis* axis,Domain* domain);
74 void axisRemoved(QAxis* axis);
74 void axisRemoved(QAxis* axis);
75
75
76 private:
76 private:
77 QStringList createLabels(QAxis* axis,qreal min, qreal max);
77 QStringList createLabels(QAxis* axis,qreal min, qreal max);
78 void calculateDomain(QAbstractSeries* series,Domain* domain);
78 void calculateDomain(QAbstractSeries* series,Domain* domain);
79 void setupCategories(QBarSeries* series);
79 void setupCategories(QBarSeries* series);
80
80
81 private:
81 private:
82 QMap<QAbstractSeries *, QAxis *> m_seriesAxisMap;
82 QMap<QAbstractSeries *, QAxis *> m_seriesAxisMap;
83 QMap<QAxis*, Domain *> m_axisDomainMap;
83 QMap<QAxis*, Domain *> m_axisDomainMap;
84 QMap<int, QAbstractSeries *> m_indexSeriesMap;
84 QMap<int, QAbstractSeries *> m_indexSeriesMap;
85 QAxis* m_axisX;
85 QAxis* m_axisX;
86 QAxis* m_axisY;
86 QAxis* m_axisY;
87
87
88 int m_domainIndex;
88 int m_domainIndex;
89 bool m_axisXInitialized;
89 bool m_axisXInitialized;
90 bool m_axisYInitialized;
90 bool m_axisYInitialized;
91 };
91 };
92
92
93 QTCOMMERCIALCHART_END_NAMESPACE
93 QTCOMMERCIALCHART_END_NAMESPACE
94
94
95 #endif /* CHARTENGINE_P_H_ */
95 #endif /* CHARTENGINE_P_H_ */
@@ -1,130 +1,142
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 "qabstractseries.h"
21 #include "qabstractseries.h"
22 #include "qabstractseries_p.h"
22 #include "qabstractseries_p.h"
23 #include "chartdataset_p.h"
23 #include "chartdataset_p.h"
24
24
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25 QTCOMMERCIALCHART_BEGIN_NAMESPACE
26
26
27 /*!
27 /*!
28 \class QAbstractSeries
28 \class QAbstractSeries
29 \brief Base class for all QtCommercial Chart series.
29 \brief Base class for all QtCommercial Chart series.
30 \mainclass
30 \mainclass
31
31
32 Usually you use the series type specific inherited classes instead of the base class.
32 Usually you use the series type specific inherited classes instead of the base class.
33 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries,
33 \sa QXYSeries, QLineSeries, QSplineSeries, QScatterSeries, QAreaSeries, QBarSeries, QStackedBarSeries,
34 QPercentBarSeries, QPieSeries
34 QPercentBarSeries, QPieSeries
35 */
35 */
36
36
37 /*!
37 /*!
38 \enum QAbstractSeries::SeriesType
38 \enum QAbstractSeries::SeriesType
39
39
40 The type of the series object.
40 The type of the series object.
41
41
42 \value SeriesTypeLine
42 \value SeriesTypeLine
43 \value SeriesTypeArea
43 \value SeriesTypeArea
44 \value SeriesTypeBar
44 \value SeriesTypeBar
45 \value SeriesTypeStackedBar
45 \value SeriesTypeStackedBar
46 \value SeriesTypePercentBar
46 \value SeriesTypePercentBar
47 \value SeriesTypeGroupedBar
47 \value SeriesTypeGroupedBar
48 \value SeriesTypePie
48 \value SeriesTypePie
49 \value SeriesTypeScatter
49 \value SeriesTypeScatter
50 \value SeriesTypeSpline
50 \value SeriesTypeSpline
51 */
51 */
52
52
53 /*!
53 /*!
54 \fn QSeriesType QAbstractSeries::type() const
54 \fn QSeriesType QAbstractSeries::type() const
55 \brief The type of the series.
55 \brief The type of the series.
56 */
56 */
57
57
58 /*!
58 /*!
59 \fn bool QAbstractSeries::setModel(QAbstractItemModel *model)
59 \fn bool QAbstractSeries::setModel(QAbstractItemModel *model)
60 \brief Use the \a model to provide data for the series. The model overrides possible user data
60 \brief Use the \a model to provide data for the series. The model overrides possible user data
61 set with QChartSeries type specific data setters. For example if you call both
61 set with QChartSeries type specific data setters. For example if you call both
62 QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is
62 QScatterSeries::addData() and QScatterSeries::setModel, only the data provided by the model is
63 used by the series. Returns true if the model is valid for the series.
63 used by the series. Returns true if the model is valid for the series.
64 */
64 */
65
65
66 /*!
66 /*!
67 \property QAbstractSeries::name
67 \property QAbstractSeries::name
68 \brief name of the series property
68 \brief name of the series property
69 */
69 */
70
70
71 /*!
71 /*!
72 \fn void QAbstractSeries::setName(const QString& name)
72 \fn void QAbstractSeries::setName(const QString& name)
73 \brief Sets a \a name for the series.
73 \brief Sets a \a name for the series.
74
74
75 The name of a series is shown in the legend for QXYSeries.
75 The name of a series is shown in the legend for QXYSeries.
76 \sa QChart::setTitle()
76 \sa QChart::setTitle()
77 \sa QPieSlice::setLabel()
77 \sa QPieSlice::setLabel()
78 \sa QBarSet::setName()
78 \sa QBarSet::setName()
79 */
79 */
80
80
81 /*!
81 /*!
82 \internal
82 \internal
83 \brief Constructs ChartSeries object with \a parent.
83 \brief Constructs ChartSeries object with \a parent.
84 */
84 */
85 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
85 QAbstractSeries::QAbstractSeries(QAbstractSeriesPrivate &d, QObject *parent) :
86 QObject(parent),
86 QObject(parent),
87 d_ptr(&d)
87 d_ptr(&d)
88 {
88 {
89 }
89 }
90
90
91 /*!
91 /*!
92 \brief Virtual destructor for the chart series.
92 \brief Virtual destructor for the chart series.
93 */
93 */
94 QAbstractSeries::~QAbstractSeries()
94 QAbstractSeries::~QAbstractSeries()
95 {
95 {
96 if(d_ptr->m_dataset) qFatal("Still binded series detected !");
96 if(d_ptr->m_dataset) qFatal("Still binded series detected !");
97 }
97 }
98
98
99 void QAbstractSeries::setName(const QString& name)
99 void QAbstractSeries::setName(const QString& name)
100 {
100 {
101 d_ptr->m_name = name;
101 d_ptr->m_name = name;
102 }
102 }
103
103
104 /*!
104 /*!
105 \brief Returns the name of the series.
105 \brief Returns the name of the series.
106 \sa setName()
106 \sa setName()
107 */
107 */
108 QString QAbstractSeries::name() const
108 QString QAbstractSeries::name() const
109 {
109 {
110 return d_ptr->m_name;
110 return d_ptr->m_name;
111 }
111 }
112
112
113 /*!
114 \brief Returns the chart where series belongs to.
115
116 Set automatically when the series is added to the chart
117 and unset when the series is removed from the chart.
118 */
119 QChart* QAbstractSeries::chart() const
120 {
121 return d_ptr->m_chart;
122 }
123
113 ///////////////////////////////////////////////////////////////////////////////////////////////////
124 ///////////////////////////////////////////////////////////////////////////////////////////////////
114
125
115 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
126 QAbstractSeriesPrivate::QAbstractSeriesPrivate(QAbstractSeries* q):
116 q_ptr(q),
127 q_ptr(q),
128 m_chart(0),
117 m_dataset(0)
129 m_dataset(0)
118 {
130 {
119 }
131 }
120
132
121 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
133 QAbstractSeriesPrivate::~QAbstractSeriesPrivate()
122 {
134 {
123 }
135 }
124
136
125 #include "moc_qabstractseries.cpp"
137 #include "moc_qabstractseries.cpp"
126 #include "moc_qabstractseries_p.cpp"
138 #include "moc_qabstractseries_p.cpp"
127
139
128 QTCOMMERCIALCHART_END_NAMESPACE
140 QTCOMMERCIALCHART_END_NAMESPACE
129
141
130
142
@@ -1,66 +1,67
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 QABSTRACTSERIES_P_H
30 #ifndef QABSTRACTSERIES_P_H
31 #define QABSTRACTSERIES_P_H
31 #define QABSTRACTSERIES_P_H
32
32
33 #include "qabstractseries.h"
33 #include "qabstractseries.h"
34
34
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35 QTCOMMERCIALCHART_BEGIN_NAMESPACE
36
36
37 class Domain;
37 class Domain;
38 class ChartPresenter;
38 class ChartPresenter;
39 class Chart;
39 class Chart;
40 class LegendMarker;
40 class LegendMarker;
41 class QLegend;
41 class QLegend;
42 class ChartDataSet;
42 class ChartDataSet;
43
43
44 class QAbstractSeriesPrivate : public QObject
44 class QAbstractSeriesPrivate : public QObject
45 {
45 {
46 Q_OBJECT
46 Q_OBJECT
47 public:
47 public:
48 QAbstractSeriesPrivate(QAbstractSeries *q);
48 QAbstractSeriesPrivate(QAbstractSeries *q);
49 ~QAbstractSeriesPrivate();
49 ~QAbstractSeriesPrivate();
50
50
51 virtual void scaleDomain(Domain& domain) = 0;
51 virtual void scaleDomain(Domain& domain) = 0;
52 virtual Chart* createGraphics(ChartPresenter* presenter) = 0;
52 virtual Chart* createGraphics(ChartPresenter* presenter) = 0;
53 virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0;
53 virtual QList<LegendMarker*> createLegendMarker(QLegend* legend) = 0;
54
54
55 protected:
55 protected:
56 QAbstractSeries *q_ptr;
56 QAbstractSeries *q_ptr;
57 QChart *m_chart;
57 ChartDataSet *m_dataset;
58 ChartDataSet *m_dataset;
58 QString m_name;
59 QString m_name;
59
60
60 friend class QAbstractSeries;
61 friend class QAbstractSeries;
61 friend class ChartDataSet;
62 friend class ChartDataSet;
62 };
63 };
63
64
64 QTCOMMERCIALCHART_END_NAMESPACE
65 QTCOMMERCIALCHART_END_NAMESPACE
65
66
66 #endif
67 #endif
@@ -1,585 +1,594
1 #include <QtTest/QtTest>
1 #include <QtTest/QtTest>
2 #include <qchartview.h>
2 #include <qchartview.h>
3 #include <qlineseries.h>
3 #include <qlineseries.h>
4 #include <qareaseries.h>
4 #include <qareaseries.h>
5 #include <qscatterseries.h>
5 #include <qscatterseries.h>
6 #include <qsplineseries.h>
6 #include <qsplineseries.h>
7 #include <qpieseries.h>
7 #include <qpieseries.h>
8 #include <qbarseries.h>
8 #include <qbarseries.h>
9 #include <qpercentbarseries.h>
9 #include <qpercentbarseries.h>
10 #include <qstackedbarseries.h>
10 #include <qstackedbarseries.h>
11
11
12 QTCOMMERCIALCHART_USE_NAMESPACE
12 QTCOMMERCIALCHART_USE_NAMESPACE
13
13
14 Q_DECLARE_METATYPE(QAxis *)
14 Q_DECLARE_METATYPE(QAxis *)
15 Q_DECLARE_METATYPE(QAbstractSeries *)
15 Q_DECLARE_METATYPE(QAbstractSeries *)
16 Q_DECLARE_METATYPE(QChart::AnimationOption)
16 Q_DECLARE_METATYPE(QChart::AnimationOption)
17 Q_DECLARE_METATYPE(QBrush)
17 Q_DECLARE_METATYPE(QBrush)
18 Q_DECLARE_METATYPE(QPen)
18 Q_DECLARE_METATYPE(QPen)
19 Q_DECLARE_METATYPE(QChart::ChartTheme)
19 Q_DECLARE_METATYPE(QChart::ChartTheme)
20
20
21 class tst_QChart : public QObject
21 class tst_QChart : public QObject
22 {
22 {
23 Q_OBJECT
23 Q_OBJECT
24
24
25 public slots:
25 public slots:
26 void initTestCase();
26 void initTestCase();
27 void cleanupTestCase();
27 void cleanupTestCase();
28 void init();
28 void init();
29 void cleanup();
29 void cleanup();
30
30
31 private slots:
31 private slots:
32 void qchart_data();
32 void qchart_data();
33 void qchart();
33 void qchart();
34
34
35 void addSeries_data();
35 void addSeries_data();
36 void addSeries();
36 void addSeries();
37 void animationOptions_data();
37 void animationOptions_data();
38 void animationOptions();
38 void animationOptions();
39 void axisX_data();
39 void axisX_data();
40 void axisX();
40 void axisX();
41 void axisY_data();
41 void axisY_data();
42 void axisY();
42 void axisY();
43 void backgroundBrush_data();
43 void backgroundBrush_data();
44 void backgroundBrush();
44 void backgroundBrush();
45 void backgroundPen_data();
45 void backgroundPen_data();
46 void backgroundPen();
46 void backgroundPen();
47 void isBackgroundVisible_data();
47 void isBackgroundVisible_data();
48 void isBackgroundVisible();
48 void isBackgroundVisible();
49 void legend_data();
49 void legend_data();
50 void legend();
50 void legend();
51 void margins_data();
51 void margins_data();
52 void margins();
52 void margins();
53 void removeAllSeries_data();
53 void removeAllSeries_data();
54 void removeAllSeries();
54 void removeAllSeries();
55 void removeSeries_data();
55 void removeSeries_data();
56 void removeSeries();
56 void removeSeries();
57 void scrollDown_data();
57 void scrollDown_data();
58 void scrollDown();
58 void scrollDown();
59 void scrollLeft_data();
59 void scrollLeft_data();
60 void scrollLeft();
60 void scrollLeft();
61 void scrollRight_data();
61 void scrollRight_data();
62 void scrollRight();
62 void scrollRight();
63 void scrollUp_data();
63 void scrollUp_data();
64 void scrollUp();
64 void scrollUp();
65 void theme_data();
65 void theme_data();
66 void theme();
66 void theme();
67 void title_data();
67 void title_data();
68 void title();
68 void title();
69 void titleBrush_data();
69 void titleBrush_data();
70 void titleBrush();
70 void titleBrush();
71 void titleFont_data();
71 void titleFont_data();
72 void titleFont();
72 void titleFont();
73 void zoomIn_data();
73 void zoomIn_data();
74 void zoomIn();
74 void zoomIn();
75 void zoomOut_data();
75 void zoomOut_data();
76 void zoomOut();
76 void zoomOut();
77
77
78 private:
78 private:
79 void createTestData();
79 void createTestData();
80
80
81 private:
81 private:
82 QChartView* m_view;
82 QChartView* m_view;
83 QChart* m_chart;
83 QChart* m_chart;
84 };
84 };
85
85
86 void tst_QChart::initTestCase()
86 void tst_QChart::initTestCase()
87 {
87 {
88
88
89 }
89 }
90
90
91 void tst_QChart::cleanupTestCase()
91 void tst_QChart::cleanupTestCase()
92 {
92 {
93
93
94 }
94 }
95
95
96 void tst_QChart::init()
96 void tst_QChart::init()
97 {
97 {
98 m_view = new QChartView(new QChart());
98 m_view = new QChartView(new QChart());
99 m_chart = m_view->chart();
99 m_chart = m_view->chart();
100 }
100 }
101
101
102 void tst_QChart::createTestData()
102 void tst_QChart::createTestData()
103 {
103 {
104 QLineSeries* series0 = new QLineSeries(this);
104 QLineSeries* series0 = new QLineSeries(this);
105 *series0 << QPointF(0, 0) << QPointF(100, 100);
105 *series0 << QPointF(0, 0) << QPointF(100, 100);
106 m_chart->addSeries(series0);
106 m_chart->addSeries(series0);
107 m_view->show();
107 m_view->show();
108 QTest::qWaitForWindowShown(m_view);
108 QTest::qWaitForWindowShown(m_view);
109 }
109 }
110
110
111 void tst_QChart::cleanup()
111 void tst_QChart::cleanup()
112 {
112 {
113 delete m_view;
113 delete m_view;
114 m_view = 0;
114 m_view = 0;
115 m_chart = 0;
115 m_chart = 0;
116 }
116 }
117
117
118 void tst_QChart::qchart_data()
118 void tst_QChart::qchart_data()
119 {
119 {
120 }
120 }
121
121
122 void tst_QChart::qchart()
122 void tst_QChart::qchart()
123 {
123 {
124 QVERIFY(m_chart);
124 QVERIFY(m_chart);
125 QVERIFY(m_chart->legend());
125 QVERIFY(m_chart->legend());
126 QVERIFY(m_chart->legend()->isVisible());
126 QVERIFY(m_chart->legend()->isVisible());
127
127
128 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
128 QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation);
129 QVERIFY(m_chart->axisX());
129 QVERIFY(m_chart->axisX());
130 QVERIFY(m_chart->axisY());
130 QVERIFY(m_chart->axisY());
131 QVERIFY(m_chart->backgroundBrush()!=QBrush());
131 QVERIFY(m_chart->backgroundBrush()!=QBrush());
132 QVERIFY(m_chart->backgroundPen()!=QPen());
132 QVERIFY(m_chart->backgroundPen()!=QPen());
133 QCOMPARE(m_chart->isBackgroundVisible(), true);
133 QCOMPARE(m_chart->isBackgroundVisible(), true);
134
134
135 QVERIFY(m_chart->margins().top()>0);
135 QVERIFY(m_chart->margins().top()>0);
136 QVERIFY(m_chart->margins().left()>0);
136 QVERIFY(m_chart->margins().left()>0);
137 QVERIFY(m_chart->margins().right()>0);
137 QVERIFY(m_chart->margins().right()>0);
138 QVERIFY(m_chart->margins().bottom()>0);
138 QVERIFY(m_chart->margins().bottom()>0);
139
139
140 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
140 QCOMPARE(m_chart->theme(), QChart::ChartThemeLight);
141 QCOMPARE(m_chart->title(), QString());
141 QCOMPARE(m_chart->title(), QString());
142
142
143 //QCOMPARE(m_chart->titleBrush(),QBrush());
143 //QCOMPARE(m_chart->titleBrush(),QBrush());
144 //QCOMPARE(m_chart->titleFont(),QFont());
144 //QCOMPARE(m_chart->titleFont(),QFont());
145
145
146 m_chart->removeAllSeries();
146 m_chart->removeAllSeries();
147 m_chart->scrollDown();
147 m_chart->scrollDown();
148 m_chart->scrollLeft();
148 m_chart->scrollLeft();
149 m_chart->scrollRight();
149 m_chart->scrollRight();
150 m_chart->scrollUp();
150 m_chart->scrollUp();
151
151
152 m_chart->zoomIn();
152 m_chart->zoomIn();
153 m_chart->zoomIn(QRectF());
153 m_chart->zoomIn(QRectF());
154 m_chart->zoomOut();
154 m_chart->zoomOut();
155 }
155 }
156
156
157 void tst_QChart::addSeries_data()
157 void tst_QChart::addSeries_data()
158 {
158 {
159 QTest::addColumn<QAbstractSeries *>("series");
159 QTest::addColumn<QAbstractSeries *>("series");
160 QTest::addColumn<QAxis *>("axis");
160 QTest::addColumn<QAxis *>("axis");
161
161
162 QAbstractSeries* series0 = new QLineSeries(this);
162 QAbstractSeries* series0 = new QLineSeries(this);
163 QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0));
163 QAbstractSeries* series1 = new QAreaSeries(static_cast<QLineSeries*>(series0));
164 QAbstractSeries* series2 = new QScatterSeries(this);
164 QAbstractSeries* series2 = new QScatterSeries(this);
165 QAbstractSeries* series3 = new QSplineSeries(this);
165 QAbstractSeries* series3 = new QSplineSeries(this);
166 QAbstractSeries* series4 = new QPieSeries(this);
166 QAbstractSeries* series4 = new QPieSeries(this);
167 QAbstractSeries* series5 = new QBarSeries(this);
167 QAbstractSeries* series5 = new QBarSeries(this);
168 QAbstractSeries* series6 = new QPercentBarSeries(this);
168 QAbstractSeries* series6 = new QPercentBarSeries(this);
169 QAbstractSeries* series7 = new QStackedBarSeries(this);
169 QAbstractSeries* series7 = new QStackedBarSeries(this);
170
170
171 QBarSeries* s5 = static_cast<QBarSeries*> (series5);
171 QBarSeries* s5 = static_cast<QBarSeries*> (series5);
172 s5->setCategories(QBarCategories());
172 s5->setCategories(QBarCategories());
173 QPercentBarSeries* s6 = static_cast<QPercentBarSeries*> (series6);
173 QPercentBarSeries* s6 = static_cast<QPercentBarSeries*> (series6);
174 s6->setCategories(QBarCategories());
174 s6->setCategories(QBarCategories());
175 QStackedBarSeries* s7 = static_cast<QStackedBarSeries*> (series7);
175 QStackedBarSeries* s7 = static_cast<QStackedBarSeries*> (series7);
176 s7->setCategories(QBarCategories());
176 s7->setCategories(QBarCategories());
177
177
178 QAxis* axis = new QAxis(this);
178 QAxis* axis = new QAxis(this);
179
179
180 QTest::newRow("default axis: lineSeries") << series0 << (QAxis*) 0;
180 QTest::newRow("default axis: lineSeries") << series0 << (QAxis*) 0;
181 QTest::newRow("axis0: lineSeries") << series0 << axis;
181 QTest::newRow("axis0: lineSeries") << series0 << axis;
182 QTest::newRow("default axis: areaSeries") << series1 << (QAxis*) 0;
182 QTest::newRow("default axis: areaSeries") << series1 << (QAxis*) 0;
183 QTest::newRow("axis: areaSeries") << series1 << axis;
183 QTest::newRow("axis: areaSeries") << series1 << axis;
184 QTest::newRow("default axis: scatterSeries") << series2 << (QAxis*) 0;
184 QTest::newRow("default axis: scatterSeries") << series2 << (QAxis*) 0;
185 QTest::newRow("axis1: scatterSeries") << series2 << axis;
185 QTest::newRow("axis1: scatterSeries") << series2 << axis;
186 QTest::newRow("default axis: splineSeries") << series3 << (QAxis*) 0;
186 QTest::newRow("default axis: splineSeries") << series3 << (QAxis*) 0;
187 QTest::newRow("axis: splineSeries") << series3 << axis;
187 QTest::newRow("axis: splineSeries") << series3 << axis;
188 QTest::newRow("default axis: pieSeries") << series4 << (QAxis*) 0;
188 QTest::newRow("default axis: pieSeries") << series4 << (QAxis*) 0;
189 QTest::newRow("axis: pieSeries") << series4 << axis;
189 QTest::newRow("axis: pieSeries") << series4 << axis;
190 QTest::newRow("default axis: barSeries") << series5 << (QAxis*) 0;
190 QTest::newRow("default axis: barSeries") << series5 << (QAxis*) 0;
191 QTest::newRow("axis: barSeries") << series5 << axis;
191 QTest::newRow("axis: barSeries") << series5 << axis;
192 QTest::newRow("default axis: percentBarSeries") << series6 << (QAxis*) 0;
192 QTest::newRow("default axis: percentBarSeries") << series6 << (QAxis*) 0;
193 QTest::newRow("axis: barSeries") << series6 << axis;
193 QTest::newRow("axis: barSeries") << series6 << axis;
194 QTest::newRow("default axis: stackedBarSeries") << series7 << (QAxis*) 0;
194 QTest::newRow("default axis: stackedBarSeries") << series7 << (QAxis*) 0;
195 QTest::newRow("axis: barSeries") << series7 << axis;
195 QTest::newRow("axis: barSeries") << series7 << axis;
196
196
197 }
197 }
198
198
199 void tst_QChart::addSeries()
199 void tst_QChart::addSeries()
200 {
200 {
201 QFETCH(QAbstractSeries *, series);
201 QFETCH(QAbstractSeries *, series);
202 QFETCH(QAxis *, axis);
202 QFETCH(QAxis *, axis);
203 m_view->show();
203 m_view->show();
204 QTest::qWaitForWindowShown(m_view);
204 QTest::qWaitForWindowShown(m_view);
205 if(!axis) axis = m_chart->axisY();
205 if(!axis) axis = m_chart->axisY();
206 QVERIFY(!series->chart());
206 m_chart->addSeries(series,axis);
207 m_chart->addSeries(series,axis);
208 QVERIFY(series->chart() == m_chart);
207 QCOMPARE(m_chart->axisY(series),axis);
209 QCOMPARE(m_chart->axisY(series),axis);
208 m_chart->removeSeries(series);
210 m_chart->removeSeries(series);
209
211 QVERIFY(!series->chart());
210 }
212 }
211
213
212 void tst_QChart::animationOptions_data()
214 void tst_QChart::animationOptions_data()
213 {
215 {
214 QTest::addColumn<QChart::AnimationOption>("animationOptions");
216 QTest::addColumn<QChart::AnimationOption>("animationOptions");
215 QTest::newRow("AllAnimations") << QChart::AllAnimations;
217 QTest::newRow("AllAnimations") << QChart::AllAnimations;
216 QTest::newRow("NoAnimation") << QChart::NoAnimation;
218 QTest::newRow("NoAnimation") << QChart::NoAnimation;
217 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
219 QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations;
218 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
220 QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations;
219 }
221 }
220
222
221 void tst_QChart::animationOptions()
223 void tst_QChart::animationOptions()
222 {
224 {
223 createTestData();
225 createTestData();
224 QFETCH(QChart::AnimationOption, animationOptions);
226 QFETCH(QChart::AnimationOption, animationOptions);
225 m_chart->setAnimationOptions(animationOptions);
227 m_chart->setAnimationOptions(animationOptions);
226 QCOMPARE(m_chart->animationOptions(), animationOptions);
228 QCOMPARE(m_chart->animationOptions(), animationOptions);
227 }
229 }
228
230
229 void tst_QChart::axisX_data()
231 void tst_QChart::axisX_data()
230 {
232 {
231
233
232 }
234 }
233
235
234 void tst_QChart::axisX()
236 void tst_QChart::axisX()
235 {
237 {
236 QVERIFY(m_chart->axisX());
238 QVERIFY(m_chart->axisX());
237 QAxis* axis = m_chart->axisX();
239 QAxis* axis = m_chart->axisX();
238 createTestData();
240 createTestData();
239 //it should be the same axis
241 //it should be the same axis
240 QCOMPARE(axis,m_chart->axisX());
242 QCOMPARE(axis,m_chart->axisX());
241 }
243 }
242
244
243 void tst_QChart::axisY_data()
245 void tst_QChart::axisY_data()
244 {
246 {
245 QTest::addColumn<QAxis*>("axis0");
247 QTest::addColumn<QAxis*>("axis0");
246 QTest::addColumn<QAxis*>("axis1");
248 QTest::addColumn<QAxis*>("axis1");
247 QTest::addColumn<QAxis*>("axis2");
249 QTest::addColumn<QAxis*>("axis2");
248 QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis();
250 QTest::newRow("1 defualt, 2 optional") << (QAxis*)0 << new QAxis() << new QAxis();
249 QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis();
251 QTest::newRow("3 optional") << new QAxis() << new QAxis() << new QAxis();
250 }
252 }
251
253
252
254
253 void tst_QChart::axisY()
255 void tst_QChart::axisY()
254 {
256 {
255 QFETCH(QAxis*, axis0);
257 QFETCH(QAxis*, axis0);
256 QFETCH(QAxis*, axis1);
258 QFETCH(QAxis*, axis1);
257 QFETCH(QAxis*, axis2);
259 QFETCH(QAxis*, axis2);
258
260
259 QAxis* defaultAxisY = m_chart->axisY();
261 QAxis* defaultAxisY = m_chart->axisY();
260
262
261 QVERIFY2(defaultAxisY, "Missing axisY.");
263 QVERIFY2(defaultAxisY, "Missing axisY.");
262
264
263 QLineSeries* series0 = new QLineSeries();
265 QLineSeries* series0 = new QLineSeries();
264 m_chart->addSeries(series0, axis0);
266 m_chart->addSeries(series0, axis0);
265
267
266 QLineSeries* series1 = new QLineSeries();
268 QLineSeries* series1 = new QLineSeries();
267 m_chart->addSeries(series1, axis1);
269 m_chart->addSeries(series1, axis1);
268
270
269 QLineSeries* series2 = new QLineSeries();
271 QLineSeries* series2 = new QLineSeries();
270 m_chart->addSeries(series2, axis2);
272 m_chart->addSeries(series2, axis2);
271
273
272 if (!axis0)
274 if (!axis0)
273 axis0 = defaultAxisY;
275 axis0 = defaultAxisY;
274 if (!axis1)
276 if (!axis1)
275 axis1 = defaultAxisY;
277 axis1 = defaultAxisY;
276 if (!axis2)
278 if (!axis2)
277 axis2 = defaultAxisY;
279 axis2 = defaultAxisY;
278
280
279 QVERIFY(m_chart->axisY(series0) == axis0);
281 QVERIFY(m_chart->axisY(series0) == axis0);
280 QVERIFY(m_chart->axisY(series1) == axis1);
282 QVERIFY(m_chart->axisY(series1) == axis1);
281 QVERIFY(m_chart->axisY(series2) == axis2);
283 QVERIFY(m_chart->axisY(series2) == axis2);
282 }
284 }
283
285
284 void tst_QChart::backgroundBrush_data()
286 void tst_QChart::backgroundBrush_data()
285 {
287 {
286 QTest::addColumn<QBrush>("backgroundBrush");
288 QTest::addColumn<QBrush>("backgroundBrush");
287 QTest::newRow("null") << QBrush();
289 QTest::newRow("null") << QBrush();
288 QTest::newRow("blue") << QBrush(Qt::blue);
290 QTest::newRow("blue") << QBrush(Qt::blue);
289 QTest::newRow("white") << QBrush(Qt::white);
291 QTest::newRow("white") << QBrush(Qt::white);
290 QTest::newRow("black") << QBrush(Qt::black);
292 QTest::newRow("black") << QBrush(Qt::black);
291 }
293 }
292
294
293 void tst_QChart::backgroundBrush()
295 void tst_QChart::backgroundBrush()
294 {
296 {
295 QFETCH(QBrush, backgroundBrush);
297 QFETCH(QBrush, backgroundBrush);
296 m_chart->setBackgroundBrush(backgroundBrush);
298 m_chart->setBackgroundBrush(backgroundBrush);
297 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
299 QCOMPARE(m_chart->backgroundBrush(), backgroundBrush);
298 }
300 }
299
301
300 void tst_QChart::backgroundPen_data()
302 void tst_QChart::backgroundPen_data()
301 {
303 {
302 QTest::addColumn<QPen>("backgroundPen");
304 QTest::addColumn<QPen>("backgroundPen");
303 QTest::newRow("null") << QPen();
305 QTest::newRow("null") << QPen();
304 QTest::newRow("blue") << QPen(Qt::blue);
306 QTest::newRow("blue") << QPen(Qt::blue);
305 QTest::newRow("white") << QPen(Qt::white);
307 QTest::newRow("white") << QPen(Qt::white);
306 QTest::newRow("black") << QPen(Qt::black);
308 QTest::newRow("black") << QPen(Qt::black);
307 }
309 }
308
310
309
311
310 void tst_QChart::backgroundPen()
312 void tst_QChart::backgroundPen()
311 {
313 {
312 QFETCH(QPen, backgroundPen);
314 QFETCH(QPen, backgroundPen);
313 m_chart->setBackgroundPen(backgroundPen);
315 m_chart->setBackgroundPen(backgroundPen);
314 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
316 QCOMPARE(m_chart->backgroundPen(), backgroundPen);
315 }
317 }
316
318
317 void tst_QChart::isBackgroundVisible_data()
319 void tst_QChart::isBackgroundVisible_data()
318 {
320 {
319 QTest::addColumn<bool>("isBackgroundVisible");
321 QTest::addColumn<bool>("isBackgroundVisible");
320 QTest::newRow("true") << true;
322 QTest::newRow("true") << true;
321 QTest::newRow("false") << false;
323 QTest::newRow("false") << false;
322 }
324 }
323
325
324 void tst_QChart::isBackgroundVisible()
326 void tst_QChart::isBackgroundVisible()
325 {
327 {
326 QFETCH(bool, isBackgroundVisible);
328 QFETCH(bool, isBackgroundVisible);
327 m_chart->setBackgroundVisible(isBackgroundVisible);
329 m_chart->setBackgroundVisible(isBackgroundVisible);
328 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
330 QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible);
329 }
331 }
330
332
331 void tst_QChart::legend_data()
333 void tst_QChart::legend_data()
332 {
334 {
333
335
334 }
336 }
335
337
336 void tst_QChart::legend()
338 void tst_QChart::legend()
337 {
339 {
338 QVERIFY(m_chart->legend());
340 QVERIFY(m_chart->legend());
339 }
341 }
340
342
341 void tst_QChart::margins_data()
343 void tst_QChart::margins_data()
342 {
344 {
343
345
344 }
346 }
345
347
346 void tst_QChart::margins()
348 void tst_QChart::margins()
347 {
349 {
348 createTestData();
350 createTestData();
349 QRectF rect = m_chart->geometry();
351 QRectF rect = m_chart->geometry();
350
352
351 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
353 QVERIFY(m_chart->margins().top()+m_chart->margins().bottom() < rect.height());
352 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
354 QVERIFY(m_chart->margins().left()+m_chart->margins().right() < rect.width());
353 }
355 }
354
356
355 void tst_QChart::removeAllSeries_data()
357 void tst_QChart::removeAllSeries_data()
356 {
358 {
357
359
358 }
360 }
359
361
360 void tst_QChart::removeAllSeries()
362 void tst_QChart::removeAllSeries()
361 {
363 {
362 QLineSeries* series0 = new QLineSeries(this);
364 QLineSeries* series0 = new QLineSeries(this);
363 QLineSeries* series1 = new QLineSeries(this);
365 QLineSeries* series1 = new QLineSeries(this);
364 QLineSeries* series2 = new QLineSeries(this);
366 QLineSeries* series2 = new QLineSeries(this);
367 QSignalSpy deleteSpy1(series0, SIGNAL(destroyed()));
368 QSignalSpy deleteSpy2(series1, SIGNAL(destroyed()));
369 QSignalSpy deleteSpy3(series2, SIGNAL(destroyed()));
365
370
366 m_chart->addSeries(series0);
371 m_chart->addSeries(series0);
367 m_chart->addSeries(series1);
372 m_chart->addSeries(series1);
368 m_chart->addSeries(series2);
373 m_chart->addSeries(series2);
369 m_view->show();
374 m_view->show();
370 QTest::qWaitForWindowShown(m_view);
375 QTest::qWaitForWindowShown(m_view);
371
376
372 QVERIFY(m_chart->axisY(series0)!=0);
377 QVERIFY(m_chart->axisY(series0)!=0);
373 QVERIFY(m_chart->axisY(series1)!=0);
378 QVERIFY(m_chart->axisY(series1)!=0);
374 QVERIFY(m_chart->axisY(series2)!=0);
379 QVERIFY(m_chart->axisY(series2)!=0);
375
380
376 m_chart->removeAllSeries();
381 m_chart->removeAllSeries();
377
378 QVERIFY(m_chart->axisY(series0)==0);
382 QVERIFY(m_chart->axisY(series0)==0);
379 QVERIFY(m_chart->axisY(series1)==0);
383 QVERIFY(m_chart->axisY(series1)==0);
380 QVERIFY(m_chart->axisY(series2)==0);
384 QVERIFY(m_chart->axisY(series2)==0);
385 QCOMPARE(deleteSpy1.count(), 1);
386 QCOMPARE(deleteSpy2.count(), 1);
387 QCOMPARE(deleteSpy3.count(), 1);
381 }
388 }
382
389
383 void tst_QChart::removeSeries_data()
390 void tst_QChart::removeSeries_data()
384 {
391 {
385 addSeries_data();
392 addSeries_data();
386 }
393 }
387
394
388 void tst_QChart::removeSeries()
395 void tst_QChart::removeSeries()
389 {
396 {
390 QFETCH(QAbstractSeries *, series);
397 QFETCH(QAbstractSeries *, series);
391 QFETCH(QAxis *, axis);
398 QFETCH(QAxis *, axis);
399 QSignalSpy deleteSpy(series, SIGNAL(destroyed()));
392 m_view->show();
400 m_view->show();
393 QTest::qWaitForWindowShown(m_view);
401 QTest::qWaitForWindowShown(m_view);
394 if(!axis) axis = m_chart->axisY();
402 if(!axis) axis = m_chart->axisY();
395 m_chart->addSeries(series,axis);
403 m_chart->addSeries(series,axis);
396 QCOMPARE(m_chart->axisY(series),axis);
404 QCOMPARE(m_chart->axisY(series),axis);
397 m_chart->removeSeries(series);
405 m_chart->removeSeries(series);
398 QVERIFY(m_chart->axisY(series)==0);
406 QVERIFY(m_chart->axisY(series)==0);
407 QCOMPARE(deleteSpy.count(), 0);
399 }
408 }
400
409
401 void tst_QChart::scrollDown_data()
410 void tst_QChart::scrollDown_data()
402 {
411 {
403
412
404 }
413 }
405
414
406 void tst_QChart::scrollDown()
415 void tst_QChart::scrollDown()
407 {
416 {
408 createTestData();
417 createTestData();
409 qreal min = m_chart->axisY()->min();
418 qreal min = m_chart->axisY()->min();
410 m_chart->scrollDown();
419 m_chart->scrollDown();
411 QVERIFY(m_chart->axisY()->min()<min);
420 QVERIFY(m_chart->axisY()->min()<min);
412 }
421 }
413
422
414 void tst_QChart::scrollLeft_data()
423 void tst_QChart::scrollLeft_data()
415 {
424 {
416
425
417 }
426 }
418
427
419 void tst_QChart::scrollLeft()
428 void tst_QChart::scrollLeft()
420 {
429 {
421 createTestData();
430 createTestData();
422 qreal min = m_chart->axisX()->min();
431 qreal min = m_chart->axisX()->min();
423 m_chart->scrollLeft();
432 m_chart->scrollLeft();
424 QVERIFY(m_chart->axisX()->min()<min);
433 QVERIFY(m_chart->axisX()->min()<min);
425 }
434 }
426
435
427 void tst_QChart::scrollRight_data()
436 void tst_QChart::scrollRight_data()
428 {
437 {
429
438
430 }
439 }
431
440
432 void tst_QChart::scrollRight()
441 void tst_QChart::scrollRight()
433 {
442 {
434 createTestData();
443 createTestData();
435 qreal min = m_chart->axisX()->min();
444 qreal min = m_chart->axisX()->min();
436 m_chart->scrollRight();
445 m_chart->scrollRight();
437 QVERIFY(m_chart->axisX()->min()>min);
446 QVERIFY(m_chart->axisX()->min()>min);
438 }
447 }
439
448
440 void tst_QChart::scrollUp_data()
449 void tst_QChart::scrollUp_data()
441 {
450 {
442
451
443 }
452 }
444
453
445 void tst_QChart::scrollUp()
454 void tst_QChart::scrollUp()
446 {
455 {
447 createTestData();
456 createTestData();
448 qreal min = m_chart->axisY()->min();
457 qreal min = m_chart->axisY()->min();
449 m_chart->scrollUp();
458 m_chart->scrollUp();
450 QVERIFY(m_chart->axisY()->min()>min);
459 QVERIFY(m_chart->axisY()->min()>min);
451 }
460 }
452
461
453 void tst_QChart::theme_data()
462 void tst_QChart::theme_data()
454 {
463 {
455 QTest::addColumn<QChart::ChartTheme>("theme");
464 QTest::addColumn<QChart::ChartTheme>("theme");
456 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
465 QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean;
457 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
466 QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy;
458 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
467 QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs;
459 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
468 QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand;
460 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
469 QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark;
461 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
470 QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast;
462 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
471 QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight;
463 }
472 }
464
473
465 void tst_QChart::theme()
474 void tst_QChart::theme()
466 {
475 {
467 QFETCH(QChart::ChartTheme, theme);
476 QFETCH(QChart::ChartTheme, theme);
468 createTestData();
477 createTestData();
469 m_chart->setTheme(theme);
478 m_chart->setTheme(theme);
470 QVERIFY(m_chart->theme()==theme);
479 QVERIFY(m_chart->theme()==theme);
471 }
480 }
472
481
473 void tst_QChart::title_data()
482 void tst_QChart::title_data()
474 {
483 {
475 QTest::addColumn<QString>("title");
484 QTest::addColumn<QString>("title");
476 QTest::newRow("null") << QString();
485 QTest::newRow("null") << QString();
477 QTest::newRow("foo") << QString("foo");
486 QTest::newRow("foo") << QString("foo");
478 }
487 }
479
488
480 void tst_QChart::title()
489 void tst_QChart::title()
481 {
490 {
482 QFETCH(QString, title);
491 QFETCH(QString, title);
483 m_chart->setTitle(title);
492 m_chart->setTitle(title);
484 QCOMPARE(m_chart->title(), title);
493 QCOMPARE(m_chart->title(), title);
485 }
494 }
486
495
487 void tst_QChart::titleBrush_data()
496 void tst_QChart::titleBrush_data()
488 {
497 {
489 QTest::addColumn<QBrush>("titleBrush");
498 QTest::addColumn<QBrush>("titleBrush");
490 QTest::newRow("null") << QBrush();
499 QTest::newRow("null") << QBrush();
491 QTest::newRow("blue") << QBrush(Qt::blue);
500 QTest::newRow("blue") << QBrush(Qt::blue);
492 QTest::newRow("white") << QBrush(Qt::white);
501 QTest::newRow("white") << QBrush(Qt::white);
493 QTest::newRow("black") << QBrush(Qt::black);
502 QTest::newRow("black") << QBrush(Qt::black);
494 }
503 }
495
504
496 void tst_QChart::titleBrush()
505 void tst_QChart::titleBrush()
497 {
506 {
498 QFETCH(QBrush, titleBrush);
507 QFETCH(QBrush, titleBrush);
499 m_chart->setTitleBrush(titleBrush);
508 m_chart->setTitleBrush(titleBrush);
500 QCOMPARE(m_chart->titleBrush(), titleBrush);
509 QCOMPARE(m_chart->titleBrush(), titleBrush);
501 }
510 }
502
511
503 void tst_QChart::titleFont_data()
512 void tst_QChart::titleFont_data()
504 {
513 {
505 QTest::addColumn<QFont>("titleFont");
514 QTest::addColumn<QFont>("titleFont");
506 QTest::newRow("null") << QFont();
515 QTest::newRow("null") << QFont();
507 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
516 QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true);
508 }
517 }
509
518
510 void tst_QChart::titleFont()
519 void tst_QChart::titleFont()
511 {
520 {
512 QFETCH(QFont, titleFont);
521 QFETCH(QFont, titleFont);
513 m_chart->setTitleFont(titleFont);
522 m_chart->setTitleFont(titleFont);
514 QCOMPARE(m_chart->titleFont(), titleFont);
523 QCOMPARE(m_chart->titleFont(), titleFont);
515 }
524 }
516
525
517 void tst_QChart::zoomIn_data()
526 void tst_QChart::zoomIn_data()
518 {
527 {
519 QTest::addColumn<QRectF>("rect");
528 QTest::addColumn<QRectF>("rect");
520 QTest::newRow("null") << QRectF();
529 QTest::newRow("null") << QRectF();
521 QTest::newRow("100x100") << QRectF(10,10,100,100);
530 QTest::newRow("100x100") << QRectF(10,10,100,100);
522 QTest::newRow("200x200") << QRectF(10,10,200,200);
531 QTest::newRow("200x200") << QRectF(10,10,200,200);
523 }
532 }
524
533
525
534
526 void tst_QChart::zoomIn()
535 void tst_QChart::zoomIn()
527 {
536 {
528 QFETCH(QRectF, rect);
537 QFETCH(QRectF, rect);
529 createTestData();
538 createTestData();
530 QRectF marigns = m_chart->margins();
539 QRectF marigns = m_chart->margins();
531 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
540 rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom());
532 qreal minX = m_chart->axisX()->min();
541 qreal minX = m_chart->axisX()->min();
533 qreal minY = m_chart->axisY()->min();
542 qreal minY = m_chart->axisY()->min();
534 qreal maxX = m_chart->axisX()->max();
543 qreal maxX = m_chart->axisX()->max();
535 qreal maxY = m_chart->axisY()->max();
544 qreal maxY = m_chart->axisY()->max();
536 m_chart->zoomIn(rect);
545 m_chart->zoomIn(rect);
537 if(rect.isValid()){
546 if(rect.isValid()){
538 QVERIFY(minX<m_chart->axisX()->min());
547 QVERIFY(minX<m_chart->axisX()->min());
539 QVERIFY(maxX>m_chart->axisX()->max());
548 QVERIFY(maxX>m_chart->axisX()->max());
540 QVERIFY(minY<m_chart->axisY()->min());
549 QVERIFY(minY<m_chart->axisY()->min());
541 QVERIFY(maxY>m_chart->axisY()->max());
550 QVERIFY(maxY>m_chart->axisY()->max());
542 }
551 }
543 }
552 }
544
553
545 void tst_QChart::zoomOut_data()
554 void tst_QChart::zoomOut_data()
546 {
555 {
547
556
548 }
557 }
549
558
550 void tst_QChart::zoomOut()
559 void tst_QChart::zoomOut()
551 {
560 {
552 createTestData();
561 createTestData();
553 qreal minX = m_chart->axisX()->min();
562 qreal minX = m_chart->axisX()->min();
554 qreal minY = m_chart->axisY()->min();
563 qreal minY = m_chart->axisY()->min();
555 qreal maxX = m_chart->axisX()->max();
564 qreal maxX = m_chart->axisX()->max();
556 qreal maxY = m_chart->axisY()->max();
565 qreal maxY = m_chart->axisY()->max();
557
566
558 m_chart->zoomIn();
567 m_chart->zoomIn();
559
568
560 QVERIFY(minX < m_chart->axisX()->min());
569 QVERIFY(minX < m_chart->axisX()->min());
561 QVERIFY(maxX > m_chart->axisX()->max());
570 QVERIFY(maxX > m_chart->axisX()->max());
562 QVERIFY(minY < m_chart->axisY()->min());
571 QVERIFY(minY < m_chart->axisY()->min());
563 QVERIFY(maxY > m_chart->axisY()->max());
572 QVERIFY(maxY > m_chart->axisY()->max());
564
573
565 m_chart->zoomOut();
574 m_chart->zoomOut();
566
575
567 // min x may be a zero value
576 // min x may be a zero value
568 if (qFuzzyIsNull(minX))
577 if (qFuzzyIsNull(minX))
569 QVERIFY(qFuzzyIsNull(m_chart->axisX()->min()));
578 QVERIFY(qFuzzyIsNull(m_chart->axisX()->min()));
570 else
579 else
571 QCOMPARE(minX, m_chart->axisX()->min());
580 QCOMPARE(minX, m_chart->axisX()->min());
572
581
573 // min y may be a zero value
582 // min y may be a zero value
574 if (qFuzzyIsNull(minY))
583 if (qFuzzyIsNull(minY))
575 QVERIFY(qFuzzyIsNull(m_chart->axisY()->min()));
584 QVERIFY(qFuzzyIsNull(m_chart->axisY()->min()));
576 else
585 else
577 QCOMPARE(minY, m_chart->axisY()->min());
586 QCOMPARE(minY, m_chart->axisY()->min());
578
587
579 QVERIFY(maxX == m_chart->axisX()->max());
588 QVERIFY(maxX == m_chart->axisX()->max());
580 QVERIFY(maxY == m_chart->axisY()->max());
589 QVERIFY(maxY == m_chart->axisY()->max());
581 }
590 }
582
591
583 QTEST_MAIN(tst_QChart)
592 QTEST_MAIN(tst_QChart)
584 #include "tst_qchart.moc"
593 #include "tst_qchart.moc"
585
594
General Comments 0
You need to be logged in to leave comments. Login now