##// END OF EJS Templates
Adds RemoveAllSeries method to API
Michal Klocek -
r258:09026acabba0
parent child
Show More
@@ -1,334 +1,354
1 #include "chartdataset_p.h"
1 #include "chartdataset_p.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 //series
3 //series
4 #include "qlinechartseries.h"
4 #include "qlinechartseries.h"
5 #include "qbarchartseries.h"
5 #include "qbarchartseries.h"
6 #include "qstackedbarchartseries.h"
6 #include "qstackedbarchartseries.h"
7 #include "qpercentbarchartseries.h"
7 #include "qpercentbarchartseries.h"
8 #include "qpieseries.h"
8 #include "qpieseries.h"
9 #include "qscatterseries.h"
9 #include "qscatterseries.h"
10
10
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
11 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12
12
13 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
13 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent),
14 m_axisX(new QChartAxis(this)),
14 m_axisX(new QChartAxis(this)),
15 m_axisY(new QChartAxis(this)),
15 m_axisY(new QChartAxis(this)),
16 m_domainIndex(0),
16 m_domainIndex(0),
17 m_axisXInitialized(false)
17 m_axisXInitialized(false)
18 {
18 {
19 }
19 }
20
20
21 ChartDataSet::~ChartDataSet()
21 ChartDataSet::~ChartDataSet()
22 {
22 {
23 // TODO Auto-generated destructor stub
23 // TODO Auto-generated destructor stub
24 }
24 }
25
25
26 const Domain ChartDataSet::domain(QChartAxis *axisY) const
26 const Domain ChartDataSet::domain(QChartAxis *axisY) const
27 {
27 {
28 int i = m_domainMap.count(axisY);
28 int i = m_domainMap.count(axisY);
29 if(i == 0){
29 if(i == 0){
30 return Domain();
30 return Domain();
31 }
31 }
32 i = i - m_domainIndex -1;
32 i = i - m_domainIndex -1;
33 return m_domainMap.values(axisY).at(i);
33 return m_domainMap.values(axisY).at(i);
34 }
34 }
35
35
36 void ChartDataSet::addSeries(QChartSeries* series, QChartAxis *axisY)
36 void ChartDataSet::addSeries(QChartSeries* series, QChartAxis *axisY)
37 {
37 {
38 // TODO: we should check the series not already added
38 // TODO: we should check the series not already added
39
39
40 series->setParent(this); // take ownership
40 series->setParent(this); // take ownership
41 clearDomains();
41 clearDomains();
42
42
43 if(axisY==0) axisY = m_axisY;
43 if(axisY==0) axisY = m_axisY;
44 axisY->setParent(this); // take ownership
44 axisY->setParent(this); // take ownership
45
45
46 QList<QChartSeries*> seriesList = m_seriesMap.values(axisY);
46 QList<QChartSeries*> seriesList = m_seriesMap.values(axisY);
47
47
48 QList<Domain> domainList = m_domainMap.values(axisY);
48 QList<Domain> domainList = m_domainMap.values(axisY);
49
49
50 Q_ASSERT(domainList.size()<=1);
50 Q_ASSERT(domainList.size()<=1);
51
51
52 Domain domain;
52 Domain domain;
53
53
54 if(domainList.size()>0) domain = domainList.at(0);
54 if(domainList.size()>0) domain = domainList.at(0);
55
55
56 switch(series->type())
56 switch(series->type())
57 {
57 {
58 case QChartSeries::SeriesTypeLine: {
58 case QChartSeries::SeriesTypeLine: {
59
59
60 QLineChartSeries* xyseries = static_cast<QLineChartSeries*>(series);
60 QLineChartSeries* xyseries = static_cast<QLineChartSeries*>(series);
61
61
62 for (int i = 0; i < xyseries->count(); i++)
62 for (int i = 0; i < xyseries->count(); i++)
63 {
63 {
64 qreal x = xyseries->x(i);
64 qreal x = xyseries->x(i);
65 qreal y = xyseries->y(i);
65 qreal y = xyseries->y(i);
66 domain.m_minX = qMin(domain.m_minX,x);
66 domain.m_minX = qMin(domain.m_minX,x);
67 domain.m_minY = qMin(domain.m_minY,y);
67 domain.m_minY = qMin(domain.m_minY,y);
68 domain.m_maxX = qMax(domain.m_maxX,x);
68 domain.m_maxX = qMax(domain.m_maxX,x);
69 domain.m_maxY = qMax(domain.m_maxY,y);
69 domain.m_maxY = qMax(domain.m_maxY,y);
70 }
70 }
71 break;
71 break;
72 }
72 }
73 case QChartSeries::SeriesTypeBar: {
73 case QChartSeries::SeriesTypeBar: {
74 qDebug() << "QChartSeries::SeriesTypeBar";
74 qDebug() << "QChartSeries::SeriesTypeBar";
75 QBarChartSeries* barSeries = static_cast<QBarChartSeries*>(series);
75 QBarChartSeries* barSeries = static_cast<QBarChartSeries*>(series);
76 qreal x = barSeries->countCategories();
76 qreal x = barSeries->countCategories();
77 qreal y = barSeries->max();
77 qreal y = barSeries->max();
78 domain.m_minX = qMin(domain.m_minX,x);
78 domain.m_minX = qMin(domain.m_minX,x);
79 domain.m_minY = qMin(domain.m_minY,y);
79 domain.m_minY = qMin(domain.m_minY,y);
80 domain.m_maxX = qMax(domain.m_maxX,x);
80 domain.m_maxX = qMax(domain.m_maxX,x);
81 domain.m_maxY = qMax(domain.m_maxY,y);
81 domain.m_maxY = qMax(domain.m_maxY,y);
82 break;
82 break;
83 }
83 }
84 case QChartSeries::SeriesTypeStackedBar: {
84 case QChartSeries::SeriesTypeStackedBar: {
85 qDebug() << "QChartSeries::SeriesTypeStackedBar";
85 qDebug() << "QChartSeries::SeriesTypeStackedBar";
86
86
87 QStackedBarChartSeries* stackedBarSeries = static_cast<QStackedBarChartSeries*>(series);
87 QStackedBarChartSeries* stackedBarSeries = static_cast<QStackedBarChartSeries*>(series);
88 qreal x = stackedBarSeries->countCategories();
88 qreal x = stackedBarSeries->countCategories();
89 qreal y = stackedBarSeries->maxCategorySum();
89 qreal y = stackedBarSeries->maxCategorySum();
90 domain.m_minX = qMin(domain.m_minX,x);
90 domain.m_minX = qMin(domain.m_minX,x);
91 domain.m_minY = qMin(domain.m_minY,y);
91 domain.m_minY = qMin(domain.m_minY,y);
92 domain.m_maxX = qMax(domain.m_maxX,x);
92 domain.m_maxX = qMax(domain.m_maxX,x);
93 domain.m_maxY = qMax(domain.m_maxY,y);
93 domain.m_maxY = qMax(domain.m_maxY,y);
94 break;
94 break;
95 }
95 }
96 case QChartSeries::SeriesTypePercentBar: {
96 case QChartSeries::SeriesTypePercentBar: {
97 qDebug() << "QChartSeries::SeriesTypePercentBar";
97 qDebug() << "QChartSeries::SeriesTypePercentBar";
98
98
99 QPercentBarChartSeries* percentBarSeries = static_cast<QPercentBarChartSeries*>(series);
99 QPercentBarChartSeries* percentBarSeries = static_cast<QPercentBarChartSeries*>(series);
100 qreal x = percentBarSeries->countCategories();
100 qreal x = percentBarSeries->countCategories();
101 domain.m_minX = qMin(domain.m_minX,x);
101 domain.m_minX = qMin(domain.m_minX,x);
102 domain.m_minY = 0;
102 domain.m_minY = 0;
103 domain.m_maxX = qMax(domain.m_maxX,x);
103 domain.m_maxX = qMax(domain.m_maxX,x);
104 domain.m_maxY = 100;
104 domain.m_maxY = 100;
105 break;
105 break;
106 }
106 }
107
107
108 case QChartSeries::SeriesTypePie: {
108 case QChartSeries::SeriesTypePie: {
109 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
109 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
110 // TODO: domain stuff
110 // TODO: domain stuff
111 break;
111 break;
112 }
112 }
113
113
114 case QChartSeries::SeriesTypeScatter: {
114 case QChartSeries::SeriesTypeScatter: {
115 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
115 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
116 Q_ASSERT(scatterSeries);
116 Q_ASSERT(scatterSeries);
117 foreach (QPointF point, scatterSeries->data()) {
117 foreach (QPointF point, scatterSeries->data()) {
118 domain.m_minX = qMin(domain.m_minX, point.x());
118 domain.m_minX = qMin(domain.m_minX, point.x());
119 domain.m_maxX = qMax(domain.m_maxX, point.x());
119 domain.m_maxX = qMax(domain.m_maxX, point.x());
120 domain.m_minY = qMin(domain.m_minY, point.y());
120 domain.m_minY = qMin(domain.m_minY, point.y());
121 domain.m_maxY = qMax(domain.m_maxY, point.y());
121 domain.m_maxY = qMax(domain.m_maxY, point.y());
122 }
122 }
123 break;
123 break;
124 }
124 }
125
125
126 default: {
126 default: {
127 qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
127 qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported";
128 return;
128 return;
129 break;
129 break;
130 }
130 }
131
131
132 }
132 }
133
133
134 if(!m_domainMap.contains(axisY))
134 if(!m_domainMap.contains(axisY))
135 {
135 {
136 emit axisAdded(axisY);
136 emit axisAdded(axisY);
137 QObject::connect(axisY,SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal)));
137 QObject::connect(axisY,SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal)));
138 QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal)));
138 QObject::connect(axisY,SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal)));
139 QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*)));
139 QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*)));
140 }
140 }
141 m_domainMap.replace(axisY,domain);
141 m_domainMap.replace(axisY,domain);
142 m_seriesMap.insert(axisY,series);
142 m_seriesMap.insert(axisY,series);
143
143
144 if(!m_axisXInitialized)
144 if(!m_axisXInitialized)
145 {
145 {
146 emit axisAdded(axisX());
146 emit axisAdded(axisX());
147 QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal)));
147 QObject::connect(axisX(),SIGNAL(minChanged(qreal)),this,SLOT(handleMinChanged(qreal)));
148 QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal)));
148 QObject::connect(axisX(),SIGNAL(maxChanged(qreal)),this,SLOT(handleMaxChanged(qreal)));
149 QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*)));
149 QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*)));
150 m_axisXInitialized=true;
150 m_axisXInitialized=true;
151 }
151 }
152
152
153
153
154 emit seriesAdded(series);
154 emit seriesAdded(series);
155 QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY);
155 QStringList ylabels = createLabels(axisY,domain.m_minY,domain.m_maxY);
156 QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
156 QStringList xlabels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
157 emit axisLabelsChanged(axisY,ylabels);
157 emit axisLabelsChanged(axisY,ylabels);
158 emit axisLabelsChanged(axisX(),xlabels);
158 emit axisLabelsChanged(axisX(),xlabels);
159 emit seriesDomainChanged(series,domain);
159 emit seriesDomainChanged(series,domain);
160
160
161 }
161 }
162
162
163 void ChartDataSet::removeSeries(QChartSeries* series)
163 void ChartDataSet::removeSeries(QChartSeries* series)
164 {
164 {
165 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
165 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
166 foreach(QChartAxis* axis , keys) {
166 foreach(QChartAxis* axis , keys) {
167 if(m_seriesMap.contains(axis,series)){
167 if(m_seriesMap.contains(axis,series)){
168 emit seriesRemoved(series);
168 emit seriesRemoved(series);
169 m_seriesMap.remove(axis,series);
169 m_seriesMap.remove(axis,series);
170 //remove axis if no longer there
170 //remove axis if no longer there
171 if(!m_seriesMap.contains(axis) && axis != m_axisY){
171 if(!m_seriesMap.contains(axis)){
172 emit axisRemoved(axis);
172 emit axisRemoved(axis);
173 m_domainMap.remove(axis);
173 m_domainMap.remove(axis);
174 if(axis != m_axisY)
174 delete axis;
175 delete axis;
175 }
176 }
177 series->setParent(0);
176 break;
178 break;
177 }
179 }
178 }
180 }
179 }
181 }
180
182
183 void ChartDataSet::removeAllSeries()
184 {
185 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
186 foreach(QChartAxis* axis , keys) {
187 QList<QChartSeries*> seriesList = m_seriesMap.values(axis);
188 for(int i =0 ; i < seriesList.size();i++ )
189 {
190 emit seriesRemoved(seriesList.at(i));
191 delete(seriesList.at(i));
192 }
193 m_seriesMap.remove(axis);
194 m_domainMap.remove(axis);
195 emit axisRemoved(axis);
196 if(axis != m_axisY) delete axis;
197 }
198 m_domainIndex=0;
199 }
200
181 bool ChartDataSet::nextDomain()
201 bool ChartDataSet::nextDomain()
182 {
202 {
183 int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1;
203 int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1;
184
204
185 if (m_domainIndex < limit) {
205 if (m_domainIndex < limit) {
186 m_domainIndex++;
206 m_domainIndex++;
187 setDomain(m_domainIndex);
207 setDomain(m_domainIndex);
188 return true;
208 return true;
189 }
209 }
190 else {
210 else {
191 return false;
211 return false;
192 }
212 }
193 }
213 }
194
214
195 bool ChartDataSet::previousDomain()
215 bool ChartDataSet::previousDomain()
196 {
216 {
197 if (m_domainIndex > 0) {
217 if (m_domainIndex > 0) {
198 m_domainIndex--;
218 m_domainIndex--;
199 setDomain(m_domainIndex);
219 setDomain(m_domainIndex);
200 return true;
220 return true;
201 }
221 }
202 else {
222 else {
203 return false;
223 return false;
204 }
224 }
205 }
225 }
206
226
207 void ChartDataSet::setDomain(int index)
227 void ChartDataSet::setDomain(int index)
208 {
228 {
209 QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
229 QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
210 foreach (QChartAxis* axis , domainList) {
230 foreach (QChartAxis* axis , domainList) {
211 int i = m_domainMap.count(axis) - index -1;
231 int i = m_domainMap.count(axis) - index -1;
212 Q_ASSERT(i>=0);
232 Q_ASSERT(i>=0);
213 Domain domain = m_domainMap.values(axis).at(i);
233 Domain domain = m_domainMap.values(axis).at(i);
214 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
234 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
215 QList<QChartSeries*> seriesList = m_seriesMap.values(axis);
235 QList<QChartSeries*> seriesList = m_seriesMap.values(axis);
216 foreach(QChartSeries* series, seriesList) {
236 foreach(QChartSeries* series, seriesList) {
217 emit seriesDomainChanged(series,domain);
237 emit seriesDomainChanged(series,domain);
218 }
238 }
219 emit axisLabelsChanged(axis,labels);
239 emit axisLabelsChanged(axis,labels);
220 }
240 }
221
241
222 Domain domain = m_domainMap.value(axisY());
242 Domain domain = m_domainMap.value(axisY());
223 QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
243 QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
224 emit axisLabelsChanged(axisX(),labels);
244 emit axisLabelsChanged(axisX(),labels);
225 }
245 }
226
246
227 void ChartDataSet::clearDomains(int toIndex)
247 void ChartDataSet::clearDomains(int toIndex)
228 {
248 {
229 Q_ASSERT(toIndex>=0);
249 Q_ASSERT(toIndex>=0);
230
250
231 m_domainIndex = toIndex;
251 m_domainIndex = toIndex;
232
252
233 QList<QChartAxis*> keys = m_domainMap.uniqueKeys();
253 QList<QChartAxis*> keys = m_domainMap.uniqueKeys();
234
254
235 foreach (QChartAxis* key , keys)
255 foreach (QChartAxis* key , keys)
236 {
256 {
237 QList<Domain> domains = m_domainMap.values(key);
257 QList<Domain> domains = m_domainMap.values(key);
238 m_domainMap.remove(key);
258 m_domainMap.remove(key);
239 int i = domains.size() - toIndex - 1;
259 int i = domains.size() - toIndex - 1;
240 while(i--){
260 while(i--){
241 domains.removeFirst();
261 domains.removeFirst();
242 }
262 }
243 for(int j=domains.size()-1; j>=0 ;j--)
263 for(int j=domains.size()-1; j>=0 ;j--)
244 m_domainMap.insert(key,domains.at(j));
264 m_domainMap.insert(key,domains.at(j));
245 }
265 }
246 }
266 }
247
267
248 void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport)
268 void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport)
249 {
269 {
250 Q_ASSERT(rect.isValid());
270 Q_ASSERT(rect.isValid());
251 Q_ASSERT(viewport.isValid());
271 Q_ASSERT(viewport.isValid());
252
272
253 clearDomains(m_domainIndex);
273 clearDomains(m_domainIndex);
254
274
255 QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
275 QList<QChartAxis*> domainList = m_domainMap.uniqueKeys();
256
276
257 foreach (QChartAxis* axis , domainList){
277 foreach (QChartAxis* axis , domainList){
258 Domain domain(m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()));
278 Domain domain(m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()));
259 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
279 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
260 QList<QChartSeries*> seriesList = m_seriesMap.values(axis);
280 QList<QChartSeries*> seriesList = m_seriesMap.values(axis);
261 foreach(QChartSeries* series, seriesList){
281 foreach(QChartSeries* series, seriesList){
262 emit seriesDomainChanged(series,domain);
282 emit seriesDomainChanged(series,domain);
263 }
283 }
264 emit axisLabelsChanged(axis,labels);
284 emit axisLabelsChanged(axis,labels);
265 m_domainMap.insert(axis,domain);
285 m_domainMap.insert(axis,domain);
266 }
286 }
267
287
268 Domain domain = m_domainMap.value(axisY());
288 Domain domain = m_domainMap.value(axisY());
269 QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
289 QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX);
270 emit axisLabelsChanged(axisX(),labels);
290 emit axisLabelsChanged(axisX(),labels);
271
291
272 m_domainIndex++;
292 m_domainIndex++;
273 }
293 }
274
294
275 QChartAxis* ChartDataSet::axisY(QChartSeries* series) const
295 QChartAxis* ChartDataSet::axisY(QChartSeries* series) const
276 {
296 {
277 if(series == 0) return m_axisY;
297 if(series == 0) return m_axisY;
278
298
279 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
299 QList<QChartAxis*> keys = m_seriesMap.uniqueKeys();
280
300
281 foreach(QChartAxis* axis , keys) {
301 foreach(QChartAxis* axis , keys) {
282 if(m_seriesMap.contains(axis,series)){
302 if(m_seriesMap.contains(axis,series)){
283 return axis;
303 return axis;
284 }
304 }
285 }
305 }
286 return 0;
306 return 0;
287 }
307 }
288
308
289 QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max)
309 QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max)
290 {
310 {
291 Q_ASSERT(max>=min);
311 Q_ASSERT(max>=min);
292
312
293 QStringList labels;
313 QStringList labels;
294
314
295 int ticks = axis->ticksCount()-1;
315 int ticks = axis->ticksCount()-1;
296
316
297 for(int i=0; i<= ticks; i++){
317 for(int i=0; i<= ticks; i++){
298 qreal value = min + (i * (max - min)/ ticks);
318 qreal value = min + (i * (max - min)/ ticks);
299 QString label = axis->axisTickLabel(value);
319 QString label = axis->axisTickLabel(value);
300 if(label.isEmpty()){
320 if(label.isEmpty()){
301 labels << QString::number(value);
321 labels << QString::number(value);
302 }else{
322 }else{
303 labels << label;
323 labels << label;
304 }
324 }
305 }
325 }
306 return labels;
326 return labels;
307 }
327 }
308
328
309
329
310 void ChartDataSet::handleMinChanged(qreal min)
330 void ChartDataSet::handleMinChanged(qreal min)
311 {
331 {
312
332
313 }
333 }
314
334
315 void ChartDataSet::handleMaxChanged(qreal max)
335 void ChartDataSet::handleMaxChanged(qreal max)
316 {
336 {
317
337
318 }
338 }
319
339
320 void ChartDataSet::handleTickChanged(QChartAxis* axis)
340 void ChartDataSet::handleTickChanged(QChartAxis* axis)
321 {
341 {
322 Domain domain = m_domainMap.value(axisY());
342 Domain domain = m_domainMap.value(axisY());
323 if(axis==axisX()){
343 if(axis==axisX()){
324 QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX);
344 QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX);
325 emit axisLabelsChanged(axis,labels);
345 emit axisLabelsChanged(axis,labels);
326 }else{
346 }else{
327 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
347 QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY);
328 emit axisLabelsChanged(axis,labels);
348 emit axisLabelsChanged(axis,labels);
329 }
349 }
330 }
350 }
331
351
332 #include "moc_chartdataset_p.cpp"
352 #include "moc_chartdataset_p.cpp"
333
353
334 QTCOMMERCIALCHART_END_NAMESPACE
354 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,59 +1,60
1 #ifndef CHARTDATASET_P_H_
1 #ifndef CHARTDATASET_P_H_
2 #define CHARTDATASET_P_H_
2 #define CHARTDATASET_P_H_
3
3
4 #include "qchartseries.h"
4 #include "qchartseries.h"
5 #include "domain_p.h"
5 #include "domain_p.h"
6 #include <QVector>
6 #include <QVector>
7
7
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
8 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9
9
10 class QChartAxis;
10 class QChartAxis;
11
11
12 class ChartDataSet : public QObject
12 class ChartDataSet : public QObject
13 {
13 {
14 Q_OBJECT
14 Q_OBJECT
15 public:
15 public:
16 ChartDataSet(QObject* parent=0);
16 ChartDataSet(QObject* parent=0);
17 virtual ~ChartDataSet();
17 virtual ~ChartDataSet();
18
18
19 void addSeries(QChartSeries* series,QChartAxis *axisY = 0);
19 void addSeries(QChartSeries* series,QChartAxis *axisY = 0);
20 void removeSeries(QChartSeries* series);
20 void removeSeries(QChartSeries* series);
21 void removeAllSeries();
21 void addDomain(const QRectF& rect, const QRectF& viewport);
22 void addDomain(const QRectF& rect, const QRectF& viewport);
22 bool nextDomain();
23 bool nextDomain();
23 bool previousDomain();
24 bool previousDomain();
24 void clearDomains(int toIndex =0);
25 void clearDomains(int toIndex =0);
25 const Domain domain(QChartAxis *axisY) const;
26 const Domain domain(QChartAxis *axisY) const;
26 int domainIndex() const {return m_domainIndex;}
27 int domainIndex() const {return m_domainIndex;}
27
28
28 QChartAxis* axisX() const { return m_axisX;};
29 QChartAxis* axisX() const { return m_axisX;};
29 QChartAxis* axisY(QChartSeries* series = 0) const;
30 QChartAxis* axisY(QChartSeries* series = 0) const;
30
31
31 signals:
32 signals:
32 void seriesAdded(QChartSeries* series);
33 void seriesAdded(QChartSeries* series);
33 void seriesRemoved(QChartSeries* series);
34 void seriesRemoved(QChartSeries* series);
34 void axisAdded(QChartAxis* axis);
35 void axisAdded(QChartAxis* axis);
35 void axisRemoved(QChartAxis* axis);
36 void axisRemoved(QChartAxis* axis);
36 void axisLabelsChanged(QChartAxis* axis, const QStringList& labels);
37 void axisLabelsChanged(QChartAxis* axis, const QStringList& labels);
37 void seriesDomainChanged(QChartSeries* series,const Domain& domain);
38 void seriesDomainChanged(QChartSeries* series,const Domain& domain);
38
39
39 private slots:
40 private slots:
40 void handleMinChanged(qreal min);
41 void handleMinChanged(qreal min);
41 void handleMaxChanged(qreal max);
42 void handleMaxChanged(qreal max);
42 void handleTickChanged(QChartAxis*);
43 void handleTickChanged(QChartAxis*);
43
44
44 private:
45 private:
45 void setDomain(int index);
46 void setDomain(int index);
46 QStringList createLabels(QChartAxis* axis,qreal min, qreal max);
47 QStringList createLabels(QChartAxis* axis,qreal min, qreal max);
47
48
48 private:
49 private:
49 QMultiMap<QChartAxis*, Domain> m_domainMap;
50 QMultiMap<QChartAxis*, Domain> m_domainMap;
50 QMultiMap<QChartAxis*, QChartSeries*> m_seriesMap;
51 QMultiMap<QChartAxis*, QChartSeries*> m_seriesMap;
51 QChartAxis* m_axisX;
52 QChartAxis* m_axisX;
52 QChartAxis* m_axisY;
53 QChartAxis* m_axisY;
53 int m_domainIndex;
54 int m_domainIndex;
54 bool m_axisXInitialized;
55 bool m_axisXInitialized;
55 };
56 };
56
57
57 QTCOMMERCIALCHART_END_NAMESPACE
58 QTCOMMERCIALCHART_END_NAMESPACE
58
59
59 #endif /* CHARTENGINE_P_H_ */
60 #endif /* CHARTENGINE_P_H_ */
@@ -1,153 +1,158
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include "chartdataset_p.h"
4 #include "chartdataset_p.h"
5 #include <QGraphicsScene>
5 #include <QGraphicsScene>
6 #include <QGraphicsSceneResizeEvent>
6 #include <QGraphicsSceneResizeEvent>
7 #include <QDebug>
7 #include <QDebug>
8
8
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
9 QTCOMMERCIALCHART_BEGIN_NAMESPACE
10
10
11 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
11 QChart::QChart(QGraphicsItem *parent, Qt::WindowFlags wFlags) : QGraphicsWidget(parent,wFlags),
12 m_backgroundItem(0),
12 m_backgroundItem(0),
13 m_titleItem(0),
13 m_titleItem(0),
14 m_dataset(new ChartDataSet(this)),
14 m_dataset(new ChartDataSet(this)),
15 m_presenter(new ChartPresenter(this,m_dataset))
15 m_presenter(new ChartPresenter(this,m_dataset))
16 {
16 {
17 }
17 }
18
18
19 QChart::~QChart() {}
19 QChart::~QChart() {}
20
20
21 void QChart::addSeries(QChartSeries* series,QChartAxis* axisY)
21 void QChart::addSeries(QChartSeries* series,QChartAxis* axisY)
22 {
22 {
23 m_dataset->addSeries(series,axisY);
23 m_dataset->addSeries(series,axisY);
24 }
24 }
25
25
26 void QChart::removeSeries(QChartSeries* series)
26 void QChart::removeSeries(QChartSeries* series)
27 {
27 {
28 m_dataset->removeSeries(series);
28 m_dataset->removeSeries(series);
29 }
29 }
30
30
31 void QChart::removeAllSeries()
32 {
33 m_dataset->removeAllSeries();
34 }
35
31 void QChart::setChartBackgroundBrush(const QBrush& brush)
36 void QChart::setChartBackgroundBrush(const QBrush& brush)
32 {
37 {
33 createChartBackgroundItem();
38 createChartBackgroundItem();
34 m_backgroundItem->setBrush(brush);
39 m_backgroundItem->setBrush(brush);
35 m_backgroundItem->update();
40 m_backgroundItem->update();
36 }
41 }
37
42
38 void QChart::setChartBackgroundPen(const QPen& pen)
43 void QChart::setChartBackgroundPen(const QPen& pen)
39 {
44 {
40 createChartBackgroundItem();
45 createChartBackgroundItem();
41 m_backgroundItem->setPen(pen);
46 m_backgroundItem->setPen(pen);
42 m_backgroundItem->update();
47 m_backgroundItem->update();
43 }
48 }
44
49
45 void QChart::setChartTitle(const QString& title)
50 void QChart::setChartTitle(const QString& title)
46 {
51 {
47 createChartTitleItem();
52 createChartTitleItem();
48 m_titleItem->setPlainText(title);
53 m_titleItem->setPlainText(title);
49 }
54 }
50
55
51 void QChart::setChartTitleFont(const QFont& font)
56 void QChart::setChartTitleFont(const QFont& font)
52 {
57 {
53 createChartTitleItem();
58 createChartTitleItem();
54 m_titleItem->setFont(font);
59 m_titleItem->setFont(font);
55 }
60 }
56
61
57 void QChart::createChartBackgroundItem()
62 void QChart::createChartBackgroundItem()
58 {
63 {
59 if(!m_backgroundItem) {
64 if(!m_backgroundItem) {
60 m_backgroundItem = new QGraphicsRectItem(this);
65 m_backgroundItem = new QGraphicsRectItem(this);
61 m_backgroundItem->setZValue(-1);
66 m_backgroundItem->setZValue(-1);
62 }
67 }
63 }
68 }
64
69
65 void QChart::createChartTitleItem()
70 void QChart::createChartTitleItem()
66 {
71 {
67 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
72 if(!m_titleItem) m_titleItem = new QGraphicsTextItem(this);
68 }
73 }
69
74
70 int QChart::margin() const
75 int QChart::margin() const
71 {
76 {
72 return m_presenter->margin();
77 return m_presenter->margin();
73 }
78 }
74
79
75 void QChart::setMargin(int margin)
80 void QChart::setMargin(int margin)
76 {
81 {
77 m_presenter->setMargin(margin);
82 m_presenter->setMargin(margin);
78 }
83 }
79
84
80 void QChart::setChartTheme(QChart::ChartTheme theme)
85 void QChart::setChartTheme(QChart::ChartTheme theme)
81 {
86 {
82 m_presenter->setChartTheme(theme);
87 m_presenter->setChartTheme(theme);
83 }
88 }
84
89
85 QChart::ChartTheme QChart::chartTheme() const
90 QChart::ChartTheme QChart::chartTheme() const
86 {
91 {
87 return m_presenter->chartTheme();
92 return m_presenter->chartTheme();
88 }
93 }
89
94
90 void QChart::zoomIn()
95 void QChart::zoomIn()
91 {
96 {
92 if (!m_dataset->nextDomain()) {
97 if (!m_dataset->nextDomain()) {
93 QRectF rect = m_presenter->geometry();
98 QRectF rect = m_presenter->geometry();
94 rect.setWidth(rect.width()/2);
99 rect.setWidth(rect.width()/2);
95 rect.setHeight(rect.height()/2);
100 rect.setHeight(rect.height()/2);
96 rect.moveCenter(m_presenter->geometry().center());
101 rect.moveCenter(m_presenter->geometry().center());
97 zoomIn(rect);
102 zoomIn(rect);
98 }
103 }
99 }
104 }
100
105
101 void QChart::zoomIn(const QRectF& rect)
106 void QChart::zoomIn(const QRectF& rect)
102 {
107 {
103 if(!rect.isValid()) return;
108 if(!rect.isValid()) return;
104 QRectF r = rect.normalized();
109 QRectF r = rect.normalized();
105 int margin = m_presenter->margin();
110 int margin = m_presenter->margin();
106 r.translate(-margin, -margin);
111 r.translate(-margin, -margin);
107 m_dataset->addDomain(r,m_presenter->geometry());
112 m_dataset->addDomain(r,m_presenter->geometry());
108 }
113 }
109
114
110 void QChart::zoomOut()
115 void QChart::zoomOut()
111 {
116 {
112 m_dataset->previousDomain();
117 m_dataset->previousDomain();
113 }
118 }
114
119
115 void QChart::zoomReset()
120 void QChart::zoomReset()
116 {
121 {
117 m_dataset->clearDomains();
122 m_dataset->clearDomains();
118 }
123 }
119
124
120 QChartAxis* QChart::axisX() const
125 QChartAxis* QChart::axisX() const
121 {
126 {
122 return m_dataset->axisX();
127 return m_dataset->axisX();
123 }
128 }
124
129
125 QChartAxis* QChart::axisY() const
130 QChartAxis* QChart::axisY() const
126 {
131 {
127 return m_dataset->axisY();
132 return m_dataset->axisY();
128 }
133 }
129
134
130 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
135 void QChart::resizeEvent(QGraphicsSceneResizeEvent *event)
131 {
136 {
132
137
133 m_rect = QRectF(QPoint(0,0),event->newSize());
138 m_rect = QRectF(QPoint(0,0),event->newSize());
134 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
139 QRectF rect = m_rect.adjusted(margin(),margin(), -margin(), -margin());
135
140
136 // recalculate title position
141 // recalculate title position
137 if (m_titleItem) {
142 if (m_titleItem) {
138 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
143 QPointF center = m_rect.center() -m_titleItem->boundingRect().center();
139 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
144 m_titleItem->setPos(center.x(),m_rect.top()/2 + margin()/2);
140 }
145 }
141
146
142 //recalculate background gradient
147 //recalculate background gradient
143 if (m_backgroundItem) {
148 if (m_backgroundItem) {
144 m_backgroundItem->setRect(rect);
149 m_backgroundItem->setRect(rect);
145 }
150 }
146
151
147 QGraphicsWidget::resizeEvent(event);
152 QGraphicsWidget::resizeEvent(event);
148 update();
153 update();
149 }
154 }
150
155
151 #include "moc_qchart.cpp"
156 #include "moc_qchart.cpp"
152
157
153 QTCOMMERCIALCHART_END_NAMESPACE
158 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,84 +1,85
1 #ifndef CHART_H
1 #ifndef CHART_H
2 #define CHART_H
2 #define CHART_H
3
3
4 #include <qchartglobal.h>
4 #include <qchartglobal.h>
5 #include <qchartseries.h>
5 #include <qchartseries.h>
6 #include <QGraphicsWidget>
6 #include <QGraphicsWidget>
7 #include <QLinearGradient>
7 #include <QLinearGradient>
8 #include <QFont>
8 #include <QFont>
9
9
10 class QGraphicsSceneResizeEvent;
10 class QGraphicsSceneResizeEvent;
11
11
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13
13
14 class AxisItem;
14 class AxisItem;
15 class QChartSeries;
15 class QChartSeries;
16 class PlotDomain;
16 class PlotDomain;
17 class BarPresenter;
17 class BarPresenter;
18 class QChartAxis;
18 class QChartAxis;
19 class ChartTheme;
19 class ChartTheme;
20 class ChartItem;
20 class ChartItem;
21 class ChartDataSet;
21 class ChartDataSet;
22 class ChartPresenter;
22 class ChartPresenter;
23
23
24 /*!
24 /*!
25 * TODO: define the responsibilities
25 * TODO: define the responsibilities
26 */
26 */
27 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
27 class QTCOMMERCIALCHART_EXPORT QChart : public QGraphicsWidget
28 {
28 {
29 Q_OBJECT
29 Q_OBJECT
30 public:
30 public:
31 enum ChartTheme {
31 enum ChartTheme {
32 /*! The default theme follows the GUI style of the Operating System */
32 /*! The default theme follows the GUI style of the Operating System */
33 ChartThemeDefault,
33 ChartThemeDefault,
34 ChartThemeVanilla,
34 ChartThemeVanilla,
35 ChartThemeIcy,
35 ChartThemeIcy,
36 ChartThemeGrayscale,
36 ChartThemeGrayscale,
37 ChartThemeScientific,
37 ChartThemeScientific,
38 //ChartThemeUnnamed1
38 //ChartThemeUnnamed1
39 };
39 };
40
40
41 public:
41 public:
42 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
42 QChart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
43 ~QChart();
43 ~QChart();
44
44
45 void addSeries(QChartSeries* series,QChartAxis *axisY=0);
45 void addSeries(QChartSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership
46 void removeSeries(QChartSeries* series);
46 void removeSeries(QChartSeries* series); //returns ownership , deletes axis if no series attached
47 void removeAllSeries(); // deletes series and axis
47
48
48 void setMargin(int margin);
49 void setMargin(int margin);
49 int margin() const;
50 int margin() const;
50 void setChartTheme(QChart::ChartTheme theme);
51 void setChartTheme(QChart::ChartTheme theme);
51 QChart::ChartTheme chartTheme() const;
52 QChart::ChartTheme chartTheme() const;
52
53
53 void setChartTitle(const QString& title);
54 void setChartTitle(const QString& title);
54 void setChartTitleFont(const QFont& font);
55 void setChartTitleFont(const QFont& font);
55 void setChartBackgroundBrush(const QBrush& brush);
56 void setChartBackgroundBrush(const QBrush& brush);
56 void setChartBackgroundPen(const QPen& pen);
57 void setChartBackgroundPen(const QPen& pen);
57
58
58 void zoomIn();
59 void zoomIn();
59 void zoomIn(const QRectF& rect);
60 void zoomIn(const QRectF& rect);
60 void zoomOut();
61 void zoomOut();
61 void zoomReset();
62 void zoomReset();
62
63
63 QChartAxis* axisX() const;
64 QChartAxis* axisX() const;
64 QChartAxis* axisY() const;
65 QChartAxis* axisY() const;
65
66
66 protected:
67 protected:
67 void resizeEvent(QGraphicsSceneResizeEvent *event);
68 void resizeEvent(QGraphicsSceneResizeEvent *event);
68
69
69 private:
70 private:
70 inline void createChartBackgroundItem();
71 inline void createChartBackgroundItem();
71 inline void createChartTitleItem();
72 inline void createChartTitleItem();
72
73
73 private:
74 private:
74 Q_DISABLE_COPY(QChart)
75 Q_DISABLE_COPY(QChart)
75 QGraphicsRectItem* m_backgroundItem;
76 QGraphicsRectItem* m_backgroundItem;
76 QGraphicsTextItem* m_titleItem;
77 QGraphicsTextItem* m_titleItem;
77 QRectF m_rect;
78 QRectF m_rect;
78 ChartDataSet *m_dataset;
79 ChartDataSet *m_dataset;
79 ChartPresenter *m_presenter;
80 ChartPresenter *m_presenter;
80 };
81 };
81
82
82 QTCOMMERCIALCHART_END_NAMESPACE
83 QTCOMMERCIALCHART_END_NAMESPACE
83
84
84 #endif
85 #endif
@@ -1,221 +1,226
1 #include "qchartview.h"
1 #include "qchartview.h"
2 #include "qchart.h"
2 #include "qchart.h"
3 #include "qchartaxis.h"
3 #include "qchartaxis.h"
4 #include <QGraphicsView>
4 #include <QGraphicsView>
5 #include <QGraphicsScene>
5 #include <QGraphicsScene>
6 #include <QRubberBand>
6 #include <QRubberBand>
7 #include <QResizeEvent>
7 #include <QResizeEvent>
8 #include <QDebug>
8 #include <QDebug>
9
9
10 /*!
10 /*!
11 \class QChartView
11 \class QChartView
12 \brief Chart widget.
12 \brief Chart widget.
13 */
13 */
14
14
15 QTCOMMERCIALCHART_BEGIN_NAMESPACE
15 QTCOMMERCIALCHART_BEGIN_NAMESPACE
16
16
17 QChartView::QChartView(QWidget *parent) :
17 QChartView::QChartView(QWidget *parent) :
18 QGraphicsView(parent),
18 QGraphicsView(parent),
19 m_scene(new QGraphicsScene(this)),
19 m_scene(new QGraphicsScene(this)),
20 m_chart(new QChart()),
20 m_chart(new QChart()),
21 m_rubberBand(0),
21 m_rubberBand(0),
22 m_verticalRubberBand(false),
22 m_verticalRubberBand(false),
23 m_horizonalRubberBand(false)
23 m_horizonalRubberBand(false)
24 {
24 {
25 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
25 setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
26 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
26 setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
27 setScene(m_scene);
27 setScene(m_scene);
28 m_chart->setMargin(50);
28 m_chart->setMargin(50);
29 m_scene->addItem(m_chart);
29 m_scene->addItem(m_chart);
30 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
30 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
31 }
31 }
32
32
33 QChartView::~QChartView()
33 QChartView::~QChartView()
34 {
34 {
35 }
35 }
36
36
37 void QChartView::resizeEvent(QResizeEvent *event)
37 void QChartView::resizeEvent(QResizeEvent *event)
38 {
38 {
39 m_scene->setSceneRect(0,0,size().width(),size().height());
39 m_scene->setSceneRect(0,0,size().width(),size().height());
40 m_chart->resize(size());
40 m_chart->resize(size());
41 QWidget::resizeEvent(event);
41 QWidget::resizeEvent(event);
42 }
42 }
43
43
44 void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY)
44 void QChartView::addSeries(QChartSeries* series,QChartAxis *axisY)
45 {
45 {
46 m_chart->addSeries(series,axisY);
46 m_chart->addSeries(series,axisY);
47 }
47 }
48
48
49 void QChartView::removeSeries(QChartSeries* series)
49 void QChartView::removeSeries(QChartSeries* series)
50 {
50 {
51 m_chart->removeSeries(series);
51 m_chart->removeSeries(series);
52 }
52 }
53
53
54 void QChartView::removeAllSeries()
55 {
56 m_chart->removeAllSeries();
57 }
58
54 void QChartView::zoomIn()
59 void QChartView::zoomIn()
55 {
60 {
56 m_chart->zoomIn();
61 m_chart->zoomIn();
57 }
62 }
58
63
59 void QChartView::zoomIn(const QRect& rect)
64 void QChartView::zoomIn(const QRect& rect)
60 {
65 {
61 m_chart->zoomIn(rect);
66 m_chart->zoomIn(rect);
62 }
67 }
63
68
64 void QChartView::zoomOut()
69 void QChartView::zoomOut()
65 {
70 {
66 m_chart->zoomOut();
71 m_chart->zoomOut();
67 }
72 }
68
73
69 int QChartView::margin() const
74 int QChartView::margin() const
70 {
75 {
71 return m_chart->margin();
76 return m_chart->margin();
72 }
77 }
73
78
74 void QChartView::setChartTitle(const QString& title)
79 void QChartView::setChartTitle(const QString& title)
75 {
80 {
76 m_chart->setChartTitle(title);
81 m_chart->setChartTitle(title);
77 }
82 }
78
83
79 void QChartView::setChartTitleFont(const QFont& font)
84 void QChartView::setChartTitleFont(const QFont& font)
80 {
85 {
81 m_chart->setChartTitleFont(font);
86 m_chart->setChartTitleFont(font);
82 }
87 }
83
88
84 void QChartView::setChartBackgroundBrush(const QBrush& brush)
89 void QChartView::setChartBackgroundBrush(const QBrush& brush)
85 {
90 {
86 m_chart->setChartBackgroundBrush(brush);
91 m_chart->setChartBackgroundBrush(brush);
87 }
92 }
88 void QChartView::setChartBackgroundPen(const QPen& pen)
93 void QChartView::setChartBackgroundPen(const QPen& pen)
89 {
94 {
90 m_chart->setChartBackgroundPen(pen);
95 m_chart->setChartBackgroundPen(pen);
91 }
96 }
92
97
93 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
98 void QChartView::setRubberBandPolicy(const RubberBandPolicy policy)
94 {
99 {
95 switch(policy) {
100 switch(policy) {
96 case VerticalRubberBand:
101 case VerticalRubberBand:
97 m_verticalRubberBand = true;
102 m_verticalRubberBand = true;
98 m_horizonalRubberBand = false;
103 m_horizonalRubberBand = false;
99 break;
104 break;
100 case HorizonalRubberBand:
105 case HorizonalRubberBand:
101 m_verticalRubberBand = false;
106 m_verticalRubberBand = false;
102 m_horizonalRubberBand = true;
107 m_horizonalRubberBand = true;
103 break;
108 break;
104 case RectangleRubberBand:
109 case RectangleRubberBand:
105 m_verticalRubberBand = true;
110 m_verticalRubberBand = true;
106 m_horizonalRubberBand = true;
111 m_horizonalRubberBand = true;
107 break;
112 break;
108 case NoRubberBand:
113 case NoRubberBand:
109 default:
114 default:
110 delete m_rubberBand;
115 delete m_rubberBand;
111 m_rubberBand=0;
116 m_rubberBand=0;
112 m_horizonalRubberBand = false;
117 m_horizonalRubberBand = false;
113 m_verticalRubberBand = false;
118 m_verticalRubberBand = false;
114 return;
119 return;
115 }
120 }
116 if(!m_rubberBand) {
121 if(!m_rubberBand) {
117 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
122 m_rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
118 m_rubberBand->setEnabled(true);
123 m_rubberBand->setEnabled(true);
119 }
124 }
120 }
125 }
121
126
122 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
127 QChartView::RubberBandPolicy QChartView::rubberBandPolicy() const
123 {
128 {
124 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
129 if(m_horizonalRubberBand && m_verticalRubberBand) return RectangleRubberBand;
125 if(m_horizonalRubberBand) return HorizonalRubberBand;
130 if(m_horizonalRubberBand) return HorizonalRubberBand;
126 if(m_verticalRubberBand) return VerticalRubberBand;
131 if(m_verticalRubberBand) return VerticalRubberBand;
127 return NoRubberBand;
132 return NoRubberBand;
128 }
133 }
129
134
130 void QChartView::mousePressEvent(QMouseEvent *event)
135 void QChartView::mousePressEvent(QMouseEvent *event)
131 {
136 {
132 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
137 if(m_rubberBand && m_rubberBand->isEnabled() && event->button() == Qt::LeftButton) {
133
138
134 int margin = m_chart->margin();
139 int margin = m_chart->margin();
135 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
140 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
136
141
137 if (rect.contains(event->pos())) {
142 if (rect.contains(event->pos())) {
138 m_rubberBandOrigin = event->pos();
143 m_rubberBandOrigin = event->pos();
139 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
144 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin, QSize()));
140 m_rubberBand->show();
145 m_rubberBand->show();
141 event->accept();
146 event->accept();
142 }
147 }
143 }
148 }
144 }
149 }
145
150
146 void QChartView::mouseMoveEvent(QMouseEvent *event)
151 void QChartView::mouseMoveEvent(QMouseEvent *event)
147 {
152 {
148 if(m_rubberBand && m_rubberBand->isVisible()) {
153 if(m_rubberBand && m_rubberBand->isVisible()) {
149 int margin = m_chart->margin();
154 int margin = m_chart->margin();
150 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
155 QRect rect(margin, margin, width() - 2 * margin, height() - 2 * margin);
151 int width = event->pos().x() - m_rubberBandOrigin.x();
156 int width = event->pos().x() - m_rubberBandOrigin.x();
152 int height = event->pos().y() - m_rubberBandOrigin.y();
157 int height = event->pos().y() - m_rubberBandOrigin.y();
153 if(!m_verticalRubberBand) {
158 if(!m_verticalRubberBand) {
154 m_rubberBandOrigin.setY(rect.top());
159 m_rubberBandOrigin.setY(rect.top());
155 height = rect.height();
160 height = rect.height();
156 }
161 }
157 if(!m_horizonalRubberBand) {
162 if(!m_horizonalRubberBand) {
158 m_rubberBandOrigin.setX(rect.left());
163 m_rubberBandOrigin.setX(rect.left());
159 width= rect.width();
164 width= rect.width();
160 }
165 }
161 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
166 m_rubberBand->setGeometry(QRect(m_rubberBandOrigin.x(),m_rubberBandOrigin.y(), width,height).normalized());
162 }
167 }
163 else {
168 else {
164 QGraphicsView::mouseMoveEvent(event);
169 QGraphicsView::mouseMoveEvent(event);
165 }
170 }
166 }
171 }
167
172
168 void QChartView::mouseReleaseEvent(QMouseEvent *event)
173 void QChartView::mouseReleaseEvent(QMouseEvent *event)
169 {
174 {
170 if(m_rubberBand) {
175 if(m_rubberBand) {
171 if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
176 if (event->button() == Qt::LeftButton && m_rubberBand->isVisible()) {
172 m_rubberBand->hide();
177 m_rubberBand->hide();
173 QRect rect = m_rubberBand->geometry();
178 QRect rect = m_rubberBand->geometry();
174 m_chart->zoomIn(rect);
179 m_chart->zoomIn(rect);
175 event->accept();
180 event->accept();
176 }
181 }
177
182
178 if(event->button()==Qt::RightButton)
183 if(event->button()==Qt::RightButton)
179 m_chart->zoomReset();
184 m_chart->zoomReset();
180 }
185 }
181 else {
186 else {
182 QGraphicsView::mouseReleaseEvent(event);
187 QGraphicsView::mouseReleaseEvent(event);
183 }
188 }
184 }
189 }
185
190
186 void QChartView::keyPressEvent(QKeyEvent *event)
191 void QChartView::keyPressEvent(QKeyEvent *event)
187 {
192 {
188 switch (event->key()) {
193 switch (event->key()) {
189 case Qt::Key_Plus:
194 case Qt::Key_Plus:
190 zoomIn();
195 zoomIn();
191 break;
196 break;
192 case Qt::Key_Minus:
197 case Qt::Key_Minus:
193 zoomOut();
198 zoomOut();
194 break;
199 break;
195 default:
200 default:
196 QGraphicsView::keyPressEvent(event);
201 QGraphicsView::keyPressEvent(event);
197 break;
202 break;
198 }
203 }
199 }
204 }
200
205
201 void QChartView::setChartTheme(QChart::ChartTheme theme)
206 void QChartView::setChartTheme(QChart::ChartTheme theme)
202 {
207 {
203 m_chart->setChartTheme(theme);
208 m_chart->setChartTheme(theme);
204 }
209 }
205
210
206 QChart::ChartTheme QChartView::chartTheme() const
211 QChart::ChartTheme QChartView::chartTheme() const
207 {
212 {
208 return m_chart->chartTheme();
213 return m_chart->chartTheme();
209 }
214 }
210
215
211 QChartAxis* QChartView::axisX() const
216 QChartAxis* QChartView::axisX() const
212 {
217 {
213 return m_chart->axisX();
218 return m_chart->axisX();
214 }
219 }
215
220
216 QChartAxis* QChartView::axisY() const
221 QChartAxis* QChartView::axisY() const
217 {
222 {
218 return m_chart->axisY();
223 return m_chart->axisY();
219 }
224 }
220
225
221 QTCOMMERCIALCHART_END_NAMESPACE
226 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,70 +1,71
1 #ifndef QCHARTWIDGET_H
1 #ifndef QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
2 #define QCHARTWIDGET_H
3
3
4 #include "qchartglobal.h"
4 #include "qchartglobal.h"
5 #include "qchartseries.h"
5 #include "qchartseries.h"
6 #include "qchart.h"
6 #include "qchart.h"
7 #include <QGraphicsView>
7 #include <QGraphicsView>
8
8
9 class QGraphicsScene;
9 class QGraphicsScene;
10 class QRubberBand;
10 class QRubberBand;
11
11
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
12 QTCOMMERCIALCHART_BEGIN_NAMESPACE
13
13
14 class QChart;
14 class QChart;
15
15
16 class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView
16 class QTCOMMERCIALCHART_EXPORT QChartView : public QGraphicsView
17 {
17 {
18 public:
18 public:
19 enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand };
19 enum RubberBandPolicy { NoRubberBand, VerticalRubberBand, HorizonalRubberBand, RectangleRubberBand };
20
20
21 explicit QChartView(QWidget *parent = 0);
21 explicit QChartView(QWidget *parent = 0);
22 ~QChartView();
22 ~QChartView();
23
23
24 //implement from QWidget
24 //implement from QWidget
25 void resizeEvent(QResizeEvent *event);
25 void resizeEvent(QResizeEvent *event);
26
26
27 void addSeries(QChartSeries* series,QChartAxis* axisY=0);// takes ownership
27 void addSeries(QChartSeries* series,QChartAxis* axisY=0);// takes series ownership , takes axis ownership
28 void removeSeries(QChartSeries* series);
28 void removeSeries(QChartSeries* series); //returns ownership , deletes axis if no series attached
29 void removeAllSeries(); // deletes series and axis
29 int margin() const;
30 int margin() const;
30
31
31 void setChartTitle(const QString& title);
32 void setChartTitle(const QString& title);
32 void setChartTitleFont(const QFont& font);
33 void setChartTitleFont(const QFont& font);
33 void setChartBackgroundBrush(const QBrush& brush);
34 void setChartBackgroundBrush(const QBrush& brush);
34 void setChartBackgroundPen(const QPen& pen);
35 void setChartBackgroundPen(const QPen& pen);
35
36
36 void zoomIn();
37 void zoomIn();
37 void zoomIn(const QRect& rect);
38 void zoomIn(const QRect& rect);
38 void zoomOut();
39 void zoomOut();
39
40
40 void setRubberBandPolicy(const RubberBandPolicy );
41 void setRubberBandPolicy(const RubberBandPolicy );
41 RubberBandPolicy rubberBandPolicy() const;
42 RubberBandPolicy rubberBandPolicy() const;
42
43
43 void setChartTheme(QChart::ChartTheme theme);
44 void setChartTheme(QChart::ChartTheme theme);
44 QChart::ChartTheme chartTheme() const;
45 QChart::ChartTheme chartTheme() const;
45
46
46 QChartAxis* axisX() const;
47 QChartAxis* axisX() const;
47 QChartAxis* axisY() const;
48 QChartAxis* axisY() const;
48
49
49 protected:
50 protected:
50 void mousePressEvent(QMouseEvent *event);
51 void mousePressEvent(QMouseEvent *event);
51 void mouseMoveEvent(QMouseEvent *event);
52 void mouseMoveEvent(QMouseEvent *event);
52 void mouseReleaseEvent(QMouseEvent *event);
53 void mouseReleaseEvent(QMouseEvent *event);
53 void keyPressEvent(QKeyEvent *event);
54 void keyPressEvent(QKeyEvent *event);
54
55
55
56
56 private:
57 private:
57 QGraphicsScene *m_scene;
58 QGraphicsScene *m_scene;
58 QChart* m_chart;
59 QChart* m_chart;
59 QPoint m_rubberBandOrigin;
60 QPoint m_rubberBandOrigin;
60 QRubberBand* m_rubberBand;
61 QRubberBand* m_rubberBand;
61 bool m_verticalRubberBand;
62 bool m_verticalRubberBand;
62 bool m_horizonalRubberBand;
63 bool m_horizonalRubberBand;
63 Q_DISABLE_COPY(QChartView)
64 Q_DISABLE_COPY(QChartView)
64
65
65
66
66 };
67 };
67
68
68 QTCOMMERCIALCHART_END_NAMESPACE
69 QTCOMMERCIALCHART_END_NAMESPACE
69
70
70 #endif // QCHARTWIDGET_H
71 #endif // QCHARTWIDGET_H
@@ -1,528 +1,599
1 #include <QtTest/QtTest>
1 #include <QtTest/QtTest>
2 #include <qchartaxis.h>
2 #include <qchartaxis.h>
3 #include <qchartseries.h>
3 #include <qchartseries.h>
4 #include <qlinechartseries.h>
4 #include <qlinechartseries.h>
5 #include <private/chartdataset_p.h>
5 #include <private/chartdataset_p.h>
6 #include <private/domain_p.h>
6 #include <private/domain_p.h>
7
7
8 QTCOMMERCIALCHART_USE_NAMESPACE
8 QTCOMMERCIALCHART_USE_NAMESPACE
9
9
10 Q_DECLARE_METATYPE(Domain)
10 Q_DECLARE_METATYPE(Domain)
11 Q_DECLARE_METATYPE(QChartAxis*)
11 Q_DECLARE_METATYPE(QChartAxis*)
12 Q_DECLARE_METATYPE(QChartSeries*)
12 Q_DECLARE_METATYPE(QChartSeries*)
13 Q_DECLARE_METATYPE(QLineChartSeries*)
13 Q_DECLARE_METATYPE(QLineChartSeries*)
14
14
15 class tst_ChartDataSet: public QObject {
15 class tst_ChartDataSet: public QObject {
16 Q_OBJECT
16 Q_OBJECT
17
17
18 public slots:
18 public slots:
19 void initTestCase();
19 void initTestCase();
20 void cleanupTestCase();
20 void cleanupTestCase();
21 void init();
21 void init();
22 void cleanup();
22 void cleanup();
23
23
24 private slots:
24 private slots:
25 void chartdataset_data();
25 void chartdataset_data();
26 void chartdataset();
26 void chartdataset();
27
27
28 void addDomain_data();
28 void addDomain_data();
29 void addDomain();
29 void addDomain();
30 void addSeries_data();
30 void addSeries_data();
31 void addSeries();
31 void addSeries();
32 void axisY_data();
32 void axisY_data();
33 void axisY();
33 void axisY();
34 void clearDomains_data();
34 void clearDomains_data();
35 void clearDomains();
35 void clearDomains();
36 void domain_data();
36 void domain_data();
37 void domain();
37 void domain();
38 void nextpreviousDomain_data();
38 void nextpreviousDomain_data();
39 void nextpreviousDomain();
39 void nextpreviousDomain();
40 void removeSeries_data();
40 void removeSeries_data();
41 void removeSeries();
41 void removeSeries();
42 void removeAllSeries_data();
43 void removeAllSeries();
42 };
44 };
43
45
44 void tst_ChartDataSet::initTestCase()
46 void tst_ChartDataSet::initTestCase()
45 {
47 {
46 qRegisterMetaType<Domain>("Domain");
48 qRegisterMetaType<Domain>("Domain");
47 qRegisterMetaType<QChartAxis*>();
49 qRegisterMetaType<QChartAxis*>();
48 qRegisterMetaType<QChartSeries*>();
50 qRegisterMetaType<QChartSeries*>();
49 }
51 }
50
52
51 void tst_ChartDataSet::cleanupTestCase()
53 void tst_ChartDataSet::cleanupTestCase()
52 {
54 {
53 }
55 }
54
56
55 void tst_ChartDataSet::init()
57 void tst_ChartDataSet::init()
56 {
58 {
57 }
59 }
58
60
59 void tst_ChartDataSet::cleanup()
61 void tst_ChartDataSet::cleanup()
60 {
62 {
61 }
63 }
62
64
63 void tst_ChartDataSet::chartdataset_data()
65 void tst_ChartDataSet::chartdataset_data()
64 {
66 {
65 }
67 }
66
68
67 void tst_ChartDataSet::chartdataset()
69 void tst_ChartDataSet::chartdataset()
68 {
70 {
69 ChartDataSet dataSet;
71 ChartDataSet dataSet;
70 QVERIFY2(dataSet.axisX(), "Missing axisX.");
72 QVERIFY2(dataSet.axisX(), "Missing axisX.");
71 QVERIFY2(dataSet.axisY(), "Missing axisY.");
73 QVERIFY2(dataSet.axisY(), "Missing axisY.");
72 //check if not dangling pointer
74 //check if not dangling pointer
73 dataSet.axisX()->objectName();
75 dataSet.axisX()->objectName();
74 dataSet.axisY()->objectName();
76 dataSet.axisY()->objectName();
75 QVERIFY(dataSet.domain(dataSet.axisX())==Domain());
77 QVERIFY(dataSet.domain(dataSet.axisX())==Domain());
76 QVERIFY(dataSet.domain(dataSet.axisY())==Domain());
78 QVERIFY(dataSet.domain(dataSet.axisY())==Domain());
77 QCOMPARE(dataSet.domainIndex(), 0);
79 QCOMPARE(dataSet.domainIndex(), 0);
78 }
80 }
79
81
80 void tst_ChartDataSet::addDomain_data()
82 void tst_ChartDataSet::addDomain_data()
81 {
83 {
82 QTest::addColumn<QRectF>("rect");
84 QTest::addColumn<QRectF>("rect");
83 QTest::addColumn<QRectF>("viewport");
85 QTest::addColumn<QRectF>("viewport");
84 QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600)
86 QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600)
85 << QRectF(0, 0, 1000, 1000);
87 << QRectF(0, 0, 1000, 1000);
86 QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700)
88 QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700)
87 << QRectF(0, 0, 1000, 1000);
89 << QRectF(0, 0, 1000, 1000);
88 QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600)
90 QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600)
89 << QRectF(0, 0, 1000, 1000);
91 << QRectF(0, 0, 1000, 1000);
90 }
92 }
91
93
92 void tst_ChartDataSet::addDomain()
94 void tst_ChartDataSet::addDomain()
93 {
95 {
94 QFETCH(QRectF, rect);
96 QFETCH(QRectF, rect);
95 QFETCH(QRectF, viewport);
97 QFETCH(QRectF, viewport);
96
98
97 ChartDataSet dataSet;
99 ChartDataSet dataSet;
98
100
99 Domain domain1(0, 1000, 0, 1000);
101 Domain domain1(0, 1000, 0, 1000);
100 QLineChartSeries series;
102 QLineChartSeries series;
101 series.add(0, 0);
103 series.add(0, 0);
102 series.add(1000, 1000);
104 series.add(1000, 1000);
103
105
104 dataSet.addSeries(&series);
106 dataSet.addSeries(&series);
105
107
106 QCOMPARE(dataSet.domainIndex(), 0);
108 QCOMPARE(dataSet.domainIndex(), 0);
107
109
108 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
110 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
109 QSignalSpy spy1(&dataSet,
111 QSignalSpy spy1(&dataSet,
110 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
112 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
111 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
113 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
112 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
114 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
113 QSignalSpy spy4(&dataSet,
115 QSignalSpy spy4(&dataSet,
114 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
116 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
115 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
117 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
116
118
117 Domain domain2 = dataSet.domain(dataSet.axisY());
119 Domain domain2 = dataSet.domain(dataSet.axisY());
118 QVERIFY(domain1 == domain2);
120 QVERIFY(domain1 == domain2);
119
121
120 dataSet.addDomain(rect, viewport);
122 dataSet.addDomain(rect, viewport);
121 QCOMPARE(dataSet.domainIndex(), 1);
123 QCOMPARE(dataSet.domainIndex(), 1);
122 Domain domain3 = dataSet.domain(dataSet.axisY());
124 Domain domain3 = dataSet.domain(dataSet.axisY());
123 Domain domain4 = domain1.subDomain(rect, viewport.width(),
125 Domain domain4 = domain1.subDomain(rect, viewport.width(),
124 viewport.height());
126 viewport.height());
125 QVERIFY(domain3 == domain4);
127 QVERIFY(domain3 == domain4);
126
128
127 QCOMPARE(spy0.count(), 0);
129 QCOMPARE(spy0.count(), 0);
128 QCOMPARE(spy1.count(), 2);
130 QCOMPARE(spy1.count(), 2);
129 QCOMPARE(spy2.count(), 0);
131 QCOMPARE(spy2.count(), 0);
130 QCOMPARE(spy3.count(), 0);
132 QCOMPARE(spy3.count(), 0);
131 QCOMPARE(spy4.count(), 1);
133 QCOMPARE(spy4.count(), 1);
132 QCOMPARE(spy5.count(), 0);
134 QCOMPARE(spy5.count(), 0);
133 }
135 }
134
136
135 void tst_ChartDataSet::addSeries_data()
137 void tst_ChartDataSet::addSeries_data()
136 {
138 {
137 QTest::addColumn<int>("seriesCount");
139 QTest::addColumn<int>("seriesCount");
138 QTest::addColumn<int>("axisYCount");
140 QTest::addColumn<int>("axisYCount");
139 QTest::newRow("2 series, default axis") << 2 << 0;
141 QTest::newRow("2 series, default axis") << 2 << 0;
140 QTest::newRow("2 series, 2 new axis") << 2 << 2;
142 QTest::newRow("2 series, 2 new axis") << 2 << 2;
141 QTest::newRow("2 series, 1 new axis") << 2 << 2;
143 QTest::newRow("2 series, 1 new axis") << 2 << 2;
142 QTest::newRow("3 series, 3 new axis") << 3 << 3;
144 QTest::newRow("3 series, 3 new axis") << 3 << 3;
143 QTest::newRow("3 series, 2 new axis") << 3 << 2;
145 QTest::newRow("3 series, 2 new axis") << 3 << 2;
144 QTest::newRow("3 series, 1 new axis") << 3 << 1;
146 QTest::newRow("3 series, 1 new axis") << 3 << 1;
145 }
147 }
146
148
147 void tst_ChartDataSet::addSeries()
149 void tst_ChartDataSet::addSeries()
148 {
150 {
149 QFETCH(int, seriesCount);
151 QFETCH(int, seriesCount);
150 QFETCH(int, axisYCount);
152 QFETCH(int, axisYCount);
151
153
152 ChartDataSet dataSet;
154 ChartDataSet dataSet;
153
155
154 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
156 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
155 QSignalSpy spy1(&dataSet,
157 QSignalSpy spy1(&dataSet,
156 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
158 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
157 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
159 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
158 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
160 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
159 QSignalSpy spy4(&dataSet,
161 QSignalSpy spy4(&dataSet,
160 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
162 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
161 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
163 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
162
164
163 QList<QChartAxis*> axisList;
165 QList<QChartAxis*> axisList;
164
166
165 for (int i = 0; i < axisYCount; i++) {
167 for (int i = 0; i < axisYCount; i++) {
166 QChartAxis* axis = new QChartAxis();
168 QChartAxis* axis = new QChartAxis();
167 axisList << axis;
169 axisList << axis;
168 }
170 }
169
171
170 QList<QChartAxis*>::iterator iterator = axisList.begin();
172 QList<QChartAxis*>::iterator iterator = axisList.begin();
171
173
172 for (int i = 0; i < seriesCount; i++) {
174 for (int i = 0; i < seriesCount; i++) {
173 QChartAxis* axisY = 0;
175 QChartAxis* axisY = 0;
174 QLineChartSeries* series = new QLineChartSeries();
176 QLineChartSeries* series = new QLineChartSeries();
175 if (iterator != axisList.end()) {
177 if (iterator != axisList.end()) {
176 axisY = *iterator;
178 axisY = *iterator;
177 iterator++;
179 iterator++;
178 } else if (axisList.count() > 0) {
180 } else if (axisList.count() > 0) {
179 iterator--;
181 iterator--;
180 axisY = *iterator;
182 axisY = *iterator;
181 iterator++;
183 iterator++;
182 }
184 }
183 dataSet.addSeries(series, axisY);
185 dataSet.addSeries(series, axisY);
184 }
186 }
185
187
186 //default axis
188 //default axis
187 if (axisYCount == 0)
189 if (axisYCount == 0)
188 axisYCount+=2;
190 axisYCount+=2;
189 else
191 else
190 axisYCount++;
192 axisYCount++;
191
193
192
193
194 QCOMPARE(spy0.count(), axisYCount);
194 QCOMPARE(spy0.count(), axisYCount);
195 QCOMPARE(spy1.count(), seriesCount*2);
195 QCOMPARE(spy1.count(), seriesCount*2);
196 QCOMPARE(spy2.count(), 0);
196 QCOMPARE(spy2.count(), 0);
197 QCOMPARE(spy3.count(), seriesCount);
197 QCOMPARE(spy3.count(), seriesCount);
198 QCOMPARE(spy4.count(), seriesCount);
198 QCOMPARE(spy4.count(), seriesCount);
199 QCOMPARE(spy5.count(), 0);
199 QCOMPARE(spy5.count(), 0);
200
200
201 QCOMPARE(dataSet.domainIndex(), 0);
201 QCOMPARE(dataSet.domainIndex(), 0);
202 }
202 }
203
203
204 void tst_ChartDataSet::axisY_data()
204 void tst_ChartDataSet::axisY_data()
205 {
205 {
206 QTest::addColumn<QChartAxis*>("axisY");
206 QTest::addColumn<QChartAxis*>("axisY");
207 QTest::newRow("axisY1") << new QChartAxis();
207 QTest::newRow("axisY1") << new QChartAxis();
208 QTest::newRow("axisY2") << new QChartAxis();
208 QTest::newRow("axisY2") << new QChartAxis();
209 }
209 }
210
210
211 void tst_ChartDataSet::axisY()
211 void tst_ChartDataSet::axisY()
212 {
212 {
213 QFETCH(QChartAxis*, axisY);
213 QFETCH(QChartAxis*, axisY);
214
214
215 ChartDataSet dataSet;
215 ChartDataSet dataSet;
216
216
217 QChartAxis* defaultAxisY = dataSet.axisY();
217 QChartAxis* defaultAxisY = dataSet.axisY();
218
218
219 QVERIFY2(defaultAxisY, "Missing axisY.");
219 QVERIFY2(defaultAxisY, "Missing axisY.");
220
220
221 QLineChartSeries* series1 = new QLineChartSeries();
221 QLineChartSeries* series1 = new QLineChartSeries();
222 dataSet.addSeries(series1);
222 dataSet.addSeries(series1);
223
223
224 QLineChartSeries* series2 = new QLineChartSeries();
224 QLineChartSeries* series2 = new QLineChartSeries();
225 dataSet.addSeries(series2, axisY);
225 dataSet.addSeries(series2, axisY);
226
226
227 QVERIFY(dataSet.axisY(series1) == defaultAxisY);
227 QVERIFY(dataSet.axisY(series1) == defaultAxisY);
228 QVERIFY(dataSet.axisY(series2) == axisY);
228 QVERIFY(dataSet.axisY(series2) == axisY);
229
229
230
230
231 }
231 }
232
232
233 void tst_ChartDataSet::clearDomains_data()
233 void tst_ChartDataSet::clearDomains_data()
234 {
234 {
235 QTest::addColumn<int>("indexCount");
235 QTest::addColumn<int>("indexCount");
236 QTest::newRow("0") << 0;
236 QTest::newRow("0") << 0;
237 QTest::newRow("1") << 1;
237 QTest::newRow("1") << 1;
238 QTest::newRow("5") << 2;
238 QTest::newRow("5") << 2;
239 QTest::newRow("8") << 3;
239 QTest::newRow("8") << 3;
240 }
240 }
241
241
242 void tst_ChartDataSet::clearDomains()
242 void tst_ChartDataSet::clearDomains()
243 {
243 {
244 QFETCH(int, indexCount);
244 QFETCH(int, indexCount);
245
245
246 Domain domain1(0, 100, 0, 100);
246 Domain domain1(0, 100, 0, 100);
247 QLineChartSeries* series = new QLineChartSeries();
247 QLineChartSeries* series = new QLineChartSeries();
248 series->add(0, 0);
248 series->add(0, 0);
249 series->add(100, 100);
249 series->add(100, 100);
250
250
251 ChartDataSet dataSet;
251 ChartDataSet dataSet;
252
252
253 QCOMPARE(dataSet.domainIndex(), 0);
253 QCOMPARE(dataSet.domainIndex(), 0);
254
254
255 dataSet.addSeries(series);
255 dataSet.addSeries(series);
256
256
257 Domain domain2 = dataSet.domain(dataSet.axisY());
257 Domain domain2 = dataSet.domain(dataSet.axisY());
258
258
259 QVERIFY(domain2 == domain1);
259 QVERIFY(domain2 == domain1);
260
260
261 QList<Domain> domains;
261 QList<Domain> domains;
262
262
263 domains << domain1;
263 domains << domain1;
264
264
265 for (int i = 0; i < indexCount; i++) {
265 for (int i = 0; i < indexCount; i++) {
266 dataSet.addDomain(QRect(0, 0, 10, 10), QRect(0, 0, 100, 100));
266 dataSet.addDomain(QRect(0, 0, 10, 10), QRect(0, 0, 100, 100));
267 domains << dataSet.domain(dataSet.axisY());
267 domains << dataSet.domain(dataSet.axisY());
268 }
268 }
269
269
270 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
270 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
271 QSignalSpy spy1(&dataSet,
271 QSignalSpy spy1(&dataSet,
272 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
272 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
273 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
273 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
274 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
274 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
275 QSignalSpy spy4(&dataSet,
275 QSignalSpy spy4(&dataSet,
276 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
276 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
277 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
277 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
278
278
279 dataSet.clearDomains(indexCount);
279 dataSet.clearDomains(indexCount);
280
280
281 QCOMPARE(dataSet.domainIndex(), indexCount);
281 QCOMPARE(dataSet.domainIndex(), indexCount);
282
282
283 domain2 = dataSet.domain(dataSet.axisY());
283 domain2 = dataSet.domain(dataSet.axisY());
284
284
285 QVERIFY(domain2 == domains.at(indexCount));
285 QVERIFY(domain2 == domains.at(indexCount));
286
286
287 QCOMPARE(spy0.count(), 0);
287 QCOMPARE(spy0.count(), 0);
288 QCOMPARE(spy1.count(), 0);
288 QCOMPARE(spy1.count(), 0);
289 QCOMPARE(spy2.count(), 0);
289 QCOMPARE(spy2.count(), 0);
290 QCOMPARE(spy3.count(), 0);
290 QCOMPARE(spy3.count(), 0);
291 QCOMPARE(spy4.count(), 0);
291 QCOMPARE(spy4.count(), 0);
292 QCOMPARE(spy5.count(), 0);
292 QCOMPARE(spy5.count(), 0);
293 }
293 }
294
294
295 void tst_ChartDataSet::domain_data()
295 void tst_ChartDataSet::domain_data()
296 {
296 {
297 QTest::addColumn<Domain>("domain1");
297 QTest::addColumn<Domain>("domain1");
298 QTest::addColumn<Domain>("domain2");
298 QTest::addColumn<Domain>("domain2");
299 QTest::addColumn<Domain>("domain3");
299 QTest::addColumn<Domain>("domain3");
300 QTest::addColumn<Domain>("domain");
300 QTest::addColumn<Domain>("domain");
301 QTest::newRow("Domain(0,10,0,10)") << Domain(0, 10, 0, 10)
301 QTest::newRow("Domain(0,10,0,10)") << Domain(0, 10, 0, 10)
302 << Domain(0, 5, 0, 5) << Domain(0, 3, 0, 3) << Domain(0, 10, 0, 10);
302 << Domain(0, 5, 0, 5) << Domain(0, 3, 0, 3) << Domain(0, 10, 0, 10);
303 QTest::newRow("Domain(-1,11,0,11)") << Domain(-1, 10, 0, 10)
303 QTest::newRow("Domain(-1,11,0,11)") << Domain(-1, 10, 0, 10)
304 << Domain(0, 11, 0, 11) << Domain(0, 3, 0, 3)
304 << Domain(0, 11, 0, 11) << Domain(0, 3, 0, 3)
305 << Domain(-1, 11, 0, 11);
305 << Domain(-1, 11, 0, 11);
306 QTest::newRow("Domain(-5,5,1,8)") << Domain(-5, 0, 1, 1)
306 QTest::newRow("Domain(-5,5,1,8)") << Domain(-5, 0, 1, 1)
307 << Domain(0, 5, 0, 8) << Domain(1, 2, 1, 2) << Domain(-5, 5, 0, 8);
307 << Domain(0, 5, 0, 8) << Domain(1, 2, 1, 2) << Domain(-5, 5, 0, 8);
308 }
308 }
309
309
310 void tst_ChartDataSet::domain()
310 void tst_ChartDataSet::domain()
311 {
311 {
312 QFETCH(Domain, domain1);
312 QFETCH(Domain, domain1);
313 QFETCH(Domain, domain2);
313 QFETCH(Domain, domain2);
314 QFETCH(Domain, domain3);
314 QFETCH(Domain, domain3);
315 QFETCH(Domain, domain);
315 QFETCH(Domain, domain);
316
316
317 ChartDataSet dataSet;
317 ChartDataSet dataSet;
318 QLineChartSeries* series1 = new QLineChartSeries();
318 QLineChartSeries* series1 = new QLineChartSeries();
319 series1->add(domain1.m_minX, domain1.m_minY);
319 series1->add(domain1.m_minX, domain1.m_minY);
320 series1->add(domain1.m_maxX, domain1.m_maxY);
320 series1->add(domain1.m_maxX, domain1.m_maxY);
321 QLineChartSeries* series2 = new QLineChartSeries();
321 QLineChartSeries* series2 = new QLineChartSeries();
322 series2->add(domain2.m_minX, domain2.m_minY);
322 series2->add(domain2.m_minX, domain2.m_minY);
323 series2->add(domain2.m_maxX, domain2.m_maxY);
323 series2->add(domain2.m_maxX, domain2.m_maxY);
324 QLineChartSeries* series3 = new QLineChartSeries();
324 QLineChartSeries* series3 = new QLineChartSeries();
325 series3->add(domain3.m_minX, domain3.m_minY);
325 series3->add(domain3.m_minX, domain3.m_minY);
326 series3->add(domain3.m_maxX, domain3.m_maxY);
326 series3->add(domain3.m_maxX, domain3.m_maxY);
327
327
328 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
328 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
329 QSignalSpy spy1(&dataSet,
329 QSignalSpy spy1(&dataSet,
330 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
330 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
331 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
331 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
332 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
332 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
333 QSignalSpy spy4(&dataSet,
333 QSignalSpy spy4(&dataSet,
334 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
334 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
335 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
335 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
336
336
337 dataSet.addSeries(series1);
337 dataSet.addSeries(series1);
338 dataSet.addSeries(series2);
338 dataSet.addSeries(series2);
339 dataSet.addSeries(series3);
339 dataSet.addSeries(series3);
340
340
341 QCOMPARE(dataSet.domainIndex(), 0);
341 QCOMPARE(dataSet.domainIndex(), 0);
342 QVERIFY2(dataSet.domain(dataSet.axisY()) == domain, "Domain not equal");
342 QVERIFY2(dataSet.domain(dataSet.axisY()) == domain, "Domain not equal");
343
343
344 QCOMPARE(spy0.count(), 2);
344 QCOMPARE(spy0.count(), 2);
345 QCOMPARE(spy1.count(), 6);
345 QCOMPARE(spy1.count(), 6);
346 QCOMPARE(spy2.count(), 0);
346 QCOMPARE(spy2.count(), 0);
347 QCOMPARE(spy3.count(), 3);
347 QCOMPARE(spy3.count(), 3);
348 QCOMPARE(spy4.count(), 3);
348 QCOMPARE(spy4.count(), 3);
349 QCOMPARE(spy5.count(), 0);
349 QCOMPARE(spy5.count(), 0);
350 }
350 }
351
351
352 void tst_ChartDataSet::nextpreviousDomain_data()
352 void tst_ChartDataSet::nextpreviousDomain_data()
353 {
353 {
354 QTest::addColumn<QRectF>("rect");
354 QTest::addColumn<QRectF>("rect");
355 QTest::addColumn<QRectF>("viewport");
355 QTest::addColumn<QRectF>("viewport");
356 QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600)
356 QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600)
357 << QRectF(0, 0, 1000, 1000);
357 << QRectF(0, 0, 1000, 1000);
358 QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700)
358 QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700)
359 << QRectF(0, 0, 1000, 1000);
359 << QRectF(0, 0, 1000, 1000);
360 QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600)
360 QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600)
361 << QRectF(0, 0, 1000, 1000);
361 << QRectF(0, 0, 1000, 1000);
362 }
362 }
363
363
364 void tst_ChartDataSet::nextpreviousDomain()
364 void tst_ChartDataSet::nextpreviousDomain()
365 {
365 {
366
366
367 QFETCH(QRectF, rect);
367 QFETCH(QRectF, rect);
368 QFETCH(QRectF, viewport);
368 QFETCH(QRectF, viewport);
369
369
370 ChartDataSet dataSet;
370 ChartDataSet dataSet;
371
371
372 Domain domain1(0, 1000, 0, 1000);
372 Domain domain1(0, 1000, 0, 1000);
373 QLineChartSeries* series = new QLineChartSeries();
373 QLineChartSeries* series = new QLineChartSeries();
374 series->add(0, 0);
374 series->add(0, 0);
375 series->add(1000, 1000);
375 series->add(1000, 1000);
376
376
377 dataSet.addSeries(series);
377 dataSet.addSeries(series);
378
378
379 QCOMPARE(dataSet.domainIndex(), 0);
379 QCOMPARE(dataSet.domainIndex(), 0);
380
380
381 Domain domain2 = dataSet.domain(dataSet.axisY());
381 Domain domain2 = dataSet.domain(dataSet.axisY());
382 QVERIFY(domain1 == domain2);
382 QVERIFY(domain1 == domain2);
383
383
384 dataSet.addDomain(rect, viewport);
384 dataSet.addDomain(rect, viewport);
385 QCOMPARE(dataSet.domainIndex(), 1);
385 QCOMPARE(dataSet.domainIndex(), 1);
386 Domain domain3 = dataSet.domain(dataSet.axisY());
386 Domain domain3 = dataSet.domain(dataSet.axisY());
387 Domain domain4 = domain1.subDomain(rect, viewport.width(),
387 Domain domain4 = domain1.subDomain(rect, viewport.width(),
388 viewport.height());
388 viewport.height());
389 QVERIFY(domain3 == domain4);
389 QVERIFY(domain3 == domain4);
390
390
391 dataSet.addDomain(rect, viewport);
391 dataSet.addDomain(rect, viewport);
392 QCOMPARE(dataSet.domainIndex(), 2);
392 QCOMPARE(dataSet.domainIndex(), 2);
393 Domain domain5 = dataSet.domain(dataSet.axisY());
393 Domain domain5 = dataSet.domain(dataSet.axisY());
394 Domain domain6 = domain3.subDomain(rect, viewport.width(),
394 Domain domain6 = domain3.subDomain(rect, viewport.width(),
395 viewport.height());
395 viewport.height());
396 QVERIFY(domain5 == domain6);
396 QVERIFY(domain5 == domain6);
397
397
398 dataSet.addDomain(rect, viewport);
398 dataSet.addDomain(rect, viewport);
399 QCOMPARE(dataSet.domainIndex(), 3);
399 QCOMPARE(dataSet.domainIndex(), 3);
400 Domain domain7 = dataSet.domain(dataSet.axisY());
400 Domain domain7 = dataSet.domain(dataSet.axisY());
401 Domain domain8 = domain5.subDomain(rect, viewport.width(),
401 Domain domain8 = domain5.subDomain(rect, viewport.width(),
402 viewport.height());
402 viewport.height());
403 QVERIFY(domain7 == domain8);
403 QVERIFY(domain7 == domain8);
404
404
405 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
405 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
406 QSignalSpy spy1(&dataSet,
406 QSignalSpy spy1(&dataSet,
407 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
407 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
408 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
408 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
409 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
409 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
410 QSignalSpy spy4(&dataSet,
410 QSignalSpy spy4(&dataSet,
411 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
411 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
412 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
412 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
413
413
414 Domain domain;
414 Domain domain;
415
415
416 bool previous = dataSet.previousDomain();
416 bool previous = dataSet.previousDomain();
417 QCOMPARE(previous, true);
417 QCOMPARE(previous, true);
418 QCOMPARE(dataSet.domainIndex(), 2);
418 QCOMPARE(dataSet.domainIndex(), 2);
419 domain = dataSet.domain(dataSet.axisY());
419 domain = dataSet.domain(dataSet.axisY());
420 QVERIFY(domain == domain5);
420 QVERIFY(domain == domain5);
421 previous = dataSet.previousDomain();
421 previous = dataSet.previousDomain();
422 QCOMPARE(previous, true);
422 QCOMPARE(previous, true);
423 QCOMPARE(dataSet.domainIndex(), 1);
423 QCOMPARE(dataSet.domainIndex(), 1);
424 domain = dataSet.domain(dataSet.axisY());
424 domain = dataSet.domain(dataSet.axisY());
425 QVERIFY(domain == domain3);
425 QVERIFY(domain == domain3);
426 previous = dataSet.previousDomain();
426 previous = dataSet.previousDomain();
427 QCOMPARE(previous, true);
427 QCOMPARE(previous, true);
428 QCOMPARE(dataSet.domainIndex(), 0);
428 QCOMPARE(dataSet.domainIndex(), 0);
429 domain = dataSet.domain(dataSet.axisY());
429 domain = dataSet.domain(dataSet.axisY());
430 QVERIFY(domain == domain1);
430 QVERIFY(domain == domain1);
431 previous = dataSet.previousDomain();
431 previous = dataSet.previousDomain();
432 QCOMPARE(previous, false);
432 QCOMPARE(previous, false);
433 QCOMPARE(dataSet.domainIndex(), 0);
433 QCOMPARE(dataSet.domainIndex(), 0);
434 domain = dataSet.domain(dataSet.axisY());
434 domain = dataSet.domain(dataSet.axisY());
435 QVERIFY(domain == domain1);
435 QVERIFY(domain == domain1);
436
436
437 bool next = dataSet.nextDomain();
437 bool next = dataSet.nextDomain();
438 QCOMPARE(next, true);
438 QCOMPARE(next, true);
439 QCOMPARE(dataSet.domainIndex(),1);
439 QCOMPARE(dataSet.domainIndex(),1);
440 next = dataSet.nextDomain();
440 next = dataSet.nextDomain();
441 QCOMPARE(next, true);
441 QCOMPARE(next, true);
442 QCOMPARE(dataSet.domainIndex(),2);
442 QCOMPARE(dataSet.domainIndex(),2);
443 next = dataSet.nextDomain();
443 next = dataSet.nextDomain();
444 QCOMPARE(next, true);
444 QCOMPARE(next, true);
445 QCOMPARE(dataSet.domainIndex(),3);
445 QCOMPARE(dataSet.domainIndex(),3);
446 next = dataSet.nextDomain();
446 next = dataSet.nextDomain();
447 QCOMPARE(next, false);
447 QCOMPARE(next, false);
448 QCOMPARE(dataSet.domainIndex(),3);
448 QCOMPARE(dataSet.domainIndex(),3);
449
449
450
450
451 QCOMPARE(spy0.count(), 0);
451 QCOMPARE(spy0.count(), 0);
452 QCOMPARE(spy1.count(), 12);
452 QCOMPARE(spy1.count(), 12);
453 QCOMPARE(spy2.count(), 0);
453 QCOMPARE(spy2.count(), 0);
454 QCOMPARE(spy3.count(), 0);
454 QCOMPARE(spy3.count(), 0);
455 QCOMPARE(spy4.count(), 6);
455 QCOMPARE(spy4.count(), 6);
456 QCOMPARE(spy5.count(), 0);
456 QCOMPARE(spy5.count(), 0);
457 }
457 }
458
458
459 void tst_ChartDataSet::removeSeries_data()
459 void tst_ChartDataSet::removeSeries_data()
460 {
460 {
461 QTest::addColumn<int>("seriesCount");
461 QTest::addColumn<int>("seriesCount");
462 QTest::addColumn<int>("axisYCount");
462 QTest::addColumn<int>("axisYCount");
463 QTest::newRow("2 series, default axis") << 2 << 0;
463 QTest::newRow("2 series, default axis") << 2 << 0;
464 QTest::newRow("2 series, 2 new axis") << 2 << 2;
464 QTest::newRow("2 series, 2 new axis") << 2 << 2;
465 QTest::newRow("2 series, 1 new axis") << 2 << 2;
465 QTest::newRow("2 series, 1 new axis") << 2 << 2;
466 QTest::newRow("3 series, 3 new axis") << 3 << 3;
466 QTest::newRow("3 series, 3 new axis") << 3 << 3;
467 QTest::newRow("3 series, 2 new axis") << 3 << 2;
467 QTest::newRow("3 series, 2 new axis") << 3 << 2;
468 QTest::newRow("3 series, 1 new axis") << 3 << 1;
468 QTest::newRow("3 series, 1 new axis") << 3 << 1;
469 }
469 }
470
470
471 void tst_ChartDataSet::removeSeries()
471 void tst_ChartDataSet::removeSeries()
472 {
472 {
473 QFETCH(int, seriesCount);
473 QFETCH(int, seriesCount);
474 QFETCH(int, axisYCount);
474 QFETCH(int, axisYCount);
475
475
476 ChartDataSet dataSet;
476 ChartDataSet dataSet;
477
477
478 QList<QChartAxis*> axisList;
478 QList<QChartAxis*> axisList;
479 QList<QChartSeries*> seriesList;
479 QList<QChartSeries*> seriesList;
480
480
481 for (int i = 0; i < axisYCount; i++) {
481 for (int i = 0; i < axisYCount; i++) {
482 QChartAxis* axis = new QChartAxis();
482 QChartAxis* axis = new QChartAxis();
483 axisList << axis;
483 axisList << axis;
484 }
484 }
485
485
486 QList<QChartAxis*>::iterator iterator = axisList.begin();
486 QList<QChartAxis*>::iterator iterator = axisList.begin();
487
487
488 for (int i = 0; i < seriesCount; i++) {
488 for (int i = 0; i < seriesCount; i++) {
489 QChartAxis* axisY = 0;
489 QChartAxis* axisY = 0;
490 QLineChartSeries* series = new QLineChartSeries();
490 QLineChartSeries* series = new QLineChartSeries();
491 if (iterator != axisList.end()) {
491 if (iterator != axisList.end()) {
492 axisY = *iterator;
492 axisY = *iterator;
493 iterator++;
493 iterator++;
494 } else if (axisList.count() > 0) {
494 } else if (axisList.count() > 0) {
495 iterator--;
495 iterator--;
496 axisY = *iterator;
496 axisY = *iterator;
497 iterator++;
497 iterator++;
498 }
498 }
499 dataSet.addSeries(series, axisY);
499 dataSet.addSeries(series, axisY);
500 seriesList << series;
500 seriesList << series;
501 }
501 }
502
502
503 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
503 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
504 QSignalSpy spy1(&dataSet,
504 QSignalSpy spy1(&dataSet,
505 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
505 SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
506 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
506 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
507 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
507 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
508 QSignalSpy spy4(&dataSet,
508 QSignalSpy spy4(&dataSet,
509 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
509 SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
510 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
510 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
511
511
512 for (int i = 0; i < seriesCount; i++) {
512 for (int i = 0; i < seriesCount; i++) {
513 dataSet.removeSeries(seriesList.at(i));
513 dataSet.removeSeries(seriesList.at(i));
514 }
514 }
515
515
516 //default axis
517 if (axisYCount == 0)
518 axisYCount++;
519
516 QCOMPARE(spy0.count(), 0);
520 QCOMPARE(spy0.count(), 0);
517 QCOMPARE(spy1.count(), 0);
521 QCOMPARE(spy1.count(), 0);
518 QCOMPARE(spy2.count(), axisYCount);
522 QCOMPARE(spy2.count(), axisYCount);
519 QCOMPARE(spy3.count(), 0);
523 QCOMPARE(spy3.count(), 0);
520 QCOMPARE(spy4.count(), 0);
524 QCOMPARE(spy4.count(), 0);
521 QCOMPARE(spy5.count(), seriesCount);
525 QCOMPARE(spy5.count(), seriesCount);
522
526
523 QCOMPARE(dataSet.domainIndex(), 0);
527 QCOMPARE(dataSet.domainIndex(), 0);
528
529 qDeleteAll(seriesList);
530 }
531
532 void tst_ChartDataSet::removeAllSeries_data()
533 {
534 QTest::addColumn<int>("seriesCount");
535 QTest::addColumn<int>("axisYCount");
536 QTest::newRow("2 series, default axis") << 2 << 0;
537 QTest::newRow("2 series, 2 new axis") << 2 << 2;
538 QTest::newRow("2 series, 1 new axis") << 2 << 2;
539 QTest::newRow("3 series, 3 new axis") << 3 << 3;
540 QTest::newRow("3 series, 2 new axis") << 3 << 2;
541 QTest::newRow("3 series, 1 new axis") << 3 << 1;
524 }
542 }
525
543
544 void tst_ChartDataSet::removeAllSeries()
545 {
546 QFETCH(int, seriesCount);
547 QFETCH(int, axisYCount);
548
549 ChartDataSet dataSet;
550
551 QList<QChartAxis*> axisList;
552
553 for (int i = 0; i < axisYCount; i++) {
554 QChartAxis* axis = new QChartAxis();
555 axisList << axis;
556 }
557
558 QList<QChartAxis*>::iterator iterator = axisList.begin();
559
560 for (int i = 0; i < seriesCount; i++) {
561 QChartAxis* axisY = 0;
562 QLineChartSeries* series = new QLineChartSeries();
563 if (iterator != axisList.end()) {
564 axisY = *iterator;
565 iterator++;
566 } else if (axisList.count() > 0) {
567 iterator--;
568 axisY = *iterator;
569 iterator++;
570 }
571 dataSet.addSeries(series, axisY);
572 }
573
574 QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*)));
575 QSignalSpy spy1(&dataSet, SIGNAL(axisLabelsChanged(QChartAxis*, QStringList const&)));
576 QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*)));
577 QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QChartSeries*)));
578 QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QChartSeries*, Domain const&)));
579 QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QChartSeries*)));
580
581 dataSet.removeAllSeries();
582 //default axis
583 if (axisYCount == 0)
584 axisYCount++;
585
586 QCOMPARE(spy0.count(), 0);
587 QCOMPARE(spy1.count(), 0);
588 QCOMPARE(spy2.count(), axisYCount);
589 QCOMPARE(spy3.count(), 0);
590 QCOMPARE(spy4.count(), 0);
591 QCOMPARE(spy5.count(), seriesCount);
592
593 QCOMPARE(dataSet.domainIndex(), 0);
594 }
595
596
526 QTEST_MAIN(tst_ChartDataSet)
597 QTEST_MAIN(tst_ChartDataSet)
527 #include "tst_chartdataset.moc"
598 #include "tst_chartdataset.moc"
528
599
General Comments 0
You need to be logged in to leave comments. Login now