##// END OF EJS Templates
Fix all tst_chartdataset test cases
Michal Klocek -
r1593:c1bed7868e27
parent child
Show More
@@ -1,289 +1,290
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 "qvaluesaxis.h"
21 #include "qvaluesaxis.h"
22 #include "qvaluesaxis_p.h"
22 #include "qvaluesaxis_p.h"
23 #include "chartvaluesaxisx_p.h"
23 #include "chartvaluesaxisx_p.h"
24 #include "chartvaluesaxisy_p.h"
24 #include "chartvaluesaxisy_p.h"
25 #include <QDebug>
25 #include <QDebug>
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28 /*!
28 /*!
29 \class QValuesAxis
29 \class QValuesAxis
30 \brief The QValuesAxis class is used for manipulating chart's axis.
30 \brief The QValuesAxis class is used for manipulating chart's axis.
31 \mainclass
31 \mainclass
32
32
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
33 Axis can be setup to show axis line with tick marks, grid lines and shades.
34 */
34 */
35
35
36 /*!
36 /*!
37 \qmlclass Axis QValuesAxis
37 \qmlclass Axis QValuesAxis
38 \brief The Axis element is used for manipulating chart's axes
38 \brief The Axis element is used for manipulating chart's axes
39
39
40 Axis can be setup to show axis line with tick marks, grid lines and shades.
40 Axis can be setup to show axis line with tick marks, grid lines and shades.
41
41
42 To access Axes you can use ChartView API. For example:
42 To access Axes you can use ChartView API. For example:
43 \code
43 \code
44 ChartView {
44 ChartView {
45 axisX.min: 0
45 axisX.min: 0
46 axisX.max: 3
46 axisX.max: 3
47 axisX.ticksCount: 4
47 axisX.ticksCount: 4
48 axisY.min: 0
48 axisY.min: 0
49 axisY.max: 4
49 axisY.max: 4
50 // Add a few series...
50 // Add a few series...
51 }
51 }
52 \endcode
52 \endcode
53 */
53 */
54
54
55 /*!
55 /*!
56 \property QValuesAxis::min
56 \property QValuesAxis::min
57 Defines the minimum value on the axis.
57 Defines the minimum value on the axis.
58 */
58 */
59 /*!
59 /*!
60 \qmlproperty real Axis::min
60 \qmlproperty real Axis::min
61 Defines the minimum value on the axis.
61 Defines the minimum value on the axis.
62 */
62 */
63
63
64 /*!
64 /*!
65 \property QValuesAxis::max
65 \property QValuesAxis::max
66 Defines the maximum value on the axis.
66 Defines the maximum value on the axis.
67 */
67 */
68 /*!
68 /*!
69 \qmlproperty real Axis::max
69 \qmlproperty real Axis::max
70 Defines the maximum value on the axis.
70 Defines the maximum value on the axis.
71 */
71 */
72
72
73 /*!
73 /*!
74 \fn void QValuesAxis::minChanged(qreal min)
74 \fn void QValuesAxis::minChanged(qreal min)
75 Axis emits signal when \a min of axis has changed.
75 Axis emits signal when \a min of axis has changed.
76 */
76 */
77
77
78 /*!
78 /*!
79 \fn void QValuesAxis::maxChanged(qreal max)
79 \fn void QValuesAxis::maxChanged(qreal max)
80 Axis emits signal when \a max of axis has changed.
80 Axis emits signal when \a max of axis has changed.
81 */
81 */
82
82
83 /*!
83 /*!
84 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
84 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
85 Axis emits signal when \a min or \a max of axis has changed.
85 Axis emits signal when \a min or \a max of axis has changed.
86 */
86 */
87
87
88 /*!
88 /*!
89 \property QValuesAxis::ticksCount
89 \property QValuesAxis::ticksCount
90 The number of tick marks for the axis.
90 The number of tick marks for the axis.
91 */
91 */
92
92
93 /*!
93 /*!
94 \qmlproperty int Axis::ticksCount
94 \qmlproperty int Axis::ticksCount
95 The number of tick marks for the axis.
95 The number of tick marks for the axis.
96 */
96 */
97
97
98 /*!
98 /*!
99 \property QValuesAxis::niceNumbersEnabled
99 \property QValuesAxis::niceNumbersEnabled
100 Whether the nice numbers algorithm is enabled or not for the axis.
100 Whether the nice numbers algorithm is enabled or not for the axis.
101 */
101 */
102
102
103 /*!
103 /*!
104 \qmlproperty bool Axis::niceNumbersEnabled
104 \qmlproperty bool Axis::niceNumbersEnabled
105 Whether the nice numbers algorithm is enabled or not for the axis.
105 Whether the nice numbers algorithm is enabled or not for the axis.
106 */
106 */
107
107
108 QValuesAxis::QValuesAxis(QObject *parent) :
108 QValuesAxis::QValuesAxis(QObject *parent) :
109 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
109 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
110 {
110 {
111
111
112 }
112 }
113
113
114 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
114 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
115 {
115 {
116
116
117 }
117 }
118
118
119 QValuesAxis::~QValuesAxis()
119 QValuesAxis::~QValuesAxis()
120 {
120 {
121
121
122 }
122 }
123
123
124 void QValuesAxis::setMin(qreal min)
124 void QValuesAxis::setMin(qreal min)
125 {
125 {
126 Q_D(QValuesAxis);
126 Q_D(QValuesAxis);
127 setRange(min,d->m_max);
127 setRange(min,d->m_max);
128 }
128 }
129
129
130 qreal QValuesAxis::min() const
130 qreal QValuesAxis::min() const
131 {
131 {
132 Q_D(const QValuesAxis);
132 Q_D(const QValuesAxis);
133 return d->m_min;
133 return d->m_min;
134 }
134 }
135
135
136 void QValuesAxis::setMax(qreal max)
136 void QValuesAxis::setMax(qreal max)
137 {
137 {
138 Q_D(QValuesAxis);
138 Q_D(QValuesAxis);
139 setRange(d->m_min,max);
139 setRange(d->m_min,max);
140 }
140 }
141
141
142 qreal QValuesAxis::max() const
142 qreal QValuesAxis::max() const
143 {
143 {
144 Q_D(const QValuesAxis);
144 Q_D(const QValuesAxis);
145 return d->m_max;
145 return d->m_max;
146 }
146 }
147
147
148 /*!
148 /*!
149 Sets range from \a min to \a max on the axis.
149 Sets range from \a min to \a max on the axis.
150 */
150 */
151 void QValuesAxis::setRange(qreal min, qreal max)
151 void QValuesAxis::setRange(qreal min, qreal max)
152 {
152 {
153 Q_D(QValuesAxis);
153 Q_D(QValuesAxis);
154 bool changed = false;
154 bool changed = false;
155 if (!qFuzzyIsNull(d->m_min - min)) {
155 if (!qFuzzyIsNull(d->m_min - min)) {
156 d->m_min = min;
156 d->m_min = min;
157 changed = true;
157 changed = true;
158 emit minChanged(min);
158 emit minChanged(min);
159 }
159 }
160
160
161 if (!qFuzzyIsNull(d->m_max - max)) {
161 if (!qFuzzyIsNull(d->m_max - max)) {
162 d->m_max = max;
162 d->m_max = max;
163 changed = true;
163 changed = true;
164 emit maxChanged(max);
164 emit maxChanged(max);
165 }
165 }
166
166
167 if (changed) {
167 if (changed) {
168 emit rangeChanged(d->m_min,d->m_max);
168 emit rangeChanged(d->m_min,d->m_max);
169 if(!signalsBlocked()){
169 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
170 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
170 }
171 }
171 // d->setRange(min,max);
172 }
172 }
173 }
173
174
174 /*!
175 /*!
175 Sets \a count for ticks on the axis.
176 Sets \a count for ticks on the axis.
176 */
177 */
177 void QValuesAxis::setTicksCount(int count)
178 void QValuesAxis::setTicksCount(int count)
178 {
179 {
179 Q_D(QValuesAxis);
180 Q_D(QValuesAxis);
180 if (d->m_ticksCount != count) {
181 if (d->m_ticksCount != count) {
181 d->m_ticksCount = count;
182 d->m_ticksCount = count;
182 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
183 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
183 }
184 }
184 }
185 }
185
186
186 /*!
187 /*!
187 \fn int QValuesAxis::ticksCount() const
188 \fn int QValuesAxis::ticksCount() const
188 Return number of ticks on the axis
189 Return number of ticks on the axis
189 */
190 */
190 int QValuesAxis::ticksCount() const
191 int QValuesAxis::ticksCount() const
191 {
192 {
192 Q_D(const QValuesAxis);
193 Q_D(const QValuesAxis);
193 return d->m_ticksCount;
194 return d->m_ticksCount;
194 }
195 }
195
196
196 void QValuesAxis::setNiceNumbersEnabled(bool enable)
197 void QValuesAxis::setNiceNumbersEnabled(bool enable)
197 {
198 {
198 Q_D(QValuesAxis);
199 Q_D(QValuesAxis);
199 if (d->m_niceNumbers != enable){
200 if (d->m_niceNumbers != enable){
200 d->m_niceNumbers = enable;
201 d->m_niceNumbers = enable;
201 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
202 emit d->changed(d->m_min, d->m_max, d->m_ticksCount, d->m_niceNumbers);
202 }
203 }
203 }
204 }
204
205
205 bool QValuesAxis::niceNumbersEnabled() const
206 bool QValuesAxis::niceNumbersEnabled() const
206 {
207 {
207 Q_D(const QValuesAxis);
208 Q_D(const QValuesAxis);
208 return d->m_niceNumbers;
209 return d->m_niceNumbers;
209 }
210 }
210
211
211 QAbstractAxis::AxisType QValuesAxis::type() const
212 QAbstractAxis::AxisType QValuesAxis::type() const
212 {
213 {
213 return AxisTypeValues;
214 return AxisTypeValues;
214 }
215 }
215
216
216 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
217 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
217
218
218 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
219 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
219 QAbstractAxisPrivate(q),
220 QAbstractAxisPrivate(q),
220 m_niceNumbers(false)
221 m_niceNumbers(false)
221 {
222 {
222
223
223 }
224 }
224
225
225 QValuesAxisPrivate::~QValuesAxisPrivate()
226 QValuesAxisPrivate::~QValuesAxisPrivate()
226 {
227 {
227
228
228 }
229 }
229
230
230 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
231 void QValuesAxisPrivate::handleAxisRangeChanged(qreal min, qreal max,int count)
231 {
232 {
232 Q_Q(QValuesAxis);
233 Q_Q(QValuesAxis);
233 q->setRange(min,max);
234 q->setRange(min,max);
234 q->setTicksCount(count);
235 q->setTicksCount(count);
235 }
236 }
236
237
237
238
238 void QValuesAxisPrivate::setMin(const QVariant &min)
239 void QValuesAxisPrivate::setMin(const QVariant &min)
239 {
240 {
240 Q_Q(QValuesAxis);
241 Q_Q(QValuesAxis);
241 bool ok;
242 bool ok;
242 qreal value = min.toReal(&ok);
243 qreal value = min.toReal(&ok);
243 if(ok) q->setMin(value);
244 if(ok) q->setMin(value);
244 }
245 }
245
246
246 void QValuesAxisPrivate::setMax(const QVariant &max)
247 void QValuesAxisPrivate::setMax(const QVariant &max)
247 {
248 {
248 Q_Q(QValuesAxis);
249 Q_Q(QValuesAxis);
249 bool ok;
250 bool ok;
250 qreal value = max.toReal(&ok);
251 qreal value = max.toReal(&ok);
251 if(ok) q->setMax(value);
252 if(ok) q->setMax(value);
252 }
253 }
253
254
254 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max, bool force)
255 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max, bool force)
255 {
256 {
256 Q_UNUSED(force); // TODO: use this
257 Q_UNUSED(force); // TODO: use this
257 Q_Q(QValuesAxis);
258 Q_Q(QValuesAxis);
258 bool ok1;
259 bool ok1;
259 bool ok2;
260 bool ok2;
260 qreal value1 = min.toReal(&ok1);
261 qreal value1 = min.toReal(&ok1);
261 qreal value2 = max.toReal(&ok2);
262 qreal value2 = max.toReal(&ok2);
262 if(ok1&&ok2) q->setRange(value1,value2);
263 if(ok1&&ok2) q->setRange(value1,value2);
263 }
264 }
264
265
265 int QValuesAxisPrivate::ticksCount() const
266 int QValuesAxisPrivate::ticksCount() const
266 {
267 {
267 return m_ticksCount;
268 return m_ticksCount;
268 }
269 }
269
270
270 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
271 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
271 {
272 {
272 Q_Q(QValuesAxis);
273 Q_Q(QValuesAxis);
273 if(m_orientation == Qt::Vertical){
274 if(m_orientation == Qt::Vertical){
274 return new ChartValuesAxisY(q,presenter);
275 return new ChartValuesAxisY(q,presenter);
275 }else{
276 }else{
276 return new ChartValuesAxisX(q,presenter);
277 return new ChartValuesAxisX(q,presenter);
277 }
278 }
278
279
279 }
280 }
280
281
281 void QValuesAxisPrivate::updateRange()
282 void QValuesAxisPrivate::updateRange()
282 {
283 {
283 setRange(m_min,m_max,true);
284 setRange(m_min,m_max,true);
284 }
285 }
285
286
286 #include "moc_qvaluesaxis.cpp"
287 #include "moc_qvaluesaxis.cpp"
287 #include "moc_qvaluesaxis_p.cpp"
288 #include "moc_qvaluesaxis_p.cpp"
288
289
289 QTCOMMERCIALCHART_END_NAMESPACE
290 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,417 +1,447
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 "qchart.h"
23 #include "qvaluesaxis.h"
23 #include "qvaluesaxis.h"
24 #include "qcategoriesaxis.h"
24 #include "qcategoriesaxis.h"
25 #include "qvaluesaxis_p.h"
25 #include "qvaluesaxis_p.h"
26 #include "qabstractseries_p.h"
26 #include "qabstractseries_p.h"
27 #include "qabstractbarseries.h"
27 #include "qabstractbarseries.h"
28 #include "qstackedbarseries.h"
28 #include "qstackedbarseries.h"
29 #include "qpercentbarseries.h"
29 #include "qpercentbarseries.h"
30 #include "qpieseries.h"
30 #include "qpieseries.h"
31
31
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
32 QTCOMMERCIALCHART_BEGIN_NAMESPACE
33
33
34 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent),
34 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent),
35 m_domainIndex(0)
35 m_domainIndex(0)
36 {
36 {
37
37
38 }
38 }
39
39
40 ChartDataSet::~ChartDataSet()
40 ChartDataSet::~ChartDataSet()
41 {
41 {
42 removeAllSeries();
42 removeAllSeries();
43 }
43 }
44
44
45 void ChartDataSet::addSeries(QAbstractSeries* series)
45 void ChartDataSet::addSeries(QAbstractSeries* series)
46 {
46 {
47 Domain* domain = m_seriesDomainMap.value(series);
47 Domain* domain = m_seriesDomainMap.value(series);
48
48
49 if(domain) {
49 if(domain) {
50 qWarning() << "Can not add series. Series already on the chart";
50 qWarning() << "Can not add series. Series already on the chart";
51 return;
51 return;
52 }
52 }
53
53
54 series->setParent(this); // take ownership
54 series->setParent(this); // take ownership
55
55
56 domain = new Domain(series);
56 domain = new Domain(series);
57
57
58 m_seriesDomainMap.insert(series,domain);
58 m_seriesDomainMap.insert(series,domain);
59
59
60 series->d_ptr->scaleDomain(*domain);
60 series->d_ptr->scaleDomain(*domain);
61
61
62 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
62 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
63
63
64 int key=0;
64 int key=0;
65 while (i.hasNext()) {
65 while (i.hasNext()) {
66 i.next();
66 i.next();
67 if(i.key()!=key) {
67 if(i.key()!=key) {
68 break;
68 break;
69 }
69 }
70 key++;
70 key++;
71 }
71 }
72
72
73 m_indexSeriesMap.insert(key,series);
73 m_indexSeriesMap.insert(key,series);
74
74
75 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
75 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
76 series->d_ptr->m_dataset = this;
76 series->d_ptr->m_dataset = this;
77
77
78 emit seriesAdded(series,domain);
78 emit seriesAdded(series,domain);
79
79
80 }
80 }
81
81
82 void ChartDataSet::createDefaultAxes()
82 void ChartDataSet::createDefaultAxes()
83 {
83 {
84
84
85 if(m_seriesDomainMap.isEmpty()) return;
85 if(m_seriesDomainMap.isEmpty()) return;
86
86
87 QAbstractAxis::AxisTypes typeX(0);
87 QAbstractAxis::AxisTypes typeX(0);
88 QAbstractAxis::AxisTypes typeY(0);
88 QAbstractAxis::AxisTypes typeY(0);
89
89
90 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
90 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
91 while (i.hasNext()) {
91 while (i.hasNext()) {
92 i.next();
92 i.next();
93 removeAxes(i.key());
93 removeAxes(i.key());
94 }
94 }
95
95
96 i.toFront();
96 i.toFront();
97
97
98 while (i.hasNext()) {
98 while (i.hasNext()) {
99 i.next();
99 i.next();
100 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
100 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
101 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
101 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
102 if(axisX) typeX&=axisX->type();
102 if(axisX) typeX&=axisX->type();
103 else typeX|=i.key()->d_ptr->defaultAxisXType();
103 else typeX|=i.key()->d_ptr->defaultAxisXType();
104 if(axisY) typeY&=axisY->type();
104 if(axisY) typeY&=axisY->type();
105 else typeY|=i.key()->d_ptr->defaultAxisYType();
105 else typeY|=i.key()->d_ptr->defaultAxisYType();
106 }
106 }
107
107
108
108
109 if(typeX.testFlag(QAbstractAxis::AxisTypeValues) && typeX.testFlag(QAbstractAxis::AxisTypeCategories))
109 if(typeX.testFlag(QAbstractAxis::AxisTypeValues) && typeX.testFlag(QAbstractAxis::AxisTypeCategories))
110 {
110 {
111 i.toFront();
111 i.toFront();
112 while (i.hasNext()) {
112 while (i.hasNext()) {
113 i.next();
113 i.next();
114 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisXType());
114 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisXType());
115 i.key()->d_ptr->initializeAxisX(axis);
115 i.key()->d_ptr->initializeAxisX(axis);
116 addAxisX(axis,i.key());
116 addAxisX(axis,i.key());
117 emit axisAdded(axis,i.value());
117 emit axisAdded(axis,i.value());
118 }
118 }
119
119
120 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
120 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
121 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeX)));
121 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeX)));
122 i.toFront();
122 i.toFront();
123 while (i.hasNext()) {
123 while (i.hasNext()) {
124 i.next();
124 i.next();
125 i.key()->d_ptr->initializeAxisX(axis);
125 i.key()->d_ptr->initializeAxisX(axis);
126 addAxisX(axis,i.key());
126 addAxisX(axis,i.key());
127 }
127 }
128 emit axisAdded(axis,i.value());
128 emit axisAdded(axis,i.value());
129
129
130 }
130 }
131
131
132 if(typeY.testFlag(QAbstractAxis::AxisTypeValues) && typeY.testFlag(QAbstractAxis::AxisTypeCategories))
132 if(typeY.testFlag(QAbstractAxis::AxisTypeValues) && typeY.testFlag(QAbstractAxis::AxisTypeCategories))
133 {
133 {
134 i.toFront();
134 i.toFront();
135 while (i.hasNext()) {
135 while (i.hasNext()) {
136 i.next();
136 i.next();
137 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisYType());
137 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisYType());
138 i.key()->d_ptr->initializeAxisY(axis);
138 i.key()->d_ptr->initializeAxisY(axis);
139 addAxisY(axis,i.key());
139 addAxisY(axis,i.key());
140 emit axisAdded(axis,i.value());
140 emit axisAdded(axis,i.value());
141 }
141 }
142
142
143 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
143 }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){
144 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeY)));
144 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeY)));
145 i.toFront();
145 i.toFront();
146 while (i.hasNext()) {
146 while (i.hasNext()) {
147 i.next();
147 i.next();
148 i.key()->d_ptr->initializeAxisY(axis);
148 i.key()->d_ptr->initializeAxisY(axis);
149 addAxisY(axis,i.key());
149 addAxisY(axis,i.key());
150 }
150 }
151 emit axisAdded(axis,i.value());
151 emit axisAdded(axis,i.value());
152
152
153 }
153 }
154 }
154 }
155
155
156
156
157 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type)
157 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type)
158 {
158 {
159 QAbstractAxis* axis =0;
159 QAbstractAxis* axis =0;
160
160
161 switch(type) {
161 switch(type) {
162 case QAbstractAxis::AxisTypeValues:
162 case QAbstractAxis::AxisTypeValues:
163 axis = new QValuesAxis(this);
163 axis = new QValuesAxis(this);
164 break;
164 break;
165 case QAbstractAxis::AxisTypeCategories:
165 case QAbstractAxis::AxisTypeCategories:
166 axis = new QCategoriesAxis(this);
166 axis = new QCategoriesAxis(this);
167 break;
167 break;
168 default:
168 default:
169 axis = 0;
169 axis = 0;
170 break;
170 break;
171 }
171 }
172
172
173 return axis;
173 return axis;
174 }
174 }
175
175
176 void ChartDataSet::addAxisX(QAbstractAxis* axis,QAbstractSeries* series) {
176 void ChartDataSet::addAxisX(QAbstractAxis* axis,QAbstractSeries* series) {
177 Domain* domain = m_seriesDomainMap.value(series);
177 Domain* domain = m_seriesDomainMap.value(series);
178 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
178 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
179 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
179 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
180 axis->d_ptr->m_orientation=Qt::Horizontal;
180 axis->d_ptr->m_orientation=Qt::Horizontal;
181 m_seriesAxisXMap.insert(series,axis);
181 m_seriesAxisXMap.insert(series,axis);
182 }
182 }
183
183
184 void ChartDataSet::addAxisY(QAbstractAxis* axis,QAbstractSeries* series) {
184 void ChartDataSet::addAxisY(QAbstractAxis* axis,QAbstractSeries* series) {
185 Domain* domain = m_seriesDomainMap.value(series);
185 Domain* domain = m_seriesDomainMap.value(series);
186 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
186 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
187 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
187 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
188 axis->d_ptr->m_orientation=Qt::Vertical;
188 axis->d_ptr->m_orientation=Qt::Vertical;
189 m_seriesAxisYMap.insert(series,axis);
189 m_seriesAxisYMap.insert(series,axis);
190 }
190 }
191
191
192 void ChartDataSet::removeSeries(QAbstractSeries* series)
192 void ChartDataSet::removeSeries(QAbstractSeries* series)
193 {
193 {
194 Domain* domain = m_seriesDomainMap.take(series);
194 Domain* domain = m_seriesDomainMap.take(series);
195
195
196 if(!domain) {
196 if(!domain) {
197 qWarning()<<"Can not remove series. Series not found on the chart.";
197 qWarning()<<"Can not remove series. Series not found on the chart.";
198 }
198 }
199
199
200 emit seriesRemoved(series);
200 emit seriesRemoved(series);
201
201
202 delete domain;
202 delete domain;
203 domain = 0;
203 domain = 0;
204
204
205 int key = seriesIndex(series);
205 int key = seriesIndex(series);
206 Q_ASSERT(key!=-1);
206 Q_ASSERT(key!=-1);
207
207
208 m_indexSeriesMap.remove(key);
208 m_indexSeriesMap.remove(key);
209
209
210 series->setParent(0);
210 series->setParent(0);
211 series->d_ptr->m_chart = 0;
211 series->d_ptr->m_chart = 0;
212 series->d_ptr->m_dataset = 0;
212 series->d_ptr->m_dataset = 0;
213
213
214 removeAxes(series);
214 removeAxes(series);
215 }
215 }
216
216
217 void ChartDataSet::removeAxes(QAbstractSeries* series)
217 void ChartDataSet::removeAxes(QAbstractSeries* series)
218 {
218 {
219 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
219 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
220
220
221 if(axisX) {
221 if(axisX) {
222 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
222 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
223 int x = axesX.indexOf(axisX);
223 int x = axesX.indexOf(axisX);
224
224
225 if(x==-1) {
225 if(x==-1) {
226 emit axisRemoved(axisX);
226 emit axisRemoved(axisX);
227 axisX->deleteLater();
227 axisX->deleteLater();
228 }
228 }
229 }
229 }
230
230
231 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
231 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
232
232
233 if(axisY) {
233 if(axisY) {
234 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
234 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
235
235
236 int y = axesY.indexOf(axisY);
236 int y = axesY.indexOf(axisY);
237
237
238 if(y==-1) {
238 if(y==-1) {
239 emit axisRemoved(axisY);
239 emit axisRemoved(axisY);
240 axisY->deleteLater();
240 axisY->deleteLater();
241 }
241 }
242 }
242 }
243 }
243 }
244
244
245 void ChartDataSet::removeAllSeries()
245 void ChartDataSet::removeAllSeries()
246 {
246 {
247 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
247 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
248 foreach(QAbstractSeries *s , series) {
248 foreach(QAbstractSeries *s , series) {
249 removeSeries(s);
249 removeSeries(s);
250 }
250 }
251
251
252 Q_ASSERT(m_seriesAxisXMap.count()==0);
252 Q_ASSERT(m_seriesAxisXMap.count()==0);
253 Q_ASSERT(m_seriesAxisXMap.count()==0);
253 Q_ASSERT(m_seriesAxisXMap.count()==0);
254 Q_ASSERT(m_seriesDomainMap.count()==0);
254 Q_ASSERT(m_seriesDomainMap.count()==0);
255
255
256 qDeleteAll(series);
256 qDeleteAll(series);
257 }
257 }
258
258
259 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
259 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
260 {
260 {
261 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
262
263 blockAxisSignals(true);
264
261 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
265 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
266
262 while (i.hasNext()) {
267 while (i.hasNext()) {
263 i.next();
268 i.next();
264 i.value()->zoomIn(rect,size);
269 i.value()->zoomIn(rect,size);
265 }
270 }
271
272 blockAxisSignals(false);
273
266 }
274 }
267
275
268 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
276 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
269 {
277 {
278 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
279
280 blockAxisSignals(true);
281
270 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
282 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
283
271 while (i.hasNext()) {
284 while (i.hasNext()) {
272 i.next();
285 i.next();
273 i.value()->zoomOut(rect,size);
286 i.value()->zoomOut(rect,size);
274 }
287 }
288
289 blockAxisSignals(false);
290 }
291
292 void ChartDataSet::blockAxisSignals(bool enabled)
293 {
294 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
295
296 while (i.hasNext()) {
297 i.next();
298 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
299 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
300 if(axisX) axisX->blockSignals(enabled);
301 if(axisY) axisY->blockSignals(enabled);
302 }
275 }
303 }
276
304
277 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
305 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
278 {
306 {
279 int count=0;
307 int count=0;
280 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
308 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
281 while (i.hasNext()) {
309 while (i.hasNext()) {
282 i.next();
310 i.next();
283 if(i.key()->type()==type) count++;
311 if(i.key()->type()==type) count++;
284 }
312 }
285 return count;
313 return count;
286 }
314 }
287
315
288 int ChartDataSet::seriesIndex(QAbstractSeries *series)
316 int ChartDataSet::seriesIndex(QAbstractSeries *series)
289 {
317 {
290 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
318 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
291 while (i.hasNext()) {
319 while (i.hasNext()) {
292 i.next();
320 i.next();
293 if (i.value() == series)
321 if (i.value() == series)
294 return i.key();
322 return i.key();
295 }
323 }
296 return -1;
324 return -1;
297 }
325 }
298
326
299 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
327 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
300 {
328 {
301 if(series == 0) return m_seriesAxisXMap.begin().value();
329 if(series == 0) return m_seriesAxisXMap.begin().value();
302 return m_seriesAxisXMap.value(series);
330 return m_seriesAxisXMap.value(series);
303 }
331 }
304
332
305 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
333 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
306 {
334 {
307 if(series == 0) return m_seriesAxisYMap.begin().value();
335 if(series == 0) return m_seriesAxisYMap.begin().value();
308 return m_seriesAxisYMap.value(series);
336 return m_seriesAxisYMap.value(series);
309 }
337 }
310
338
311 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
339 void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis)
312 {
340 {
313 Q_ASSERT(axis);
341 Q_ASSERT(axis);
314 Domain* domain = m_seriesDomainMap.value(series);
342 Domain* domain = m_seriesDomainMap.value(series);
315
343
316 if(!domain) {
344 if(!domain) {
317 qWarning() << "Series not found on the chart.";
345 qWarning() << "Series not found on the chart.";
318 return;
346 return;
319 }
347 }
320
348
321 if(axis->d_ptr->m_orientation==Qt::Vertical) {
349 if(axis->d_ptr->m_orientation==Qt::Vertical) {
322 qWarning()<<"Axis already defined as axis Y";
350 qWarning()<<"Axis already defined as axis Y";
323 return;
351 return;
324 }
352 }
325
353
326 QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series);
354 QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series);
327 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
355 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
328
356
329 if(oldAxis) {
357 if(oldAxis) {
330
358
331 int x = axesX.indexOf(oldAxis);
359 int x = axesX.indexOf(oldAxis);
332 if(x==-1) {
360 if(x==-1) {
333 emit axisRemoved(oldAxis);
361 emit axisRemoved(oldAxis);
334 oldAxis->deleteLater();
362 oldAxis->deleteLater();
335 }
363 }
336 }
364 }
337
365
338 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
366 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool)));
339 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
367 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
340
368
341 int x = axesX.indexOf(axis);
369 int x = axesX.indexOf(axis);
342 if(x==-1) {
370 if(x==-1) {
343 axis->d_ptr->m_orientation=Qt::Horizontal;
371 axis->d_ptr->m_orientation=Qt::Horizontal;
344 emit axisAdded(axis,domain);
372 emit axisAdded(axis,domain);
345 }
373 }
346
374
347 m_seriesAxisXMap.insert(series,axis);
375 m_seriesAxisXMap.insert(series,axis);
348
376
349 // Force range update
377 // Force range update
350 axis->d_ptr->updateRange();
378 axis->d_ptr->updateRange();
351 }
379 }
352
380
353 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
381 void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis)
354 {
382 {
355 Q_ASSERT(axis);
383 Q_ASSERT(axis);
356 Domain* domain = m_seriesDomainMap.value(series);
384 Domain* domain = m_seriesDomainMap.value(series);
357
385
358 if(!domain) {
386 if(!domain) {
359 qWarning() << "Series not found on the chart.";
387 qWarning() << "Series not found on the chart.";
360 return;
388 return;
361 }
389 }
362
390
363 if(axis->d_ptr->m_orientation==Qt::Horizontal) {
391 if(axis->d_ptr->m_orientation==Qt::Horizontal) {
364 qWarning()<<"Axis already defined as axis X";
392 qWarning()<<"Axis already defined as axis X";
365 return;
393 return;
366 }
394 }
367
395
368 QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series);
396 QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series);
369 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
397 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
370
398
371 if(oldAxis) {
399 if(oldAxis) {
372 int y = axesY.indexOf(oldAxis);
400 int y = axesY.indexOf(oldAxis);
373 if(y==-1) {
401 if(y==-1) {
374 emit axisRemoved(oldAxis);
402 emit axisRemoved(oldAxis);
375 oldAxis->deleteLater();
403 oldAxis->deleteLater();
376 }
404 }
377 }
405 }
378
406
379 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
407 QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool)));
380 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
408 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int)));
381
409
382 int y = axesY.indexOf(axis);
410 int y = axesY.indexOf(axis);
383 if(y==-1) {
411 if(y==-1) {
384 axis->d_ptr->m_orientation=Qt::Vertical;
412 axis->d_ptr->m_orientation=Qt::Vertical;
385 emit axisAdded(axis,domain);
413 emit axisAdded(axis,domain);
386 }
414 }
387
415
388 m_seriesAxisYMap.insert(series,axis);
416 m_seriesAxisYMap.insert(series,axis);
389 }
417 }
390
418
391 Domain* ChartDataSet::domain(QAbstractSeries *series) const
419 Domain* ChartDataSet::domain(QAbstractSeries *series) const
392 {
420 {
393 return m_seriesDomainMap.value(series);
421 return m_seriesDomainMap.value(series);
394 }
422 }
395
423
396 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
424 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
397 {
425 {
426 blockAxisSignals(true);
398 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
427 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
399 while (i.hasNext()) {
428 while (i.hasNext()) {
400 i.next();
429 i.next();
401 i.value()->move(dx,dy,size);
430 i.value()->move(dx,dy,size);
402 }
431 }
432 blockAxisSignals(false);
403 }
433 }
404
434
405 QList<QAbstractSeries*> ChartDataSet::series() const
435 QList<QAbstractSeries*> ChartDataSet::series() const
406 {
436 {
407 return m_seriesAxisXMap.keys();
437 return m_seriesAxisXMap.keys();
408 }
438 }
409
439
410 void ChartDataSet::updateSeries(QAbstractSeries *series)
440 void ChartDataSet::updateSeries(QAbstractSeries *series)
411 {
441 {
412 emit seriesUpdated(series);
442 emit seriesUpdated(series);
413 }
443 }
414
444
415 #include "moc_chartdataset_p.cpp"
445 #include "moc_chartdataset_p.cpp"
416
446
417 QTCOMMERCIALCHART_END_NAMESPACE
447 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,97 +1,98
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 "qabstractaxis_p.h"
35 #include "qabstractaxis_p.h"
36 #include <QVector>
36 #include <QVector>
37
37
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
38 QTCOMMERCIALCHART_BEGIN_NAMESPACE
39
39
40 class QAbstractAxis;
40 class QAbstractAxis;
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(QChart* parent=0);
46 ChartDataSet(QChart* parent=0);
47 virtual ~ChartDataSet();
47 virtual ~ChartDataSet();
48
48
49 void addSeries(QAbstractSeries* series);
49 void addSeries(QAbstractSeries* series);
50 void removeSeries(QAbstractSeries* series);
50 void 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 QAbstractAxis* axisX(QAbstractSeries *series) const;
61 QAbstractAxis* axisX(QAbstractSeries *series) const;
62 QAbstractAxis* axisY(QAbstractSeries *series) const;
62 QAbstractAxis* axisY(QAbstractSeries *series) const;
63
63
64 void setAxisX(QAbstractSeries *series, QAbstractAxis *axis);
64 void setAxisX(QAbstractSeries *series, QAbstractAxis *axis);
65 void setAxisY(QAbstractSeries *series, QAbstractAxis *axis);
65 void setAxisY(QAbstractSeries *series, QAbstractAxis *axis);
66
66
67 QList<QAbstractSeries*> series() const;
67 QList<QAbstractSeries*> series() const;
68 Domain* domain(QAbstractSeries *series) const;
68 Domain* domain(QAbstractSeries *series) const;
69
69
70 void createDefaultAxes();
70 void createDefaultAxes();
71
71
72 Q_SIGNALS:
72 Q_SIGNALS:
73 void seriesAdded(QAbstractSeries* series, Domain* domain);
73 void seriesAdded(QAbstractSeries* series, Domain* domain);
74 void seriesRemoved(QAbstractSeries* series);
74 void seriesRemoved(QAbstractSeries* series);
75 void seriesUpdated(QAbstractSeries* series);
75 void seriesUpdated(QAbstractSeries* series);
76 void axisAdded(QAbstractAxis* axis,Domain* domain);
76 void axisAdded(QAbstractAxis* axis,Domain* domain);
77 void axisRemoved(QAbstractAxis* axis);
77 void axisRemoved(QAbstractAxis* axis);
78
78
79 private:
79 private:
80 void calculateDomain(QAbstractSeries* series,Domain* domain);
80 void calculateDomain(QAbstractSeries* series,Domain* domain);
81 QAbstractAxis* createAxis(QAbstractAxis::AxisType type);
81 QAbstractAxis* createAxis(QAbstractAxis::AxisType type);
82 void addAxisX(QAbstractAxis* axis,QAbstractSeries* series);
82 void addAxisX(QAbstractAxis* axis,QAbstractSeries* series);
83 void addAxisY(QAbstractAxis* axis,QAbstractSeries* series);
83 void addAxisY(QAbstractAxis* axis,QAbstractSeries* series);
84 void removeAxes(QAbstractSeries* series);
84 void removeAxes(QAbstractSeries* series);
85 void blockAxisSignals(bool enabled);
85
86
86 private:
87 private:
87 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap;
88 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisXMap;
88 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap;
89 QMap<QAbstractSeries*, QAbstractAxis*> m_seriesAxisYMap;
89 QMap<QAbstractSeries*, Domain*> m_seriesDomainMap;
90 QMap<QAbstractSeries*, Domain*> m_seriesDomainMap;
90 QMap<int, QAbstractSeries*> m_indexSeriesMap;
91 QMap<int, QAbstractSeries*> m_indexSeriesMap;
91 int m_domainIndex;
92 int m_domainIndex;
92
93
93 };
94 };
94
95
95 QTCOMMERCIALCHART_END_NAMESPACE
96 QTCOMMERCIALCHART_END_NAMESPACE
96
97
97 #endif /* CHARTENGINE_P_H_ */
98 #endif /* CHARTENGINE_P_H_ */
@@ -1,636 +1,624
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include <QtTest/QtTest>
21 #include <QtTest/QtTest>
22 #include <qabstractaxis.h>
22 #include <qabstractaxis.h>
23 #include <qvaluesaxis.h>
23 #include <qvaluesaxis.h>
24 #include <qcategoriesaxis.h>
24 #include <qcategoriesaxis.h>
25 #include <qlineseries.h>
25 #include <qlineseries.h>
26 #include <qareaseries.h>
26 #include <qareaseries.h>
27 #include <qscatterseries.h>
27 #include <qscatterseries.h>
28 #include <qsplineseries.h>
28 #include <qsplineseries.h>
29 #include <qpieseries.h>
29 #include <qpieseries.h>
30 #include <qgroupedbarseries.h>
30 #include <qgroupedbarseries.h>
31 #include <qpercentbarseries.h>
31 #include <qpercentbarseries.h>
32 #include <qstackedbarseries.h>
32 #include <qstackedbarseries.h>
33 #include <private/chartdataset_p.h>
33 #include <private/chartdataset_p.h>
34 #include <private/domain_p.h>
34 #include <private/domain_p.h>
35 #include <tst_definitions.h>
35 #include <tst_definitions.h>
36
36
37 QTCOMMERCIALCHART_USE_NAMESPACE
37 QTCOMMERCIALCHART_USE_NAMESPACE
38
38
39 Q_DECLARE_METATYPE(Domain *)
39 Q_DECLARE_METATYPE(Domain *)
40 Q_DECLARE_METATYPE(QAbstractAxis *)
40 Q_DECLARE_METATYPE(QAbstractAxis *)
41 Q_DECLARE_METATYPE(QAbstractSeries *)
41 Q_DECLARE_METATYPE(QAbstractSeries *)
42 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
42 Q_DECLARE_METATYPE(QList<QAbstractSeries *>)
43 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
43 Q_DECLARE_METATYPE(QList<QAbstractAxis *>)
44 Q_DECLARE_METATYPE(QLineSeries *)
44 Q_DECLARE_METATYPE(QLineSeries *)
45
45
46 class tst_ChartDataSet: public QObject {
46 class tst_ChartDataSet: public QObject {
47
47
48 Q_OBJECT
48 Q_OBJECT
49
49
50 public Q_SLOTS:
50 public Q_SLOTS:
51 void initTestCase();
51 void initTestCase();
52 void cleanupTestCase();
52 void cleanupTestCase();
53 void init();
53 void init();
54 void cleanup();
54 void cleanup();
55
55
56 private Q_SLOTS:
56 private Q_SLOTS:
57 void chartdataset_data();
57 void chartdataset_data();
58 void chartdataset();
58 void chartdataset();
59 void addSeries_data();
59 void addSeries_data();
60 void addSeries();
60 void addSeries();
61 void setAxisX_data();
61 void setAxisX_data();
62 void setAxisX();
62 void setAxisX();
63 void setAxisY_data();
63 void setAxisY_data();
64 void setAxisY();
64 void setAxisY();
65 void removeSeries_data();
65 void removeSeries_data();
66 void removeSeries();
66 void removeSeries();
67 void removeAllSeries_data();
67 void removeAllSeries_data();
68 void removeAllSeries();
68 void removeAllSeries();
69 void seriesCount_data();
69 void seriesCount_data();
70 void seriesCount();
70 void seriesCount();
71 void seriesIndex_data();
71 void seriesIndex_data();
72 void seriesIndex();
72 void seriesIndex();
73 void domain_data();
73 void domain_data();
74 void domain();
74 void domain();
75 void zoomInDomain_data();
75 void zoomInDomain_data();
76 void zoomInDomain();
76 void zoomInDomain();
77 /*
78 void zoomOutDomain_data();
77 void zoomOutDomain_data();
79 void zoomOutDomain();
78 void zoomOutDomain();
80 void scrollDomain_data();
79 void scrollDomain_data();
81 void scrollDomain();
80 void scrollDomain();
82 */
81
83 private:
82 private:
84 ChartDataSet* m_dataset;
83 ChartDataSet* m_dataset;
85 };
84 };
86
85
87 void tst_ChartDataSet::initTestCase()
86 void tst_ChartDataSet::initTestCase()
88 {
87 {
89 qRegisterMetaType<Domain*>();
88 qRegisterMetaType<Domain*>();
90 qRegisterMetaType<QAbstractAxis*>();
89 qRegisterMetaType<QAbstractAxis*>();
91 qRegisterMetaType<QAbstractSeries*>();
90 qRegisterMetaType<QAbstractSeries*>();
92 }
91 }
93
92
94 void tst_ChartDataSet::cleanupTestCase()
93 void tst_ChartDataSet::cleanupTestCase()
95 {
94 {
96 }
95 }
97
96
98 void tst_ChartDataSet::init()
97 void tst_ChartDataSet::init()
99 {
98 {
100 m_dataset = new ChartDataSet();
99 m_dataset = new ChartDataSet();
101 }
100 }
102
101
103
102
104 void tst_ChartDataSet::cleanup()
103 void tst_ChartDataSet::cleanup()
105 {
104 {
106 QList<QAbstractSeries*> series = m_dataset->series();
105 QList<QAbstractSeries*> series = m_dataset->series();
107 foreach(QAbstractSeries* serie, series)
106 foreach(QAbstractSeries* serie, series)
108 {
107 {
109 m_dataset->removeSeries(serie);
108 m_dataset->removeSeries(serie);
110 }
109 }
111 }
110 }
112
111
113 void tst_ChartDataSet::chartdataset_data()
112 void tst_ChartDataSet::chartdataset_data()
114 {
113 {
115 }
114 }
116
115
117 void tst_ChartDataSet::chartdataset()
116 void tst_ChartDataSet::chartdataset()
118 {
117 {
119 QVERIFY(m_dataset->axisX(0) == 0);
118 QVERIFY(m_dataset->axisX(0) == 0);
120 QVERIFY(m_dataset->axisY(0) == 0);
119 QVERIFY(m_dataset->axisY(0) == 0);
121 QLineSeries* series = new QLineSeries(this);
120 QLineSeries* series = new QLineSeries(this);
122 QCOMPARE(m_dataset->seriesIndex(series),-1);
121 QCOMPARE(m_dataset->seriesIndex(series),-1);
123 QVERIFY(m_dataset->domain(series) == 0);
122 QVERIFY(m_dataset->domain(series) == 0);
124 QVERIFY(m_dataset->axisX(series) == 0);
123 QVERIFY(m_dataset->axisX(series) == 0);
125 QVERIFY(m_dataset->axisY(series) == 0);
124 QVERIFY(m_dataset->axisY(series) == 0);
126 m_dataset->createDefaultAxes();
125 m_dataset->createDefaultAxes();
127 }
126 }
128
127
129
128
130 void tst_ChartDataSet::addSeries_data()
129 void tst_ChartDataSet::addSeries_data()
131 {
130 {
132 QTest::addColumn<QAbstractSeries*>("series");
131 QTest::addColumn<QAbstractSeries*>("series");
133
132
134 QAbstractSeries* line = new QLineSeries(this);
133 QAbstractSeries* line = new QLineSeries(this);
135 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
134 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
136 QAbstractSeries* scatter = new QScatterSeries(this);
135 QAbstractSeries* scatter = new QScatterSeries(this);
137 QAbstractSeries* spline = new QSplineSeries(this);
136 QAbstractSeries* spline = new QSplineSeries(this);
138 QAbstractSeries* pie = new QPieSeries(this);
137 QAbstractSeries* pie = new QPieSeries(this);
139 QAbstractSeries* bar = new QGroupedBarSeries(this);
138 QAbstractSeries* bar = new QGroupedBarSeries(this);
140 QAbstractSeries* percent = new QPercentBarSeries(this);
139 QAbstractSeries* percent = new QPercentBarSeries(this);
141 QAbstractSeries* stacked = new QStackedBarSeries(this);
140 QAbstractSeries* stacked = new QStackedBarSeries(this);
142
141
143 QTest::newRow("line") << line;
142 QTest::newRow("line") << line;
144 QTest::newRow("area") << area;
143 QTest::newRow("area") << area;
145 QTest::newRow("scatter") << scatter;
144 QTest::newRow("scatter") << scatter;
146 QTest::newRow("spline") << spline;
145 QTest::newRow("spline") << spline;
147 QTest::newRow("pie") << pie;
146 QTest::newRow("pie") << pie;
148 QTest::newRow("bar") << bar;
147 QTest::newRow("bar") << bar;
149 QTest::newRow("percent") << percent;
148 QTest::newRow("percent") << percent;
150 QTest::newRow("stacked") << stacked;
149 QTest::newRow("stacked") << stacked;
151 }
150 }
152
151
153 void tst_ChartDataSet::addSeries()
152 void tst_ChartDataSet::addSeries()
154 {
153 {
155
154
156 QFETCH(QAbstractSeries*, series);
155 QFETCH(QAbstractSeries*, series);
157
156
158 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
157 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
159 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
158 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
160 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
159 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
161 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
160 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
162
161
163 m_dataset->addSeries(series);
162 m_dataset->addSeries(series);
164 m_dataset->createDefaultAxes();
163 m_dataset->createDefaultAxes();
165 if(series->type()==QAbstractSeries::SeriesTypePie){
164 if(series->type()==QAbstractSeries::SeriesTypePie){
166 TRY_COMPARE(spy0.count(), 0);
165 TRY_COMPARE(spy0.count(), 0);
167 }else{
166 }else{
168 TRY_COMPARE(spy0.count(), 2);
167 TRY_COMPARE(spy0.count(), 2);
169 }
168 }
170 TRY_COMPARE(spy1.count(), 0);
169 TRY_COMPARE(spy1.count(), 0);
171 TRY_COMPARE(spy2.count(), 1);
170 TRY_COMPARE(spy2.count(), 1);
172 TRY_COMPARE(spy3.count(), 0);
171 TRY_COMPARE(spy3.count(), 0);
173 }
172 }
174
173
175
174
176 void tst_ChartDataSet::setAxisX_data()
175 void tst_ChartDataSet::setAxisX_data()
177 {
176 {
178
177
179 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
178 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
180 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
179 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
181 QTest::addColumn<int>("axisCount");
180 QTest::addColumn<int>("axisCount");
182
181
183 QAbstractSeries* line = new QLineSeries(this);
182 QAbstractSeries* line = new QLineSeries(this);
184 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
183 QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line));
185 QAbstractSeries* scatter = new QScatterSeries(this);
184 QAbstractSeries* scatter = new QScatterSeries(this);
186 QAbstractSeries* spline = new QSplineSeries(this);
185 QAbstractSeries* spline = new QSplineSeries(this);
187 QAbstractSeries* pie = new QPieSeries(this);
186 QAbstractSeries* pie = new QPieSeries(this);
188 QAbstractSeries* bar = new QGroupedBarSeries(this);
187 QAbstractSeries* bar = new QGroupedBarSeries(this);
189 QAbstractSeries* percent = new QPercentBarSeries(this);
188 QAbstractSeries* percent = new QPercentBarSeries(this);
190 QAbstractSeries* stacked = new QStackedBarSeries(this);
189 QAbstractSeries* stacked = new QStackedBarSeries(this);
191
190
192 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
191 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
193 << (QList<QAbstractSeries*>() << line << spline << scatter)
192 << (QList<QAbstractSeries*>() << line << spline << scatter)
194 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3;
193 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this) << new QValuesAxis(this)) << 3;
195
194
196 QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area)
195 QTest::newRow("area: axis 0") << (QList<QAbstractSeries*>() << area)
197 << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1;
196 << (QList<QAbstractAxis*>() << new QValuesAxis(this)) << 1;
198
197
199 QList<QAbstractAxis*> axes0;
198 QList<QAbstractAxis*> axes0;
200 axes0 << new QValuesAxis(this) << new QValuesAxis(this);
199 axes0 << new QValuesAxis(this) << new QValuesAxis(this);
201 axes0 << axes0.last();
200 axes0 << axes0.last();
202 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1")
201 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 1")
203 << (QList<QAbstractSeries*>() << line << spline << scatter)
202 << (QList<QAbstractSeries*>() << line << spline << scatter)
204 << axes0 << 2;
203 << axes0 << 2;
205 //TODO: add more test cases
204 //TODO: add more test cases
206 }
205 }
207
206
208 void tst_ChartDataSet::setAxisX()
207 void tst_ChartDataSet::setAxisX()
209 {
208 {
210 QFETCH(QList<QAbstractSeries*>, seriesList);
209 QFETCH(QList<QAbstractSeries*>, seriesList);
211 QFETCH(QList<QAbstractAxis*>, axisList);
210 QFETCH(QList<QAbstractAxis*>, axisList);
212 QFETCH(int, axisCount);
211 QFETCH(int, axisCount);
213
212
214 Q_ASSERT(seriesList.count() == axisList.count());
213 Q_ASSERT(seriesList.count() == axisList.count());
215
214
216 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
215 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
217 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
216 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
218 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
217 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
219 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
218 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
220
219
221 foreach(QAbstractSeries* series, seriesList){
220 foreach(QAbstractSeries* series, seriesList){
222 m_dataset->addSeries(series);
221 m_dataset->addSeries(series);
223 }
222 }
224
223
225 TRY_COMPARE(spy0.count(), 0);
224 TRY_COMPARE(spy0.count(), 0);
226 TRY_COMPARE(spy1.count(), 0);
225 TRY_COMPARE(spy1.count(), 0);
227 TRY_COMPARE(spy2.count(), seriesList.count());
226 TRY_COMPARE(spy2.count(), seriesList.count());
228 TRY_COMPARE(spy3.count(), 0);
227 TRY_COMPARE(spy3.count(), 0);
229
228
230 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
229 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
231 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
230 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
232 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
231 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
233 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
232 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
234
233
235 for(int i=0 ; i < seriesList.count(); i++){
234 for(int i=0 ; i < seriesList.count(); i++){
236 m_dataset->setAxisX(seriesList.at(i),axisList.at(i));
235 m_dataset->setAxisX(seriesList.at(i),axisList.at(i));
237 }
236 }
238
237
239 TRY_COMPARE(spy4.count(), axisCount);
238 TRY_COMPARE(spy4.count(), axisCount);
240 TRY_COMPARE(spy5.count(), 0);
239 TRY_COMPARE(spy5.count(), 0);
241 TRY_COMPARE(spy6.count(), 0);
240 TRY_COMPARE(spy6.count(), 0);
242 TRY_COMPARE(spy7.count(), 0);
241 TRY_COMPARE(spy7.count(), 0);
243
242
244 for(int i=0 ; i < seriesList.count(); i++){
243 for(int i=0 ; i < seriesList.count(); i++){
245 QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i));
244 QVERIFY(m_dataset->axisX(seriesList.at(i)) == axisList.at(i));
246 }
245 }
247 }
246 }
248
247
249 void tst_ChartDataSet::setAxisY_data()
248 void tst_ChartDataSet::setAxisY_data()
250 {
249 {
251 setAxisX_data();
250 setAxisX_data();
252 }
251 }
253
252
254 void tst_ChartDataSet::setAxisY()
253 void tst_ChartDataSet::setAxisY()
255 {
254 {
256 QFETCH(QList<QAbstractSeries*>, seriesList);
255 QFETCH(QList<QAbstractSeries*>, seriesList);
257 QFETCH(QList<QAbstractAxis*>, axisList);
256 QFETCH(QList<QAbstractAxis*>, axisList);
258 QFETCH(int, axisCount);
257 QFETCH(int, axisCount);
259
258
260 Q_ASSERT(seriesList.count() == axisList.count());
259 Q_ASSERT(seriesList.count() == axisList.count());
261
260
262 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
261 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
263 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
262 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
264 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
263 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
265 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
264 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
266
265
267 foreach(QAbstractSeries* series, seriesList){
266 foreach(QAbstractSeries* series, seriesList){
268 m_dataset->addSeries(series);
267 m_dataset->addSeries(series);
269 }
268 }
270
269
271 TRY_COMPARE(spy0.count(), 0);
270 TRY_COMPARE(spy0.count(), 0);
272 TRY_COMPARE(spy1.count(), 0);
271 TRY_COMPARE(spy1.count(), 0);
273 TRY_COMPARE(spy2.count(), seriesList.count());
272 TRY_COMPARE(spy2.count(), seriesList.count());
274 TRY_COMPARE(spy3.count(), 0);
273 TRY_COMPARE(spy3.count(), 0);
275
274
276 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
275 QSignalSpy spy4(m_dataset, SIGNAL(axisAdded(QAbstractAxis*,Domain*)));
277 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
276 QSignalSpy spy5(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
278 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
277 QSignalSpy spy6(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *,Domain*)));
279 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
278 QSignalSpy spy7(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
280
279
281 for(int i=0 ; i < seriesList.count(); i++){
280 for(int i=0 ; i < seriesList.count(); i++){
282 m_dataset->setAxisY(seriesList.at(i),axisList.at(i));
281 m_dataset->setAxisY(seriesList.at(i),axisList.at(i));
283 }
282 }
284
283
285 TRY_COMPARE(spy4.count(), axisCount);
284 TRY_COMPARE(spy4.count(), axisCount);
286 TRY_COMPARE(spy5.count(), 0);
285 TRY_COMPARE(spy5.count(), 0);
287 TRY_COMPARE(spy6.count(), 0);
286 TRY_COMPARE(spy6.count(), 0);
288 TRY_COMPARE(spy7.count(), 0);
287 TRY_COMPARE(spy7.count(), 0);
289
288
290 for(int i=0 ; i < seriesList.count(); i++){
289 for(int i=0 ; i < seriesList.count(); i++){
291 QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i));
290 QVERIFY(m_dataset->axisY(seriesList.at(i)) == axisList.at(i));
292 }
291 }
293 }
292 }
294
293
295 void tst_ChartDataSet::removeSeries_data()
294 void tst_ChartDataSet::removeSeries_data()
296 {
295 {
297 addSeries_data();
296 addSeries_data();
298 }
297 }
299
298
300 void tst_ChartDataSet::removeSeries()
299 void tst_ChartDataSet::removeSeries()
301 {
300 {
302 QFETCH(QAbstractSeries*, series);
301 QFETCH(QAbstractSeries*, series);
303
302
304 m_dataset->addSeries(series);
303 m_dataset->addSeries(series);
305 m_dataset->createDefaultAxes();
304 m_dataset->createDefaultAxes();
306
305
307 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
306 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis*, Domain *)));
308 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
307 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis*)));
309 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
308 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
310 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
309 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
311
310
312 m_dataset->removeSeries(series);
311 m_dataset->removeSeries(series);
313
312
314 TRY_COMPARE(spy0.count(), 0);
313 TRY_COMPARE(spy0.count(), 0);
315 if (series->type() == QAbstractSeries::SeriesTypePie) {
314 if (series->type() == QAbstractSeries::SeriesTypePie) {
316 TRY_COMPARE(spy1.count(), 0);
315 TRY_COMPARE(spy1.count(), 0);
317 }
316 }
318 else {
317 else {
319 TRY_COMPARE(spy1.count(), 2);
318 TRY_COMPARE(spy1.count(), 2);
320 }
319 }
321 TRY_COMPARE(spy2.count(), 0);
320 TRY_COMPARE(spy2.count(), 0);
322 TRY_COMPARE(spy3.count(), 1);
321 TRY_COMPARE(spy3.count(), 1);
323 }
322 }
324
323
325 void tst_ChartDataSet::removeAllSeries_data()
324 void tst_ChartDataSet::removeAllSeries_data()
326 {
325 {
327 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
326 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
328 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
327 QTest::addColumn<QList<QAbstractAxis*> >("axisList");
329 QTest::addColumn<int>("axisCount");
328 QTest::addColumn<int>("axisCount");
330
329
331 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
330 QTest::newRow("line,spline,scatter: axis 0 axis1 axis 2")
332 << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this)
331 << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QSplineSeries(this)
333 << new QScatterSeries(this))
332 << new QScatterSeries(this))
334 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this)
333 << (QList<QAbstractAxis*>() << new QValuesAxis(this) << new QValuesAxis(this)
335 << new QValuesAxis(this)) << 3;
334 << new QValuesAxis(this)) << 3;
336 //TODO:
335 //TODO:
337 }
336 }
338
337
339 void tst_ChartDataSet::removeAllSeries()
338 void tst_ChartDataSet::removeAllSeries()
340 {
339 {
341 QFETCH(QList<QAbstractSeries*>, seriesList);
340 QFETCH(QList<QAbstractSeries*>, seriesList);
342 QFETCH(QList<QAbstractAxis*>, axisList);
341 QFETCH(QList<QAbstractAxis*>, axisList);
343 QFETCH(int, axisCount);
342 QFETCH(int, axisCount);
344
343
345 foreach(QAbstractSeries* series, seriesList) {
344 foreach(QAbstractSeries* series, seriesList) {
346 m_dataset->addSeries(series);
345 m_dataset->addSeries(series);
347 }
346 }
348
347
349 for (int i = 0; i < seriesList.count(); i++) {
348 for (int i = 0; i < seriesList.count(); i++) {
350 m_dataset->setAxisX(seriesList.at(i), axisList.at(i));
349 m_dataset->setAxisX(seriesList.at(i), axisList.at(i));
351 }
350 }
352
351
353 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
352 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
354 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
353 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
355 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
354 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
356 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
355 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
357
356
358 m_dataset->removeAllSeries();
357 m_dataset->removeAllSeries();
359
358
360 TRY_COMPARE(spy0.count(), 0);
359 TRY_COMPARE(spy0.count(), 0);
361 TRY_COMPARE(spy1.count(), axisCount);
360 TRY_COMPARE(spy1.count(), axisCount);
362 TRY_COMPARE(spy2.count(), 0);
361 TRY_COMPARE(spy2.count(), 0);
363 TRY_COMPARE(spy3.count(), seriesList.count());
362 TRY_COMPARE(spy3.count(), seriesList.count());
364 }
363 }
365
364
366
365
367 void tst_ChartDataSet::seriesCount_data()
366 void tst_ChartDataSet::seriesCount_data()
368 {
367 {
369 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
368 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
370 QTest::addColumn<int>("seriesCount");
369 QTest::addColumn<int>("seriesCount");
371
370
372 QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3;
371 QTest::newRow("line,line, line, spline 3") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) ) << 3;
373 QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2;
372 QTest::newRow("scatter,scatter, line, line 2") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) ) << 2;
374 }
373 }
375
374
376 void tst_ChartDataSet::seriesCount()
375 void tst_ChartDataSet::seriesCount()
377 {
376 {
378 QFETCH(QList<QAbstractSeries*>, seriesList);
377 QFETCH(QList<QAbstractSeries*>, seriesList);
379 QFETCH(int, seriesCount);
378 QFETCH(int, seriesCount);
380
379
381 foreach(QAbstractSeries* series, seriesList){
380 foreach(QAbstractSeries* series, seriesList){
382 m_dataset->addSeries(series);
381 m_dataset->addSeries(series);
383 }
382 }
384
383
385 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
384 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
386 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
385 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
387 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
386 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
388 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
387 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
389
388
390 QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount);
389 QCOMPARE(m_dataset->seriesCount(seriesList.at(0)->type()),seriesCount);
391 TRY_COMPARE(spy0.count(), 0);
390 TRY_COMPARE(spy0.count(), 0);
392 TRY_COMPARE(spy1.count(), 0);
391 TRY_COMPARE(spy1.count(), 0);
393 TRY_COMPARE(spy2.count(), 0);
392 TRY_COMPARE(spy2.count(), 0);
394 TRY_COMPARE(spy3.count(), 0);
393 TRY_COMPARE(spy3.count(), 0);
395 }
394 }
396
395
397 void tst_ChartDataSet::seriesIndex_data()
396 void tst_ChartDataSet::seriesIndex_data()
398 {
397 {
399 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
398 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
400
399
401 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
400 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
402 QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) );
401 QTest::newRow("scatter,scatter, line, line") << (QList<QAbstractSeries*>() << new QScatterSeries(this) << new QScatterSeries(this) << new QLineSeries(this) << new QLineSeries(this) );
403 }
402 }
404
403
405 void tst_ChartDataSet::seriesIndex()
404 void tst_ChartDataSet::seriesIndex()
406 {
405 {
407
406
408 QFETCH(QList<QAbstractSeries*>, seriesList);
407 QFETCH(QList<QAbstractSeries*>, seriesList);
409
408
410 foreach(QAbstractSeries* series, seriesList) {
409 foreach(QAbstractSeries* series, seriesList) {
411 m_dataset->addSeries(series);
410 m_dataset->addSeries(series);
412 }
411 }
413
412
414 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
413 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *,Domain*)));
415 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
414 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
416 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)));
415 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries*,Domain*)));
417 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
416 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries*)));
418
417
419 for (int i = 0; i < seriesList.count(); i++) {
418 for (int i = 0; i < seriesList.count(); i++) {
420 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
419 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
421 }
420 }
422
421
423 TRY_COMPARE(spy0.count(), 0);
422 TRY_COMPARE(spy0.count(), 0);
424 TRY_COMPARE(spy1.count(), 0);
423 TRY_COMPARE(spy1.count(), 0);
425 TRY_COMPARE(spy2.count(), 0);
424 TRY_COMPARE(spy2.count(), 0);
426 TRY_COMPARE(spy3.count(), 0);
425 TRY_COMPARE(spy3.count(), 0);
427
426
428 foreach(QAbstractSeries* series, seriesList) {
427 foreach(QAbstractSeries* series, seriesList) {
429 m_dataset->removeSeries(series);
428 m_dataset->removeSeries(series);
430 }
429 }
431
430
432 for (int i = 0; i < seriesList.count(); i++) {
431 for (int i = 0; i < seriesList.count(); i++) {
433 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
432 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
434 }
433 }
435
434
436 foreach(QAbstractSeries* series, seriesList) {
435 foreach(QAbstractSeries* series, seriesList) {
437 m_dataset->addSeries(series);
436 m_dataset->addSeries(series);
438 }
437 }
439
438
440 for (int i = 0; i < seriesList.count(); i++) {
439 for (int i = 0; i < seriesList.count(); i++) {
441 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
440 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
442 }
441 }
443
442
444 m_dataset->removeSeries(seriesList.at(1));
443 m_dataset->removeSeries(seriesList.at(1));
445
444
446 for (int i = 0; i < seriesList.count(); i++) {
445 for (int i = 0; i < seriesList.count(); i++) {
447 if (i != 1)
446 if (i != 1)
448 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
447 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
449 else
448 else
450 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
449 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
451 }
450 }
452
451
453 m_dataset->addSeries(seriesList.at(1));
452 m_dataset->addSeries(seriesList.at(1));
454
453
455 for (int i = 0; i < seriesList.count(); i++) {
454 for (int i = 0; i < seriesList.count(); i++) {
456 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
455 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
457 }
456 }
458
457
459 m_dataset->removeSeries(seriesList.at(2));
458 m_dataset->removeSeries(seriesList.at(2));
460
459
461 for (int i = 0; i < seriesList.count(); i++) {
460 for (int i = 0; i < seriesList.count(); i++) {
462 if (i != 2)
461 if (i != 2)
463 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
462 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
464 else
463 else
465 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
464 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
466 }
465 }
467
466
468 m_dataset->removeSeries(seriesList.at(0));
467 m_dataset->removeSeries(seriesList.at(0));
469
468
470 for (int i = 0; i < seriesList.count(); i++) {
469 for (int i = 0; i < seriesList.count(); i++) {
471 if (i != 2 && i != 0)
470 if (i != 2 && i != 0)
472 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
471 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
473 else
472 else
474 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
473 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), -1);
475 }
474 }
476
475
477 m_dataset->addSeries(seriesList.at(2));
476 m_dataset->addSeries(seriesList.at(2));
478 m_dataset->addSeries(seriesList.at(0));
477 m_dataset->addSeries(seriesList.at(0));
479
478
480 for (int i = 0; i < seriesList.count(); i++) {
479 for (int i = 0; i < seriesList.count(); i++) {
481 if (i == 2)
480 if (i == 2)
482 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0);
481 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 0);
483 else if (i == 0)
482 else if (i == 0)
484 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2);
483 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), 2);
485 else
484 else
486 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
485 QCOMPARE(m_dataset->seriesIndex(seriesList.at(i)), i);
487 }
486 }
488
487
489 }
488 }
490
489
491 void tst_ChartDataSet::domain_data()
490 void tst_ChartDataSet::domain_data()
492 {
491 {
493 addSeries_data();
492 addSeries_data();
494 }
493 }
495
494
496 void tst_ChartDataSet::domain()
495 void tst_ChartDataSet::domain()
497 {
496 {
498 QFETCH(QAbstractSeries*, series);
497 QFETCH(QAbstractSeries*, series);
499
498
500 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
499 QSignalSpy spy0(m_dataset, SIGNAL(axisAdded(QAbstractAxis *, Domain *)));
501 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
500 QSignalSpy spy1(m_dataset, SIGNAL(axisRemoved(QAbstractAxis *)));
502 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
501 QSignalSpy spy2(m_dataset, SIGNAL(seriesAdded(QAbstractSeries *, Domain *)));
503 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
502 QSignalSpy spy3(m_dataset, SIGNAL(seriesRemoved(QAbstractSeries *)));
504
503
505 m_dataset->addSeries(series);
504 m_dataset->addSeries(series);
506 QVERIFY(m_dataset->domain(series));
505 QVERIFY(m_dataset->domain(series));
507
506
508
507
509 TRY_COMPARE(spy0.count(), 0);
508 TRY_COMPARE(spy0.count(), 0);
510 TRY_COMPARE(spy1.count(), 0);
509 TRY_COMPARE(spy1.count(), 0);
511 TRY_COMPARE(spy2.count(), 1);
510 TRY_COMPARE(spy2.count(), 1);
512
511
513 QList<QVariant> arguments = spy2.takeFirst();
512 QList<QVariant> arguments = spy2.takeFirst();
514 Domain *domain = (Domain *) arguments.at(1).value<Domain *>();
513 Domain *domain = (Domain *) arguments.at(1).value<Domain *>();
515 QVERIFY(m_dataset->domain(series) == domain);
514 QVERIFY(m_dataset->domain(series) == domain);
516
515
517 TRY_COMPARE(spy3.count(), 0);
516 TRY_COMPARE(spy3.count(), 0);
518
517
519 }
518 }
520
519
521 void tst_ChartDataSet::zoomInDomain_data()
520 void tst_ChartDataSet::zoomInDomain_data()
522 {
521 {
522 QTest::addColumn<bool >("sameAxis");
523 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
523 QTest::addColumn<QList<QAbstractSeries*> >("seriesList");
524 QTest::newRow("line,line, line, spline") << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
524 QTest::newRow("sameAxis: line,line, line, spline") << true << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
525 QTest::newRow("separeateAxis: line,line, line, spline") << false << (QList<QAbstractSeries*>() << new QLineSeries(this) << new QLineSeries(this) << new QLineSeries(this) << new QSplineSeries(this) );
525 }
526 }
526
527
527 void tst_ChartDataSet::zoomInDomain()
528 void tst_ChartDataSet::zoomInDomain()
528 {
529 {
530 QFETCH(bool, sameAxis);
529 QFETCH(QList<QAbstractSeries*>, seriesList);
531 QFETCH(QList<QAbstractSeries*>, seriesList);
530
532
531 foreach(QAbstractSeries* series, seriesList) {
533 foreach(QAbstractSeries* series, seriesList) {
532 m_dataset->addSeries(series);
534 m_dataset->addSeries(series);
533 }
535 }
534
536
535 /*
537 if(sameAxis) m_dataset->createDefaultAxes();
536 QValuesAxis* axis = new QValuesAxis();
537
538 for (int i = 0; i < seriesList.count(); i++) {
539 m_dataset->setAxisX(seriesList.at(i), axis);
540 }
541 */
542 m_dataset->createDefaultAxes();
543
544
545
538
546 QList<QSignalSpy*> spyList;
539 QList<QSignalSpy*> spyList;
547
540
548 foreach(QAbstractSeries* series, seriesList) {
541 foreach(QAbstractSeries* series, seriesList) {
549 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
542 spyList << new QSignalSpy(m_dataset->domain(series),SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
550 }
543 }
551
544
552 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
545 m_dataset->zoomInDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
553
546
554 foreach(QSignalSpy* spy, spyList) {
547 foreach(QSignalSpy* spy, spyList) {
555 TRY_COMPARE(spy->count(), 1);
548 TRY_COMPARE(spy->count(), 1);
556 }
549 }
557
550
558 qDeleteAll(spyList);
551 qDeleteAll(spyList);
559 }
552 }
560
553
561 /*
554
555
562 void tst_ChartDataSet::zoomOutDomain_data()
556 void tst_ChartDataSet::zoomOutDomain_data()
563 {
557 {
564 addSeries_data();
558 zoomInDomain_data();
565 }
559 }
566
560
567 void tst_ChartDataSet::zoomOutDomain()
561 void tst_ChartDataSet::zoomOutDomain()
568 {
562 {
569 QFETCH(QLineSeries*, series0);
563 QFETCH(bool, sameAxis);
570 QFETCH(QAxis*, axis0);
564 QFETCH(QList<QAbstractSeries*>, seriesList);
571 QFETCH(QLineSeries*, series1);
572 QFETCH(QAxis*, axis1);
573 QFETCH(QLineSeries*, series2);
574 QFETCH(QAxis*, axis2);
575 QFETCH(int, axisCount);
576
565
577 Q_UNUSED(axisCount);
566 foreach(QAbstractSeries* series, seriesList) {
567 m_dataset->addSeries(series);
568 }
578
569
579 m_dataset->addSeries(series0, axis0);
570 if (sameAxis)
580 m_dataset->addSeries(series1, axis1);
571 m_dataset->createDefaultAxes();
581 m_dataset->addSeries(series2, axis2);
582
572
583 Domain* domain0 = m_dataset->domain(series0);
573 QList<QSignalSpy*> spyList;
584 Domain* domain1 = m_dataset->domain(series1);
585 Domain* domain2 = m_dataset->domain(series2);
586
574
587 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
575 foreach(QAbstractSeries* series, seriesList) {
588 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
576 spyList << new QSignalSpy(m_dataset->domain(series), SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
589 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
577 }
590
578
591 m_dataset->zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000));
579 m_dataset->zoomOutDomain(QRect(0, 0, 100, 100), QSize(1000, 1000));
592
580
593 TRY_COMPARE(spy0.count(), 1);
581 foreach(QSignalSpy* spy, spyList) {
594 TRY_COMPARE(spy1.count(), 1);
582 TRY_COMPARE(spy->count(), 1);
595 TRY_COMPARE(spy2.count(), 1);
583 }
584
585 qDeleteAll (spyList);
596 }
586 }
597
587
598 void tst_ChartDataSet::scrollDomain_data()
588 void tst_ChartDataSet::scrollDomain_data()
599 {
589 {
600 addSeries_data();
590 zoomInDomain_data();
601 }
591 }
602
592
603 void tst_ChartDataSet::scrollDomain()
593 void tst_ChartDataSet::scrollDomain()
604 {
594 {
605 QFETCH(QLineSeries*, series0);
595 QFETCH(bool, sameAxis);
606 QFETCH(QAxis*, axis0);
596 QFETCH(QList<QAbstractSeries*>, seriesList);
607 QFETCH(QLineSeries*, series1);
608 QFETCH(QAxis*, axis1);
609 QFETCH(QLineSeries*, series2);
610 QFETCH(QAxis*, axis2);
611 QFETCH(int, axisCount);
612
597
613 Q_UNUSED(axisCount);
598 foreach(QAbstractSeries* series, seriesList) {
599 m_dataset->addSeries(series);
600 }
614
601
615 m_dataset->addSeries(series0, axis0);
602 if (sameAxis)
616 m_dataset->addSeries(series1, axis1);
603 m_dataset->createDefaultAxes();
617 m_dataset->addSeries(series2, axis2);
618
604
619 Domain* domain0 = m_dataset->domain(series0);
605 QList<QSignalSpy*> spyList;
620 Domain* domain1 = m_dataset->domain(series1);
621 Domain* domain2 = m_dataset->domain(series2);
622
606
623 QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
607 foreach(QAbstractSeries* series, seriesList) {
624 QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
608 spyList
625 QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
609 << new QSignalSpy(m_dataset->domain(series),
610 SIGNAL(domainChanged(qreal,qreal,qreal,qreal)));
611 }
626
612
627 m_dataset->scrollDomain(10,10,QSize(1000,1000));
613 m_dataset->scrollDomain(10, 10, QSize(1000, 1000));
628
614
629 TRY_COMPARE(spy0.count(), 1);
615 foreach(QSignalSpy* spy, spyList) {
630 TRY_COMPARE(spy1.count(), 1);
616 TRY_COMPARE(spy->count(), 1);
631 TRY_COMPARE(spy2.count(), 1);
632 }
617 }
633 */
618
619 qDeleteAll(spyList);
620 }
621
634 QTEST_MAIN(tst_ChartDataSet)
622 QTEST_MAIN(tst_ChartDataSet)
635 #include "tst_chartdataset.moc"
623 #include "tst_chartdataset.moc"
636
624
General Comments 0
You need to be logged in to leave comments. Login now