@@ -1,335 +1,362 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "chartdataset_p.h" |
|
22 | 22 | #include "qchartaxis.h" |
|
23 | 23 | //series |
|
24 | 24 | #include "qlineseries.h" |
|
25 | 25 | #include "qareaseries.h" |
|
26 | 26 | #include "qbarseries.h" |
|
27 | 27 | #include "qstackedbarseries.h" |
|
28 | 28 | #include "qpercentbarseries.h" |
|
29 | 29 | #include "qpieseries.h" |
|
30 | 30 | #include "qscatterseries.h" |
|
31 | 31 | #include "qsplineseries.h" |
|
32 | 32 | |
|
33 | 33 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
34 | 34 | |
|
35 | 35 | ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), |
|
36 | 36 | m_axisX(new QChartAxis(this)), |
|
37 | 37 | m_axisY(new QChartAxis(this)), |
|
38 | 38 | m_domainIndex(0), |
|
39 | 39 | m_axisXInitialized(false) |
|
40 | 40 | { |
|
41 | 41 | } |
|
42 | 42 | |
|
43 | 43 | ChartDataSet::~ChartDataSet() |
|
44 | 44 | { |
|
45 | 45 | } |
|
46 | 46 | |
|
47 | 47 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) |
|
48 | 48 | { |
|
49 | 49 | if(axisY==0) axisY = m_axisY; |
|
50 | 50 | |
|
51 | if (seriesIndex(series) > -1) { | |
|
51 | QChartAxis* axis = m_seriesAxisMap.value(series); | |
|
52 | ||
|
53 | if(axis) { | |
|
52 | 54 | qWarning() << "Can not add series. Series already on the chart"; |
|
53 | 55 | return; |
|
54 | 56 | } |
|
55 | 57 | |
|
56 | 58 | if(!series->parent()){ |
|
57 | 59 | series->setParent(this); // take ownership |
|
58 | 60 | }; |
|
59 | 61 | |
|
60 | 62 | if(!axisY->parent()){ |
|
61 | 63 | axisY->setParent(this); // take ownership |
|
62 | 64 | } |
|
63 | 65 | |
|
64 | 66 | Domain* domain = m_axisDomainMap.value(axisY); |
|
65 | if (!domain) { | |
|
67 | ||
|
68 | if(!domain) { | |
|
66 | 69 | domain = new Domain(axisY); |
|
67 | 70 | QObject::connect(axisY,SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
68 | 71 | QObject::connect(axisX(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
69 | 72 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axisY,SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
70 | 73 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axisX(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
71 | 74 | //initialize |
|
72 | 75 | m_axisDomainMap.insert(axisY,domain); |
|
73 | 76 | emit axisAdded(axisY,domain); |
|
74 | 77 | } |
|
75 | 78 | |
|
76 |
if |
|
|
77 |
emit axisAdded(axisX(), |
|
|
78 |
m_axisXInitialized |
|
|
79 | if(!m_axisXInitialized){ | |
|
80 | emit axisAdded(axisX(),domain); | |
|
81 | m_axisXInitialized=true; | |
|
79 | 82 | } |
|
80 | 83 | |
|
81 |
calculateDomain(series, |
|
|
84 | calculateDomain(series,domain); | |
|
82 | 85 | |
|
83 |
m_seriesAxis |
|
|
86 | m_seriesAxisMap.insert(series,axisY); | |
|
87 | ||
|
88 | QMapIterator<int, QSeries*> i(m_indexSeriesMap); | |
|
89 | ||
|
90 | int key=0; | |
|
91 | while (i.hasNext()) { | |
|
92 | i.next(); | |
|
93 | if(i.key()!=key) { | |
|
94 | break; | |
|
95 | } | |
|
96 | key++; | |
|
97 | } | |
|
98 | ||
|
99 | m_indexSeriesMap.insert(key,series); | |
|
100 | ||
|
101 | emit seriesAdded(series,domain); | |
|
84 | 102 | |
|
85 | emit seriesAdded(series, domain); | |
|
86 | 103 | } |
|
87 | 104 | |
|
88 | 105 | void ChartDataSet::removeSeries(QSeries* series) |
|
89 | 106 | { |
|
90 | int index = seriesIndex(series); | |
|
91 | if (index < 0) { | |
|
92 | qWarning() << "Can not remove series. Series not found on the chart."; | |
|
107 | ||
|
108 | QChartAxis* axis = m_seriesAxisMap.value(series); | |
|
109 | ||
|
110 | if(!axis){ | |
|
111 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
|
93 | 112 | return; |
|
94 | 113 | } |
|
114 | emit seriesRemoved(series); | |
|
115 | m_seriesAxisMap.remove(series); | |
|
116 | int key = seriesIndex(series); | |
|
117 | Q_ASSERT(key!=-1); | |
|
95 | 118 | |
|
96 | // Remove the series and the axis from the container | |
|
97 | QChartAxis* axis = m_seriesAxisList.at(index).second; | |
|
98 | m_seriesAxisList.removeAt(index); | |
|
119 | m_indexSeriesMap.remove(key); | |
|
99 | 120 | |
|
100 | // Delete the series | |
|
101 | emit seriesRemoved(series); | |
|
102 | if (series->parent() == this) { | |
|
121 | if(series->parent()==this){ | |
|
103 | 122 | delete series; |
|
104 |
series |
|
|
123 | series=0; | |
|
105 | 124 | } |
|
106 | 125 | |
|
107 | // Check if the Y axis is still in use | |
|
108 | bool yAxisInUse(false); | |
|
109 | for (int i(0); i < m_seriesAxisList.count(); i++) { | |
|
110 | QPair<QSeries *, QChartAxis *> pair = m_seriesAxisList.at(i); | |
|
111 | if (pair.second == axis) | |
|
112 | yAxisInUse = true; | |
|
113 | } | |
|
126 | QList<QChartAxis*> axes = m_seriesAxisMap.values(); | |
|
127 | ||
|
128 | int i = axes.indexOf(axis); | |
|
114 | 129 | |
|
115 | // Remove the Y axis if not in use | |
|
116 | if (!yAxisInUse) { | |
|
130 | if(i==-1){ | |
|
117 | 131 | Domain* domain = m_axisDomainMap.take(axis); |
|
118 | 132 | emit axisRemoved(axis); |
|
119 |
if |
|
|
120 | // Delete the Y axis unless it is the default one | |
|
121 | if (axis->parent() == this) { | |
|
133 | if(axis!=axisY()){ | |
|
134 | if(axis->parent()==this){ | |
|
122 | 135 | delete axis; |
|
123 |
axis |
|
|
136 | axis=0; | |
|
124 | 137 | } |
|
125 | 138 | } |
|
126 | 139 | delete domain; |
|
127 | 140 | } |
|
128 | 141 | |
|
129 | // Remove the x axis in case there are no y-axes left | |
|
130 | if (m_seriesAxisList.count() == 0) { | |
|
131 |
m_axisXInitialized |
|
|
142 | if(m_seriesAxisMap.values().size()==0) | |
|
143 | { | |
|
144 | m_axisXInitialized=false; | |
|
132 | 145 | emit axisRemoved(axisX()); |
|
133 | 146 | } |
|
134 | 147 | } |
|
135 | 148 | |
|
136 | 149 | void ChartDataSet::removeAllSeries() |
|
137 | 150 | { |
|
138 | while (m_seriesAxisList.count()) { | |
|
139 |
|
|
|
140 | removeSeries(pair.first); | |
|
151 | ||
|
152 | QList<QSeries*> series = m_seriesAxisMap.keys(); | |
|
153 | ||
|
154 | foreach(QSeries* s , series) { | |
|
155 | removeSeries(s); | |
|
141 | 156 | } |
|
142 | 157 | |
|
143 |
Q_ASSERT(m_seriesAxis |
|
|
144 |
Q_ASSERT(m_axisDomainMap.count() |
|
|
158 | Q_ASSERT(m_seriesAxisMap.count()==0); | |
|
159 | Q_ASSERT(m_axisDomainMap.count()==0); | |
|
160 | ||
|
145 | 161 | } |
|
146 | 162 | |
|
147 | 163 | //to be removed with PIMPL |
|
148 | 164 | void ChartDataSet::calculateDomain(QSeries* series,Domain* domain) |
|
149 | 165 | { |
|
150 | 166 | qreal minX(domain->minX()); |
|
151 | 167 | qreal minY(domain->minY()); |
|
152 | 168 | qreal maxX(domain->maxX()); |
|
153 | 169 | qreal maxY(domain->maxY()); |
|
154 | 170 | int tickXCount(domain->tickXCount()); |
|
155 | 171 | int tickYCount(domain->tickYCount()); |
|
156 | 172 | |
|
157 | 173 | |
|
158 | 174 | switch(series->type()) |
|
159 | 175 | { |
|
160 | 176 | case QSeries::SeriesTypeLine: |
|
161 | 177 | case QSeries::SeriesTypeSpline: |
|
162 | 178 | case QSeries::SeriesTypeScatter: |
|
163 | 179 | { |
|
164 | 180 | |
|
165 | 181 | QXYSeries* xySeries = static_cast<QXYSeries*>(series); |
|
166 | 182 | |
|
167 | 183 | for (int i = 0; i < xySeries->count(); i++) |
|
168 | 184 | { |
|
169 | 185 | qreal x = xySeries->x(i); |
|
170 | 186 | qreal y = xySeries->y(i); |
|
171 | 187 | minX = qMin(minX, x); |
|
172 | 188 | minY = qMin(minY, y); |
|
173 | 189 | maxX = qMax(maxX, x); |
|
174 | 190 | maxY = qMax(maxY, y); |
|
175 | 191 | } |
|
176 | 192 | break; |
|
177 | 193 | } |
|
178 | 194 | case QSeries::SeriesTypeArea: { |
|
179 | 195 | |
|
180 | 196 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
181 | 197 | QLineSeries* upperSeries = areaSeries->upperSeries(); |
|
182 | 198 | QLineSeries* lowerSeries = areaSeries->lowerSeries(); |
|
183 | 199 | |
|
184 | 200 | for (int i = 0; i < upperSeries->count(); i++) |
|
185 | 201 | { |
|
186 | 202 | qreal x = upperSeries->x(i); |
|
187 | 203 | qreal y = upperSeries->y(i); |
|
188 | 204 | minX = qMin(minX, x); |
|
189 | 205 | minY = qMin(minY, y); |
|
190 | 206 | maxX = qMax(maxX, x); |
|
191 | 207 | maxY = qMax(maxY, y); |
|
192 | 208 | } |
|
193 | 209 | if(lowerSeries) { |
|
194 | 210 | for (int i = 0; i < lowerSeries->count(); i++) |
|
195 | 211 | { |
|
196 | 212 | qreal x = lowerSeries->x(i); |
|
197 | 213 | qreal y = lowerSeries->y(i); |
|
198 | 214 | minX = qMin(minX, x); |
|
199 | 215 | minY = qMin(minY, y); |
|
200 | 216 | maxX = qMax(maxX, x); |
|
201 | 217 | maxY = qMax(maxY, y); |
|
202 | 218 | }} |
|
203 | 219 | break; |
|
204 | 220 | } |
|
205 | 221 | case QSeries::SeriesTypeBar: { |
|
206 | 222 | |
|
207 | 223 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
208 | 224 | qreal x = barSeries->categoryCount(); |
|
209 | 225 | qreal y = barSeries->max(); |
|
210 | 226 | minX = qMin(minX, x); |
|
211 | 227 | minY = qMin(minY, y); |
|
212 | 228 | maxX = qMax(maxX, x); |
|
213 | 229 | maxY = qMax(maxY, y); |
|
214 | 230 | tickXCount = x+1; |
|
215 | 231 | setupCategories(barSeries); |
|
216 | 232 | break; |
|
217 | 233 | } |
|
218 | 234 | case QSeries::SeriesTypeStackedBar: { |
|
219 | 235 | |
|
220 | 236 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
221 | 237 | qreal x = stackedBarSeries->categoryCount(); |
|
222 | 238 | qreal y = stackedBarSeries->maxCategorySum(); |
|
223 | 239 | minX = qMin(minX, x); |
|
224 | 240 | minY = qMin(minY, y); |
|
225 | 241 | maxX = qMax(maxX, x); |
|
226 | 242 | maxY = qMax(maxY, y); |
|
227 | 243 | tickXCount = x+1; |
|
228 | 244 | setupCategories(stackedBarSeries); |
|
229 | 245 | break; |
|
230 | 246 | } |
|
231 | 247 | case QSeries::SeriesTypePercentBar: { |
|
232 | 248 | |
|
233 | 249 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
234 | 250 | qreal x = percentBarSeries->categoryCount(); |
|
235 | 251 | minX = qMin(minX, x); |
|
236 | 252 | maxX = qMax(maxX, x); |
|
237 | 253 | minY = 0; |
|
238 | 254 | maxY = 100; |
|
239 | 255 | tickXCount = x+1; |
|
240 | 256 | setupCategories(percentBarSeries); |
|
241 | 257 | break; |
|
242 | 258 | } |
|
243 | 259 | |
|
244 | 260 | case QSeries::SeriesTypePie: { |
|
245 | 261 | //QPieSeries *pieSeries = static_cast<QPieSeries *>(series); |
|
246 | 262 | // TODO: domain stuff |
|
247 | 263 | break; |
|
248 | 264 | } |
|
249 | 265 | |
|
250 | 266 | |
|
251 | 267 | default: { |
|
252 | 268 | qDebug()<<__FUNCTION__<<"type" << series->type()<<"not supported"; |
|
253 | 269 | return; |
|
254 | 270 | } |
|
255 | 271 | |
|
256 | 272 | } |
|
257 | 273 | |
|
258 | 274 | domain->setRangeX(minX,maxX,tickXCount); |
|
259 | 275 | domain->setRangeY(minY,maxY,tickYCount); |
|
260 | 276 | } |
|
261 | 277 | |
|
262 | 278 | |
|
263 | 279 | void ChartDataSet::setupCategories(QBarSeries* series) |
|
264 | 280 | { |
|
265 | 281 | QChartAxisCategories* categories = axisX()->categories(); |
|
266 | 282 | categories->clear(); |
|
267 | 283 | categories->insert(series->categories()); |
|
268 | 284 | } |
|
269 | 285 | |
|
270 | 286 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
271 | 287 | { |
|
272 | 288 | QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap); |
|
273 | 289 | while (i.hasNext()) { |
|
274 | 290 | i.next(); |
|
275 | 291 | i.value()->zoomIn(rect,size); |
|
276 | 292 | } |
|
277 | 293 | } |
|
278 | 294 | |
|
279 | 295 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
280 | 296 | { |
|
281 | 297 | QMapIterator<QChartAxis*, Domain*> i(m_axisDomainMap); |
|
282 | 298 | while (i.hasNext()) { |
|
283 | 299 | i.next(); |
|
284 | 300 | i.value()->zoomOut(rect,size); |
|
285 | 301 | } |
|
286 | 302 | } |
|
287 | 303 | |
|
288 |
int ChartDataSet::series |
|
|
304 | int ChartDataSet::seriesCount(QSeries::QSeriesType type) | |
|
305 | { | |
|
306 | int count=0; | |
|
307 | QMapIterator<QSeries*, QChartAxis*> i(m_seriesAxisMap); | |
|
308 | while (i.hasNext()) { | |
|
309 | i.next(); | |
|
310 | if(i.key()->type()==type) count++; | |
|
311 | } | |
|
312 | return count; | |
|
313 | } | |
|
314 | ||
|
315 | int ChartDataSet::seriesIndex(QSeries *series) | |
|
289 | 316 | { |
|
290 | for (int i(0); i < m_seriesAxisList.count(); i++) { | |
|
291 | QPair<QSeries *, QChartAxis *> pair = m_seriesAxisList.at(i); | |
|
292 | if (pair.first == series) | |
|
293 | return i; | |
|
317 | QMapIterator<int, QSeries*> i(m_indexSeriesMap); | |
|
318 | while (i.hasNext()) { | |
|
319 | i.next(); | |
|
320 | if (i.value() == series) | |
|
321 | return i.key(); | |
|
294 | 322 | } |
|
295 | 323 | return -1; |
|
296 | 324 | } |
|
297 | 325 | |
|
298 | 326 | QChartAxis* ChartDataSet::axisY(QSeries* series) const |
|
299 | 327 | { |
|
300 |
if |
|
|
301 | return m_axisY; | |
|
302 | ||
|
303 | return m_seriesAxisList.at(seriesIndex(series)).second; | |
|
328 | if(series == 0) return m_axisY; | |
|
329 | return m_seriesAxisMap.value(series); | |
|
304 | 330 | } |
|
305 | 331 | |
|
306 | 332 | Domain* ChartDataSet::domain(QSeries* series) const |
|
307 | 333 | { |
|
308 |
|
|
|
309 |
|
|
|
334 | QChartAxis* axis = m_seriesAxisMap.value(series); | |
|
335 | if(axis){ | |
|
310 | 336 | return m_axisDomainMap.value(axis); |
|
311 | return 0; | |
|
337 | }else | |
|
338 | return 0; | |
|
312 | 339 | } |
|
313 | 340 | |
|
314 | 341 | Domain* ChartDataSet::domain(QChartAxis* axis) const |
|
315 | 342 | { |
|
316 | 343 | if(!axis || axis==axisX()) { |
|
317 | 344 | return m_axisDomainMap.value(axisY()); |
|
318 | 345 | } |
|
319 | 346 | else { |
|
320 | 347 | return m_axisDomainMap.value(axis); |
|
321 | 348 | } |
|
322 | 349 | } |
|
323 | 350 | |
|
324 | 351 | void ChartDataSet::scrollDomain(int dx,int dy,const QSizeF& size) |
|
325 | 352 | { |
|
326 | 353 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); |
|
327 | 354 | while (i.hasNext()) { |
|
328 | 355 | i.next(); |
|
329 | 356 | i.value()->move(dx,dy,size); |
|
330 | 357 | } |
|
331 | 358 | } |
|
332 | 359 | |
|
333 | 360 | #include "moc_chartdataset_p.cpp" |
|
334 | 361 | |
|
335 | 362 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,88 +1,90 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef CHARTDATASET_P_H_ |
|
31 | 31 | #define CHARTDATASET_P_H_ |
|
32 | 32 | |
|
33 | 33 | #include "qseries.h" |
|
34 | 34 | #include "domain_p.h" |
|
35 | 35 | #include <QVector> |
|
36 | 36 | |
|
37 | 37 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
38 | 38 | |
|
39 | 39 | class QChartAxis; |
|
40 | 40 | class QBarSeries; |
|
41 | 41 | |
|
42 | 42 | class ChartDataSet : public QObject |
|
43 | 43 | { |
|
44 | 44 | Q_OBJECT |
|
45 | 45 | public: |
|
46 | 46 | ChartDataSet(QObject* parent=0); |
|
47 | 47 | virtual ~ChartDataSet(); |
|
48 | 48 | |
|
49 | 49 | void addSeries(QSeries* series,QChartAxis *axisY = 0); |
|
50 | 50 | void removeSeries(QSeries* series); |
|
51 | 51 | void removeAllSeries(); |
|
52 | 52 | |
|
53 | 53 | void zoomInDomain(const QRectF& rect, const QSizeF& size); |
|
54 | 54 | void zoomOutDomain(const QRectF& rect, const QSizeF& size); |
|
55 | 55 | void scrollDomain(int dx,int dy,const QSizeF& size); |
|
56 | 56 | |
|
57 |
int series |
|
|
57 | int seriesCount(QSeries::QSeriesType type); | |
|
58 | int seriesIndex(QSeries *series); | |
|
58 | 59 | |
|
59 | 60 | Domain* domain(QSeries* series) const; |
|
60 | 61 | Domain* domain(QChartAxis* axis) const; |
|
61 | 62 | |
|
62 | 63 | QChartAxis* axisX() const { return m_axisX; } |
|
63 | 64 | QChartAxis* axisY(QSeries* series = 0) const; |
|
64 | 65 | |
|
65 | 66 | Q_SIGNALS: |
|
66 | 67 | void seriesAdded(QSeries* series,Domain* domain); |
|
67 | 68 | void seriesRemoved(QSeries* series); |
|
68 | 69 | void axisAdded(QChartAxis* axis,Domain* domain); |
|
69 | 70 | void axisRemoved(QChartAxis* axis); |
|
70 | 71 | |
|
71 | 72 | private: |
|
72 | 73 | QStringList createLabels(QChartAxis* axis,qreal min, qreal max); |
|
73 | 74 | void calculateDomain(QSeries* series,Domain* domain); |
|
74 | 75 | void setupCategories(QBarSeries* series); |
|
75 | 76 | |
|
76 | 77 | private: |
|
77 |
Q |
|
|
78 | QMap<QSeries*, QChartAxis*> m_seriesAxisMap; | |
|
78 | 79 | QMap<QChartAxis*, Domain*> m_axisDomainMap; |
|
80 | QMap<int,QSeries*> m_indexSeriesMap; | |
|
79 | 81 | QChartAxis* m_axisX; |
|
80 | 82 | QChartAxis* m_axisY; |
|
81 | 83 | |
|
82 | 84 | int m_domainIndex; |
|
83 | 85 | bool m_axisXInitialized; |
|
84 | 86 | }; |
|
85 | 87 | |
|
86 | 88 | QTCOMMERCIALCHART_END_NAMESPACE |
|
87 | 89 | |
|
88 | 90 | #endif /* CHARTENGINE_P_H_ */ |
@@ -1,454 +1,538 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include <QtTest/QtTest> |
|
22 | 22 | #include <qchartaxis.h> |
|
23 | 23 | #include <qlineseries.h> |
|
24 | 24 | #include <private/chartdataset_p.h> |
|
25 | 25 | #include <private/domain_p.h> |
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | 28 | |
|
29 | 29 | Q_DECLARE_METATYPE(Domain*) |
|
30 | 30 | Q_DECLARE_METATYPE(QChartAxis*) |
|
31 | 31 | Q_DECLARE_METATYPE(QSeries*) |
|
32 | 32 | Q_DECLARE_METATYPE(QLineSeries*) |
|
33 | 33 | |
|
34 | 34 | class tst_ChartDataSet: public QObject { |
|
35 | 35 | |
|
36 | 36 | Q_OBJECT |
|
37 | 37 | |
|
38 | 38 | public Q_SLOTS: |
|
39 | 39 | void initTestCase(); |
|
40 | 40 | void cleanupTestCase(); |
|
41 | 41 | void init(); |
|
42 | 42 | void cleanup(); |
|
43 | 43 | |
|
44 | 44 | private Q_SLOTS: |
|
45 | 45 | void chartdataset_data(); |
|
46 | 46 | void chartdataset(); |
|
47 | 47 | void addSeries_data(); |
|
48 | 48 | void addSeries(); |
|
49 | 49 | void removeSeries_data(); |
|
50 | 50 | void removeSeries(); |
|
51 | 51 | void removeAllSeries_data(); |
|
52 | 52 | void removeAllSeries(); |
|
53 | 53 | void axisY_data(); |
|
54 | 54 | void axisY(); |
|
55 | void seriesCount_data(); | |
|
56 | void seriesCount(); | |
|
55 | 57 | void seriesIndex_data(); |
|
56 | 58 | void seriesIndex(); |
|
57 | 59 | void domain_data(); |
|
58 | 60 | void domain(); |
|
59 | 61 | void zoomInDomain_data(); |
|
60 | 62 | void zoomInDomain(); |
|
61 | 63 | void zoomOutDomain_data(); |
|
62 | 64 | void zoomOutDomain(); |
|
63 | 65 | void scrollDomain_data(); |
|
64 | 66 | void scrollDomain(); |
|
65 | 67 | }; |
|
66 | 68 | |
|
67 | 69 | void tst_ChartDataSet::initTestCase() |
|
68 | 70 | { |
|
69 | 71 | qRegisterMetaType<Domain*>(); |
|
70 | 72 | qRegisterMetaType<QChartAxis*>(); |
|
71 | 73 | qRegisterMetaType<QSeries*>(); |
|
72 | 74 | } |
|
73 | 75 | |
|
74 | 76 | void tst_ChartDataSet::cleanupTestCase() |
|
75 | 77 | { |
|
76 | 78 | } |
|
77 | 79 | |
|
78 | 80 | void tst_ChartDataSet::init() |
|
79 | 81 | { |
|
80 | 82 | } |
|
81 | 83 | |
|
82 | 84 | void tst_ChartDataSet::cleanup() |
|
83 | 85 | { |
|
84 | 86 | } |
|
85 | 87 | |
|
86 | 88 | void tst_ChartDataSet::chartdataset_data() |
|
87 | 89 | { |
|
88 | 90 | } |
|
89 | 91 | |
|
90 | 92 | void tst_ChartDataSet::chartdataset() |
|
91 | 93 | { |
|
92 | 94 | ChartDataSet dataSet; |
|
93 | 95 | QVERIFY2(dataSet.axisX(), "Missing axisX."); |
|
94 | 96 | QVERIFY2(dataSet.axisY(), "Missing axisY."); |
|
95 | 97 | //check if not dangling pointer |
|
96 | 98 | dataSet.axisX()->objectName(); |
|
97 | 99 | dataSet.axisY()->objectName(); |
|
100 | QLineSeries* series = new QLineSeries(this); | |
|
101 | QCOMPARE(dataSet.seriesIndex(series),-1); | |
|
98 | 102 | } |
|
99 | 103 | |
|
100 | 104 | void tst_ChartDataSet::addSeries_data() |
|
101 | 105 | { |
|
102 | 106 | QTest::addColumn<QLineSeries*>("series0"); |
|
103 | 107 | QTest::addColumn<QChartAxis*>("axis0"); |
|
104 | 108 | QTest::addColumn<QLineSeries*>("series1"); |
|
105 | 109 | QTest::addColumn<QChartAxis*>("axis1"); |
|
106 | 110 | QTest::addColumn<QLineSeries*>("series2"); |
|
107 | 111 | QTest::addColumn<QChartAxis*>("axis2"); |
|
108 | 112 | QTest::addColumn<int>("axisCount"); |
|
109 | 113 | |
|
110 | 114 | QLineSeries* series0 = new QLineSeries(this); |
|
111 | 115 | QLineSeries* series1 = new QLineSeries(this); |
|
112 | 116 | QLineSeries* series2 = new QLineSeries(this); |
|
113 | 117 | |
|
114 | 118 | QChartAxis* axis0 = new QChartAxis(this); |
|
115 | 119 | QChartAxis* axis1 = new QChartAxis(this); |
|
116 | 120 | QChartAxis* axis2 = new QChartAxis(this); |
|
117 | 121 | |
|
118 | 122 | QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QChartAxis*)0 << series1 << (QChartAxis*)0 << series2 << (QChartAxis*)0 << 2; |
|
119 | 123 | QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (QChartAxis*)0 << series1 << axis0 << series2 << axis0 << 3; |
|
120 | 124 | QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1 << axis1 << series2 << axis2 << 4; |
|
121 | 125 | } |
|
122 | 126 | |
|
123 | 127 | void tst_ChartDataSet::addSeries() |
|
124 | 128 | { |
|
125 | 129 | QFETCH(QLineSeries*, series0); |
|
126 | 130 | QFETCH(QChartAxis*, axis0); |
|
127 | 131 | QFETCH(QLineSeries*, series1); |
|
128 | 132 | QFETCH(QChartAxis*, axis1); |
|
129 | 133 | QFETCH(QLineSeries*, series2); |
|
130 | 134 | QFETCH(QChartAxis*, axis2); |
|
131 | 135 | QFETCH(int, axisCount); |
|
132 | 136 | |
|
133 | 137 | ChartDataSet dataSet; |
|
134 | 138 | |
|
135 | 139 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*))); |
|
136 | 140 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
137 | 141 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*))); |
|
138 | 142 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
139 | 143 | |
|
140 | 144 | dataSet.addSeries(series0,axis0); |
|
141 | 145 | dataSet.addSeries(series1,axis1); |
|
142 | 146 | dataSet.addSeries(series2,axis2); |
|
143 | 147 | |
|
144 | 148 | QCOMPARE(spy0.count(), axisCount); |
|
145 | 149 | QCOMPARE(spy1.count(), 0); |
|
146 | 150 | QCOMPARE(spy2.count(), 3); |
|
147 | 151 | QCOMPARE(spy3.count(), 0); |
|
148 | 152 | |
|
149 | 153 | } |
|
150 | 154 | |
|
151 | 155 | void tst_ChartDataSet::removeSeries_data() |
|
152 | 156 | { |
|
153 | 157 | addSeries_data(); |
|
154 | 158 | } |
|
155 | 159 | |
|
156 | 160 | void tst_ChartDataSet::removeSeries() |
|
157 | 161 | { |
|
158 | 162 | QFETCH(QLineSeries*, series0); |
|
159 | 163 | QFETCH(QChartAxis*, axis0); |
|
160 | 164 | QFETCH(QLineSeries*, series1); |
|
161 | 165 | QFETCH(QChartAxis*, axis1); |
|
162 | 166 | QFETCH(QLineSeries*, series2); |
|
163 | 167 | QFETCH(QChartAxis*, axis2); |
|
164 | 168 | QFETCH(int, axisCount); |
|
165 | 169 | |
|
166 | 170 | ChartDataSet dataSet; |
|
167 | 171 | |
|
168 | 172 | dataSet.addSeries(series0,axis0); |
|
169 | 173 | dataSet.addSeries(series1,axis1); |
|
170 | 174 | dataSet.addSeries(series2,axis2); |
|
171 | 175 | |
|
172 | 176 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*))); |
|
173 | 177 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
174 | 178 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*))); |
|
175 | 179 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
176 | 180 | |
|
177 | 181 | dataSet.removeSeries(series0); |
|
178 | 182 | dataSet.removeSeries(series1); |
|
179 | 183 | dataSet.removeSeries(series2); |
|
180 | 184 | |
|
181 | 185 | QCOMPARE(spy0.count(), 0); |
|
182 | 186 | QCOMPARE(spy1.count(), axisCount); |
|
183 | 187 | QCOMPARE(spy2.count(), 0); |
|
184 | 188 | QCOMPARE(spy3.count(), 3); |
|
185 | 189 | } |
|
186 | 190 | |
|
187 | 191 | void tst_ChartDataSet::removeAllSeries_data() |
|
188 | 192 | { |
|
189 | 193 | addSeries_data(); |
|
190 | 194 | } |
|
191 | 195 | |
|
192 | 196 | void tst_ChartDataSet::removeAllSeries() |
|
193 | 197 | { |
|
194 | 198 | QFETCH(QLineSeries*, series0); |
|
195 | 199 | QFETCH(QChartAxis*, axis0); |
|
196 | 200 | QFETCH(QLineSeries*, series1); |
|
197 | 201 | QFETCH(QChartAxis*, axis1); |
|
198 | 202 | QFETCH(QLineSeries*, series2); |
|
199 | 203 | QFETCH(QChartAxis*, axis2); |
|
200 | 204 | QFETCH(int, axisCount); |
|
201 | 205 | |
|
202 | 206 | ChartDataSet dataSet; |
|
203 | 207 | |
|
204 | 208 | dataSet.addSeries(series0,axis0); |
|
205 | 209 | dataSet.addSeries(series1,axis1); |
|
206 | 210 | dataSet.addSeries(series2,axis2); |
|
207 | 211 | |
|
208 | 212 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*))); |
|
209 | 213 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
210 | 214 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*))); |
|
211 | 215 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
212 | 216 | |
|
213 | 217 | dataSet.removeAllSeries(); |
|
214 | 218 | |
|
215 | 219 | QCOMPARE(spy0.count(), 0); |
|
216 | 220 | QCOMPARE(spy1.count(), axisCount); |
|
217 | 221 | QCOMPARE(spy2.count(), 0); |
|
218 | 222 | QCOMPARE(spy3.count(), 3); |
|
219 | 223 | } |
|
220 | 224 | |
|
221 | 225 | |
|
222 | 226 | void tst_ChartDataSet::axisY_data() |
|
223 | 227 | { |
|
224 | 228 | QTest::addColumn<QChartAxis*>("axis0"); |
|
225 | 229 | QTest::addColumn<QChartAxis*>("axis1"); |
|
226 | 230 | QTest::addColumn<QChartAxis*>("axis2"); |
|
227 | 231 | QTest::newRow("1 defualt, 2 optional") << (QChartAxis*)0 << new QChartAxis() << new QChartAxis(); |
|
228 | 232 | QTest::newRow("3 optional") << new QChartAxis() << new QChartAxis() << new QChartAxis(); |
|
229 | 233 | } |
|
230 | 234 | |
|
231 | 235 | void tst_ChartDataSet::axisY() |
|
232 | 236 | { |
|
233 | 237 | QFETCH(QChartAxis*, axis0); |
|
234 | 238 | QFETCH(QChartAxis*, axis1); |
|
235 | 239 | QFETCH(QChartAxis*, axis2); |
|
236 | 240 | |
|
237 | 241 | ChartDataSet dataSet; |
|
238 | 242 | |
|
239 | 243 | QChartAxis* defaultAxisY = dataSet.axisY(); |
|
240 | 244 | |
|
241 | 245 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
242 | 246 | |
|
243 | 247 | QLineSeries* series0 = new QLineSeries(); |
|
244 | 248 | dataSet.addSeries(series0,axis0); |
|
245 | 249 | |
|
246 | 250 | QLineSeries* series1 = new QLineSeries(); |
|
247 | 251 | dataSet.addSeries(series1,axis1); |
|
248 | 252 | |
|
249 | 253 | QLineSeries* series2 = new QLineSeries(); |
|
250 | 254 | dataSet.addSeries(series2,axis2); |
|
251 | 255 | |
|
252 | 256 | if(!axis0) axis0=defaultAxisY ; |
|
253 | 257 | if(!axis1) axis1=defaultAxisY ; |
|
254 | 258 | if(!axis2) axis2=defaultAxisY ; |
|
255 | 259 | |
|
256 | 260 | QVERIFY(dataSet.axisY(series0) == axis0); |
|
257 | 261 | QVERIFY(dataSet.axisY(series1) == axis1); |
|
258 | 262 | QVERIFY(dataSet.axisY(series2) == axis2); |
|
259 | 263 | |
|
260 | 264 | } |
|
261 | 265 | |
|
266 | void tst_ChartDataSet::seriesCount_data() | |
|
267 | { | |
|
268 | addSeries_data(); | |
|
269 | } | |
|
270 | ||
|
271 | void tst_ChartDataSet::seriesCount() | |
|
272 | { | |
|
273 | QFETCH(QLineSeries*, series0); | |
|
274 | QFETCH(QChartAxis*, axis0); | |
|
275 | QFETCH(QLineSeries*, series1); | |
|
276 | QFETCH(QChartAxis*, axis1); | |
|
277 | QFETCH(QLineSeries*, series2); | |
|
278 | QFETCH(QChartAxis*, axis2); | |
|
279 | QFETCH(int, axisCount); | |
|
280 | Q_UNUSED(axisCount); | |
|
281 | ||
|
282 | ChartDataSet dataSet; | |
|
283 | ||
|
284 | dataSet.addSeries(series0, axis0); | |
|
285 | dataSet.addSeries(series1, axis1); | |
|
286 | dataSet.addSeries(series2, axis2); | |
|
287 | ||
|
288 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*))); | |
|
289 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
|
290 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*))); | |
|
291 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
|
292 | ||
|
293 | QCOMPARE(dataSet.seriesCount(series0->type()),3); | |
|
294 | QCOMPARE(spy0.count(), 0); | |
|
295 | QCOMPARE(spy1.count(), 0); | |
|
296 | QCOMPARE(spy2.count(), 0); | |
|
297 | QCOMPARE(spy3.count(), 0); | |
|
298 | } | |
|
299 | ||
|
262 | 300 | void tst_ChartDataSet::seriesIndex_data() |
|
263 | 301 | { |
|
264 | 302 | addSeries_data(); |
|
265 | 303 | } |
|
266 | 304 | |
|
267 | 305 | void tst_ChartDataSet::seriesIndex() |
|
268 | 306 | { |
|
307 | //TODO: rewrite this series_index_data to match better | |
|
308 | ||
|
269 | 309 | QFETCH(QLineSeries*, series0); |
|
270 | 310 | QFETCH(QChartAxis*, axis0); |
|
271 | 311 | QFETCH(QLineSeries*, series1); |
|
272 | 312 | QFETCH(QChartAxis*, axis1); |
|
273 | 313 | QFETCH(QLineSeries*, series2); |
|
274 | 314 | QFETCH(QChartAxis*, axis2); |
|
275 | 315 | QFETCH(int, axisCount); |
|
276 | 316 | Q_UNUSED(axisCount); |
|
277 | 317 | |
|
278 | 318 | ChartDataSet dataSet; |
|
279 | 319 | |
|
280 | 320 | dataSet.addSeries(series0, axis0); |
|
281 | 321 | dataSet.addSeries(series1, axis1); |
|
282 | 322 | dataSet.addSeries(series2, axis2); |
|
283 | 323 | |
|
284 | 324 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*))); |
|
285 | 325 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
286 | 326 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*))); |
|
287 | 327 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
288 | 328 | |
|
289 |
|
|
|
290 |
|
|
|
291 |
|
|
|
292 | ||
|
293 | QVERIFY(i1!=i2); | |
|
294 | QVERIFY(i0!=i2); | |
|
295 | QVERIFY(i0!=i1); | |
|
329 | QCOMPARE(dataSet.seriesIndex(series0),0); | |
|
330 | QCOMPARE(dataSet.seriesIndex(series1),1); | |
|
331 | QCOMPARE(dataSet.seriesIndex(series2),2); | |
|
296 | 332 | |
|
297 | 333 | QCOMPARE(spy0.count(), 0); |
|
298 | 334 | QCOMPARE(spy1.count(), 0); |
|
299 | 335 | QCOMPARE(spy2.count(), 0); |
|
300 | 336 | QCOMPARE(spy3.count(), 0); |
|
337 | ||
|
338 | dataSet.removeSeries(series0); | |
|
339 | dataSet.removeSeries(series1); | |
|
340 | dataSet.removeSeries(series2); | |
|
341 | ||
|
342 | QCOMPARE(dataSet.seriesIndex(series0),-1); | |
|
343 | QCOMPARE(dataSet.seriesIndex(series1),-1); | |
|
344 | QCOMPARE(dataSet.seriesIndex(series2),-1); | |
|
345 | ||
|
346 | dataSet.addSeries(series0, axis0); | |
|
347 | dataSet.addSeries(series1, axis1); | |
|
348 | dataSet.addSeries(series2, axis2); | |
|
349 | ||
|
350 | QCOMPARE(dataSet.seriesIndex(series0),0); | |
|
351 | QCOMPARE(dataSet.seriesIndex(series1),1); | |
|
352 | QCOMPARE(dataSet.seriesIndex(series2),2); | |
|
353 | ||
|
354 | dataSet.removeSeries(series1); | |
|
355 | ||
|
356 | QCOMPARE(dataSet.seriesIndex(series0),0); | |
|
357 | QCOMPARE(dataSet.seriesIndex(series1),-1); | |
|
358 | QCOMPARE(dataSet.seriesIndex(series2),2); | |
|
359 | ||
|
360 | dataSet.addSeries(series1, axis1); | |
|
361 | QCOMPARE(dataSet.seriesIndex(series0),0); | |
|
362 | QCOMPARE(dataSet.seriesIndex(series1),1); | |
|
363 | QCOMPARE(dataSet.seriesIndex(series2),2); | |
|
364 | ||
|
365 | dataSet.removeSeries(series2); | |
|
366 | QCOMPARE(dataSet.seriesIndex(series0),0); | |
|
367 | QCOMPARE(dataSet.seriesIndex(series1),1); | |
|
368 | QCOMPARE(dataSet.seriesIndex(series2),-1); | |
|
369 | ||
|
370 | dataSet.removeSeries(series0); | |
|
371 | QCOMPARE(dataSet.seriesIndex(series0),-1); | |
|
372 | QCOMPARE(dataSet.seriesIndex(series1),1); | |
|
373 | QCOMPARE(dataSet.seriesIndex(series2),-1); | |
|
374 | ||
|
375 | dataSet.addSeries(series2); | |
|
376 | QCOMPARE(dataSet.seriesIndex(series0),-1); | |
|
377 | QCOMPARE(dataSet.seriesIndex(series1),1); | |
|
378 | QCOMPARE(dataSet.seriesIndex(series2),0); | |
|
379 | ||
|
380 | dataSet.addSeries(series0); | |
|
381 | QCOMPARE(dataSet.seriesIndex(series0),2); | |
|
382 | QCOMPARE(dataSet.seriesIndex(series1),1); | |
|
383 | QCOMPARE(dataSet.seriesIndex(series2),0); | |
|
384 | ||
|
301 | 385 | } |
|
302 | 386 | |
|
303 | 387 | void tst_ChartDataSet::domain_data() |
|
304 | 388 | { |
|
305 | 389 | addSeries_data(); |
|
306 | 390 | } |
|
307 | 391 | |
|
308 | 392 | void tst_ChartDataSet::domain() |
|
309 | 393 | { |
|
310 | 394 | QFETCH(QLineSeries*, series0); |
|
311 | 395 | QFETCH(QChartAxis*, axis0); |
|
312 | 396 | QFETCH(QLineSeries*, series1); |
|
313 | 397 | QFETCH(QChartAxis*, axis1); |
|
314 | 398 | QFETCH(QLineSeries*, series2); |
|
315 | 399 | QFETCH(QChartAxis*, axis2); |
|
316 | 400 | QFETCH(int, axisCount); |
|
317 | 401 | Q_UNUSED(axisCount); |
|
318 | 402 | |
|
319 | 403 | ChartDataSet dataSet; |
|
320 | 404 | |
|
321 | 405 | dataSet.addSeries(series0, axis0); |
|
322 | 406 | dataSet.addSeries(series1, axis1); |
|
323 | 407 | dataSet.addSeries(series2, axis2); |
|
324 | 408 | |
|
325 | 409 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*))); |
|
326 | 410 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
327 | 411 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*))); |
|
328 | 412 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
329 | 413 | |
|
330 | 414 | QVERIFY(dataSet.domain(axis0)==dataSet.domain(series0)); |
|
331 | 415 | QVERIFY(dataSet.domain(axis1)==dataSet.domain(series1)); |
|
332 | 416 | QVERIFY(dataSet.domain(axis2)==dataSet.domain(series2)); |
|
333 | 417 | QCOMPARE(spy0.count(), 0); |
|
334 | 418 | QCOMPARE(spy1.count(), 0); |
|
335 | 419 | QCOMPARE(spy2.count(), 0); |
|
336 | 420 | QCOMPARE(spy3.count(), 0); |
|
337 | 421 | } |
|
338 | 422 | |
|
339 | 423 | void tst_ChartDataSet::zoomInDomain_data() |
|
340 | 424 | { |
|
341 | 425 | addSeries_data(); |
|
342 | 426 | } |
|
343 | 427 | |
|
344 | 428 | void tst_ChartDataSet::zoomInDomain() |
|
345 | 429 | { |
|
346 | 430 | QFETCH(QLineSeries*, series0); |
|
347 | 431 | QFETCH(QChartAxis*, axis0); |
|
348 | 432 | QFETCH(QLineSeries*, series1); |
|
349 | 433 | QFETCH(QChartAxis*, axis1); |
|
350 | 434 | QFETCH(QLineSeries*, series2); |
|
351 | 435 | QFETCH(QChartAxis*, axis2); |
|
352 | 436 | QFETCH(int, axisCount); |
|
353 | 437 | |
|
354 | 438 | Q_UNUSED(axisCount); |
|
355 | 439 | ChartDataSet dataSet; |
|
356 | 440 | |
|
357 | 441 | dataSet.addSeries(series0, axis0); |
|
358 | 442 | dataSet.addSeries(series1, axis1); |
|
359 | 443 | dataSet.addSeries(series2, axis2); |
|
360 | 444 | |
|
361 | 445 | Domain* domain0 = dataSet.domain(series0); |
|
362 | 446 | Domain* domain1 = dataSet.domain(series1); |
|
363 | 447 | Domain* domain2 = dataSet.domain(series2); |
|
364 | 448 | |
|
365 | 449 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
366 | 450 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
367 | 451 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
368 | 452 | |
|
369 | 453 | dataSet.zoomInDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
370 | 454 | |
|
371 | 455 | QCOMPARE(spy0.count(), 1); |
|
372 | 456 | QCOMPARE(spy1.count(), 1); |
|
373 | 457 | QCOMPARE(spy2.count(), 1); |
|
374 | 458 | } |
|
375 | 459 | |
|
376 | 460 | void tst_ChartDataSet::zoomOutDomain_data() |
|
377 | 461 | { |
|
378 | 462 | addSeries_data(); |
|
379 | 463 | } |
|
380 | 464 | |
|
381 | 465 | void tst_ChartDataSet::zoomOutDomain() |
|
382 | 466 | { |
|
383 | 467 | QFETCH(QLineSeries*, series0); |
|
384 | 468 | QFETCH(QChartAxis*, axis0); |
|
385 | 469 | QFETCH(QLineSeries*, series1); |
|
386 | 470 | QFETCH(QChartAxis*, axis1); |
|
387 | 471 | QFETCH(QLineSeries*, series2); |
|
388 | 472 | QFETCH(QChartAxis*, axis2); |
|
389 | 473 | QFETCH(int, axisCount); |
|
390 | 474 | |
|
391 | 475 | Q_UNUSED(axisCount); |
|
392 | 476 | |
|
393 | 477 | ChartDataSet dataSet; |
|
394 | 478 | |
|
395 | 479 | dataSet.addSeries(series0, axis0); |
|
396 | 480 | dataSet.addSeries(series1, axis1); |
|
397 | 481 | dataSet.addSeries(series2, axis2); |
|
398 | 482 | |
|
399 | 483 | Domain* domain0 = dataSet.domain(series0); |
|
400 | 484 | Domain* domain1 = dataSet.domain(series1); |
|
401 | 485 | Domain* domain2 = dataSet.domain(series2); |
|
402 | 486 | |
|
403 | 487 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
404 | 488 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
405 | 489 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
406 | 490 | |
|
407 | 491 | dataSet.zoomOutDomain(QRect(0,0,100,100),QSize(1000,1000)); |
|
408 | 492 | |
|
409 | 493 | QCOMPARE(spy0.count(), 1); |
|
410 | 494 | QCOMPARE(spy1.count(), 1); |
|
411 | 495 | QCOMPARE(spy2.count(), 1); |
|
412 | 496 | } |
|
413 | 497 | |
|
414 | 498 | void tst_ChartDataSet::scrollDomain_data() |
|
415 | 499 | { |
|
416 | 500 | addSeries_data(); |
|
417 | 501 | } |
|
418 | 502 | |
|
419 | 503 | void tst_ChartDataSet::scrollDomain() |
|
420 | 504 | { |
|
421 | 505 | QFETCH(QLineSeries*, series0); |
|
422 | 506 | QFETCH(QChartAxis*, axis0); |
|
423 | 507 | QFETCH(QLineSeries*, series1); |
|
424 | 508 | QFETCH(QChartAxis*, axis1); |
|
425 | 509 | QFETCH(QLineSeries*, series2); |
|
426 | 510 | QFETCH(QChartAxis*, axis2); |
|
427 | 511 | QFETCH(int, axisCount); |
|
428 | 512 | |
|
429 | 513 | Q_UNUSED(axisCount); |
|
430 | 514 | |
|
431 | 515 | ChartDataSet dataSet; |
|
432 | 516 | |
|
433 | 517 | dataSet.addSeries(series0, axis0); |
|
434 | 518 | dataSet.addSeries(series1, axis1); |
|
435 | 519 | dataSet.addSeries(series2, axis2); |
|
436 | 520 | |
|
437 | 521 | Domain* domain0 = dataSet.domain(series0); |
|
438 | 522 | Domain* domain1 = dataSet.domain(series1); |
|
439 | 523 | Domain* domain2 = dataSet.domain(series2); |
|
440 | 524 | |
|
441 | 525 | QSignalSpy spy0(domain0, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
442 | 526 | QSignalSpy spy1(domain1, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
443 | 527 | QSignalSpy spy2(domain2, SIGNAL(domainChanged(qreal,qreal,qreal,qreal))); |
|
444 | 528 | |
|
445 | 529 | dataSet.scrollDomain(10,10,QSize(1000,1000)); |
|
446 | 530 | |
|
447 | 531 | QCOMPARE(spy0.count(), 1); |
|
448 | 532 | QCOMPARE(spy1.count(), 1); |
|
449 | 533 | QCOMPARE(spy2.count(), 1); |
|
450 | 534 | } |
|
451 | 535 | |
|
452 | 536 | QTEST_MAIN(tst_ChartDataSet) |
|
453 | 537 | #include "tst_chartdataset.moc" |
|
454 | 538 |
@@ -1,348 +1,345 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "mainwidget.h" |
|
22 | 22 | #include "dataseriedialog.h" |
|
23 | 23 | #include "qchartview.h" |
|
24 | 24 | #include "qpieseries.h" |
|
25 | 25 | #include "qscatterseries.h" |
|
26 | 26 | #include "qlineseries.h" |
|
27 | 27 | #include <qareaseries.h> |
|
28 | 28 | #include <qsplineseries.h> |
|
29 | 29 | #include <qbarset.h> |
|
30 | 30 | #include <qbarseries.h> |
|
31 | 31 | #include <qstackedbarseries.h> |
|
32 | 32 | #include <qpercentbarseries.h> |
|
33 | 33 | #include <QPushButton> |
|
34 | 34 | #include <QComboBox> |
|
35 | 35 | #include <QSpinBox> |
|
36 | 36 | #include <QCheckBox> |
|
37 | 37 | #include <QGridLayout> |
|
38 | 38 | #include <QHBoxLayout> |
|
39 | 39 | #include <QLabel> |
|
40 | 40 | #include <QSpacerItem> |
|
41 | 41 | #include <QMessageBox> |
|
42 | 42 | #include <cmath> |
|
43 | 43 | #include <QDebug> |
|
44 | 44 | #include <QStandardItemModel> |
|
45 | 45 | |
|
46 | 46 | |
|
47 | 47 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
48 | 48 | |
|
49 | 49 | MainWidget::MainWidget(QWidget *parent) : |
|
50 | 50 | QWidget(parent), |
|
51 | 51 | m_addSerieDialog(0), |
|
52 | 52 | m_chart(0) |
|
53 | 53 | { |
|
54 | 54 | m_chart = new QChart(); |
|
55 | 55 | |
|
56 | 56 | // Grid layout for the controls for configuring the chart widget |
|
57 | 57 | QGridLayout *grid = new QGridLayout(); |
|
58 | 58 | QPushButton *addSeriesButton = new QPushButton("Add series"); |
|
59 | 59 | connect(addSeriesButton, SIGNAL(clicked()), this, SLOT(addSeries())); |
|
60 | 60 | grid->addWidget(addSeriesButton, 0, 1); |
|
61 | 61 | initBackroundCombo(grid); |
|
62 | 62 | initScaleControls(grid); |
|
63 | 63 | initThemeCombo(grid); |
|
64 | 64 | initCheckboxes(grid); |
|
65 | 65 | |
|
66 | 66 | // add row with empty label to make all the other rows static |
|
67 | 67 | grid->addWidget(new QLabel(""), grid->rowCount(), 0); |
|
68 | 68 | grid->setRowStretch(grid->rowCount() - 1, 1); |
|
69 | 69 | |
|
70 | 70 | // Create chart view with the chart |
|
71 | 71 | m_chartView = new QChartView(m_chart, this); |
|
72 | 72 | m_chartView->setRubberBand(QChartView::HorizonalRubberBand); |
|
73 | 73 | |
|
74 | 74 | // Another grid layout as a main layout |
|
75 | 75 | QGridLayout *mainLayout = new QGridLayout(); |
|
76 | 76 | mainLayout->addLayout(grid, 0, 0); |
|
77 | 77 | mainLayout->addWidget(m_chartView, 0, 1, 3, 1); |
|
78 | 78 | setLayout(mainLayout); |
|
79 | 79 | } |
|
80 | 80 | |
|
81 | 81 | // Combo box for selecting the chart's background |
|
82 | 82 | void MainWidget::initBackroundCombo(QGridLayout *grid) |
|
83 | 83 | { |
|
84 | 84 | QComboBox *backgroundCombo = new QComboBox(this); |
|
85 | 85 | backgroundCombo->addItem("Color"); |
|
86 | 86 | backgroundCombo->addItem("Gradient"); |
|
87 | 87 | backgroundCombo->addItem("Image"); |
|
88 | 88 | connect(backgroundCombo, SIGNAL(currentIndexChanged(int)), |
|
89 | 89 | this, SLOT(backgroundChanged(int))); |
|
90 | 90 | |
|
91 | 91 | grid->addWidget(new QLabel("Background:"), grid->rowCount(), 0); |
|
92 | 92 | grid->addWidget(backgroundCombo, grid->rowCount() - 1, 1); |
|
93 | 93 | } |
|
94 | 94 | |
|
95 | 95 | // Scale related controls (auto-scale vs. manual min-max values) |
|
96 | 96 | void MainWidget::initScaleControls(QGridLayout *grid) |
|
97 | 97 | { |
|
98 | 98 | m_autoScaleCheck = new QCheckBox("Automatic scaling"); |
|
99 | 99 | connect(m_autoScaleCheck, SIGNAL(stateChanged(int)), this, SLOT(autoScaleChanged(int))); |
|
100 | 100 | // Allow setting also non-sense values (like -2147483648 and 2147483647) |
|
101 | 101 | m_xMinSpin = new QSpinBox(); |
|
102 | 102 | m_xMinSpin->setMinimum(INT_MIN); |
|
103 | 103 | m_xMinSpin->setMaximum(INT_MAX); |
|
104 | 104 | m_xMinSpin->setValue(0); |
|
105 | 105 | connect(m_xMinSpin, SIGNAL(valueChanged(int)), this, SLOT(xMinChanged(int))); |
|
106 | 106 | m_xMaxSpin = new QSpinBox(); |
|
107 | 107 | m_xMaxSpin->setMinimum(INT_MIN); |
|
108 | 108 | m_xMaxSpin->setMaximum(INT_MAX); |
|
109 | 109 | m_xMaxSpin->setValue(10); |
|
110 | 110 | connect(m_xMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(xMaxChanged(int))); |
|
111 | 111 | m_yMinSpin = new QSpinBox(); |
|
112 | 112 | m_yMinSpin->setMinimum(INT_MIN); |
|
113 | 113 | m_yMinSpin->setMaximum(INT_MAX); |
|
114 | 114 | m_yMinSpin->setValue(0); |
|
115 | 115 | connect(m_yMinSpin, SIGNAL(valueChanged(int)), this, SLOT(yMinChanged(int))); |
|
116 | 116 | m_yMaxSpin = new QSpinBox(); |
|
117 | 117 | m_yMaxSpin->setMinimum(INT_MIN); |
|
118 | 118 | m_yMaxSpin->setMaximum(INT_MAX); |
|
119 | 119 | m_yMaxSpin->setValue(10); |
|
120 | 120 | connect(m_yMaxSpin, SIGNAL(valueChanged(int)), this, SLOT(yMaxChanged(int))); |
|
121 | 121 | |
|
122 | 122 | grid->addWidget(m_autoScaleCheck, grid->rowCount(), 0); |
|
123 | 123 | grid->addWidget(new QLabel("x min:"), grid->rowCount(), 0); |
|
124 | 124 | grid->addWidget(m_xMinSpin, grid->rowCount() - 1, 1); |
|
125 | 125 | grid->addWidget(new QLabel("x max:"), grid->rowCount(), 0); |
|
126 | 126 | grid->addWidget(m_xMaxSpin, grid->rowCount() - 1, 1); |
|
127 | 127 | grid->addWidget(new QLabel("y min:"), grid->rowCount(), 0); |
|
128 | 128 | grid->addWidget(m_yMinSpin, grid->rowCount() - 1, 1); |
|
129 | 129 | grid->addWidget(new QLabel("y max:"), grid->rowCount(), 0); |
|
130 | 130 | grid->addWidget(m_yMaxSpin, grid->rowCount() - 1, 1); |
|
131 | 131 | |
|
132 | 132 | m_autoScaleCheck->setChecked(true); |
|
133 | 133 | } |
|
134 | 134 | |
|
135 | 135 | // Combo box for selecting theme |
|
136 | 136 | void MainWidget::initThemeCombo(QGridLayout *grid) |
|
137 | 137 | { |
|
138 | 138 | QComboBox *chartTheme = new QComboBox(); |
|
139 | 139 | chartTheme->addItem("Default"); |
|
140 | 140 | chartTheme->addItem("Light"); |
|
141 | 141 | chartTheme->addItem("Blue Cerulean"); |
|
142 | 142 | chartTheme->addItem("Dark"); |
|
143 | 143 | chartTheme->addItem("Brown Sand"); |
|
144 | 144 | chartTheme->addItem("Blue NCS"); |
|
145 | 145 | chartTheme->addItem("High Contrast"); |
|
146 | 146 | chartTheme->addItem("Blue Icy"); |
|
147 | 147 | connect(chartTheme, SIGNAL(currentIndexChanged(int)), |
|
148 | 148 | this, SLOT(changeChartTheme(int))); |
|
149 | 149 | grid->addWidget(new QLabel("Chart theme:"), 8, 0); |
|
150 | 150 | grid->addWidget(chartTheme, 8, 1); |
|
151 | 151 | } |
|
152 | 152 | |
|
153 | 153 | // Different check boxes for customizing chart |
|
154 | 154 | void MainWidget::initCheckboxes(QGridLayout *grid) |
|
155 | 155 | { |
|
156 | 156 | // TODO: setZoomEnabled slot has been removed from QChartView -> Re-implement zoom on/off |
|
157 | 157 | QCheckBox *zoomCheckBox = new QCheckBox("Drag'n drop Zoom"); |
|
158 | 158 | // connect(zoomCheckBox, SIGNAL(toggled(bool)), m_chartView, SLOT(setZoomEnabled(bool))); |
|
159 | 159 | zoomCheckBox->setChecked(true); |
|
160 | 160 | grid->addWidget(zoomCheckBox, grid->rowCount(), 0); |
|
161 | 161 | |
|
162 | 162 | QCheckBox *aliasCheckBox = new QCheckBox("Anti-alias"); |
|
163 | 163 | connect(aliasCheckBox, SIGNAL(toggled(bool)), this, SLOT(antiAliasToggled(bool))); |
|
164 | 164 | aliasCheckBox->setChecked(false); |
|
165 | 165 | grid->addWidget(aliasCheckBox, grid->rowCount(), 0); |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | void MainWidget::antiAliasToggled(bool enabled) |
|
169 | 169 | { |
|
170 | 170 | m_chartView->setRenderHint(QPainter::Antialiasing, enabled); |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | void MainWidget::addSeries() |
|
174 | 174 | { |
|
175 | 175 | if (!m_addSerieDialog) { |
|
176 | 176 | m_addSerieDialog = new DataSerieDialog(this); |
|
177 | 177 | connect(m_addSerieDialog, SIGNAL(accepted(QString, int, int, QString, bool)), |
|
178 | 178 | this, SLOT(addSeries(QString, int, int, QString, bool))); |
|
179 | 179 | } |
|
180 | 180 | m_addSerieDialog->exec(); |
|
181 | 181 | } |
|
182 | 182 | |
|
183 | 183 | QList<RealList> MainWidget::generateTestData(int columnCount, int rowCount, QString dataCharacteristics) |
|
184 | 184 | { |
|
185 | 185 | // TODO: dataCharacteristics |
|
186 | 186 | QList<RealList> testData; |
|
187 | 187 | for (int j(0); j < columnCount; j++) { |
|
188 | 188 | QList <qreal> newColumn; |
|
189 | 189 | for (int i(0); i < rowCount; i++) { |
|
190 | 190 | if (dataCharacteristics == "Sin") { |
|
191 | 191 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100)); |
|
192 | 192 | } else if (dataCharacteristics == "Sin + random") { |
|
193 | 193 | newColumn.append(abs(sin(3.14159265358979 / 50 * i) * 100) + (rand() % 5)); |
|
194 | 194 | } else if (dataCharacteristics == "Random") { |
|
195 | 195 | newColumn.append(rand() % 10 + (qreal) rand() / (qreal) RAND_MAX); |
|
196 | 196 | } else if (dataCharacteristics == "Linear") { |
|
197 | 197 | //newColumn.append(i * (j + 1.0)); |
|
198 | 198 | // TODO: temporary hack to make pie work; prevent zero values: |
|
199 | 199 | newColumn.append(i * (j + 1.0) + 0.1); |
|
200 | 200 | } else { // "constant" |
|
201 | 201 | newColumn.append((j + 1.0)); |
|
202 | 202 | } |
|
203 | 203 | } |
|
204 | 204 | testData.append(newColumn); |
|
205 | 205 | } |
|
206 | 206 | return testData; |
|
207 | 207 | } |
|
208 | 208 | |
|
209 | 209 | QStringList MainWidget::generateLabels(int count) |
|
210 | 210 | { |
|
211 | 211 | QStringList result; |
|
212 | 212 | for (int i(0); i < count; i++) |
|
213 | 213 | result.append("label" + QString::number(i)); |
|
214 | 214 | return result; |
|
215 | 215 | } |
|
216 | 216 | |
|
217 | 217 | void MainWidget::addSeries(QString seriesName, int columnCount, int rowCount, QString dataCharacteristics, bool labelsEnabled) |
|
218 | 218 | { |
|
219 | 219 | qDebug() << "addSeries: " << seriesName |
|
220 | 220 | << " columnCount: " << columnCount |
|
221 | 221 | << " rowCount: " << rowCount |
|
222 | 222 | << " dataCharacteristics: " << dataCharacteristics |
|
223 | 223 | << " labels enabled: " << labelsEnabled; |
|
224 | 224 | m_defaultSeriesName = seriesName; |
|
225 | 225 | |
|
226 | 226 | QList<RealList> data = generateTestData(columnCount, rowCount, dataCharacteristics); |
|
227 | 227 | |
|
228 | 228 | // Line series and scatter series use similar data |
|
229 | 229 | if (seriesName == "Line") { |
|
230 | 230 | for (int j(0); j < data.count(); j ++) { |
|
231 | 231 | QList<qreal> column = data.at(j); |
|
232 | 232 | QLineSeries *series = new QLineSeries(); |
|
233 | series->setName("line" + QString::number(j)); | |
|
234 | 233 | for (int i(0); i < column.count(); i++) |
|
235 | 234 | series->append(i, column.at(i)); |
|
236 | 235 | m_chart->addSeries(series); |
|
237 | 236 | } |
|
238 | 237 | } else if (seriesName == "Area") { |
|
239 | 238 | // TODO: lower series for the area? |
|
240 | 239 | for (int j(0); j < data.count(); j ++) { |
|
241 | 240 | QList<qreal> column = data.at(j); |
|
242 | 241 | QLineSeries *lineSeries = new QLineSeries(); |
|
243 | 242 | for (int i(0); i < column.count(); i++) |
|
244 | 243 | lineSeries->append(i, column.at(i)); |
|
245 | 244 | QAreaSeries *areaSeries = new QAreaSeries(lineSeries); |
|
246 | areaSeries->setName("area" + QString::number(j)); | |
|
247 | 245 | m_chart->addSeries(areaSeries); |
|
248 | 246 | } |
|
249 | 247 | } else if (seriesName == "Scatter") { |
|
250 | 248 | for (int j(0); j < data.count(); j++) { |
|
251 | 249 | QList<qreal> column = data.at(j); |
|
252 | 250 | QScatterSeries *series = new QScatterSeries(); |
|
253 | series->setName("scatter" + QString::number(j)); | |
|
254 | 251 | for (int i(0); i < column.count(); i++) |
|
255 | 252 | series->append(i, column.at(i)); |
|
256 | 253 | m_chart->addSeries(series); |
|
257 | 254 | } |
|
258 | 255 | } else if (seriesName == "Pie") { |
|
259 | 256 | QStringList labels = generateLabels(rowCount); |
|
260 | 257 | for (int j(0); j < data.count(); j++) { |
|
261 | 258 | QPieSeries *series = new QPieSeries(); |
|
262 | 259 | QList<qreal> column = data.at(j); |
|
263 | 260 | for (int i(0); i < column.count(); i++) |
|
264 | 261 | series->append(column.at(i), labels.at(i)); |
|
265 | 262 | m_chart->addSeries(series); |
|
266 | 263 | } |
|
267 | 264 | } else if (seriesName == "Bar" |
|
268 | 265 | || seriesName == "Stacked bar" |
|
269 | 266 | || seriesName == "Percent bar") { |
|
270 | 267 | QStringList category; |
|
271 | 268 | QStringList labels = generateLabels(rowCount); |
|
272 | 269 | foreach(QString label, labels) |
|
273 | 270 | category << label; |
|
274 | 271 | QBarSeries* series = 0; |
|
275 | 272 | if (seriesName == "Bar") |
|
276 | 273 | series = new QBarSeries(category, this); |
|
277 | 274 | else if (seriesName == "Stacked bar") |
|
278 | 275 | series = new QStackedBarSeries(category, this); |
|
279 | 276 | else |
|
280 | 277 | series = new QPercentBarSeries(category, this); |
|
281 | 278 | |
|
282 | 279 | for (int j(0); j < data.count(); j++) { |
|
283 | 280 | QList<qreal> column = data.at(j); |
|
284 | 281 | QBarSet *set = new QBarSet("set" + QString::number(j)); |
|
285 | 282 | for (int i(0); i < column.count(); i++) |
|
286 | 283 | *set << column.at(i); |
|
287 | 284 | series->appendBarSet(set); |
|
288 | 285 | } |
|
289 | 286 | |
|
290 | 287 | // TODO: new implementation of setFloatingValuesEnabled with signals |
|
291 | 288 | //series->setFloatingValuesEnabled(true); |
|
292 | 289 | series->setToolTipEnabled(true); |
|
293 | 290 | m_chart->addSeries(series); |
|
294 | 291 | } else if (seriesName == "Spline") { |
|
295 | 292 | for (int j(0); j < data.count(); j ++) { |
|
296 | 293 | QList<qreal> column = data.at(j); |
|
297 | 294 | QSplineSeries *series = new QSplineSeries(); |
|
298 | 295 | for (int i(0); i < column.count(); i++) |
|
299 | 296 | series->append(i, column.at(i)); |
|
300 | 297 | m_chart->addSeries(series); |
|
301 | 298 | } |
|
302 | 299 | } |
|
303 | 300 | } |
|
304 | 301 | |
|
305 | 302 | void MainWidget::backgroundChanged(int itemIndex) |
|
306 | 303 | { |
|
307 | 304 | qDebug() << "backgroundChanged: " << itemIndex; |
|
308 | 305 | } |
|
309 | 306 | |
|
310 | 307 | void MainWidget::autoScaleChanged(int value) |
|
311 | 308 | { |
|
312 | 309 | if (value) { |
|
313 | 310 | // TODO: enable auto scaling |
|
314 | 311 | } else { |
|
315 | 312 | // TODO: set scaling manually (and disable auto scaling) |
|
316 | 313 | } |
|
317 | 314 | |
|
318 | 315 | m_xMinSpin->setEnabled(!value); |
|
319 | 316 | m_xMaxSpin->setEnabled(!value); |
|
320 | 317 | m_yMinSpin->setEnabled(!value); |
|
321 | 318 | m_yMaxSpin->setEnabled(!value); |
|
322 | 319 | } |
|
323 | 320 | |
|
324 | 321 | void MainWidget::xMinChanged(int value) |
|
325 | 322 | { |
|
326 | 323 | qDebug() << "xMinChanged: " << value; |
|
327 | 324 | } |
|
328 | 325 | |
|
329 | 326 | void MainWidget::xMaxChanged(int value) |
|
330 | 327 | { |
|
331 | 328 | qDebug() << "xMaxChanged: " << value; |
|
332 | 329 | } |
|
333 | 330 | |
|
334 | 331 | void MainWidget::yMinChanged(int value) |
|
335 | 332 | { |
|
336 | 333 | qDebug() << "yMinChanged: " << value; |
|
337 | 334 | } |
|
338 | 335 | |
|
339 | 336 | void MainWidget::yMaxChanged(int value) |
|
340 | 337 | { |
|
341 | 338 | qDebug() << "yMaxChanged: " << value; |
|
342 | 339 | } |
|
343 | 340 | |
|
344 | 341 | void MainWidget::changeChartTheme(int themeIndex) |
|
345 | 342 | { |
|
346 | 343 | qDebug() << "changeChartTheme: " << themeIndex; |
|
347 | 344 | m_chart->setTheme((QChart::ChartTheme) themeIndex); |
|
348 | 345 | } |
General Comments 0
You need to be logged in to leave comments.
Login now