@@ -0,0 +1,4 | |||||
|
1 | !include( ../test.pri ) { | |||
|
2 | error( "Couldn't find the test.pri file!" ) | |||
|
3 | } | |||
|
4 | SOURCES += tst_domain.cpp |
This diff has been collapsed as it changes many lines, (578 lines changed) Show them Hide them | |||||
@@ -0,0 +1,578 | |||||
|
1 | #include <QtTest/QtTest> | |||
|
2 | #include <private/domain_p.h> | |||
|
3 | ||||
|
4 | QTCOMMERCIALCHART_USE_NAMESPACE | |||
|
5 | ||||
|
6 | Q_DECLARE_METATYPE(Domain*) | |||
|
7 | Q_DECLARE_METATYPE(QSizeF) | |||
|
8 | ||||
|
9 | class tst_Domain : public QObject | |||
|
10 | { | |||
|
11 | Q_OBJECT | |||
|
12 | ||||
|
13 | public slots: | |||
|
14 | void initTestCase(); | |||
|
15 | void cleanupTestCase(); | |||
|
16 | void init(); | |||
|
17 | void cleanup(); | |||
|
18 | ||||
|
19 | private slots: | |||
|
20 | void domain(); | |||
|
21 | void handleAxisRangeXChanged_data(); | |||
|
22 | void handleAxisRangeXChanged(); | |||
|
23 | void handleAxisRangeYChanged_data(); | |||
|
24 | void handleAxisRangeYChanged(); | |||
|
25 | void isEmpty_data(); | |||
|
26 | void isEmpty(); | |||
|
27 | void maxX_data(); | |||
|
28 | void maxX(); | |||
|
29 | void maxY_data(); | |||
|
30 | void maxY(); | |||
|
31 | void minX_data(); | |||
|
32 | void minX(); | |||
|
33 | void minY_data(); | |||
|
34 | void minY(); | |||
|
35 | void operatorEquals_data(); | |||
|
36 | void operatorEquals(); | |||
|
37 | void setRange_data(); | |||
|
38 | void setRange(); | |||
|
39 | void setRangeX_data(); | |||
|
40 | void setRangeX(); | |||
|
41 | void setRangeY_data(); | |||
|
42 | void setRangeY(); | |||
|
43 | void spanX_data(); | |||
|
44 | void spanX(); | |||
|
45 | void spanY_data(); | |||
|
46 | void spanY(); | |||
|
47 | void zoom_data(); | |||
|
48 | void zoom(); | |||
|
49 | }; | |||
|
50 | ||||
|
51 | void tst_Domain::initTestCase() | |||
|
52 | { | |||
|
53 | } | |||
|
54 | ||||
|
55 | void tst_Domain::cleanupTestCase() | |||
|
56 | { | |||
|
57 | } | |||
|
58 | ||||
|
59 | void tst_Domain::init() | |||
|
60 | { | |||
|
61 | } | |||
|
62 | ||||
|
63 | void tst_Domain::cleanup() | |||
|
64 | { | |||
|
65 | } | |||
|
66 | ||||
|
67 | void tst_Domain::domain() | |||
|
68 | { | |||
|
69 | Domain domain; | |||
|
70 | ||||
|
71 | QCOMPARE(domain.isEmpty(), true); | |||
|
72 | QCOMPARE(domain.maxX(), 0.0); | |||
|
73 | QCOMPARE(domain.maxY(), 0.0); | |||
|
74 | QCOMPARE(domain.minX(), 0.0); | |||
|
75 | QCOMPARE(domain.minY(), 0.0); | |||
|
76 | } | |||
|
77 | ||||
|
78 | void tst_Domain::handleAxisRangeXChanged_data() | |||
|
79 | { | |||
|
80 | QTest::addColumn<qreal>("min"); | |||
|
81 | QTest::addColumn<qreal>("max"); | |||
|
82 | QTest::newRow("-1 1") << -1.0 << 1.0; | |||
|
83 | QTest::newRow("0 1") << 0.0 << 1.0; | |||
|
84 | QTest::newRow("-1 0") << -1.0 << 0.0; | |||
|
85 | } | |||
|
86 | ||||
|
87 | void tst_Domain::handleAxisRangeXChanged() | |||
|
88 | { | |||
|
89 | QFETCH(qreal, min); | |||
|
90 | QFETCH(qreal, max); | |||
|
91 | ||||
|
92 | Domain domain; | |||
|
93 | ||||
|
94 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); | |||
|
95 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); | |||
|
96 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); | |||
|
97 | ||||
|
98 | domain.handleAxisRangeXChanged(min, max); | |||
|
99 | ||||
|
100 | QList<QVariant> arg0 = spy0.first(); | |||
|
101 | QVERIFY(arg0.at(0).toReal() == min); | |||
|
102 | QVERIFY(arg0.at(1).toReal() == max); | |||
|
103 | ||||
|
104 | QList<QVariant> arg1 = spy1.first(); | |||
|
105 | QVERIFY(arg1.at(0).toReal() == min); | |||
|
106 | QVERIFY(arg1.at(1).toReal() == max); | |||
|
107 | ||||
|
108 | QCOMPARE(spy0.count(), 1); | |||
|
109 | QCOMPARE(spy1.count(), 1); | |||
|
110 | QCOMPARE(spy2.count(), 0); | |||
|
111 | ||||
|
112 | } | |||
|
113 | ||||
|
114 | void tst_Domain::handleAxisRangeYChanged_data() | |||
|
115 | { | |||
|
116 | QTest::addColumn<qreal>("min"); | |||
|
117 | QTest::addColumn<qreal>("max"); | |||
|
118 | QTest::newRow("-1 1") << -1.0 << 1.0; | |||
|
119 | QTest::newRow("0 1") << 0.0 << 1.0; | |||
|
120 | QTest::newRow("-1 0") << -1.0 << 0.0; | |||
|
121 | } | |||
|
122 | ||||
|
123 | ||||
|
124 | void tst_Domain::handleAxisRangeYChanged() | |||
|
125 | { | |||
|
126 | QFETCH(qreal, min); | |||
|
127 | QFETCH(qreal, max); | |||
|
128 | ||||
|
129 | Domain domain; | |||
|
130 | ||||
|
131 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); | |||
|
132 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); | |||
|
133 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); | |||
|
134 | ||||
|
135 | domain.handleAxisRangeYChanged(min, max); | |||
|
136 | ||||
|
137 | QList<QVariant> arg0 = spy0.first(); | |||
|
138 | QVERIFY(arg0.at(2).toReal() == min); | |||
|
139 | QVERIFY(arg0.at(3).toReal() == max); | |||
|
140 | ||||
|
141 | QList<QVariant> arg1 = spy2.first(); | |||
|
142 | QVERIFY(arg1.at(0).toReal() == min); | |||
|
143 | QVERIFY(arg1.at(1).toReal() == max); | |||
|
144 | ||||
|
145 | QCOMPARE(spy0.count(), 1); | |||
|
146 | QCOMPARE(spy1.count(), 0); | |||
|
147 | QCOMPARE(spy2.count(), 1); | |||
|
148 | } | |||
|
149 | ||||
|
150 | void tst_Domain::isEmpty_data() | |||
|
151 | { | |||
|
152 | QTest::addColumn<qreal>("minX"); | |||
|
153 | QTest::addColumn<qreal>("maxX"); | |||
|
154 | QTest::addColumn<qreal>("minY"); | |||
|
155 | QTest::addColumn<qreal>("maxY"); | |||
|
156 | QTest::addColumn<bool>("isEmpty"); | |||
|
157 | QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true; | |||
|
158 | QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true; | |||
|
159 | QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true; | |||
|
160 | QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false; | |||
|
161 | } | |||
|
162 | ||||
|
163 | void tst_Domain::isEmpty() | |||
|
164 | { | |||
|
165 | QFETCH(qreal, minX); | |||
|
166 | QFETCH(qreal, maxX); | |||
|
167 | QFETCH(qreal, minY); | |||
|
168 | QFETCH(qreal, maxY); | |||
|
169 | QFETCH(bool, isEmpty); | |||
|
170 | ||||
|
171 | Domain domain; | |||
|
172 | domain.setRange(minX,maxX,minY,maxY); | |||
|
173 | QCOMPARE(domain.isEmpty(), isEmpty); | |||
|
174 | } | |||
|
175 | ||||
|
176 | void tst_Domain::maxX_data() | |||
|
177 | { | |||
|
178 | QTest::addColumn<qreal>("maxX1"); | |||
|
179 | QTest::addColumn<qreal>("maxX2"); | |||
|
180 | QTest::addColumn<int>("count"); | |||
|
181 | QTest::newRow("1") << 0.0 << 1.0 << 1; | |||
|
182 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; | |||
|
183 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; | |||
|
184 | } | |||
|
185 | ||||
|
186 | void tst_Domain::maxX() | |||
|
187 | { | |||
|
188 | QFETCH(qreal, maxX1); | |||
|
189 | QFETCH(qreal, maxX2); | |||
|
190 | QFETCH(int, count); | |||
|
191 | ||||
|
192 | Domain domain; | |||
|
193 | ||||
|
194 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); | |||
|
195 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); | |||
|
196 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); | |||
|
197 | ||||
|
198 | domain.setMaxX(maxX1); | |||
|
199 | QCOMPARE(domain.maxX(), maxX1); | |||
|
200 | domain.setMaxX(maxX2); | |||
|
201 | QCOMPARE(domain.maxX(), maxX2); | |||
|
202 | ||||
|
203 | ||||
|
204 | QCOMPARE(spy0.count(), count); | |||
|
205 | QCOMPARE(spy1.count(), count); | |||
|
206 | QCOMPARE(spy2.count(), 0); | |||
|
207 | ||||
|
208 | } | |||
|
209 | ||||
|
210 | void tst_Domain::maxY_data() | |||
|
211 | { | |||
|
212 | QTest::addColumn<qreal>("maxY1"); | |||
|
213 | QTest::addColumn<qreal>("maxY2"); | |||
|
214 | QTest::addColumn<int>("count"); | |||
|
215 | QTest::newRow("1") << 0.0 << 1.0 << 1; | |||
|
216 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; | |||
|
217 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; | |||
|
218 | } | |||
|
219 | ||||
|
220 | ||||
|
221 | void tst_Domain::maxY() | |||
|
222 | { | |||
|
223 | QFETCH(qreal, maxY1); | |||
|
224 | QFETCH(qreal, maxY2); | |||
|
225 | QFETCH(int, count); | |||
|
226 | ||||
|
227 | Domain domain; | |||
|
228 | ||||
|
229 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); | |||
|
230 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); | |||
|
231 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); | |||
|
232 | ||||
|
233 | domain.setMaxY(maxY1); | |||
|
234 | QCOMPARE(domain.maxY(), maxY1); | |||
|
235 | domain.setMaxY(maxY2); | |||
|
236 | QCOMPARE(domain.maxY(), maxY2); | |||
|
237 | ||||
|
238 | QCOMPARE(spy0.count(), count); | |||
|
239 | QCOMPARE(spy1.count(), 0); | |||
|
240 | QCOMPARE(spy2.count(), count); | |||
|
241 | } | |||
|
242 | ||||
|
243 | void tst_Domain::minX_data() | |||
|
244 | { | |||
|
245 | QTest::addColumn<qreal>("minX1"); | |||
|
246 | QTest::addColumn<qreal>("minX2"); | |||
|
247 | QTest::addColumn<int>("count"); | |||
|
248 | QTest::newRow("1") << 0.0 << 1.0 << 1; | |||
|
249 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; | |||
|
250 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; | |||
|
251 | } | |||
|
252 | ||||
|
253 | ||||
|
254 | void tst_Domain::minX() | |||
|
255 | { | |||
|
256 | QFETCH(qreal, minX1); | |||
|
257 | QFETCH(qreal, minX2); | |||
|
258 | QFETCH(int, count); | |||
|
259 | ||||
|
260 | Domain domain; | |||
|
261 | ||||
|
262 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); | |||
|
263 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); | |||
|
264 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); | |||
|
265 | ||||
|
266 | domain.setMinX(minX1); | |||
|
267 | QCOMPARE(domain.minX(), minX1); | |||
|
268 | domain.setMinX(minX2); | |||
|
269 | QCOMPARE(domain.minX(), minX2); | |||
|
270 | ||||
|
271 | QCOMPARE(spy0.count(), count); | |||
|
272 | QCOMPARE(spy1.count(), count); | |||
|
273 | QCOMPARE(spy2.count(), 0); | |||
|
274 | } | |||
|
275 | ||||
|
276 | void tst_Domain::minY_data() | |||
|
277 | { | |||
|
278 | QTest::addColumn<qreal>("minY1"); | |||
|
279 | QTest::addColumn<qreal>("minY2"); | |||
|
280 | QTest::addColumn<int>("count"); | |||
|
281 | QTest::newRow("1") << 0.0 << 1.0 << 1; | |||
|
282 | QTest::newRow("1.0") << 1.0 << 1.0 << 1; | |||
|
283 | QTest::newRow("2.0") << 1.0 << 0.0 << 2; | |||
|
284 | } | |||
|
285 | ||||
|
286 | void tst_Domain::minY() | |||
|
287 | { | |||
|
288 | QFETCH(qreal, minY1); | |||
|
289 | QFETCH(qreal, minY2); | |||
|
290 | QFETCH(int, count); | |||
|
291 | ||||
|
292 | Domain domain; | |||
|
293 | ||||
|
294 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); | |||
|
295 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); | |||
|
296 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); | |||
|
297 | ||||
|
298 | domain.setMinY(minY1); | |||
|
299 | QCOMPARE(domain.minY(), minY1); | |||
|
300 | domain.setMinY(minY2); | |||
|
301 | QCOMPARE(domain.minY(), minY2); | |||
|
302 | ||||
|
303 | QCOMPARE(spy0.count(), count); | |||
|
304 | QCOMPARE(spy1.count(), 0); | |||
|
305 | QCOMPARE(spy2.count(), count); | |||
|
306 | } | |||
|
307 | ||||
|
308 | void tst_Domain::operatorEquals_data() | |||
|
309 | { | |||
|
310 | ||||
|
311 | QTest::addColumn<Domain*>("domain1"); | |||
|
312 | QTest::addColumn<Domain*>("domain2"); | |||
|
313 | QTest::addColumn<bool>("equals"); | |||
|
314 | QTest::addColumn<bool>("notEquals"); | |||
|
315 | Domain* a; | |||
|
316 | Domain* b; | |||
|
317 | a = new Domain(); | |||
|
318 | a->setRange(0,100,0,100); | |||
|
319 | b = new Domain(); | |||
|
320 | b->setRange(0,100,0,100); | |||
|
321 | QTest::newRow("equals") << a << b << true <<false; | |||
|
322 | a = new Domain(); | |||
|
323 | a->setRange(0,100,0,100); | |||
|
324 | b = new Domain(); | |||
|
325 | b->setRange(0,100,0,1); | |||
|
326 | QTest::newRow("equals") << a << b << false << true; | |||
|
327 | a = new Domain(); | |||
|
328 | a->setRange(0,100,0,100); | |||
|
329 | b = new Domain(); | |||
|
330 | b->setRange(0,1,0,100); | |||
|
331 | QTest::newRow("equals") << a << b << false << true; | |||
|
332 | ||||
|
333 | } | |||
|
334 | ||||
|
335 | void tst_Domain::operatorEquals() | |||
|
336 | { | |||
|
337 | QFETCH(Domain*, domain1); | |||
|
338 | QFETCH(Domain*, domain2); | |||
|
339 | QFETCH(bool, equals); | |||
|
340 | QFETCH(bool, notEquals); | |||
|
341 | ||||
|
342 | Domain domain; | |||
|
343 | ||||
|
344 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); | |||
|
345 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); | |||
|
346 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); | |||
|
347 | ||||
|
348 | QCOMPARE(*domain1==*domain2, equals); | |||
|
349 | QCOMPARE(*domain1!=*domain2, notEquals); | |||
|
350 | ||||
|
351 | QCOMPARE(spy0.count(), 0); | |||
|
352 | QCOMPARE(spy1.count(), 0); | |||
|
353 | QCOMPARE(spy2.count(), 0); | |||
|
354 | } | |||
|
355 | ||||
|
356 | void tst_Domain::setRange_data() | |||
|
357 | { | |||
|
358 | QTest::addColumn<qreal>("minX"); | |||
|
359 | QTest::addColumn<qreal>("maxX"); | |||
|
360 | QTest::addColumn<qreal>("minY"); | |||
|
361 | QTest::addColumn<qreal>("maxY"); | |||
|
362 | QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0; | |||
|
363 | QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0; | |||
|
364 | QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0; | |||
|
365 | } | |||
|
366 | ||||
|
367 | void tst_Domain::setRange() | |||
|
368 | { | |||
|
369 | QFETCH(qreal, minX); | |||
|
370 | QFETCH(qreal, maxX); | |||
|
371 | QFETCH(qreal, minY); | |||
|
372 | QFETCH(qreal, maxY); | |||
|
373 | ||||
|
374 | Domain domain; | |||
|
375 | ||||
|
376 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); | |||
|
377 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); | |||
|
378 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); | |||
|
379 | ||||
|
380 | domain.setRange(minX, maxX, minY, maxY); | |||
|
381 | ||||
|
382 | QCOMPARE(domain.minX(), minX); | |||
|
383 | QCOMPARE(domain.maxX(), maxX); | |||
|
384 | QCOMPARE(domain.minY(), minY); | |||
|
385 | QCOMPARE(domain.maxY(), maxY); | |||
|
386 | ||||
|
387 | QCOMPARE(spy0.count(), 1); | |||
|
388 | QCOMPARE(spy1.count(), 1); | |||
|
389 | QCOMPARE(spy2.count(), 1); | |||
|
390 | ||||
|
391 | ||||
|
392 | } | |||
|
393 | ||||
|
394 | void tst_Domain::setRangeX_data() | |||
|
395 | { | |||
|
396 | QTest::addColumn<qreal>("min"); | |||
|
397 | QTest::addColumn<qreal>("max"); | |||
|
398 | QTest::newRow("-1 1") << -1.0 << 1.0; | |||
|
399 | QTest::newRow("0 1") << 0.0 << 1.0; | |||
|
400 | QTest::newRow("-1 0") << -1.0 << 0.0; | |||
|
401 | } | |||
|
402 | ||||
|
403 | void tst_Domain::setRangeX() | |||
|
404 | { | |||
|
405 | QFETCH(qreal, min); | |||
|
406 | QFETCH(qreal, max); | |||
|
407 | ||||
|
408 | Domain domain; | |||
|
409 | ||||
|
410 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); | |||
|
411 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); | |||
|
412 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); | |||
|
413 | ||||
|
414 | domain.setRangeX(min, max); | |||
|
415 | ||||
|
416 | QList<QVariant> arg0 = spy0.first(); | |||
|
417 | QVERIFY(arg0.at(0).toReal() == min); | |||
|
418 | QVERIFY(arg0.at(1).toReal() == max); | |||
|
419 | ||||
|
420 | QList<QVariant> arg1 = spy1.first(); | |||
|
421 | QVERIFY(arg1.at(0).toReal() == min); | |||
|
422 | QVERIFY(arg1.at(1).toReal() == max); | |||
|
423 | ||||
|
424 | QCOMPARE(spy0.count(), 1); | |||
|
425 | QCOMPARE(spy1.count(), 1); | |||
|
426 | QCOMPARE(spy2.count(), 0); | |||
|
427 | } | |||
|
428 | ||||
|
429 | void tst_Domain::setRangeY_data() | |||
|
430 | { | |||
|
431 | QTest::addColumn<qreal>("min"); | |||
|
432 | QTest::addColumn<qreal>("max"); | |||
|
433 | QTest::newRow("-1 1") << -1.0 << 1.0; | |||
|
434 | QTest::newRow("0 1") << 0.0 << 1.0; | |||
|
435 | QTest::newRow("-1 0") << -1.0 << 0.0; | |||
|
436 | } | |||
|
437 | ||||
|
438 | void tst_Domain::setRangeY() | |||
|
439 | { | |||
|
440 | QFETCH(qreal, min); | |||
|
441 | QFETCH(qreal, max); | |||
|
442 | ||||
|
443 | Domain domain; | |||
|
444 | ||||
|
445 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); | |||
|
446 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); | |||
|
447 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); | |||
|
448 | ||||
|
449 | domain.setRangeY(min, max); | |||
|
450 | ||||
|
451 | QList<QVariant> arg0 = spy0.first(); | |||
|
452 | QVERIFY(arg0.at(2).toReal() == min); | |||
|
453 | QVERIFY(arg0.at(3).toReal() == max); | |||
|
454 | ||||
|
455 | QList<QVariant> arg1 = spy2.first(); | |||
|
456 | QVERIFY(arg1.at(0).toReal() == min); | |||
|
457 | QVERIFY(arg1.at(1).toReal() == max); | |||
|
458 | ||||
|
459 | QCOMPARE(spy0.count(), 1); | |||
|
460 | QCOMPARE(spy1.count(), 0); | |||
|
461 | QCOMPARE(spy2.count(), 1); | |||
|
462 | } | |||
|
463 | ||||
|
464 | void tst_Domain::spanX_data() | |||
|
465 | { | |||
|
466 | QTest::addColumn<qreal>("minX"); | |||
|
467 | QTest::addColumn<qreal>("maxX"); | |||
|
468 | QTest::addColumn<qreal>("spanX"); | |||
|
469 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; | |||
|
470 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; | |||
|
471 | } | |||
|
472 | ||||
|
473 | void tst_Domain::spanX() | |||
|
474 | { | |||
|
475 | QFETCH(qreal, minX); | |||
|
476 | QFETCH(qreal, maxX); | |||
|
477 | QFETCH(qreal, spanX); | |||
|
478 | ||||
|
479 | Domain domain; | |||
|
480 | ||||
|
481 | domain.setRangeX(minX,maxX); | |||
|
482 | ||||
|
483 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); | |||
|
484 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); | |||
|
485 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); | |||
|
486 | ||||
|
487 | QCOMPARE(domain.spanX(), spanX); | |||
|
488 | ||||
|
489 | QCOMPARE(spy0.count(), 0); | |||
|
490 | QCOMPARE(spy1.count(), 0); | |||
|
491 | QCOMPARE(spy2.count(), 0); | |||
|
492 | } | |||
|
493 | ||||
|
494 | void tst_Domain::spanY_data() | |||
|
495 | { | |||
|
496 | QTest::addColumn<qreal>("minY"); | |||
|
497 | QTest::addColumn<qreal>("maxY"); | |||
|
498 | QTest::addColumn<qreal>("spanY"); | |||
|
499 | QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0; | |||
|
500 | QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0; | |||
|
501 | } | |||
|
502 | ||||
|
503 | void tst_Domain::spanY() | |||
|
504 | { | |||
|
505 | QFETCH(qreal, minY); | |||
|
506 | QFETCH(qreal, maxY); | |||
|
507 | QFETCH(qreal, spanY); | |||
|
508 | ||||
|
509 | Domain domain; | |||
|
510 | ||||
|
511 | domain.setRangeY(minY,maxY); | |||
|
512 | ||||
|
513 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); | |||
|
514 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); | |||
|
515 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); | |||
|
516 | ||||
|
517 | QCOMPARE(domain.spanY(), spanY); | |||
|
518 | ||||
|
519 | QCOMPARE(spy0.count(), 0); | |||
|
520 | QCOMPARE(spy1.count(), 0); | |||
|
521 | QCOMPARE(spy2.count(), 0); | |||
|
522 | } | |||
|
523 | ||||
|
524 | ||||
|
525 | void tst_Domain::zoom_data() | |||
|
526 | { | |||
|
527 | QTest::addColumn<QRectF>("rect0"); | |||
|
528 | QTest::addColumn<QSizeF>("size0"); | |||
|
529 | QTest::addColumn<QRectF>("rect1"); | |||
|
530 | QTest::addColumn<QSizeF>("size1"); | |||
|
531 | QTest::addColumn<QRectF>("rect2"); | |||
|
532 | QTest::addColumn<QSizeF>("size2"); | |||
|
533 | QTest::newRow("first") << QRectF(10,10,100,100) << QSizeF(1000,1000) << QRectF(20,20,100,100) << QSizeF(1000,1000) << QRectF(50,50,100,100) << QSizeF(1000,1000); | |||
|
534 | QTest::newRow("scound") << QRectF(10,10,50,50) << QSizeF(1000,1000) << QRectF(20,20,100,100) << QSizeF(1000,1000) << QRectF(50,50,100,100) << QSizeF(1000,1000); | |||
|
535 | QTest::newRow("third") << QRectF(10,10,10,10) << QSizeF(100,100) << QRectF(20,20,20,20) << QSizeF(100,100) << QRectF(50,50,50,50) << QSizeF(100,100); | |||
|
536 | } | |||
|
537 | ||||
|
538 | void tst_Domain::zoom() | |||
|
539 | { | |||
|
540 | QFETCH(QRectF, rect0); | |||
|
541 | QFETCH(QSizeF, size0); | |||
|
542 | QFETCH(QRectF, rect1); | |||
|
543 | QFETCH(QSizeF, size1); | |||
|
544 | QFETCH(QRectF, rect2); | |||
|
545 | QFETCH(QSizeF, size2); | |||
|
546 | ||||
|
547 | Domain domain; | |||
|
548 | ||||
|
549 | domain.setRange(0,1000,0,1000); | |||
|
550 | ||||
|
551 | QSignalSpy spy0(&domain, SIGNAL(domainChanged(qreal, qreal, qreal, qreal))); | |||
|
552 | QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal, qreal))); | |||
|
553 | QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal, qreal))); | |||
|
554 | ||||
|
555 | Domain domain0; | |||
|
556 | domain0.setRange(domain.minX(),domain.maxX(),domain.minY(),domain.maxY()); | |||
|
557 | domain.zoomIn(rect0, size0); | |||
|
558 | Domain domain1; | |||
|
559 | domain1.setRange(domain.minX(),domain.maxX(),domain.minY(),domain.maxY()); | |||
|
560 | domain.zoomIn(rect1, size1); | |||
|
561 | Domain domain2; | |||
|
562 | domain2.setRange(domain.minX(),domain.maxX(),domain.minY(),domain.maxY()); | |||
|
563 | domain.zoomIn(rect2, size2); | |||
|
564 | domain.zoomOut(rect2, size2); | |||
|
565 | QCOMPARE(domain == domain2,true); | |||
|
566 | domain.zoomOut(rect1, size1); | |||
|
567 | QCOMPARE(domain == domain1,true); | |||
|
568 | domain.zoomOut(rect0, size0); | |||
|
569 | QCOMPARE(domain == domain0,true); | |||
|
570 | QCOMPARE(spy0.count(), 6); | |||
|
571 | QCOMPARE(spy1.count(), 6); | |||
|
572 | QCOMPARE(spy2.count(), 6); | |||
|
573 | ||||
|
574 | } | |||
|
575 | ||||
|
576 | QTEST_MAIN(tst_Domain) | |||
|
577 | #include "tst_domain.moc" | |||
|
578 |
@@ -1,7 +1,6 | |||||
1 | #include "areachartitem_p.h" |
|
1 | #include "areachartitem_p.h" | |
2 | #include "qareaseries.h" |
|
2 | #include "qareaseries.h" | |
3 | #include "qlineseries.h" |
|
3 | #include "qlineseries.h" | |
4 | #include "chartpresenter_p.h" |
|
|||
5 | #include <QPainter> |
|
4 | #include <QPainter> | |
6 |
|
5 | |||
7 |
|
6 | |||
@@ -9,20 +8,17 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
9 |
|
8 | |||
10 | //TODO: optimize : remove points which are not visible |
|
9 | //TODO: optimize : remove points which are not visible | |
11 |
|
10 | |||
12 |
AreaChartItem::AreaChartItem( |
|
11 | AreaChartItem::AreaChartItem(QAreaSeries* areaSeries,QGraphicsItem *parent):ChartItem(parent), | |
13 | m_presenter(presenter), |
|
|||
14 | m_series(areaSeries), |
|
12 | m_series(areaSeries), | |
15 | m_upper(0), |
|
13 | m_upper(0), | |
16 | m_lower(0) |
|
14 | m_lower(0) | |
17 | { |
|
15 | { | |
18 | //m_items.setZValue(ChartPresenter::LineChartZValue); |
|
16 | //m_items.setZValue(ChartPresenter::LineChartZValue); | |
19 |
m_upper = new AreaBoundItem(this, |
|
17 | m_upper = new AreaBoundItem(this,m_series->upperSeries()); | |
20 | if(m_series->lowerSeries()){ |
|
18 | if(m_series->lowerSeries()){ | |
21 |
m_lower = new AreaBoundItem(this, |
|
19 | m_lower = new AreaBoundItem(this,m_series->lowerSeries()); | |
22 | } |
|
20 | } | |
23 | setZValue(ChartPresenter::LineChartZValue); |
|
|||
24 |
|
21 | |||
25 | QObject::connect(presenter,SIGNAL(geometryChanged(const QRectF&)),this,SLOT(handleGeometryChanged(const QRectF&))); |
|
|||
26 | QObject::connect(areaSeries,SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
22 | QObject::connect(areaSeries,SIGNAL(updated()),this,SLOT(handleUpdated())); | |
27 |
|
23 | |||
28 | handleUpdated(); |
|
24 | handleUpdated(); | |
@@ -82,11 +78,11 void AreaChartItem::handleUpdated() | |||||
82 | update(); |
|
78 | update(); | |
83 | } |
|
79 | } | |
84 |
|
80 | |||
85 |
void AreaChartItem::handleDomainChanged( |
|
81 | void AreaChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
86 | { |
|
82 | { | |
87 |
m_upper->handleDomainChanged( |
|
83 | m_upper->handleDomainChanged(minX,maxX,minY,maxY); | |
88 | if(m_lower) |
|
84 | if(m_lower) | |
89 |
m_lower->handleDomainChanged( |
|
85 | m_lower->handleDomainChanged(minX,maxX,minY,maxY); | |
90 | } |
|
86 | } | |
91 |
|
87 | |||
92 | void AreaChartItem::handleGeometryChanged(const QRectF& rect) |
|
88 | void AreaChartItem::handleGeometryChanged(const QRectF& rect) |
@@ -15,7 +15,7 class AreaChartItem : public QObject ,public ChartItem | |||||
15 | { |
|
15 | { | |
16 | Q_OBJECT |
|
16 | Q_OBJECT | |
17 | public: |
|
17 | public: | |
18 |
AreaChartItem( |
|
18 | AreaChartItem(QAreaSeries* areaSeries, QGraphicsItem *parent = 0); | |
19 | ~ AreaChartItem(); |
|
19 | ~ AreaChartItem(); | |
20 |
|
20 | |||
21 | //from QGraphicsItem |
|
21 | //from QGraphicsItem | |
@@ -29,15 +29,14 public: | |||||
29 | void updatePath(); |
|
29 | void updatePath(); | |
30 | public slots: |
|
30 | public slots: | |
31 | void handleUpdated(); |
|
31 | void handleUpdated(); | |
32 |
void handleDomainChanged( |
|
32 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
33 | void handleGeometryChanged(const QRectF& size); |
|
33 | void handleGeometryChanged(const QRectF& size); | |
34 |
|
34 | |||
35 | private: |
|
35 | private: | |
36 | ChartPresenter* m_presenter; |
|
|||
37 | QPainterPath m_path; |
|
|||
38 | QAreaSeries* m_series; |
|
36 | QAreaSeries* m_series; | |
39 | LineChartItem* m_upper; |
|
37 | LineChartItem* m_upper; | |
40 | LineChartItem* m_lower; |
|
38 | LineChartItem* m_lower; | |
|
39 | QPainterPath m_path; | |||
41 | QRectF m_rect; |
|
40 | QRectF m_rect; | |
42 | QRectF m_clipRect; |
|
41 | QRectF m_clipRect; | |
43 | QPen m_pen; |
|
42 | QPen m_pen; | |
@@ -47,7 +46,7 private: | |||||
47 | class AreaBoundItem : public LineChartItem |
|
46 | class AreaBoundItem : public LineChartItem | |
48 | { |
|
47 | { | |
49 | public: |
|
48 | public: | |
50 |
AreaBoundItem(AreaChartItem* item, |
|
49 | AreaBoundItem(AreaChartItem* item,QLineSeries* lineSeries):LineChartItem(lineSeries), | |
51 | m_item(item){}; |
|
50 | m_item(item){}; | |
52 |
|
51 | |||
53 | ~AreaBoundItem(){}; |
|
52 | ~AreaBoundItem(){}; |
@@ -7,8 +7,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
7 |
|
7 | |||
8 | const static int duration = 500; |
|
8 | const static int duration = 500; | |
9 |
|
9 | |||
10 | AxisAnimationItem::AxisAnimationItem(AxisType type,QGraphicsItem* parent) : |
|
10 | AxisAnimationItem::AxisAnimationItem(QChartAxis* axis,AxisType type,QGraphicsItem* parent) : | |
11 | AxisItem(type,parent), |
|
11 | AxisItem(axis,type,parent), | |
12 | m_animation(new AxisAnimator(this,this)) |
|
12 | m_animation(new AxisAnimator(this,this)) | |
13 | { |
|
13 | { | |
14 | } |
|
14 | } |
@@ -15,7 +15,7 class AxisAnimationItem : public AxisItem | |||||
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 |
|
16 | |||
17 | public: |
|
17 | public: | |
18 | AxisAnimationItem(AxisType type = X_AXIS,QGraphicsItem* parent = 0); |
|
18 | AxisAnimationItem(QChartAxis* axis,AxisType type = X_AXIS,QGraphicsItem* parent = 0); | |
19 | ~AxisAnimationItem(); |
|
19 | ~AxisAnimationItem(); | |
20 |
|
20 | |||
21 | void setLabelsAngle(int angle); |
|
21 | void setLabelsAngle(int angle); |
@@ -8,8 +8,9 static int label_padding = 5; | |||||
8 |
|
8 | |||
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
9 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
10 |
|
10 | |||
11 | AxisItem::AxisItem(AxisType type,QGraphicsItem* parent) : |
|
11 | AxisItem::AxisItem(QChartAxis* axis,AxisType type,QGraphicsItem* parent) : | |
12 | ChartItem(parent), |
|
12 | ChartItem(parent), | |
|
13 | m_chartAxis(axis), | |||
13 | m_type(type), |
|
14 | m_type(type), | |
14 | m_labelsAngle(0), |
|
15 | m_labelsAngle(0), | |
15 | m_grid(parent), |
|
16 | m_grid(parent), | |
@@ -22,6 +23,8 m_axis(parent) | |||||
22 | m_shades.setZValue(ChartPresenter::ShadesZValue); |
|
23 | m_shades.setZValue(ChartPresenter::ShadesZValue); | |
23 | m_grid.setZValue(ChartPresenter::GridZValue); |
|
24 | m_grid.setZValue(ChartPresenter::GridZValue); | |
24 | setFlags(QGraphicsItem::ItemHasNoContents); |
|
25 | setFlags(QGraphicsItem::ItemHasNoContents); | |
|
26 | ||||
|
27 | QObject::connect(m_chartAxis,SIGNAL(updated()),this,SLOT(handleAxisUpdated())); | |||
25 | } |
|
28 | } | |
26 |
|
29 | |||
27 | AxisItem::~AxisItem() |
|
30 | AxisItem::~AxisItem() | |
@@ -74,72 +77,27 void AxisItem::updateItems(QVector<qreal>& oldLayout,QVector<qreal>& newLayout) | |||||
74 | oldLayout=newLayout; |
|
77 | oldLayout=newLayout; | |
75 | } |
|
78 | } | |
76 |
|
79 | |||
77 | void AxisItem::handleAxisUpdate(QChartAxis* axis) |
|
80 | QStringList AxisItem::createLabels(int ticks, qreal min, qreal max) | |
78 | { |
|
81 | { | |
79 | if(m_layoutVector.count()==0) return; |
|
|||
80 |
|
82 | |||
81 | if(axis->isAxisVisible()) { |
|
|||
82 | setAxisOpacity(100); |
|
|||
83 | } |
|
|||
84 | else { |
|
|||
85 | setAxisOpacity(0); |
|
|||
86 | } |
|
|||
87 |
|
83 | |||
88 | if(axis->isGridVisible()) { |
|
84 | Q_ASSERT(max>=min); | |
89 | setGridOpacity(100); |
|
|||
90 | } |
|
|||
91 | else { |
|
|||
92 | setGridOpacity(0); |
|
|||
93 | } |
|
|||
94 |
|
85 | |||
95 | if(axis->labelsVisible()) |
|
86 | QStringList labels; | |
96 | { |
|
|||
97 | setLabelsOpacity(100); |
|
|||
98 | } |
|
|||
99 | else { |
|
|||
100 | setLabelsOpacity(0); |
|
|||
101 | } |
|
|||
102 |
|
87 | |||
103 | if(axis->shadesVisible()) { |
|
88 | //int ticks = axis->ticksCount()-1; | |
104 | setShadesOpacity(axis->shadesOpacity()); |
|
|||
105 | } |
|
|||
106 | else { |
|
|||
107 | setShadesOpacity(0); |
|
|||
108 | } |
|
|||
109 |
|
89 | |||
110 | setLabelsAngle(axis->labelsAngle()); |
|
90 | for(int i=0; i<= ticks; i++) { | |
111 | setAxisPen(axis->axisPen()); |
|
91 | qreal value = min + (i * (max - min)/ ticks); | |
112 | setLabelsPen(axis->labelsPen()); |
|
92 | QString label ;//= axis->axisTickLabel(value); | |
113 | setLabelsBrush(axis->labelsBrush()); |
|
93 | if(label.isEmpty()) { | |
114 | setLabelsFont(axis->labelsFont()); |
|
94 | labels << QString::number(value); | |
115 | setGridPen(axis->gridPen()); |
|
|||
116 | setShadesPen(axis->shadesPen()); |
|
|||
117 | setShadesBrush(axis->shadesBrush()); |
|
|||
118 | } |
|
95 | } | |
119 |
|
96 | else { | ||
120 | void AxisItem::handleRangeChanged(QChartAxis* axis,const QStringList& labels) |
|
97 | labels << label; | |
121 | { |
|
|||
122 | int diff = m_thicksList.size() - labels.size(); |
|
|||
123 |
|
||||
124 | if(diff>0){ |
|
|||
125 | clear(diff); |
|
|||
126 | }else if(diff<0){ |
|
|||
127 | createItems(-diff); |
|
|||
128 | } |
|
98 | } | |
129 | m_thicksList=labels; |
|
|||
130 | QVector<qreal> vector = calculateLayout(); |
|
|||
131 | updateItems(m_layoutVector,vector); |
|
|||
132 | if(diff!=0) handleAxisUpdate(axis); |
|
|||
133 | } |
|
99 | } | |
134 |
|
100 | return labels; | ||
135 | void AxisItem::handleGeometryChanged(const QRectF& rect) |
|
|||
136 | { |
|
|||
137 | m_rect = rect; |
|
|||
138 |
|
||||
139 | if(m_thicksList.size()==0) return; |
|
|||
140 |
|
||||
141 | QVector<qreal> vector = calculateLayout(); |
|
|||
142 | updateItems(m_layoutVector,vector); |
|
|||
143 | } |
|
101 | } | |
144 |
|
102 | |||
145 | void AxisItem::setAxisOpacity(qreal opacity) |
|
103 | void AxisItem::setAxisOpacity(qreal opacity) | |
@@ -334,6 +292,85 void AxisItem::applyLayout(const QVector<qreal>& points) | |||||
334 | } |
|
292 | } | |
335 | } |
|
293 | } | |
336 |
|
294 | |||
|
295 | //handlers | |||
|
296 | ||||
|
297 | void AxisItem::handleAxisUpdated() | |||
|
298 | { | |||
|
299 | if(m_layoutVector.count()==0) return; | |||
|
300 | ||||
|
301 | if(m_chartAxis->isAxisVisible()) { | |||
|
302 | setAxisOpacity(100); | |||
|
303 | } | |||
|
304 | else { | |||
|
305 | setAxisOpacity(0); | |||
|
306 | } | |||
|
307 | ||||
|
308 | if(m_chartAxis->isGridVisible()) { | |||
|
309 | setGridOpacity(100); | |||
|
310 | } | |||
|
311 | else { | |||
|
312 | setGridOpacity(0); | |||
|
313 | } | |||
|
314 | ||||
|
315 | if(m_chartAxis->labelsVisible()) | |||
|
316 | { | |||
|
317 | setLabelsOpacity(100); | |||
|
318 | } | |||
|
319 | else { | |||
|
320 | setLabelsOpacity(0); | |||
|
321 | } | |||
|
322 | ||||
|
323 | if(m_chartAxis->shadesVisible()) { | |||
|
324 | setShadesOpacity(m_chartAxis->shadesOpacity()); | |||
|
325 | } | |||
|
326 | else { | |||
|
327 | setShadesOpacity(0); | |||
|
328 | } | |||
|
329 | ||||
|
330 | setLabelsAngle(m_chartAxis->labelsAngle()); | |||
|
331 | setAxisPen(m_chartAxis->axisPen()); | |||
|
332 | setLabelsPen(m_chartAxis->labelsPen()); | |||
|
333 | setLabelsBrush(m_chartAxis->labelsBrush()); | |||
|
334 | setLabelsFont(m_chartAxis->labelsFont()); | |||
|
335 | setGridPen(m_chartAxis->gridPen()); | |||
|
336 | setShadesPen(m_chartAxis->shadesPen()); | |||
|
337 | setShadesBrush(m_chartAxis->shadesBrush()); | |||
|
338 | } | |||
|
339 | ||||
|
340 | void AxisItem::handleRangeChanged(qreal min, qreal max) | |||
|
341 | { | |||
|
342 | if(min == max) return; | |||
|
343 | ||||
|
344 | QStringList labels = createLabels(4,min,max); | |||
|
345 | ||||
|
346 | int diff = m_thicksList.size() - labels.size(); | |||
|
347 | ||||
|
348 | if(diff>0){ | |||
|
349 | clear(diff); | |||
|
350 | }else if(diff<0){ | |||
|
351 | createItems(-diff); | |||
|
352 | } | |||
|
353 | m_thicksList=labels; | |||
|
354 | ||||
|
355 | if(m_rect.isEmpty()) return; | |||
|
356 | ||||
|
357 | QVector<qreal> vector = calculateLayout(); | |||
|
358 | ||||
|
359 | updateItems(m_layoutVector,vector); | |||
|
360 | ||||
|
361 | if(diff!=0) handleAxisUpdated(); | |||
|
362 | } | |||
|
363 | ||||
|
364 | void AxisItem::handleGeometryChanged(const QRectF& rect) | |||
|
365 | { | |||
|
366 | m_rect = rect; | |||
|
367 | ||||
|
368 | if(m_thicksList.size()==0) return; | |||
|
369 | ||||
|
370 | QVector<qreal> vector = calculateLayout(); | |||
|
371 | updateItems(m_layoutVector,vector); | |||
|
372 | } | |||
|
373 | ||||
337 | //TODO "nice numbers algorithm" |
|
374 | //TODO "nice numbers algorithm" | |
338 | #include "moc_axisitem_p.cpp" |
|
375 | #include "moc_axisitem_p.cpp" | |
339 |
|
376 |
@@ -15,7 +15,7 class AxisItem : public QObject, public ChartItem | |||||
15 | public: |
|
15 | public: | |
16 | enum AxisType{X_AXIS,Y_AXIS}; |
|
16 | enum AxisType{X_AXIS,Y_AXIS}; | |
17 |
|
17 | |||
18 | AxisItem(AxisType type = X_AXIS,QGraphicsItem* parent = 0); |
|
18 | AxisItem(QChartAxis* axis,AxisType type = X_AXIS,QGraphicsItem* parent = 0); | |
19 | ~AxisItem(); |
|
19 | ~AxisItem(); | |
20 |
|
20 | |||
21 | //from QGraphicsItem |
|
21 | //from QGraphicsItem | |
@@ -50,9 +50,10 public: | |||||
50 | void setLabelsFont(const QFont& font); |
|
50 | void setLabelsFont(const QFont& font); | |
51 |
|
51 | |||
52 | public slots: |
|
52 | public slots: | |
53 |
void handleAxisUpdate( |
|
53 | void handleAxisUpdated();//qchartaxis update calls | |
54 | void handleRangeChanged(QChartAxis* axis,const QStringList& labels); //labels from dataset |
|
54 | void handleRangeChanged(qreal min , qreal max); //domain update calls | |
55 |
void handleGeometryChanged(const QRectF& size); // |
|
55 | void handleGeometryChanged(const QRectF& size); //geometry update calls | |
|
56 | ||||
56 | public: |
|
57 | public: | |
57 | virtual void updateItems(QVector<qreal>& oldLayout,QVector<qreal>& newLayout); |
|
58 | virtual void updateItems(QVector<qreal>& oldLayout,QVector<qreal>& newLayout); | |
58 | QVector<qreal> calculateLayout() const; |
|
59 | QVector<qreal> calculateLayout() const; | |
@@ -61,7 +62,9 public: | |||||
61 | private: |
|
62 | private: | |
62 | void clear(int count); |
|
63 | void clear(int count); | |
63 | void createItems(int count); |
|
64 | void createItems(int count); | |
|
65 | QStringList createLabels(int ticks, qreal min, qreal max); | |||
64 | private: |
|
66 | private: | |
|
67 | QChartAxis* m_chartAxis; | |||
65 | AxisType m_type; |
|
68 | AxisType m_type; | |
66 | QRectF m_rect; |
|
69 | QRectF m_rect; | |
67 | int m_labelsAngle; |
|
70 | int m_labelsAngle; |
@@ -22,39 +22,102 ChartDataSet::ChartDataSet(QObject *parent):QObject(parent), | |||||
22 |
|
22 | |||
23 | ChartDataSet::~ChartDataSet() |
|
23 | ChartDataSet::~ChartDataSet() | |
24 | { |
|
24 | { | |
25 | // TODO Auto-generated destructor stub |
|
|||
26 | } |
|
25 | } | |
27 |
|
26 | |||
28 |
|
|
27 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |
29 | { |
|
28 | { | |
30 | int i = m_domainMap.count(axisY); |
|
29 | if(axisY==0) axisY = m_axisY; | |
31 | if(i == 0){ |
|
30 | ||
32 | return Domain(); |
|
31 | QChartAxis* axis = m_seriesAxisMap.value(series); | |
|
32 | ||||
|
33 | if(axis) { | |||
|
34 | qWarning() << "Can not add series. Series already on the chart"; | |||
|
35 | return; | |||
|
36 | } | |||
|
37 | ||||
|
38 | if(!series->parent()){ | |||
|
39 | series->setParent(this); // take ownership | |||
|
40 | }; | |||
|
41 | ||||
|
42 | if(!axisY->parent()){ | |||
|
43 | axisY->setParent(this); // take ownership | |||
33 | } |
|
44 | } | |
34 | i = i - m_domainIndex -1; |
|
45 | ||
35 |
|
|
46 | Domain* domain = m_axisDomainMap.value(axisY); | |
|
47 | ||||
|
48 | if(!domain) { | |||
|
49 | domain = new Domain(); | |||
|
50 | ||||
|
51 | QObject::connect(axisY,SIGNAL(rangeChanged(qreal,qreal)),domain,SLOT(handleAxisRangeXChanged(qreal,qreal))); | |||
|
52 | QObject::connect(axisX(),SIGNAL(rangeChanged(qreal,qreal)),domain,SLOT(handleAxisRangeYChanged(qreal,qreal))); | |||
|
53 | ||||
|
54 | m_axisDomainMap.insert(axisY,domain); | |||
|
55 | emit axisAdded(axisY,domain); | |||
36 | } |
|
56 | } | |
37 |
|
57 | |||
38 | void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) |
|
58 | if(!m_axisXInitialized){ | |
|
59 | emit axisAdded(axisX(),domain); | |||
|
60 | m_axisXInitialized=true; | |||
|
61 | } | |||
|
62 | ||||
|
63 | calculateDomain(series,domain); | |||
|
64 | ||||
|
65 | m_seriesAxisMap.insert(series,axisY); | |||
|
66 | emit seriesAdded(series,domain); | |||
|
67 | ||||
|
68 | } | |||
|
69 | ||||
|
70 | void ChartDataSet::removeSeries(QSeries* series) | |||
39 | { |
|
71 | { | |
40 | // TODO: we should check the series not already added |
|
|||
41 |
|
72 | |||
42 | series->setParent(this);// take ownership |
|
73 | QChartAxis* axis = m_seriesAxisMap.value(series); | |
43 | clearDomains(); |
|
|||
44 |
|
74 | |||
45 | if(axisY==0) axisY = m_axisY; |
|
75 | if(!axis){ | |
46 | axisY->setParent(this);// take ownership |
|
76 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
|
77 | return; | |||
|
78 | } | |||
|
79 | emit seriesRemoved(series); | |||
|
80 | m_seriesAxisMap.remove(series); | |||
|
81 | ||||
|
82 | if(series->parent()==this){ | |||
|
83 | delete series; | |||
|
84 | series=0; | |||
|
85 | } | |||
|
86 | ||||
|
87 | QList<QChartAxis*> axes = m_seriesAxisMap.values(); | |||
|
88 | ||||
|
89 | int i = axes.indexOf(axis); | |||
|
90 | ||||
|
91 | if(i==-1){ | |||
|
92 | Domain* domain = m_axisDomainMap.take(axis); | |||
|
93 | emit axisRemoved(axis); | |||
|
94 | delete domain; | |||
|
95 | } | |||
47 |
|
96 | |||
48 | QList<QSeries*> seriesList = m_seriesMap.values(axisY); |
|
97 | if(m_seriesAxisMap.values().size()==0) | |
|
98 | { | |||
|
99 | m_axisXInitialized=false; | |||
|
100 | emit axisRemoved(axisX()); | |||
|
101 | } | |||
|
102 | } | |||
49 |
|
103 | |||
50 | QList<Domain> domainList = m_domainMap.values(axisY); |
|
104 | void ChartDataSet::removeAllSeries() | |
|
105 | { | |||
51 |
|
106 | |||
52 | Q_ASSERT(domainList.size()<=1); |
|
107 | QList<QSeries*> series = m_seriesAxisMap.keys(); | |
53 |
|
108 | |||
54 | Domain domain; |
|
109 | foreach(QSeries* s , series) { | |
|
110 | removeSeries(s); | |||
|
111 | } | |||
|
112 | ||||
|
113 | Q_ASSERT(m_seriesAxisMap.count()==0); | |||
|
114 | Q_ASSERT(m_axisDomainMap.count()==0); | |||
55 |
|
115 | |||
56 | if(domainList.size()>0) domain = domainList.at(0); |
|
116 | } | |
57 |
|
117 | |||
|
118 | //to be removed with PIMPL | |||
|
119 | void ChartDataSet::calculateDomain(QSeries* series,Domain* domain) const | |||
|
120 | { | |||
58 | switch(series->type()) |
|
121 | switch(series->type()) | |
59 | { |
|
122 | { | |
60 | case QSeries::SeriesTypeLine: { |
|
123 | case QSeries::SeriesTypeLine: { | |
@@ -65,10 +128,10 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||||
65 | { |
|
128 | { | |
66 | qreal x = lineSeries->x(i); |
|
129 | qreal x = lineSeries->x(i); | |
67 | qreal y = lineSeries->y(i); |
|
130 | qreal y = lineSeries->y(i); | |
68 |
domain |
|
131 | domain->setMinX(qMin(domain->minX(),x)); | |
69 |
domain |
|
132 | domain->setMinY(qMin(domain->minY(),y)); | |
70 |
domain |
|
133 | domain->setMaxX(qMax(domain->maxX(),x)); | |
71 |
domain |
|
134 | domain->setMaxY(qMax(domain->maxY(),y)); | |
72 | } |
|
135 | } | |
73 | break; |
|
136 | break; | |
74 | } |
|
137 | } | |
@@ -83,20 +146,20 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||||
83 | { |
|
146 | { | |
84 |
qreal x = |
|
147 | qreal x = upperSeries->x(i); | |
85 |
qreal y = |
|
148 | qreal y = upperSeries->y(i); | |
86 |
domain |
|
149 | domain->setMinX(qMin(domain->minX(),x)); | |
87 |
domain |
|
150 | domain->setMinY(qMin(domain->minY(),y)); | |
88 |
domain |
|
151 | domain->setMaxX(qMax(domain->maxX(),x)); | |
89 |
domain |
|
152 | domain->setMaxY(qMax(domain->maxY(),y)); | |
90 | } |
|
153 | } | |
91 | if(lowerSeries){ |
|
154 | if(lowerSeries) { | |
92 | for (int i = 0; i < lowerSeries->count(); i++) |
|
155 | for (int i = 0; i < lowerSeries->count(); i++) | |
93 | { |
|
156 | { | |
94 | qreal x = lowerSeries->x(i); |
|
157 | qreal x = lowerSeries->x(i); | |
95 | qreal y = lowerSeries->y(i); |
|
158 | qreal y = lowerSeries->y(i); | |
96 |
domain |
|
159 | domain->setMinX(qMin(domain->minX(),x)); | |
97 |
domain |
|
160 | domain->setMinY(qMin(domain->minY(),y)); | |
98 |
domain |
|
161 | domain->setMaxX(qMax(domain->maxX(),x)); | |
99 |
domain |
|
162 | domain->setMaxY(qMax(domain->maxY(),y)); | |
100 | }} |
|
163 | }} | |
101 | break; |
|
164 | break; | |
102 | } |
|
165 | } | |
@@ -105,10 +168,10 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||||
105 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); |
|
168 | QBarSeries* barSeries = static_cast<QBarSeries*>(series); | |
106 | qreal x = barSeries->categoryCount(); |
|
169 | qreal x = barSeries->categoryCount(); | |
107 | qreal y = barSeries->max(); |
|
170 | qreal y = barSeries->max(); | |
108 |
domain |
|
171 | domain->setMinX(qMin(domain->minX(),x)); | |
109 |
domain |
|
172 | domain->setMinY(qMin(domain->minY(),y)); | |
110 |
domain |
|
173 | domain->setMaxX(qMax(domain->maxX(),x)); | |
111 |
domain |
|
174 | domain->setMaxY(qMax(domain->maxY(),y)); | |
112 | break; |
|
175 | break; | |
113 | } |
|
176 | } | |
114 | case QSeries::SeriesTypeStackedBar: { |
|
177 | case QSeries::SeriesTypeStackedBar: { | |
@@ -117,10 +180,10 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||||
117 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); |
|
180 | QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series); | |
118 | qreal x = stackedBarSeries->categoryCount(); |
|
181 | qreal x = stackedBarSeries->categoryCount(); | |
119 | qreal y = stackedBarSeries->maxCategorySum(); |
|
182 | qreal y = stackedBarSeries->maxCategorySum(); | |
120 |
domain |
|
183 | domain->setMinX(qMin(domain->minX(),x)); | |
121 |
domain |
|
184 | domain->setMinY(qMin(domain->minY(),y)); | |
122 |
domain |
|
185 | domain->setMaxX(qMax(domain->maxX(),x)); | |
123 |
domain |
|
186 | domain->setMaxY(qMax(domain->maxY(),y)); | |
124 | break; |
|
187 | break; | |
125 | } |
|
188 | } | |
126 | case QSeries::SeriesTypePercentBar: { |
|
189 | case QSeries::SeriesTypePercentBar: { | |
@@ -128,10 +191,10 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||||
128 |
|
191 | |||
129 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); |
|
192 | QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series); | |
130 | qreal x = percentBarSeries->categoryCount(); |
|
193 | qreal x = percentBarSeries->categoryCount(); | |
131 |
domain |
|
194 | domain->setMinX(qMin(domain->minX(),x)); | |
132 |
domain |
|
195 | domain->setMinY(0); | |
133 |
domain |
|
196 | domain->setMaxX(qMax(domain->maxX(),x)); | |
134 |
domain |
|
197 | domain->setMaxY(100); | |
135 | break; |
|
198 | break; | |
136 | } |
|
199 | } | |
137 |
|
200 | |||
@@ -145,10 +208,10 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||||
145 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); |
|
208 | QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series); | |
146 | Q_ASSERT(scatterSeries); |
|
209 | Q_ASSERT(scatterSeries); | |
147 | foreach (QPointF point, scatterSeries->data()) { |
|
210 | foreach (QPointF point, scatterSeries->data()) { | |
148 |
domain |
|
211 | domain->setMinX(qMin(domain->minX(), point.x())); | |
149 |
domain |
|
212 | domain->setMinY(qMax(domain->maxX(), point.x())); | |
150 |
domain |
|
213 | domain->setMaxX(qMin(domain->minY(), point.y())); | |
151 |
domain |
|
214 | domain->setMaxY(qMax(domain->maxY(), point.y())); | |
152 | } |
|
215 | } | |
153 | break; |
|
216 | break; | |
154 | } |
|
217 | } | |
@@ -160,10 +223,10 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||||
160 | { |
|
223 | { | |
161 | qreal x = splineSeries->x(i); |
|
224 | qreal x = splineSeries->x(i); | |
162 | qreal y = splineSeries->y(i); |
|
225 | qreal y = splineSeries->y(i); | |
163 |
domain |
|
226 | domain->setMinX(qMin(domain->minX(),x)); | |
164 |
domain |
|
227 | domain->setMinY(qMin(domain->minY(),y)); | |
165 |
domain |
|
228 | domain->setMaxX(qMax(domain->maxX(),x)); | |
166 |
domain |
|
229 | domain->setMaxY(qMax(domain->maxY(),y)); | |
167 | } |
|
230 | } | |
168 | break; |
|
231 | break; | |
169 | } |
|
232 | } | |
@@ -175,272 +238,49 void ChartDataSet::addSeries(QSeries* series, QChartAxis *axisY) | |||||
175 | } |
|
238 | } | |
176 |
|
239 | |||
177 | } |
|
240 | } | |
178 |
|
||||
179 | if(!m_domainMap.contains(axisY)) |
|
|||
180 | { |
|
|||
181 | emit axisAdded(axisY); |
|
|||
182 | QObject::connect(axisY,SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*))); |
|
|||
183 | QObject::connect(axisY,SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
|||
184 | } |
|
|||
185 |
|
||||
186 | if(!m_axisXInitialized) |
|
|||
187 | { |
|
|||
188 | emit axisAdded(axisX()); |
|
|||
189 | QObject::connect(axisX(),SIGNAL(rangeChanged(QChartAxis*)),this,SLOT(handleRangeChanged(QChartAxis*))); |
|
|||
190 | QObject::connect(axisX(),SIGNAL(ticksChanged(QChartAxis*)),this,SLOT(handleTickChanged(QChartAxis*))); |
|
|||
191 | m_axisXInitialized=true; |
|
|||
192 | } |
|
|||
193 |
|
||||
194 | m_domainMap.replace(axisY,domain); |
|
|||
195 | m_seriesMap.insert(axisY,series); |
|
|||
196 | emit seriesAdded(series); |
|
|||
197 | setDomain(m_domainIndex,axisY); |
|
|||
198 |
|
||||
199 | } |
|
|||
200 |
|
||||
201 | void ChartDataSet::removeSeries(QSeries* series) |
|
|||
202 | { |
|
|||
203 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
|||
204 | foreach(QChartAxis* axis , keys) { |
|
|||
205 | if(m_seriesMap.contains(axis,series)) { |
|
|||
206 | emit seriesRemoved(series); |
|
|||
207 | m_seriesMap.remove(axis,series); |
|
|||
208 | //remove axis if no longer there |
|
|||
209 | if(!m_seriesMap.contains(axis)) { |
|
|||
210 | emit axisRemoved(axis); |
|
|||
211 | m_domainMap.remove(axis); |
|
|||
212 | if(axis != m_axisY) |
|
|||
213 | delete axis; |
|
|||
214 | } |
|
|||
215 | series->setParent(0); |
|
|||
216 | break; |
|
|||
217 | } |
|
|||
218 | } |
|
|||
219 | } |
|
241 | } | |
220 |
|
242 | |||
221 | void ChartDataSet::removeAllSeries() |
|
243 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
222 | { |
|
|||
223 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
|||
224 | foreach(QChartAxis* axis , keys) { |
|
|||
225 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
|||
226 | for(int i =0; i < seriesList.size();i++ ) |
|
|||
227 | { |
|
244 | { | |
228 | emit seriesRemoved(seriesList.at(i)); |
|
245 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); | |
229 | delete(seriesList.at(i)); |
|
246 | while (i.hasNext()) { | |
230 |
|
|
247 | i.next(); | |
231 | m_seriesMap.remove(axis); |
|
248 | i.value()->zoomIn(rect,size); | |
232 | m_domainMap.remove(axis); |
|
|||
233 | emit axisRemoved(axis); |
|
|||
234 | if(axis != m_axisY) delete axis; |
|
|||
235 | } |
|
249 | } | |
236 | m_domainIndex=0; |
|
|||
237 | } |
|
250 | } | |
238 |
|
251 | |||
239 | bool ChartDataSet::nextDomain() |
|
252 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
240 | { |
|
253 | { | |
241 | int limit = (m_domainMap.values().size()/m_domainMap.uniqueKeys().size())-1; |
|
254 | QMapIterator<QChartAxis*, Domain*> i( m_axisDomainMap); | |
242 |
|
255 | while (i.hasNext()) { | ||
243 | if (m_domainIndex < limit) { |
|
256 | i.next(); | |
244 | m_domainIndex++; |
|
257 | i.value()->zoomOut(rect,size); | |
245 | setDomain(m_domainIndex); |
|
|||
246 | return true; |
|
|||
247 | } |
|
|||
248 | else { |
|
|||
249 | return false; |
|
|||
250 | } |
|
258 | } | |
251 | } |
|
259 | } | |
252 |
|
260 | |||
253 | bool ChartDataSet::previousDomain() |
|
|||
254 | { |
|
|||
255 | if (m_domainIndex > 0) { |
|
|||
256 | m_domainIndex--; |
|
|||
257 | setDomain(m_domainIndex); |
|
|||
258 | return true; |
|
|||
259 | } |
|
|||
260 | else { |
|
|||
261 | return false; |
|
|||
262 | } |
|
|||
263 | } |
|
|||
264 |
|
||||
265 | void ChartDataSet::setDomain(int index) |
|
|||
266 | { |
|
|||
267 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
|||
268 |
|
||||
269 | if(domainList.count()==0) return; |
|
|||
270 |
|
||||
271 | Domain domain; |
|
|||
272 |
|
||||
273 | foreach (QChartAxis* axis , domainList) { |
|
|||
274 | int i = m_domainMap.count(axis) - index -1; |
|
|||
275 | Q_ASSERT(i>=0); |
|
|||
276 | domain = m_domainMap.values(axis).at(i); |
|
|||
277 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
|||
278 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
|||
279 | foreach(QSeries* series, seriesList) { |
|
|||
280 | emit seriesDomainChanged(series,domain); |
|
|||
281 | } |
|
|||
282 | axis->updateRange(domain.m_minY,domain.m_maxY); |
|
|||
283 | emit axisRangeChanged(axis,labels); |
|
|||
284 |
|
||||
285 | } |
|
|||
286 |
|
||||
287 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
|||
288 | axisX()->updateRange(domain.m_minX,domain.m_maxY); |
|
|||
289 | emit axisRangeChanged(axisX(),labels); |
|
|||
290 | } |
|
|||
291 |
|
||||
292 | void ChartDataSet::setDomain(int index,QChartAxis* axis) |
|
|||
293 | { |
|
|||
294 | int i = m_domainMap.count(axis) - index -1; |
|
|||
295 | Q_ASSERT(i>=0); |
|
|||
296 | Domain domain = m_domainMap.values(axis).at(i); |
|
|||
297 | { |
|
|||
298 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
|||
299 | QList<QSeries*> seriesList = m_seriesMap.values(axis); |
|
|||
300 | foreach(QSeries* series, seriesList) { |
|
|||
301 | emit seriesDomainChanged(series,domain); |
|
|||
302 | } |
|
|||
303 | axis->updateRange(domain.m_minY,domain.m_maxY); |
|
|||
304 | emit axisRangeChanged(axis,labels); |
|
|||
305 | } |
|
|||
306 |
|
||||
307 | QStringList labels = createLabels(axisX(),domain.m_minX,domain.m_maxX); |
|
|||
308 | axisX()->updateRange(domain.m_minX,domain.m_maxY); |
|
|||
309 | emit axisRangeChanged(axisX(),labels); |
|
|||
310 | } |
|
|||
311 |
|
||||
312 | void ChartDataSet::clearDomains(int toIndex) |
|
|||
313 | { |
|
|||
314 | Q_ASSERT(toIndex>=0); |
|
|||
315 |
|
||||
316 | m_domainIndex = toIndex; |
|
|||
317 |
|
||||
318 | QList<QChartAxis*> keys = m_domainMap.uniqueKeys(); |
|
|||
319 |
|
||||
320 | foreach (QChartAxis* key , keys) |
|
|||
321 | { |
|
|||
322 | QList<Domain> domains = m_domainMap.values(key); |
|
|||
323 | m_domainMap.remove(key); |
|
|||
324 | int i = domains.size() - toIndex - 1; |
|
|||
325 | while(i--) { |
|
|||
326 | domains.removeFirst(); |
|
|||
327 | } |
|
|||
328 | for(int j=domains.size()-1; j>=0;j--) |
|
|||
329 | m_domainMap.insert(key,domains.at(j)); |
|
|||
330 | } |
|
|||
331 | } |
|
|||
332 |
|
||||
333 | void ChartDataSet::addDomain(const QRectF& rect, const QRectF& viewport) |
|
|||
334 | { |
|
|||
335 | Q_ASSERT(rect.isValid()); |
|
|||
336 | Q_ASSERT(viewport.isValid()); |
|
|||
337 |
|
||||
338 | clearDomains(m_domainIndex); |
|
|||
339 |
|
||||
340 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
|||
341 |
|
||||
342 | Domain domain; |
|
|||
343 |
|
||||
344 | foreach (QChartAxis* axis , domainList) { |
|
|||
345 | domain = m_domainMap.value(axis).subDomain(rect,viewport.width(),viewport.height()); |
|
|||
346 | m_domainMap.insert(axis,domain); |
|
|||
347 | } |
|
|||
348 |
|
||||
349 | setDomain(++m_domainIndex); |
|
|||
350 | } |
|
|||
351 |
|
||||
352 | QChartAxis* ChartDataSet::axisY(QSeries* series) const |
|
261 | QChartAxis* ChartDataSet::axisY(QSeries* series) const | |
353 | { |
|
262 | { | |
354 | if(series == 0) return m_axisY; |
|
263 | if(series == 0) return m_axisY; | |
355 |
|
264 | return m_seriesAxisMap.value(series); | ||
356 | QList<QChartAxis*> keys = m_seriesMap.uniqueKeys(); |
|
|||
357 |
|
||||
358 | foreach(QChartAxis* axis , keys) { |
|
|||
359 | if(m_seriesMap.contains(axis,series)) { |
|
|||
360 | return axis; |
|
|||
361 | } |
|
|||
362 | } |
|
|||
363 | return 0; |
|
|||
364 | } |
|
|||
365 |
|
||||
366 | QStringList ChartDataSet::createLabels(QChartAxis* axis,qreal min, qreal max) |
|
|||
367 | { |
|
|||
368 | Q_ASSERT(max>=min); |
|
|||
369 |
|
||||
370 | QStringList labels; |
|
|||
371 |
|
||||
372 | int ticks = axis->ticksCount()-1; |
|
|||
373 |
|
||||
374 | for(int i=0; i<= ticks; i++) { |
|
|||
375 | qreal value = min + (i * (max - min)/ ticks); |
|
|||
376 | QString label = axis->axisTickLabel(value); |
|
|||
377 | if(label.isEmpty()) { |
|
|||
378 | labels << QString::number(value); |
|
|||
379 | } |
|
|||
380 | else { |
|
|||
381 | labels << label; |
|
|||
382 | } |
|
|||
383 | } |
|
|||
384 | return labels; |
|
|||
385 | } |
|
265 | } | |
386 |
|
266 | |||
387 | void ChartDataSet::handleRangeChanged(QChartAxis* axis) |
|
267 | Domain* ChartDataSet::domain(QSeries* series) const | |
388 | { |
|
268 | { | |
389 | qreal min = axis->min(); |
|
269 | QChartAxis* axis = m_seriesAxisMap.value(series); | |
390 | qreal max = axis->max(); |
|
270 | if(axis){ | |
391 |
|
271 | return m_axisDomainMap.value(axis); | ||
392 | if(axis==axisX()) { |
|
272 | }else | |
393 |
|
273 | return 0; | ||
394 | m_domainIndex=0; |
|
|||
395 |
|
||||
396 | clearDomains(m_domainIndex); |
|
|||
397 |
|
||||
398 | QList<QChartAxis*> domainList = m_domainMap.uniqueKeys(); |
|
|||
399 |
|
||||
400 | foreach (QChartAxis* axis , domainList) { |
|
|||
401 |
|
||||
402 | Q_ASSERT(m_domainMap.values(axis).size()==1); |
|
|||
403 |
|
||||
404 | Domain domain = m_domainMap.value(axis); |
|
|||
405 | domain.m_minX=min; |
|
|||
406 | domain.m_maxX=max; |
|
|||
407 | m_domainMap.replace(axis,domain); |
|
|||
408 | } |
|
|||
409 |
|
||||
410 | setDomain(m_domainIndex); |
|
|||
411 |
|
||||
412 | } |
|
274 | } | |
413 | else { |
|
|||
414 |
|
275 | |||
415 | QList<Domain> domains = m_domainMap.values(axis); |
|
276 | Domain* ChartDataSet::domain(QChartAxis* axis) const | |
416 | m_domainMap.remove(axis); |
|
|||
417 |
|
||||
418 | for(int i=0;i<domains.size();i++) |
|
|||
419 | { |
|
277 | { | |
420 | domains[i].m_minY=min; |
|
278 | return m_axisDomainMap.value(axis); | |
421 | domains[i].m_maxY=max; |
|
|||
422 | } |
|
|||
423 |
|
||||
424 | for(int j=domains.size()-1; j>=0;j--) |
|
|||
425 | m_domainMap.insert(axis,domains.at(j)); |
|
|||
426 |
|
||||
427 | setDomain(m_domainIndex,axis); |
|
|||
428 | } |
|
279 | } | |
429 |
|
280 | |||
430 | } |
|
281 | QChartAxis* ChartDataSet::axis(QSeries* series) const | |
431 |
|
||||
432 | void ChartDataSet::handleTickChanged(QChartAxis* axis) |
|
|||
433 | { |
|
282 | { | |
434 | if(axis==axisX()) { |
|
283 | return m_seriesAxisMap.value(series); | |
435 | Domain domain = m_domainMap.value(axisY()); |
|
|||
436 | QStringList labels = createLabels(axis,domain.m_minX,domain.m_maxX); |
|
|||
437 | emit axisRangeChanged(axis,labels); |
|
|||
438 | } |
|
|||
439 | else { |
|
|||
440 | Domain domain = m_domainMap.value(axis); |
|
|||
441 | QStringList labels = createLabels(axis,domain.m_minY,domain.m_maxY); |
|
|||
442 | emit axisRangeChanged(axis,labels); |
|
|||
443 | } |
|
|||
444 | } |
|
284 | } | |
445 |
|
285 | |||
446 | #include "moc_chartdataset_p.cpp" |
|
286 | #include "moc_chartdataset_p.cpp" |
@@ -19,38 +19,33 public: | |||||
19 | void addSeries(QSeries* series,QChartAxis *axisY = 0); |
|
19 | void addSeries(QSeries* series,QChartAxis *axisY = 0); | |
20 | void removeSeries(QSeries* series); |
|
20 | void removeSeries(QSeries* series); | |
21 | void removeAllSeries(); |
|
21 | void removeAllSeries(); | |
22 | void addDomain(const QRectF& rect, const QRectF& viewport); |
|
22 | ||
23 | bool nextDomain(); |
|
23 | void zoomInDomain(const QRectF& rect, const QSizeF& size); | |
24 | bool previousDomain(); |
|
24 | void zoomOutDomain(const QRectF& rect, const QSizeF& size); | |
25 | void clearDomains(int toIndex =0); |
|
25 | ||
26 |
|
|
26 | Domain* domain(QSeries* series) const; | |
27 | int domainIndex() const {return m_domainIndex;} |
|
27 | Domain* domain(QChartAxis* axis) const; | |
28 | void setDomain(int index); |
|
28 | QChartAxis* axis(QSeries* series) const; | |
29 | void setDomain(int index,QChartAxis* axis); |
|
|||
30 |
|
29 | |||
31 | QChartAxis* axisX() const { return m_axisX;}; |
|
30 | QChartAxis* axisX() const { return m_axisX;}; | |
32 | QChartAxis* axisY(QSeries* series = 0) const; |
|
31 | QChartAxis* axisY(QSeries* series = 0) const; | |
33 |
|
32 | |||
34 | signals: |
|
33 | signals: | |
35 | void seriesAdded(QSeries* series); |
|
34 | void seriesAdded(QSeries* series,Domain* domain); | |
36 | void seriesRemoved(QSeries* series); |
|
35 | void seriesRemoved(QSeries* series); | |
37 | void axisAdded(QChartAxis* axis); |
|
36 | void axisAdded(QChartAxis* axis,Domain* domain); | |
38 | void axisRemoved(QChartAxis* axis); |
|
37 | void axisRemoved(QChartAxis* axis); | |
39 | void axisRangeChanged(QChartAxis* axis, const QStringList& labels); |
|
|||
40 | void seriesDomainChanged(QSeries* series,const Domain& domain); |
|
|||
41 |
|
||||
42 | private slots: |
|
|||
43 | void handleRangeChanged(QChartAxis*); |
|
|||
44 | void handleTickChanged(QChartAxis*); |
|
|||
45 |
|
38 | |||
46 | private: |
|
39 | private: | |
47 | QStringList createLabels(QChartAxis* axis,qreal min, qreal max); |
|
40 | QStringList createLabels(QChartAxis* axis,qreal min, qreal max); | |
|
41 | void calculateDomain(QSeries* series,Domain* domain) const; | |||
48 |
|
42 | |||
49 | private: |
|
43 | private: | |
50 |
QM |
|
44 | QMap<QSeries*, QChartAxis*> m_seriesAxisMap; | |
51 |
QM |
|
45 | QMap<QChartAxis*, Domain*> m_axisDomainMap; | |
52 | QChartAxis* m_axisX; |
|
46 | QChartAxis* m_axisX; | |
53 | QChartAxis* m_axisY; |
|
47 | QChartAxis* m_axisY; | |
|
48 | ||||
54 | int m_domainIndex; |
|
49 | int m_domainIndex; | |
55 | bool m_axisXInitialized; |
|
50 | bool m_axisXInitialized; | |
56 | }; |
|
51 | }; |
@@ -31,13 +31,13 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(char | |||||
31 | m_chart(chart), |
|
31 | m_chart(chart), | |
32 | m_dataset(dataset), |
|
32 | m_dataset(dataset), | |
33 | m_chartTheme(0), |
|
33 | m_chartTheme(0), | |
|
34 | m_zoomIndex(0), | |||
34 | m_marginSize(0), |
|
35 | m_marginSize(0), | |
35 | m_rect(QRectF(QPoint(0,0),m_chart->size())), |
|
36 | m_rect(QRectF(QPoint(0,0),m_chart->size())), | |
36 |
m_options( |
|
37 | m_options(QChart::NoAnimation) | |
37 | { |
|
38 | { | |
38 | createConnections(); |
|
39 | createConnections(); | |
39 | setChartTheme(QChart::ChartThemeDefault); |
|
40 | setChartTheme(QChart::ChartThemeDefault); | |
40 |
|
||||
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | ChartPresenter::~ChartPresenter() |
|
43 | ChartPresenter::~ChartPresenter() | |
@@ -47,12 +47,10 ChartPresenter::~ChartPresenter() | |||||
47 | void ChartPresenter::createConnections() |
|
47 | void ChartPresenter::createConnections() | |
48 | { |
|
48 | { | |
49 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); |
|
49 | QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged())); | |
50 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*)),this,SLOT(handleSeriesAdded(QSeries*))); |
|
50 | QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*))); | |
51 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); |
|
51 | QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*))); | |
52 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*))); |
|
52 | QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*))); | |
53 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); |
|
53 | QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*))); | |
54 | QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QSeries*,const Domain&))); |
|
|||
55 | QObject::connect(m_dataset,SIGNAL(axisRangeChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisRangeChanged(QChartAxis*,const QStringList&))); |
|
|||
56 | } |
|
54 | } | |
57 |
|
55 | |||
58 |
|
56 | |||
@@ -63,8 +61,26 QRectF ChartPresenter::geometry() const | |||||
63 |
|
61 | |||
64 | void ChartPresenter::handleGeometryChanged() |
|
62 | void ChartPresenter::handleGeometryChanged() | |
65 | { |
|
63 | { | |
66 |
|
|
64 | QRectF rect(QPoint(0,0),m_chart->size()); | |
67 |
|
|
65 | rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize); | |
|
66 | ||||
|
67 | //rewrite zoom stack | |||
|
68 | for(int i=0;i<m_zoomStack.count();i++){ | |||
|
69 | QRectF r = m_zoomStack[i]; | |||
|
70 | qreal w = rect.width()/m_rect.width(); | |||
|
71 | qreal h = rect.height()/m_rect.height(); | |||
|
72 | QPointF tl = r.topLeft(); | |||
|
73 | tl.setX(tl.x()*w); | |||
|
74 | tl.setY(tl.y()*h); | |||
|
75 | QPointF br = r.bottomRight(); | |||
|
76 | br.setX(br.x()*w); | |||
|
77 | br.setY(br.y()*h); | |||
|
78 | r.setTopLeft(tl); | |||
|
79 | r.setBottomRight(br); | |||
|
80 | m_zoomStack[i]=r; | |||
|
81 | } | |||
|
82 | ||||
|
83 | m_rect = rect; | |||
68 | Q_ASSERT(m_rect.isValid()); |
|
84 | Q_ASSERT(m_rect.isValid()); | |
69 | emit geometryChanged(m_rect); |
|
85 | emit geometryChanged(m_rect); | |
70 | } |
|
86 | } | |
@@ -79,22 +95,30 void ChartPresenter::setMargin(int margin) | |||||
79 | m_marginSize = margin; |
|
95 | m_marginSize = margin; | |
80 | } |
|
96 | } | |
81 |
|
97 | |||
82 | void ChartPresenter::handleAxisAdded(QChartAxis* axis) |
|
98 | void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain) | |
83 | { |
|
99 | { | |
84 |
|
100 | |||
85 | AxisItem* item ; |
|
101 | AxisItem* item ; | |
86 |
|
102 | |||
87 | if(!m_options.testFlag(QChart::GridAxisAnimations)) |
|
103 | if(!m_options.testFlag(QChart::GridAxisAnimations)) | |
88 | { |
|
104 | { | |
89 | item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
105 | item = new AxisItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
90 | }else{ |
|
106 | }else{ | |
91 | item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); |
|
107 | item = new AxisAnimationItem(axis,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart); | |
|
108 | } | |||
|
109 | if(axis==m_dataset->axisX()){ | |||
|
110 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal))); | |||
|
111 | //initialize | |||
|
112 | item->handleRangeChanged(domain->minX(),domain->maxX()); | |||
|
113 | } | |||
|
114 | else{ | |||
|
115 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal)),item,SLOT(handleRangeChanged(qreal,qreal))); | |||
|
116 | //initialize | |||
|
117 | item->handleRangeChanged(domain->minY(),domain->maxY()); | |||
92 | } |
|
118 | } | |
93 |
|
119 | |||
94 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); |
|
120 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |
95 | QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*))); |
|
121 | //initialize | |
96 |
|
||||
97 | item->handleAxisUpdate(axis); |
|
|||
98 | item->handleGeometryChanged(m_rect); |
|
122 | item->handleGeometryChanged(m_rect); | |
99 | m_chartTheme->decorate(axis,item); |
|
123 | m_chartTheme->decorate(axis,item); | |
100 | m_axisItems.insert(axis,item); |
|
124 | m_axisItems.insert(axis,item); | |
@@ -108,7 +132,7 void ChartPresenter::handleAxisRemoved(QChartAxis* axis) | |||||
108 | } |
|
132 | } | |
109 |
|
133 | |||
110 |
|
134 | |||
111 | void ChartPresenter::handleSeriesAdded(QSeries* series) |
|
135 | void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain) | |
112 | { |
|
136 | { | |
113 | switch(series->type()) |
|
137 | switch(series->type()) | |
114 | { |
|
138 | { | |
@@ -117,13 +141,18 void ChartPresenter::handleSeriesAdded(QSeries* series) | |||||
117 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); |
|
141 | QLineSeries* lineSeries = static_cast<QLineSeries*>(series); | |
118 | LineChartItem* item; |
|
142 | LineChartItem* item; | |
119 | if(m_options.testFlag(QChart::SeriesAnimations)){ |
|
143 | if(m_options.testFlag(QChart::SeriesAnimations)){ | |
120 |
item = new LineChartAnimationItem( |
|
144 | item = new LineChartAnimationItem(lineSeries,m_chart); | |
121 | }else{ |
|
145 | }else{ | |
122 |
item = new LineChartItem( |
|
146 | item = new LineChartItem(lineSeries,m_chart); | |
123 | } |
|
147 | } | |
|
148 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |||
|
149 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |||
|
150 | //initialize | |||
|
151 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |||
|
152 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |||
|
153 | //decorate | |||
124 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); |
|
154 | m_chartTheme->decorate(item,lineSeries,m_chartItems.count()); | |
125 | m_chartItems.insert(series,item); |
|
155 | m_chartItems.insert(series,item); | |
126 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
|||
127 | break; |
|
156 | break; | |
128 | } |
|
157 | } | |
129 |
|
158 | |||
@@ -132,14 +161,19 void ChartPresenter::handleSeriesAdded(QSeries* series) | |||||
132 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); |
|
161 | QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series); | |
133 | AreaChartItem* item; |
|
162 | AreaChartItem* item; | |
134 | if(m_options.testFlag(QChart::SeriesAnimations)) { |
|
163 | if(m_options.testFlag(QChart::SeriesAnimations)) { | |
135 |
item = new AreaChartItem( |
|
164 | item = new AreaChartItem(areaSeries,m_chart); | |
136 | } |
|
165 | } | |
137 | else { |
|
166 | else { | |
138 |
item = new AreaChartItem( |
|
167 | item = new AreaChartItem(areaSeries,m_chart); | |
139 | } |
|
168 | } | |
|
169 | QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&))); | |||
|
170 | QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),item,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal))); | |||
|
171 | //initialize | |||
|
172 | item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY()); | |||
|
173 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); | |||
|
174 | //decorate | |||
140 | m_chartTheme->decorate(item,areaSeries,m_chartItems.count()); |
|
175 | m_chartTheme->decorate(item,areaSeries,m_chartItems.count()); | |
141 | m_chartItems.insert(series,item); |
|
176 | m_chartItems.insert(series,item); | |
142 | if(m_rect.isValid()) item->handleGeometryChanged(m_rect); |
|
|||
143 | break; |
|
177 | break; | |
144 | } |
|
178 | } | |
145 |
|
179 | |||
@@ -228,6 +262,8 void ChartPresenter::handleSeriesAdded(QSeries* series) | |||||
228 | break; |
|
262 | break; | |
229 | } |
|
263 | } | |
230 | } |
|
264 | } | |
|
265 | ||||
|
266 | zoomReset(); | |||
231 | } |
|
267 | } | |
232 |
|
268 | |||
233 | void ChartPresenter::handleSeriesRemoved(QSeries* series) |
|
269 | void ChartPresenter::handleSeriesRemoved(QSeries* series) | |
@@ -236,16 +272,6 void ChartPresenter::handleSeriesRemoved(QSeries* series) | |||||
236 | delete item; |
|
272 | delete item; | |
237 | } |
|
273 | } | |
238 |
|
274 | |||
239 | void ChartPresenter::handleSeriesDomainChanged(QSeries* series, const Domain& domain) |
|
|||
240 | { |
|
|||
241 | m_chartItems.value(series)->handleDomainChanged(domain); |
|
|||
242 | } |
|
|||
243 |
|
||||
244 | void ChartPresenter::handleAxisRangeChanged(QChartAxis* axis,const QStringList& labels) |
|
|||
245 | { |
|
|||
246 | m_axisItems.value(axis)->handleRangeChanged(axis,labels); |
|
|||
247 | } |
|
|||
248 |
|
||||
249 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) |
|
275 | void ChartPresenter::setChartTheme(QChart::ChartTheme theme) | |
250 | { |
|
276 | { | |
251 | delete m_chartTheme; |
|
277 | delete m_chartTheme; | |
@@ -281,23 +307,50 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options) | |||||
281 | m_options=options; |
|
307 | m_options=options; | |
282 |
|
308 | |||
283 | //recreate elements |
|
309 | //recreate elements | |
284 |
|
||||
285 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); |
|
310 | QList<QChartAxis*> axisList = m_axisItems.uniqueKeys(); | |
286 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); |
|
311 | QList<QSeries*> seriesList = m_chartItems.uniqueKeys(); | |
287 |
|
312 | |||
288 | foreach(QChartAxis* axis, axisList) { |
|
313 | foreach(QChartAxis* axis, axisList) { | |
289 | handleAxisRemoved(axis); |
|
314 | handleAxisRemoved(axis); | |
290 | handleAxisAdded(axis); |
|
315 | handleAxisAdded(axis,m_dataset->domain(axis)); | |
291 | } |
|
316 | } | |
292 | foreach(QSeries* series, seriesList) { |
|
317 | foreach(QSeries* series, seriesList) { | |
293 | handleSeriesRemoved(series); |
|
318 | handleSeriesRemoved(series); | |
294 | handleSeriesAdded(series); |
|
319 | handleSeriesAdded(series,m_dataset->domain(series)); | |
|
320 | } | |||
|
321 | } | |||
295 | } |
|
322 | } | |
296 |
|
323 | |||
297 | //now reintialize view data |
|
324 | void ChartPresenter::zoomIn() | |
298 | //TODO: make it more nice |
|
325 | { | |
299 | m_dataset->setDomain(m_dataset->domainIndex()); |
|
326 | QRectF rect = geometry(); | |
|
327 | rect.setWidth(rect.width()/2); | |||
|
328 | rect.setHeight(rect.height()/2); | |||
|
329 | rect.moveCenter(geometry().center()); | |||
|
330 | zoomIn(rect); | |||
300 | } |
|
331 | } | |
|
332 | ||||
|
333 | void ChartPresenter::zoomIn(const QRectF& rect) | |||
|
334 | { | |||
|
335 | QRectF r = rect.normalized(); | |||
|
336 | r.translate(-m_marginSize, -m_marginSize); | |||
|
337 | m_dataset->zoomInDomain(r,geometry().size()); | |||
|
338 | m_zoomStack<<r; | |||
|
339 | m_zoomIndex++; | |||
|
340 | } | |||
|
341 | ||||
|
342 | void ChartPresenter::zoomOut() | |||
|
343 | { | |||
|
344 | if(m_zoomIndex==0) return; | |||
|
345 | m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size()); | |||
|
346 | m_zoomIndex--; | |||
|
347 | m_zoomStack.resize(m_zoomIndex); | |||
|
348 | } | |||
|
349 | ||||
|
350 | void ChartPresenter::zoomReset() | |||
|
351 | { | |||
|
352 | m_zoomIndex=0; | |||
|
353 | m_zoomStack.resize(m_zoomIndex); | |||
301 | } |
|
354 | } | |
302 |
|
355 | |||
303 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
|
356 | QChart::AnimationOptions ChartPresenter::animationOptions() const |
@@ -43,26 +43,34 public: | |||||
43 | void setAnimationOptions(QChart::AnimationOptions options); |
|
43 | void setAnimationOptions(QChart::AnimationOptions options); | |
44 | QChart::AnimationOptions animationOptions() const; |
|
44 | QChart::AnimationOptions animationOptions() const; | |
45 |
|
45 | |||
|
46 | void zoomIn(); | |||
|
47 | void zoomIn(const QRectF& rect); | |||
|
48 | void zoomOut(); | |||
|
49 | void zoomReset(); | |||
|
50 | ||||
|
51 | ||||
46 | private: |
|
52 | private: | |
47 | void createConnections(); |
|
53 | void createConnections(); | |
48 |
|
54 | |||
49 | public slots: |
|
55 | public slots: | |
50 | void handleSeriesAdded(QSeries* series); |
|
56 | void handleSeriesAdded(QSeries* series,Domain* domain); | |
51 | void handleSeriesRemoved(QSeries* series); |
|
57 | void handleSeriesRemoved(QSeries* series); | |
52 | void handleAxisAdded(QChartAxis* axis); |
|
58 | void handleAxisAdded(QChartAxis* axis,Domain* domain); | |
53 | void handleAxisRemoved(QChartAxis* axis); |
|
59 | void handleAxisRemoved(QChartAxis* axis); | |
54 | void handleSeriesDomainChanged(QSeries* series, const Domain& domain); |
|
|||
55 | void handleAxisRangeChanged(QChartAxis* axis, const QStringList& labels); |
|
|||
56 | void handleGeometryChanged(); |
|
60 | void handleGeometryChanged(); | |
|
61 | ||||
57 | signals: |
|
62 | signals: | |
58 | void geometryChanged(const QRectF& rect); |
|
63 | void geometryChanged(const QRectF& rect); | |
|
64 | ||||
59 | private: |
|
65 | private: | |
60 | QMap<QSeries*,ChartItem*> m_chartItems; |
|
|||
61 | QMap<QChartAxis*,AxisItem*> m_axisItems; |
|
|||
62 | QChart* m_chart; |
|
66 | QChart* m_chart; | |
63 | ChartDataSet* m_dataset; |
|
67 | ChartDataSet* m_dataset; | |
64 | ChartTheme *m_chartTheme; |
|
68 | ChartTheme *m_chartTheme; | |
|
69 | int m_zoomIndex; | |||
65 | int m_marginSize; |
|
70 | int m_marginSize; | |
|
71 | QMap<QSeries*,ChartItem*> m_chartItems; | |||
|
72 | QMap<QChartAxis*,AxisItem*> m_axisItems; | |||
|
73 | QVector<QRectF> m_zoomStack; | |||
66 | QRectF m_rect; |
|
74 | QRectF m_rect; | |
67 | QChart::AnimationOptions m_options; |
|
75 | QChart::AnimationOptions m_options; | |
68 |
|
76 |
@@ -2,11 +2,11 | |||||
2 |
|
2 | |||
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
3 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
4 |
|
4 | |||
5 | Domain::Domain(qreal minX, qreal maxX, qreal minY, qreal maxY): |
|
5 | Domain::Domain(QObject* parent):QObject(parent), | |
6 |
m_minX( |
|
6 | m_minX(0), | |
7 |
m_maxX( |
|
7 | m_maxX(0), | |
8 |
m_minY( |
|
8 | m_minY(0), | |
9 |
m_maxY( |
|
9 | m_maxY(0) | |
10 | { |
|
10 | { | |
11 | } |
|
11 | } | |
12 |
|
12 | |||
@@ -14,6 +14,59 Domain::~Domain() | |||||
14 | { |
|
14 | { | |
15 | } |
|
15 | } | |
16 |
|
16 | |||
|
17 | void Domain::setRange(qreal minX, qreal maxX, qreal minY, qreal maxY) | |||
|
18 | { | |||
|
19 | bool changed = false; | |||
|
20 | ||||
|
21 | if(m_minX!=minX || m_maxX!=maxX) | |||
|
22 | { | |||
|
23 | m_minX=minX; | |||
|
24 | m_maxX=maxX; | |||
|
25 | changed=true; | |||
|
26 | emit rangeXChanged(minX,maxX); | |||
|
27 | } | |||
|
28 | ||||
|
29 | if(m_minY!=minY || m_maxY!=maxY){ | |||
|
30 | m_minY=minY; | |||
|
31 | m_maxY=maxY; | |||
|
32 | changed=true; | |||
|
33 | emit rangeYChanged(minY,maxY); | |||
|
34 | } | |||
|
35 | ||||
|
36 | if(changed){ | |||
|
37 | emit domainChanged(m_minX, m_maxX, m_minY, m_maxY); | |||
|
38 | } | |||
|
39 | } | |||
|
40 | void Domain::setRangeX(qreal min, qreal max) | |||
|
41 | { | |||
|
42 | setRange(min,max,m_minY, m_maxY); | |||
|
43 | } | |||
|
44 | void Domain::setRangeY(qreal min, qreal max) | |||
|
45 | { | |||
|
46 | setRange(m_minX, m_maxX, min, max); | |||
|
47 | } | |||
|
48 | ||||
|
49 | void Domain::setMinX(qreal min) | |||
|
50 | { | |||
|
51 | setRange(min, m_maxX, m_minY, m_maxY); | |||
|
52 | } | |||
|
53 | ||||
|
54 | void Domain::setMaxX(qreal max) | |||
|
55 | { | |||
|
56 | setRange(m_minX, max, m_minY, m_maxY); | |||
|
57 | } | |||
|
58 | ||||
|
59 | void Domain::setMinY(qreal min) | |||
|
60 | { | |||
|
61 | setRange(m_minX, m_maxX, min, m_maxY); | |||
|
62 | } | |||
|
63 | ||||
|
64 | void Domain::setMaxY(qreal max) | |||
|
65 | { | |||
|
66 | setRange(m_minX, m_maxX, m_minY, max); | |||
|
67 | ||||
|
68 | } | |||
|
69 | ||||
17 | qreal Domain::spanX() const |
|
70 | qreal Domain::spanX() const | |
18 | { |
|
71 | { | |
19 |
|
|
72 | Q_ASSERT(m_maxX >= m_minX); | |
@@ -31,19 +84,44 bool Domain::isEmpty() const | |||||
31 | return spanX()==0 || spanY()==0; |
|
84 | return spanX()==0 || spanY()==0; | |
32 | } |
|
85 | } | |
33 |
|
86 | |||
34 | Domain Domain::subDomain(const QRectF& rect, qreal maxWidth,qreal maxHeight) const |
|
87 | void Domain::zoomIn(const QRectF& rect, const QSizeF& size) | |
35 | { |
|
88 | { | |
36 | Domain domain; |
|
89 | qreal dx = spanX() / size.width(); | |
|
90 | qreal dy = spanY() / size.height(); | |||
37 |
|
91 | |||
38 | qreal dx = spanX() / maxWidth; |
|
92 | m_maxX = m_minX + dx * rect.right(); | |
39 | qreal dy = spanY() / maxHeight; |
|
93 | m_minX = m_minX + dx * rect.left(); | |
|
94 | m_minY = m_maxY - dy * rect.bottom(); | |||
|
95 | m_maxY = m_maxY - dy * rect.top(); | |||
40 |
|
96 | |||
41 | domain.m_minX = m_minX + dx * rect.left(); |
|
97 | emit domainChanged(m_minX, m_maxX, m_minY, m_maxY); | |
42 | domain.m_maxX = m_minX + dx * rect.right(); |
|
98 | emit rangeXChanged(m_minX, m_maxX); | |
43 | domain.m_minY = m_maxY - dy * rect.bottom(); |
|
99 | emit rangeYChanged(m_minY, m_maxY); | |
44 | domain.m_maxY = m_maxY - dy * rect.top(); |
|
100 | } | |
|
101 | ||||
|
102 | void Domain::zoomOut(const QRectF& rect, const QSizeF& size) | |||
|
103 | { | |||
|
104 | qreal dx = spanX() / rect.width(); | |||
|
105 | qreal dy = spanY() / rect.height(); | |||
45 |
|
106 | |||
46 | return domain; |
|
107 | m_minX = m_maxX - dx * rect.right(); | |
|
108 | m_maxX = m_minX + dx * size.width(); | |||
|
109 | m_maxY = m_minY + dy * rect.bottom(); | |||
|
110 | m_minY = m_maxY - dy * size.height(); | |||
|
111 | ||||
|
112 | emit domainChanged(m_minX, m_maxX, m_minY, m_maxY); | |||
|
113 | emit rangeXChanged(m_minX, m_maxX); | |||
|
114 | emit rangeYChanged(m_minY, m_maxY); | |||
|
115 | } | |||
|
116 | ||||
|
117 | void Domain::handleAxisRangeXChanged(qreal min,qreal max) | |||
|
118 | { | |||
|
119 | setRangeX(min,max); | |||
|
120 | } | |||
|
121 | ||||
|
122 | void Domain::handleAxisRangeYChanged(qreal min,qreal max) | |||
|
123 | { | |||
|
124 | setRangeY(min,max); | |||
47 | } |
|
125 | } | |
48 |
|
126 | |||
49 | bool operator== (const Domain &domain1, const Domain &domain2) |
|
127 | bool operator== (const Domain &domain1, const Domain &domain2) | |
@@ -59,11 +137,12 bool operator!= (const Domain &domain1, const Domain &domain2) | |||||
59 | return !(domain1 == domain2); |
|
137 | return !(domain1 == domain2); | |
60 | } |
|
138 | } | |
61 |
|
139 | |||
62 |
|
||||
63 | QDebug operator<<(QDebug dbg, const Domain &domain) |
|
140 | QDebug operator<<(QDebug dbg, const Domain &domain) | |
64 | { |
|
141 | { | |
65 | dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')'; |
|
142 | dbg.nospace() << "Domain("<<domain.m_minX<<','<<domain.m_maxX<<','<<domain.m_minY<<','<<domain.m_maxY<<')'; | |
66 | return dbg.maybeSpace(); |
|
143 | return dbg.maybeSpace(); | |
67 | } |
|
144 | } | |
68 |
|
145 | |||
|
146 | #include "moc_domain_p.cpp" | |||
|
147 | ||||
69 | QTCOMMERCIALCHART_END_NAMESPACE |
|
148 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,15 +1,30 | |||||
1 | #ifndef DOMAIN_H_ |
|
1 | #ifndef DOMAIN_H_ | |
2 | #define DOMAIN_H_ |
|
2 | #define DOMAIN_H_ | |
3 | #include "qchartglobal.h" |
|
3 | #include "qchartglobal.h" | |
4 | #include <QRect> |
|
4 | #include <QRectF> | |
|
5 | #include <QSizeF> | |||
5 |
|
6 | |||
6 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
7 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
7 |
|
8 | |||
8 | class Domain { |
|
9 | class Domain: public QObject { | |
|
10 | Q_OBJECT | |||
9 | public: |
|
11 | public: | |
10 | Domain(qreal minX=0, qreal maxX=0, qreal minY=0, qreal maxY=0); |
|
12 | explicit Domain(QObject* object=0); | |
11 |
|
|
13 | virtual ~Domain(); | |
12 |
|
14 | |||
|
15 | void setRange(qreal minX, qreal maxX, qreal minY, qreal maxY); | |||
|
16 | void setRangeX(qreal min, qreal max); | |||
|
17 | void setRangeY(qreal min, qreal max); | |||
|
18 | void setMinX(qreal min); | |||
|
19 | void setMaxX(qreal max); | |||
|
20 | void setMinY(qreal min); | |||
|
21 | void setMaxY(qreal max); | |||
|
22 | ||||
|
23 | qreal minX() const {return m_minX;}; | |||
|
24 | qreal maxX() const {return m_maxX;}; | |||
|
25 | qreal minY() const {return m_minY;}; | |||
|
26 | qreal maxY() const {return m_maxY;}; | |||
|
27 | ||||
13 |
|
|
28 | qreal spanX() const; | |
14 |
|
|
29 | qreal spanY() const; | |
15 |
|
|
30 | bool isEmpty() const; | |
@@ -18,9 +33,19 public: | |||||
18 |
|
|
33 | friend bool operator!= (const Domain &domain1, const Domain &domain2); | |
19 |
|
|
34 | friend QDebug operator<<(QDebug dbg, const Domain &domain); | |
20 |
|
35 | |||
21 | Domain subDomain(const QRectF& rect, qreal maxWidth, qreal maxHeight) const; |
|
36 | void zoomIn(const QRectF& rect, const QSizeF& size); | |
|
37 | void zoomOut(const QRectF& rect, const QSizeF& size); | |||
22 |
|
38 | |||
23 | public: |
|
39 | signals: | |
|
40 | void domainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |||
|
41 | void rangeXChanged(qreal min, qreal max); | |||
|
42 | void rangeYChanged(qreal min, qreal max); | |||
|
43 | ||||
|
44 | public slots: | |||
|
45 | void handleAxisRangeXChanged(qreal min,qreal max); | |||
|
46 | void handleAxisRangeYChanged(qreal min,qreal max); | |||
|
47 | ||||
|
48 | private: | |||
24 |
|
|
49 | qreal m_minX; | |
25 |
|
|
50 | qreal m_maxX; | |
26 |
|
|
51 | qreal m_minY; |
@@ -9,8 +9,8 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
9 |
|
9 | |||
10 | const static int duration = 500; |
|
10 | const static int duration = 500; | |
11 |
|
11 | |||
12 |
LineChartAnimationItem::LineChartAnimationItem( |
|
12 | LineChartAnimationItem::LineChartAnimationItem(QLineSeries* series,QGraphicsItem *parent): | |
13 |
LineChartItem( |
|
13 | LineChartItem(series,parent), | |
14 | m_animation(new LineChartAnimatator(this,this)), |
|
14 | m_animation(new LineChartAnimatator(this,this)), | |
15 | m_dirty(false) |
|
15 | m_dirty(false) | |
16 | { |
|
16 | { |
@@ -15,7 +15,7 class LineChartAnimationItem : public LineChartItem { | |||||
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 |
|
16 | |||
17 | public: |
|
17 | public: | |
18 |
LineChartAnimationItem( |
|
18 | LineChartAnimationItem(QLineSeries *series, QGraphicsItem *parent = 0); | |
19 | virtual ~LineChartAnimationItem(); |
|
19 | virtual ~LineChartAnimationItem(); | |
20 |
|
20 | |||
21 | protected: |
|
21 | protected: |
@@ -8,19 +8,23 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
8 |
|
8 | |||
9 | //TODO: optimize : remove points which are not visible |
|
9 | //TODO: optimize : remove points which are not visible | |
10 |
|
10 | |||
11 |
LineChartItem::LineChartItem( |
|
11 | LineChartItem::LineChartItem(QLineSeries* series,QGraphicsItem *parent):ChartItem(parent), | |
12 | m_presenter(presenter), |
|
12 | m_minX(0), | |
|
13 | m_maxX(0), | |||
|
14 | m_minY(0), | |||
|
15 | m_maxY(0), | |||
13 | m_series(series), |
|
16 | m_series(series), | |
14 | m_items(this) |
|
17 | m_items(this) | |
15 | { |
|
18 | { | |
16 | //m_items.setZValue(ChartPresenter::LineChartZValue); |
|
19 | //m_items.setZValue(ChartPresenter::LineChartZValue); | |
17 | setZValue(ChartPresenter::LineChartZValue); |
|
20 | setZValue(ChartPresenter::LineChartZValue); | |
18 |
|
21 | |||
19 | QObject::connect(presenter,SIGNAL(geometryChanged(const QRectF&)),this,SLOT(handleGeometryChanged(const QRectF&))); |
|
|||
20 | QObject::connect(series,SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int))); |
|
22 | QObject::connect(series,SIGNAL(pointReplaced(int)),this,SLOT(handlePointReplaced(int))); | |
21 | QObject::connect(series,SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int))); |
|
23 | QObject::connect(series,SIGNAL(pointAdded(int)),this,SLOT(handlePointAdded(int))); | |
22 | QObject::connect(series,SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int))); |
|
24 | QObject::connect(series,SIGNAL(pointRemoved(int)),this,SLOT(handlePointRemoved(int))); | |
23 | QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated())); |
|
25 | QObject::connect(series,SIGNAL(updated()),this,SLOT(handleUpdated())); | |
|
26 | ||||
|
27 | handleUpdated(); | |||
24 | } |
|
28 | } | |
25 |
|
29 | |||
26 | QRectF LineChartItem::boundingRect() const |
|
30 | QRectF LineChartItem::boundingRect() const | |
@@ -52,23 +56,23 void LineChartItem::clearPoints(int count) | |||||
52 |
|
56 | |||
53 | QPointF LineChartItem::calculateGeometryPoint(int index) const |
|
57 | QPointF LineChartItem::calculateGeometryPoint(int index) const | |
54 | { |
|
58 | { | |
55 |
const qreal deltaX = m_size.width()/ |
|
59 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
56 |
const qreal deltaY = m_size.height()/ |
|
60 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
57 |
qreal x = (m_series->x(index) - |
|
61 | qreal x = (m_series->x(index) - m_minX)* deltaX; | |
58 |
qreal y = (m_series->y(index) - |
|
62 | qreal y = (m_series->y(index) - m_minY)*-deltaY + m_size.height(); | |
59 | return QPointF(x,y); |
|
63 | return QPointF(x,y); | |
60 | } |
|
64 | } | |
61 |
|
65 | |||
62 | QVector<QPointF> LineChartItem::calculateGeometryPoints() const |
|
66 | QVector<QPointF> LineChartItem::calculateGeometryPoints() const | |
63 | { |
|
67 | { | |
64 |
const qreal deltaX = m_size.width()/ |
|
68 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
65 |
const qreal deltaY = m_size.height()/ |
|
69 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
66 |
|
70 | |||
67 | QVector<QPointF> points; |
|
71 | QVector<QPointF> points; | |
68 | points.reserve(m_series->count()); |
|
72 | points.reserve(m_series->count()); | |
69 | for (int i = 0; i < m_series->count(); ++i) { |
|
73 | for (int i = 0; i < m_series->count(); ++i) { | |
70 |
qreal x = (m_series->x(i) - |
|
74 | qreal x = (m_series->x(i) - m_minX)* deltaX; | |
71 |
qreal y = (m_series->y(i) - |
|
75 | qreal y = (m_series->y(i) - m_minY)*-deltaY + m_size.height(); | |
72 | points << QPointF(x,y); |
|
76 | points << QPointF(x,y); | |
73 | } |
|
77 | } | |
74 | return points; |
|
78 | return points; | |
@@ -97,13 +101,21 void LineChartItem::applyGeometry(QVector<QPointF>& points) | |||||
97 | path.moveTo(point); |
|
101 | path.moveTo(point); | |
98 | QGraphicsItem* item = items.at(0); |
|
102 | QGraphicsItem* item = items.at(0); | |
99 | item->setPos(point.x()-1,point.y()-1); |
|
103 | item->setPos(point.x()-1,point.y()-1); | |
100 |
if(!m_clipRect.contains(point)) |
|
104 | if(!m_clipRect.contains(point)) { | |
|
105 | item->setVisible(false); | |||
|
106 | }else{ | |||
|
107 | item->setVisible(true); | |||
|
108 | } | |||
101 |
|
109 | |||
102 | for(int i=1 ; i< points.size();i++) { |
|
110 | for(int i=1 ; i< points.size();i++) { | |
103 | QGraphicsItem* item = items.at(i); |
|
111 | QGraphicsItem* item = items.at(i); | |
104 | const QPointF& point = points.at(i); |
|
112 | const QPointF& point = points.at(i); | |
105 | item->setPos(point.x()-1,point.y()-1); |
|
113 | item->setPos(point.x()-1,point.y()-1); | |
106 |
if(!m_clipRect.contains(point)) |
|
114 | if(!m_clipRect.contains(point)) { | |
|
115 | item->setVisible(false); | |||
|
116 | }else{ | |||
|
117 | item->setVisible(true); | |||
|
118 | } | |||
107 | path.lineTo(point); |
|
119 | path.lineTo(point); | |
108 | } |
|
120 | } | |
109 |
|
121 | |||
@@ -152,12 +164,14 void LineChartItem::handlePointReplaced(int index) | |||||
152 | update(); |
|
164 | update(); | |
153 | } |
|
165 | } | |
154 |
|
166 | |||
155 |
void LineChartItem::handleDomainChanged( |
|
167 | void LineChartItem::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
156 | { |
|
168 | { | |
|
169 | m_minX=minX; | |||
|
170 | m_maxX=maxX; | |||
|
171 | m_minY=minY; | |||
|
172 | m_maxY=maxY; | |||
157 |
|
173 | |||
158 | m_domain = domain; |
|
174 | if( (m_maxX - m_minX) == 0|| (m_maxY - m_minY) == 0) return; | |
159 |
|
||||
160 | if(m_domain.isEmpty()) return; |
|
|||
161 | if(!m_clipRect.isValid()) return; |
|
175 | if(!m_clipRect.isValid()) return; | |
162 |
|
176 | |||
163 | QVector<QPointF> points = calculateGeometryPoints(); |
|
177 | QVector<QPointF> points = calculateGeometryPoints(); | |
@@ -182,7 +196,7 void LineChartItem::handleGeometryChanged(const QRectF& rect) | |||||
182 | m_clipRect=rect.translated(-rect.topLeft()); |
|
196 | m_clipRect=rect.translated(-rect.topLeft()); | |
183 | setPos(rect.topLeft()); |
|
197 | setPos(rect.topLeft()); | |
184 |
|
198 | |||
185 | if(m_domain.isEmpty()) return; |
|
199 | if( (m_maxX - m_minX) == 0|| (m_maxY - m_minY) == 0) return; | |
186 |
|
200 | |||
187 | QVector<QPointF> points = calculateGeometryPoints(); |
|
201 | QVector<QPointF> points = calculateGeometryPoints(); | |
188 |
|
202 |
@@ -14,7 +14,7 class LineChartItem : public QObject , public ChartItem | |||||
14 | { |
|
14 | { | |
15 | Q_OBJECT |
|
15 | Q_OBJECT | |
16 | public: |
|
16 | public: | |
17 |
LineChartItem( |
|
17 | LineChartItem(QLineSeries* series,QGraphicsItem *parent = 0); | |
18 | ~ LineChartItem(){}; |
|
18 | ~ LineChartItem(){}; | |
19 |
|
19 | |||
20 | //from QGraphicsItem |
|
20 | //from QGraphicsItem | |
@@ -30,7 +30,7 public slots: | |||||
30 | void handlePointRemoved(int index); |
|
30 | void handlePointRemoved(int index); | |
31 | void handlePointReplaced(int index); |
|
31 | void handlePointReplaced(int index); | |
32 | void handleUpdated(); |
|
32 | void handleUpdated(); | |
33 |
void handleDomainChanged( |
|
33 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
34 | void handleGeometryChanged(const QRectF& size); |
|
34 | void handleGeometryChanged(const QRectF& size); | |
35 |
|
35 | |||
36 | public: |
|
36 | public: | |
@@ -43,13 +43,15 public: | |||||
43 | QVector<QPointF> calculateGeometryPoints() const; |
|
43 | QVector<QPointF> calculateGeometryPoints() const; | |
44 |
|
44 | |||
45 | protected: |
|
45 | protected: | |
|
46 | qreal m_minX; | |||
|
47 | qreal m_maxX; | |||
|
48 | qreal m_minY; | |||
|
49 | qreal m_maxY; | |||
46 | QPainterPath m_path; |
|
50 | QPainterPath m_path; | |
47 | QRectF m_rect; |
|
51 | QRectF m_rect; | |
48 | QLineSeries* m_series; |
|
52 | QLineSeries* m_series; | |
49 | ChartPresenter* m_presenter; |
|
|||
50 |
QSizeF m_size; |
|
53 | QSizeF m_size; | |
51 | QRectF m_clipRect; |
|
54 | QRectF m_clipRect; | |
52 | Domain m_domain; |
|
|||
53 | QGraphicsItemGroup m_items; |
|
55 | QGraphicsItemGroup m_items; | |
54 | QVector<QPointF> m_points; |
|
56 | QVector<QPointF> m_points; | |
55 | QPen m_pen; |
|
57 | QPen m_pen; |
@@ -40,10 +40,11 class QTCOMMERCIALCHART_EXPORT QLineSeries : public QSeries | |||||
40 |
|
|
40 | friend QDebug operator<< (QDebug d, const QLineSeries series); | |
41 |
|
41 | |||
42 |
|
|
42 | signals: | |
|
43 | void updated(); | |||
43 |
|
|
44 | void pointReplaced(int index); | |
44 |
|
|
45 | void pointRemoved(int index); | |
45 |
|
|
46 | void pointAdded(int index); | |
46 | void updated(); |
|
47 | ||
47 |
|
48 | |||
48 |
|
|
49 | protected: | |
49 |
|
|
50 | QVector<qreal> m_x; |
@@ -187,13 +187,7 QChart::ChartTheme QChart::chartTheme() const | |||||
187 | */ |
|
187 | */ | |
188 | void QChart::zoomIn() |
|
188 | void QChart::zoomIn() | |
189 | { |
|
189 | { | |
190 | if (!m_dataset->nextDomain()) { |
|
190 | m_presenter->zoomIn(); | |
191 | QRectF rect = m_presenter->geometry(); |
|
|||
192 | rect.setWidth(rect.width()/2); |
|
|||
193 | rect.setHeight(rect.height()/2); |
|
|||
194 | rect.moveCenter(m_presenter->geometry().center()); |
|
|||
195 | zoomIn(rect); |
|
|||
196 | } |
|
|||
197 | } |
|
191 | } | |
198 |
|
192 | |||
199 | /*! |
|
193 | /*! | |
@@ -201,11 +195,9 void QChart::zoomIn() | |||||
201 | */ |
|
195 | */ | |
202 | void QChart::zoomIn(const QRectF& rect) |
|
196 | void QChart::zoomIn(const QRectF& rect) | |
203 | { |
|
197 | { | |
|
198 | ||||
204 | if(!rect.isValid()) return; |
|
199 | if(!rect.isValid()) return; | |
205 | QRectF r = rect.normalized(); |
|
200 | m_presenter->zoomIn(rect); | |
206 | int margin = m_presenter->margin(); |
|
|||
207 | r.translate(-margin, -margin); |
|
|||
208 | m_dataset->addDomain(r,m_presenter->geometry()); |
|
|||
209 | } |
|
201 | } | |
210 |
|
202 | |||
211 | /*! |
|
203 | /*! | |
@@ -213,7 +205,7 void QChart::zoomIn(const QRectF& rect) | |||||
213 | */ |
|
205 | */ | |
214 | void QChart::zoomOut() |
|
206 | void QChart::zoomOut() | |
215 | { |
|
207 | { | |
216 | m_dataset->previousDomain(); |
|
208 | m_presenter->zoomOut(); | |
217 | } |
|
209 | } | |
218 |
|
210 | |||
219 | /*! |
|
211 | /*! | |
@@ -221,7 +213,7 void QChart::zoomOut() | |||||
221 | */ |
|
213 | */ | |
222 | void QChart::zoomReset() |
|
214 | void QChart::zoomReset() | |
223 | { |
|
215 | { | |
224 | m_dataset->clearDomains(); |
|
216 | m_presenter->zoomReset(); | |
225 | } |
|
217 | } | |
226 |
|
218 | |||
227 | /*! |
|
219 | /*! |
@@ -113,29 +113,25 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
113 | \fn void QChartAxis::maxChanged(qreal max) |
|
113 | \fn void QChartAxis::maxChanged(qreal max) | |
114 | \brief Axis emits signal when \a max of axis has changed. |
|
114 | \brief Axis emits signal when \a max of axis has changed. | |
115 | */ |
|
115 | */ | |
116 | /*! |
|
|||
117 | \fn int QChartAxis::ticksCount() const |
|
|||
118 | \brief Return number of ticks on the axis |
|
|||
119 | \sa setTicksCount() |
|
|||
120 | */ |
|
|||
121 |
|
116 | |||
122 | /*! |
|
117 | /*! | |
123 |
|
|
118 | \fn void QChartAxis::rangeChanged(qreal min, qreal max) | |
124 | \brief \internal |
|
119 | \brief Axis emits signal when \a min or \a max of axis has changed. | |
125 | */ |
|
120 | */ | |
126 |
|
121 | |||
127 | /*! |
|
122 | /*! | |
128 |
|
|
123 | \fn int QChartAxis::ticksCount() const | |
129 | \brief \internal |
|
124 | \brief Return number of ticks on the axis | |
|
125 | \sa setTicksCount() | |||
130 | */ |
|
126 | */ | |
131 |
|
127 | |||
132 | /*! |
|
128 | /*! | |
133 |
\fn void QChartAxis:: |
|
129 | \fn void QChartAxis::update() | |
134 | \brief \internal |
|
130 | \brief \internal | |
135 | */ |
|
131 | */ | |
136 |
|
132 | |||
137 | /*! |
|
133 | /*! | |
138 |
\fn void QChartAxis:: |
|
134 | \fn void QChartAxis::handleAxisRangeChanged(qreal min, qreal max) | |
139 | \brief \internal \a min \a max |
|
135 | \brief \internal \a min \a max | |
140 | */ |
|
136 | */ | |
141 |
|
137 | |||
@@ -171,8 +167,10 QChartAxis::~QChartAxis() | |||||
171 | */ |
|
167 | */ | |
172 | void QChartAxis::setAxisPen(const QPen& pen) |
|
168 | void QChartAxis::setAxisPen(const QPen& pen) | |
173 | { |
|
169 | { | |
|
170 | if (pen != m_axisPen) { | |||
174 | m_axisPen=pen; |
|
171 | m_axisPen=pen; | |
175 |
emit update( |
|
172 | emit updated(); | |
|
173 | } | |||
176 | } |
|
174 | } | |
177 |
|
175 | |||
178 | /*! |
|
176 | /*! | |
@@ -180,8 +178,10 void QChartAxis::setAxisPen(const QPen& pen) | |||||
180 | */ |
|
178 | */ | |
181 | void QChartAxis::setAxisVisible(bool visible) |
|
179 | void QChartAxis::setAxisVisible(bool visible) | |
182 | { |
|
180 | { | |
|
181 | if (m_axisVisible!=visible) { | |||
183 | m_axisVisible=visible; |
|
182 | m_axisVisible=visible; | |
184 |
emit update( |
|
183 | emit updated(); | |
|
184 | } | |||
185 | } |
|
185 | } | |
186 |
|
186 | |||
187 | /*! |
|
187 | /*! | |
@@ -189,8 +189,10 void QChartAxis::setAxisVisible(bool visible) | |||||
189 | */ |
|
189 | */ | |
190 | void QChartAxis::setGridVisible(bool visible) |
|
190 | void QChartAxis::setGridVisible(bool visible) | |
191 | { |
|
191 | { | |
|
192 | if (m_gridVisible!=visible) { | |||
192 | m_gridVisible=visible; |
|
193 | m_gridVisible=visible; | |
193 |
emit update( |
|
194 | emit updated(); | |
|
195 | } | |||
194 | } |
|
196 | } | |
195 |
|
197 | |||
196 | /*! |
|
198 | /*! | |
@@ -198,8 +200,10 void QChartAxis::setGridVisible(bool visible) | |||||
198 | */ |
|
200 | */ | |
199 | void QChartAxis::setGridPen(const QPen& pen) |
|
201 | void QChartAxis::setGridPen(const QPen& pen) | |
200 | { |
|
202 | { | |
|
203 | if (m_gridPen!=pen) { | |||
201 | m_gridPen=pen; |
|
204 | m_gridPen=pen; | |
202 |
emit update( |
|
205 | emit updated(); | |
|
206 | } | |||
203 | } |
|
207 | } | |
204 |
|
208 | |||
205 | /*! |
|
209 | /*! | |
@@ -207,8 +211,10 void QChartAxis::setGridPen(const QPen& pen) | |||||
207 | */ |
|
211 | */ | |
208 | void QChartAxis::setLabelsVisible(bool visible) |
|
212 | void QChartAxis::setLabelsVisible(bool visible) | |
209 | { |
|
213 | { | |
|
214 | if(m_labelsVisible!=visible) { | |||
210 | m_labelsVisible=visible; |
|
215 | m_labelsVisible=visible; | |
211 |
emit update( |
|
216 | emit updated(); | |
|
217 | } | |||
212 | } |
|
218 | } | |
213 |
|
219 | |||
214 | /*! |
|
220 | /*! | |
@@ -216,8 +222,10 void QChartAxis::setLabelsVisible(bool visible) | |||||
216 | */ |
|
222 | */ | |
217 | void QChartAxis::setLabelsPen(const QPen& pen) |
|
223 | void QChartAxis::setLabelsPen(const QPen& pen) | |
218 | { |
|
224 | { | |
|
225 | if(m_labelsPen!=pen) { | |||
219 | m_labelsPen=pen; |
|
226 | m_labelsPen=pen; | |
220 |
emit update( |
|
227 | emit updated(); | |
|
228 | } | |||
221 | } |
|
229 | } | |
222 |
|
230 | |||
223 | /*! |
|
231 | /*! | |
@@ -225,8 +233,10 void QChartAxis::setLabelsPen(const QPen& pen) | |||||
225 | */ |
|
233 | */ | |
226 | void QChartAxis::setLabelsBrush(const QBrush& brush) |
|
234 | void QChartAxis::setLabelsBrush(const QBrush& brush) | |
227 | { |
|
235 | { | |
|
236 | if(m_labelsBrush!=brush) { | |||
228 | m_labelsBrush=brush; |
|
237 | m_labelsBrush=brush; | |
229 |
emit update( |
|
238 | emit updated(); | |
|
239 | } | |||
230 | } |
|
240 | } | |
231 |
|
241 | |||
232 | /*! |
|
242 | /*! | |
@@ -234,8 +244,10 void QChartAxis::setLabelsBrush(const QBrush& brush) | |||||
234 | */ |
|
244 | */ | |
235 | void QChartAxis::setLabelsFont(const QFont& font) |
|
245 | void QChartAxis::setLabelsFont(const QFont& font) | |
236 | { |
|
246 | { | |
|
247 | if(m_labelsFont!=font) { | |||
237 | m_labelsFont=font; |
|
248 | m_labelsFont=font; | |
238 |
emit update( |
|
249 | emit updated(); | |
|
250 | } | |||
239 | } |
|
251 | } | |
240 |
|
252 | |||
241 | /*! |
|
253 | /*! | |
@@ -243,8 +255,10 void QChartAxis::setLabelsFont(const QFont& font) | |||||
243 | */ |
|
255 | */ | |
244 | void QChartAxis::setLabelsAngle(int angle) |
|
256 | void QChartAxis::setLabelsAngle(int angle) | |
245 | { |
|
257 | { | |
|
258 | if(m_labelsAngle!=angle) { | |||
246 | m_labelsAngle=angle; |
|
259 | m_labelsAngle=angle; | |
247 |
|
|
260 | emit updated(); | |
|
261 | } | |||
248 | } |
|
262 | } | |
249 |
|
263 | |||
250 | /*! |
|
264 | /*! | |
@@ -252,8 +266,10 void QChartAxis::setLabelsAngle(int angle) | |||||
252 | */ |
|
266 | */ | |
253 | void QChartAxis::setShadesVisible(bool visible) |
|
267 | void QChartAxis::setShadesVisible(bool visible) | |
254 | { |
|
268 | { | |
|
269 | if(m_shadesVisible!=visible) { | |||
255 | m_shadesVisible=visible; |
|
270 | m_shadesVisible=visible; | |
256 |
emit update( |
|
271 | emit updated(); | |
|
272 | } | |||
257 | } |
|
273 | } | |
258 |
|
274 | |||
259 | /*! |
|
275 | /*! | |
@@ -261,8 +277,10 void QChartAxis::setShadesVisible(bool visible) | |||||
261 | */ |
|
277 | */ | |
262 | void QChartAxis::setShadesPen(const QPen& pen) |
|
278 | void QChartAxis::setShadesPen(const QPen& pen) | |
263 | { |
|
279 | { | |
|
280 | if(m_shadesPen!=pen) { | |||
264 |
|
|
281 | m_shadesPen=pen; | |
265 |
|
|
282 | emit updated(); | |
|
283 | } | |||
266 | } |
|
284 | } | |
267 |
|
285 | |||
268 | /*! |
|
286 | /*! | |
@@ -270,8 +288,10 void QChartAxis::setShadesPen(const QPen& pen) | |||||
270 | */ |
|
288 | */ | |
271 | void QChartAxis::setShadesBrush(const QBrush& brush) |
|
289 | void QChartAxis::setShadesBrush(const QBrush& brush) | |
272 | { |
|
290 | { | |
|
291 | if(m_shadesBrush!=brush) { | |||
273 | m_shadesBrush=brush; |
|
292 | m_shadesBrush=brush; | |
274 |
emit update( |
|
293 | emit updated(); | |
|
294 | } | |||
275 | } |
|
295 | } | |
276 |
|
296 | |||
277 | /*! |
|
297 | /*! | |
@@ -279,8 +299,10 void QChartAxis::setShadesBrush(const QBrush& brush) | |||||
279 | */ |
|
299 | */ | |
280 | void QChartAxis::setShadesOpacity(qreal opacity) |
|
300 | void QChartAxis::setShadesOpacity(qreal opacity) | |
281 | { |
|
301 | { | |
|
302 | if(m_shadesOpacity!=opacity) { | |||
282 | m_shadesOpacity=opacity; |
|
303 | m_shadesOpacity=opacity; | |
283 |
emit update( |
|
304 | emit updated(); | |
|
305 | } | |||
284 | } |
|
306 | } | |
285 |
|
307 | |||
286 | /*! |
|
308 | /*! | |
@@ -288,10 +310,7 void QChartAxis::setShadesOpacity(qreal opacity) | |||||
288 | */ |
|
310 | */ | |
289 | void QChartAxis::setMin(qreal min) |
|
311 | void QChartAxis::setMin(qreal min) | |
290 | { |
|
312 | { | |
291 | if(m_min!=min) { |
|
313 | setRange(min,m_max); | |
292 | m_min=min; |
|
|||
293 | emit rangeChanged(this); |
|
|||
294 | } |
|
|||
295 | } |
|
314 | } | |
296 |
|
315 | |||
297 | /*! |
|
316 | /*! | |
@@ -299,10 +318,7 void QChartAxis::setMin(qreal min) | |||||
299 | */ |
|
318 | */ | |
300 | void QChartAxis::setMax(qreal max) |
|
319 | void QChartAxis::setMax(qreal max) | |
301 | { |
|
320 | { | |
302 | if(m_max!=max) { |
|
321 | setRange(m_min,max); | |
303 | m_max=max; |
|
|||
304 | emit rangeChanged(this); |
|
|||
305 | } |
|
|||
306 | } |
|
322 | } | |
307 |
|
323 | |||
308 | /*! |
|
324 | /*! | |
@@ -310,22 +326,23 void QChartAxis::setMax(qreal max) | |||||
310 | */ |
|
326 | */ | |
311 | void QChartAxis::setRange(qreal min, qreal max) |
|
327 | void QChartAxis::setRange(qreal min, qreal max) | |
312 | { |
|
328 | { | |
313 | setMin(min); |
|
329 | bool changed = false; | |
314 | setMax(max); |
|
330 | if(m_min!=min) { | |
|
331 | m_min=min; | |||
|
332 | emit minChanged(min); | |||
315 | } |
|
333 | } | |
316 |
|
334 | |||
317 | void QChartAxis::updateRange(qreal min, qreal max) |
|
|||
318 | { |
|
|||
319 | if(m_max!=max){ |
|
335 | if(m_max!=max) { | |
|
336 | m_max=max; | |||
320 | emit maxChanged(max); |
|
337 | emit maxChanged(max); | |
321 | } |
|
338 | } | |
322 |
|
339 | |||
323 | if(m_min!=min){ |
|
340 | if(changed) emit rangeChanged(m_min,m_max); | |
324 | emit minChanged(min); |
|
|||
325 | } |
|
341 | } | |
326 |
|
342 | |||
327 | m_max=max; |
|
343 | void QChartAxis::handleAxisRangeChanged(qreal min, qreal max) | |
328 | m_min=min; |
|
344 | { | |
|
345 | setRange(min,max); | |||
329 | } |
|
346 | } | |
330 |
|
347 | |||
331 | /*! |
|
348 | /*! | |
@@ -333,8 +350,10 void QChartAxis::updateRange(qreal min, qreal max) | |||||
333 | */ |
|
350 | */ | |
334 | void QChartAxis::setTicksCount(int count) |
|
351 | void QChartAxis::setTicksCount(int count) | |
335 | { |
|
352 | { | |
|
353 | if(m_ticksCount!=count) { | |||
336 | m_ticksCount=count; |
|
354 | m_ticksCount=count; | |
337 | emit ticksChanged(this); |
|
355 | emit updated(); | |
|
356 | } | |||
338 | } |
|
357 | } | |
339 |
|
358 | |||
340 | /*! |
|
359 | /*! | |
@@ -343,7 +362,7 void QChartAxis::setTicksCount(int count) | |||||
343 | void QChartAxis::addAxisTickLabel(qreal value,const QString& label) |
|
362 | void QChartAxis::addAxisTickLabel(qreal value,const QString& label) | |
344 | { |
|
363 | { | |
345 | m_ticks.insert(value,label); |
|
364 | m_ticks.insert(value,label); | |
346 | emit ticksChanged(this); |
|
365 | emit updated(); | |
347 | } |
|
366 | } | |
348 |
|
367 | |||
349 | /*! |
|
368 | /*! | |
@@ -352,7 +371,7 void QChartAxis::addAxisTickLabel(qreal value,const QString& label) | |||||
352 | void QChartAxis::removeAxisTickLabel(qreal value) |
|
371 | void QChartAxis::removeAxisTickLabel(qreal value) | |
353 | { |
|
372 | { | |
354 | m_ticks.remove(value); |
|
373 | m_ticks.remove(value); | |
355 | emit ticksChanged(this); |
|
374 | emit updated(); | |
356 | } |
|
375 | } | |
357 |
|
376 | |||
358 | /*! |
|
377 | /*! | |
@@ -369,7 +388,7 QString QChartAxis::axisTickLabel(qreal value) const | |||||
369 | void QChartAxis::clearAxisTickLabels() |
|
388 | void QChartAxis::clearAxisTickLabels() | |
370 | { |
|
389 | { | |
371 | m_ticks.clear(); |
|
390 | m_ticks.clear(); | |
372 | emit ticksChanged(this); |
|
391 | emit updated(); | |
373 | } |
|
392 | } | |
374 |
|
393 | |||
375 | #include "moc_qchartaxis.cpp" |
|
394 | #include "moc_qchartaxis.cpp" |
@@ -64,16 +64,17 public: | |||||
64 | QString axisTickLabel(qreal value) const ; |
|
64 | QString axisTickLabel(qreal value) const ; | |
65 | void clearAxisTickLabels(); |
|
65 | void clearAxisTickLabels(); | |
66 |
|
66 | |||
67 | //internal |
|
|||
68 | void updateRange(qreal min, qreal max); |
|
|||
69 |
|
||||
70 | signals: |
|
67 | signals: | |
71 | void minChanged(qreal min); |
|
68 | void minChanged(qreal min); | |
72 | void maxChanged(qreal max); |
|
69 | void maxChanged(qreal max); | |
73 | //private signal |
|
70 | void rangeChanged(qreal min, qreal max); | |
74 | void update(QChartAxis*); |
|
71 | ||
75 | void rangeChanged(QChartAxis*); |
|
72 | //intral signal | |
76 | void ticksChanged(QChartAxis*); |
|
73 | void updated(); | |
|
74 | ||||
|
75 | //internal slot | |||
|
76 | public slots: | |||
|
77 | void handleAxisRangeChanged(qreal min, qreal max); | |||
77 |
|
78 | |||
78 | private: |
|
79 | private: | |
79 | bool m_axisVisible; |
|
80 | bool m_axisVisible; |
@@ -13,9 +13,12 QTCOMMERCIALCHART_BEGIN_NAMESPACE | |||||
13 |
|
13 | |||
14 | ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *parent) : |
|
14 | ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *parent) : | |
15 | ChartItem(parent), |
|
15 | ChartItem(parent), | |
|
16 | m_minX(0), | |||
|
17 | m_maxX(0), | |||
|
18 | m_minY(0), | |||
|
19 | m_maxY(0), | |||
16 | m_series(series), |
|
20 | m_series(series), | |
17 |
m_boundingRect() |
|
21 | m_boundingRect() | |
18 | m_visibleChartArea() |
|
|||
19 | { |
|
22 | { | |
20 | if (parent) |
|
23 | if (parent) | |
21 | m_boundingRect = parent->boundingRect(); |
|
24 | m_boundingRect = parent->boundingRect(); | |
@@ -33,9 +36,12 ScatterPresenter::ScatterPresenter(QScatterSeries *series, QGraphicsObject *pare | |||||
33 | // setGraphicsEffect(dropShadow); |
|
36 | // setGraphicsEffect(dropShadow); | |
34 | } |
|
37 | } | |
35 |
|
38 | |||
36 |
void ScatterPresenter::handleDomainChanged( |
|
39 | void ScatterPresenter::handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY) | |
37 | { |
|
40 | { | |
38 | m_visibleChartArea = domain; |
|
41 | m_minX=minX; | |
|
42 | m_maxX=maxX; | |||
|
43 | m_minY=minY; | |||
|
44 | m_maxY=maxY; | |||
39 | changeGeometry(); |
|
45 | changeGeometry(); | |
40 | } |
|
46 | } | |
41 |
|
47 | |||
@@ -98,8 +104,8 void ScatterPresenter::mousePressEvent(QGraphicsSceneMouseEvent *event) | |||||
98 | void ScatterPresenter::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) |
|
104 | void ScatterPresenter::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) | |
99 | { |
|
105 | { | |
100 | QPointF clickedPoint( |
|
106 | QPointF clickedPoint( | |
101 |
|
|
107 | m_minX + (event->lastPos().x() / m_boundingRect.width()) * (m_maxX-m_minX), | |
102 |
|
|
108 | m_maxY - (event->lastPos().y() / m_boundingRect.height()) * (m_maxY-m_minY)); | |
103 | emit clicked(clickedPoint); |
|
109 | emit clicked(clickedPoint); | |
104 | } |
|
110 | } | |
105 |
|
111 | |||
@@ -107,8 +113,8 void ScatterPresenter::changeGeometry() | |||||
107 | { |
|
113 | { | |
108 | if (m_boundingRect.isValid()) { |
|
114 | if (m_boundingRect.isValid()) { | |
109 | prepareGeometryChange(); |
|
115 | prepareGeometryChange(); | |
110 |
qreal scalex = m_boundingRect.width() / |
|
116 | qreal scalex = m_boundingRect.width() / (m_maxX-m_minX); | |
111 |
qreal scaley = m_boundingRect.height() / |
|
117 | qreal scaley = m_boundingRect.height() / (m_maxY-m_minY); | |
112 |
|
118 | |||
113 | int shape = m_series->shape(); |
|
119 | int shape = m_series->shape(); | |
114 | m_path = QPainterPath(); |
|
120 | m_path = QPainterPath(); | |
@@ -117,8 +123,8 void ScatterPresenter::changeGeometry() | |||||
117 |
|
123 | |||
118 | foreach (QPointF point, m_series->data()) { |
|
124 | foreach (QPointF point, m_series->data()) { | |
119 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing |
|
125 | // Convert relative coordinates to absolute pixel coordinates that can be used for drawing | |
120 |
qreal x = point.x() * scalex - |
|
126 | qreal x = point.x() * scalex - m_minX * scalex - size / 2; | |
121 |
qreal y = m_boundingRect.height() - point.y() * scaley + |
|
127 | qreal y = m_boundingRect.height() - point.y() * scaley + m_minY * scaley - size / 2; | |
122 |
|
128 | |||
123 | if (x < scene()->width() && y < scene()->height()) { |
|
129 | if (x < scene()->width() && y < scene()->height()) { | |
124 | switch (shape) { |
|
130 | switch (shape) { |
@@ -27,19 +27,23 Q_SIGNALS: | |||||
27 | void clicked(QPointF coordinates); |
|
27 | void clicked(QPointF coordinates); | |
28 |
|
28 | |||
29 | public Q_SLOTS: |
|
29 | public Q_SLOTS: | |
30 |
void handleDomainChanged( |
|
30 | void handleDomainChanged(qreal minX, qreal maxX, qreal minY, qreal maxY); | |
31 | void handleGeometryChanged(const QRectF& rect); |
|
31 | void handleGeometryChanged(const QRectF& rect); | |
32 | void handleModelChanged(); |
|
32 | void handleModelChanged(); | |
33 |
|
33 | |||
34 | public: |
|
34 | public: | |
35 | void changeGeometry(); |
|
35 | void changeGeometry(); | |
36 |
|
36 | |||
|
37 | qreal m_minX; | |||
|
38 | qreal m_maxX; | |||
|
39 | qreal m_minY; | |||
|
40 | qreal m_maxY; | |||
37 | QScatterSeries *m_series; |
|
41 | QScatterSeries *m_series; | |
38 | QRectF m_boundingRect; |
|
42 | QRectF m_boundingRect; | |
39 | Domain m_visibleChartArea; |
|
|||
40 | QPen m_markerPen; |
|
43 | QPen m_markerPen; | |
41 | QBrush m_markerBrush; |
|
44 | QBrush m_markerBrush; | |
42 | QPainterPath m_path; |
|
45 | QPainterPath m_path; | |
|
46 | ||||
43 | }; |
|
47 | }; | |
44 |
|
48 | |||
45 | QTCOMMERCIALCHART_END_NAMESPACE |
|
49 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -4,7 +4,7 | |||||
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
4 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
5 |
|
5 | |||
6 | SplinePresenter::SplinePresenter(QSplineSeries* series, QGraphicsObject *parent) : |
|
6 | SplinePresenter::SplinePresenter(QSplineSeries* series, QGraphicsObject *parent) : | |
7 |
LineChartItem( |
|
7 | LineChartItem(series, parent)//,m_boundingRect() | |
8 | { |
|
8 | { | |
9 | // |
|
9 | // | |
10 | } |
|
10 | } | |
@@ -14,10 +14,10 SplinePresenter::SplinePresenter(QSplineSeries* series, QGraphicsObject *parent) | |||||
14 | QPointF SplinePresenter::calculateGeometryControlPoint(int index) const |
|
14 | QPointF SplinePresenter::calculateGeometryControlPoint(int index) const | |
15 | { |
|
15 | { | |
16 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); |
|
16 | QSplineSeries* splineSeries = qobject_cast<QSplineSeries*>(m_series); | |
17 |
const qreal deltaX = m_size.width()/ |
|
17 | const qreal deltaX = m_size.width()/(m_maxX-m_minX); | |
18 |
const qreal deltaY = m_size.height()/ |
|
18 | const qreal deltaY = m_size.height()/(m_maxY-m_minY); | |
19 |
qreal x = (splineSeries->controlPoint(index).x() - |
|
19 | qreal x = (splineSeries->controlPoint(index).x() - m_minX)* deltaX; | |
20 |
qreal y = (splineSeries->controlPoint(index).y() - |
|
20 | qreal y = (splineSeries->controlPoint(index).y() - m_minY)*-deltaY + m_size.height(); | |
21 | return QPointF(x,y); |
|
21 | return QPointF(x,y); | |
22 | } |
|
22 | } | |
23 |
|
23 |
@@ -1,2 +1,2 | |||||
1 | TEMPLATE = subdirs |
|
1 | TEMPLATE = subdirs | |
2 | SUBDIRS += chartdataset No newline at end of file |
|
2 | SUBDIRS += chartdataset domain No newline at end of file |
This diff has been collapsed as it changes many lines, (633 lines changed) Show them Hide them | |||||
@@ -6,7 +6,7 | |||||
6 |
|
6 | |||
7 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
7 | QTCOMMERCIALCHART_USE_NAMESPACE | |
8 |
|
8 | |||
9 | Q_DECLARE_METATYPE(Domain) |
|
9 | Q_DECLARE_METATYPE(Domain*) | |
10 | Q_DECLARE_METATYPE(QChartAxis*) |
|
10 | Q_DECLARE_METATYPE(QChartAxis*) | |
11 | Q_DECLARE_METATYPE(QSeries*) |
|
11 | Q_DECLARE_METATYPE(QSeries*) | |
12 | Q_DECLARE_METATYPE(QLineSeries*) |
|
12 | Q_DECLARE_METATYPE(QLineSeries*) | |
@@ -24,27 +24,20 private slots: | |||||
24 | void chartdataset_data(); |
|
24 | void chartdataset_data(); | |
25 | void chartdataset(); |
|
25 | void chartdataset(); | |
26 |
|
26 | |||
27 | void addDomain_data(); |
|
|||
28 | void addDomain(); |
|
|||
29 | void addSeries_data(); |
|
27 | void addSeries_data(); | |
30 | void addSeries(); |
|
28 | void addSeries(); | |
31 | void axisY_data(); |
|
|||
32 | void axisY(); |
|
|||
33 | void clearDomains_data(); |
|
|||
34 | void clearDomains(); |
|
|||
35 | void domain_data(); |
|
|||
36 | void domain(); |
|
|||
37 | void nextpreviousDomain_data(); |
|
|||
38 | void nextpreviousDomain(); |
|
|||
39 | void removeSeries_data(); |
|
29 | void removeSeries_data(); | |
40 | void removeSeries(); |
|
30 | void removeSeries(); | |
41 | void removeAllSeries_data(); |
|
31 | void removeAllSeries_data(); | |
42 | void removeAllSeries(); |
|
32 | void removeAllSeries(); | |
|
33 | void axisY_data(); | |||
|
34 | void axisY(); | |||
|
35 | ||||
43 | }; |
|
36 | }; | |
44 |
|
37 | |||
45 | void tst_ChartDataSet::initTestCase() |
|
38 | void tst_ChartDataSet::initTestCase() | |
46 | { |
|
39 | { | |
47 |
|
|
40 | qRegisterMetaType<Domain*>(); | |
48 | qRegisterMetaType<QChartAxis*>(); |
|
41 | qRegisterMetaType<QChartAxis*>(); | |
49 | qRegisterMetaType<QSeries*>(); |
|
42 | qRegisterMetaType<QSeries*>(); | |
50 | } |
|
43 | } | |
@@ -73,541 +66,211 void tst_ChartDataSet::chartdataset() | |||||
73 | //check if not dangling pointer |
|
66 | //check if not dangling pointer | |
74 | dataSet.axisX()->objectName(); |
|
67 | dataSet.axisX()->objectName(); | |
75 | dataSet.axisY()->objectName(); |
|
68 | dataSet.axisY()->objectName(); | |
76 | QVERIFY(dataSet.domain(dataSet.axisX())==Domain()); |
|
|||
77 | QVERIFY(dataSet.domain(dataSet.axisY())==Domain()); |
|
|||
78 | QCOMPARE(dataSet.domainIndex(), 0); |
|
|||
79 | } |
|
69 | } | |
80 |
|
70 | |||
81 |
void tst_ChartDataSet::add |
|
71 | void tst_ChartDataSet::addSeries_data() | |
82 | { |
|
72 | { | |
83 |
QTest::addColumn<Q |
|
73 | QTest::addColumn<QLineSeries*>("series0"); | |
84 |
|
|
74 | QTest::addColumn<QChartAxis*>("axis0"); | |
85 | QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600) |
|
75 | QTest::addColumn<QLineSeries*>("series1"); | |
86 | << QRectF(0, 0, 1000, 1000); |
|
76 | QTest::addColumn<QChartAxis*>("axis1"); | |
87 | QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700) |
|
77 | QTest::addColumn<QLineSeries*>("series2"); | |
88 | << QRectF(0, 0, 1000, 1000); |
|
78 | QTest::addColumn<QChartAxis*>("axis2"); | |
89 | QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600) |
|
79 | QTest::addColumn<int>("axisCount"); | |
90 | << QRectF(0, 0, 1000, 1000); |
|
|||
91 | } |
|
|||
92 |
|
80 | |||
93 | void tst_ChartDataSet::addDomain() |
|
81 | QLineSeries* series0 = new QLineSeries(this); | |
94 | { |
|
82 | QLineSeries* series1 = new QLineSeries(this); | |
95 | QFETCH(QRectF, rect); |
|
83 | QLineSeries* series2 = new QLineSeries(this); | |
96 | QFETCH(QRectF, viewport); |
|
|||
97 |
|
84 | |||
98 | ChartDataSet dataSet; |
|
85 | QChartAxis* axis0 = new QChartAxis(this); | |
99 |
|
86 | QChartAxis* axis1 = new QChartAxis(this); | ||
100 | Domain domain1(0, 1000, 0, 1000); |
|
87 | QChartAxis* axis2 = new QChartAxis(this); | |
101 | QLineSeries series; |
|
|||
102 | series.add(0, 0); |
|
|||
103 | series.add(1000, 1000); |
|
|||
104 |
|
||||
105 | dataSet.addSeries(&series); |
|
|||
106 |
|
||||
107 | QCOMPARE(dataSet.domainIndex(), 0); |
|
|||
108 |
|
||||
109 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
|||
110 | QSignalSpy spy1(&dataSet, |
|
|||
111 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); |
|
|||
112 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
|||
113 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); |
|
|||
114 | QSignalSpy spy4(&dataSet, |
|
|||
115 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
|||
116 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
|||
117 |
|
||||
118 | Domain domain2 = dataSet.domain(dataSet.axisY()); |
|
|||
119 | QVERIFY(domain1 == domain2); |
|
|||
120 |
|
||||
121 | dataSet.addDomain(rect, viewport); |
|
|||
122 | QCOMPARE(dataSet.domainIndex(), 1); |
|
|||
123 | Domain domain3 = dataSet.domain(dataSet.axisY()); |
|
|||
124 | Domain domain4 = domain1.subDomain(rect, viewport.width(), |
|
|||
125 | viewport.height()); |
|
|||
126 | QVERIFY(domain3 == domain4); |
|
|||
127 |
|
||||
128 | QCOMPARE(spy0.count(), 0); |
|
|||
129 | QCOMPARE(spy1.count(), 2); |
|
|||
130 | QCOMPARE(spy2.count(), 0); |
|
|||
131 | QCOMPARE(spy3.count(), 0); |
|
|||
132 | QCOMPARE(spy4.count(), 1); |
|
|||
133 | QCOMPARE(spy5.count(), 0); |
|
|||
134 | } |
|
|||
135 |
|
88 | |||
136 | void tst_ChartDataSet::addSeries_data() |
|
89 | QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QChartAxis*)0 << series1 << (QChartAxis*)0 << series2 << (QChartAxis*)0 << 2; | |
137 | { |
|
90 | QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (QChartAxis*)0 << series1 << axis0 << series2 << axis0 << 3; | |
138 | QTest::addColumn<int>("defaultAxisCount"); |
|
91 | QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1 << axis1 << series2 << axis2 << 4; | |
139 | QTest::addColumn<int>("firstAxisCount"); |
|
|||
140 | QTest::addColumn<int>("secoundAxisCount"); |
|
|||
141 | QTest::newRow("2 ,1 ,0") << 2 << 1 << 0; |
|
|||
142 | QTest::newRow("2 series, 2 new axis") << 2 << 0 << 2; |
|
|||
143 | QTest::newRow("2 series, 1 new axis") << 2 << 0 << 2; |
|
|||
144 | QTest::newRow("3 series, 3 new axis") << 3 << 0 << 3; |
|
|||
145 | QTest::newRow("3 series, 2 new axis") << 3 << 0 << 2; |
|
|||
146 | QTest::newRow("3 series, 1 new axis") << 3 << 0 << 1; |
|
|||
147 | QTest::newRow("3 series, default + 1 new axis") << 3 << 0 << 1; |
|
|||
148 | } |
|
92 | } | |
149 |
|
93 | |||
150 | void tst_ChartDataSet::addSeries() |
|
94 | void tst_ChartDataSet::addSeries() | |
151 | { |
|
95 | { | |
152 | QFETCH(int, defaultAxisCount); |
|
96 | QFETCH(QLineSeries*, series0); | |
153 |
QFETCH( |
|
97 | QFETCH(QChartAxis*, axis0); | |
154 |
QFETCH( |
|
98 | QFETCH(QLineSeries*, series1); | |
|
99 | QFETCH(QChartAxis*, axis1); | |||
|
100 | QFETCH(QLineSeries*, series2); | |||
|
101 | QFETCH(QChartAxis*, axis2); | |||
|
102 | QFETCH(int, axisCount); | |||
155 |
|
103 | |||
156 | ChartDataSet dataSet; |
|
104 | ChartDataSet dataSet; | |
157 |
|
105 | |||
158 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
106 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*))); | |
159 |
QSignalSpy spy1(&dataSet, SIGNAL(axisR |
|
107 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |
160 |
QSignalSpy spy2(&dataSet, SIGNAL( |
|
108 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*))); | |
161 |
QSignalSpy spy3(&dataSet, SIGNAL(series |
|
109 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |
162 | QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
|||
163 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
|||
164 |
|
110 | |||
165 | for (int i = 0; i < defaultAxisCount; i++) { |
|
111 | dataSet.addSeries(series0,axis0); | |
166 | QLineSeries* series = new QLineSeries(); |
|
112 | dataSet.addSeries(series1,axis1); | |
167 |
|
|
113 | dataSet.addSeries(series2,axis2); | |
168 | } |
|
|||
169 |
|
||||
170 | QChartAxis* firstAxis = new QChartAxis(); |
|
|||
171 |
|
||||
172 | for (int i = 0; i < firstAxisCount; i++) { |
|
|||
173 | QLineSeries* series = new QLineSeries(); |
|
|||
174 | dataSet.addSeries(series, firstAxis); |
|
|||
175 | } |
|
|||
176 |
|
||||
177 | QChartAxis* secoundAxis = new QChartAxis(); |
|
|||
178 |
|
||||
179 | for (int i = 0; i < secoundAxisCount; i++) { |
|
|||
180 | QLineSeries* series = new QLineSeries(); |
|
|||
181 | dataSet.addSeries(series, secoundAxis); |
|
|||
182 | } |
|
|||
183 |
|
||||
184 | int axisCount = 1; |
|
|||
185 |
|
||||
186 | if (defaultAxisCount > 0) |
|
|||
187 | axisCount++; |
|
|||
188 | if (firstAxisCount > 0) |
|
|||
189 | axisCount++; |
|
|||
190 | if (secoundAxisCount > 0) |
|
|||
191 | axisCount++; |
|
|||
192 |
|
114 | |||
193 | QCOMPARE(spy0.count(), axisCount); |
|
115 | QCOMPARE(spy0.count(), axisCount); | |
194 | QCOMPARE(spy1.count(), (defaultAxisCount + firstAxisCount + secoundAxisCount)*2); |
|
116 | QCOMPARE(spy1.count(), 0); | |
195 |
QCOMPARE(spy2.count(), |
|
117 | QCOMPARE(spy2.count(), 3); | |
196 | QCOMPARE(spy3.count(), defaultAxisCount + firstAxisCount + secoundAxisCount); |
|
118 | QCOMPARE(spy3.count(), 0); | |
197 |
|
||||
198 | int i = 0; |
|
|||
199 | while (defaultAxisCount) { |
|
|||
200 | i+=defaultAxisCount; |
|
|||
201 | defaultAxisCount--; |
|
|||
202 | } |
|
|||
203 | int j = 0; |
|
|||
204 | while (firstAxisCount>0) { |
|
|||
205 | j += firstAxisCount; |
|
|||
206 | firstAxisCount--; |
|
|||
207 | } |
|
|||
208 | int k = 0; |
|
|||
209 | while (secoundAxisCount>0) { |
|
|||
210 | k += secoundAxisCount; |
|
|||
211 | secoundAxisCount--; |
|
|||
212 | } |
|
|||
213 | QCOMPARE(spy4.count(),i + j + k); |
|
|||
214 | QCOMPARE(spy5.count(), 0); |
|
|||
215 |
|
||||
216 | QCOMPARE(dataSet.domainIndex(), 0); |
|
|||
217 | } |
|
|||
218 |
|
||||
219 | void tst_ChartDataSet::axisY_data() |
|
|||
220 | { |
|
|||
221 | QTest::addColumn<QChartAxis*>("axisY"); |
|
|||
222 | QTest::newRow("axisY1") << new QChartAxis(); |
|
|||
223 | QTest::newRow("axisY2") << new QChartAxis(); |
|
|||
224 | } |
|
|||
225 |
|
||||
226 | void tst_ChartDataSet::axisY() |
|
|||
227 | { |
|
|||
228 | QFETCH(QChartAxis*, axisY); |
|
|||
229 |
|
||||
230 | ChartDataSet dataSet; |
|
|||
231 |
|
||||
232 | QChartAxis* defaultAxisY = dataSet.axisY(); |
|
|||
233 |
|
||||
234 | QVERIFY2(defaultAxisY, "Missing axisY."); |
|
|||
235 |
|
||||
236 | QLineSeries* series1 = new QLineSeries(); |
|
|||
237 | dataSet.addSeries(series1); |
|
|||
238 |
|
||||
239 | QLineSeries* series2 = new QLineSeries(); |
|
|||
240 | dataSet.addSeries(series2, axisY); |
|
|||
241 |
|
||||
242 | QVERIFY(dataSet.axisY(series1) == defaultAxisY); |
|
|||
243 | QVERIFY(dataSet.axisY(series2) == axisY); |
|
|||
244 |
|
||||
245 |
|
119 | |||
246 | } |
|
120 | } | |
247 |
|
121 | |||
248 |
void tst_ChartDataSet:: |
|
122 | void tst_ChartDataSet::removeSeries_data() | |
249 | { |
|
123 | { | |
250 |
|
|
124 | QTest::addColumn<QLineSeries*>("series0"); | |
251 | QTest::newRow("0") << 0; |
|
125 | QTest::addColumn<QChartAxis*>("axis0"); | |
252 | QTest::newRow("1") << 1; |
|
126 | QTest::addColumn<QLineSeries*>("series1"); | |
253 | QTest::newRow("5") << 2; |
|
127 | QTest::addColumn<QChartAxis*>("axis1"); | |
254 | QTest::newRow("8") << 3; |
|
128 | QTest::addColumn<QLineSeries*>("series2"); | |
|
129 | QTest::addColumn<QChartAxis*>("axis2"); | |||
|
130 | QTest::addColumn<int>("axisCount"); | |||
|
131 | ||||
|
132 | QLineSeries* series0 = new QLineSeries(this); | |||
|
133 | QLineSeries* series1 = new QLineSeries(this); | |||
|
134 | QLineSeries* series2 = new QLineSeries(this); | |||
|
135 | ||||
|
136 | QChartAxis* axis0 = new QChartAxis(this); | |||
|
137 | QChartAxis* axis1 = new QChartAxis(this); | |||
|
138 | QChartAxis* axis2 = new QChartAxis(this); | |||
|
139 | ||||
|
140 | QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QChartAxis*) 0 | |||
|
141 | << series1 << (QChartAxis*) 0 << series2 << (QChartAxis*) 0 << 2; | |||
|
142 | QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (QChartAxis*) 0 | |||
|
143 | << series1 << axis0 << series2 << axis0 << 3; | |||
|
144 | QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1 | |||
|
145 | << axis1 << series2 << axis2 << 4; | |||
255 | } |
|
146 | } | |
256 |
|
147 | |||
257 |
void tst_ChartDataSet:: |
|
148 | void tst_ChartDataSet::removeSeries() | |
258 | { |
|
149 | { | |
259 | QFETCH(int, indexCount); |
|
150 | QFETCH(QLineSeries*, series0); | |
260 |
|
151 | QFETCH(QChartAxis*, axis0); | ||
261 | Domain domain1(0, 100, 0, 100); |
|
152 | QFETCH(QLineSeries*, series1); | |
262 | QLineSeries* series = new QLineSeries(); |
|
153 | QFETCH(QChartAxis*, axis1); | |
263 | series->add(0, 0); |
|
154 | QFETCH(QLineSeries*, series2); | |
264 | series->add(100, 100); |
|
155 | QFETCH(QChartAxis*, axis2); | |
|
156 | QFETCH(int, axisCount); | |||
265 |
|
157 | |||
266 |
|
|
158 | ChartDataSet dataSet; | |
267 |
|
159 | |||
268 | QCOMPARE(dataSet.domainIndex(), 0); |
|
160 | dataSet.addSeries(series0,axis0); | |
269 |
|
161 | dataSet.addSeries(series1,axis1); | ||
270 |
|
|
162 | dataSet.addSeries(series2,axis2); | |
271 |
|
163 | |||
272 | Domain domain2 = dataSet.domain(dataSet.axisY()); |
|
164 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*))); | |
|
165 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |||
|
166 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*))); | |||
|
167 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |||
273 |
|
168 | |||
274 | QVERIFY(domain2 == domain1); |
|
169 | dataSet.removeSeries(series0); | |
275 |
|
170 | dataSet.removeSeries(series1); | ||
276 | QList<Domain> domains; |
|
171 | dataSet.removeSeries(series2); | |
277 |
|
||||
278 | domains << domain1; |
|
|||
279 |
|
||||
280 | for (int i = 0; i < indexCount; i++) { |
|
|||
281 | dataSet.addDomain(QRect(0, 0, 10, 10), QRect(0, 0, 100, 100)); |
|
|||
282 | domains << dataSet.domain(dataSet.axisY()); |
|
|||
283 | } |
|
|||
284 |
|
||||
285 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
|||
286 | QSignalSpy spy1(&dataSet, |
|
|||
287 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); |
|
|||
288 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
|||
289 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); |
|
|||
290 | QSignalSpy spy4(&dataSet, |
|
|||
291 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
|||
292 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
|||
293 |
|
||||
294 | dataSet.clearDomains(indexCount); |
|
|||
295 |
|
||||
296 | QCOMPARE(dataSet.domainIndex(), indexCount); |
|
|||
297 |
|
||||
298 | domain2 = dataSet.domain(dataSet.axisY()); |
|
|||
299 |
|
||||
300 | QVERIFY(domain2 == domains.at(indexCount)); |
|
|||
301 |
|
172 | |||
302 |
|
|
173 | QCOMPARE(spy0.count(), 0); | |
303 |
|
|
174 | QCOMPARE(spy1.count(), axisCount); | |
304 | QCOMPARE(spy2.count(), 0); |
|
|||
305 | QCOMPARE(spy3.count(), 0); |
|
|||
306 | QCOMPARE(spy4.count(), 0); |
|
|||
307 | QCOMPARE(spy5.count(), 0); |
|
|||
308 | } |
|
|||
309 |
|
||||
310 | void tst_ChartDataSet::domain_data() |
|
|||
311 | { |
|
|||
312 | QTest::addColumn<Domain>("domain1"); |
|
|||
313 | QTest::addColumn<Domain>("domain2"); |
|
|||
314 | QTest::addColumn<Domain>("domain3"); |
|
|||
315 | QTest::addColumn<Domain>("domain"); |
|
|||
316 | QTest::newRow("Domain(0,10,0,10)") << Domain(0, 10, 0, 10) |
|
|||
317 | << Domain(0, 5, 0, 5) << Domain(0, 3, 0, 3) << Domain(0, 10, 0, 10); |
|
|||
318 | QTest::newRow("Domain(-1,11,0,11)") << Domain(-1, 10, 0, 10) |
|
|||
319 | << Domain(0, 11, 0, 11) << Domain(0, 3, 0, 3) |
|
|||
320 | << Domain(-1, 11, 0, 11); |
|
|||
321 | QTest::newRow("Domain(-5,5,1,8)") << Domain(-5, 0, 1, 1) |
|
|||
322 | << Domain(0, 5, 0, 8) << Domain(1, 2, 1, 2) << Domain(-5, 5, 0, 8); |
|
|||
323 | } |
|
|||
324 |
|
||||
325 | void tst_ChartDataSet::domain() |
|
|||
326 | { |
|
|||
327 | QFETCH(Domain, domain1); |
|
|||
328 | QFETCH(Domain, domain2); |
|
|||
329 | QFETCH(Domain, domain3); |
|
|||
330 | QFETCH(Domain, domain); |
|
|||
331 |
|
||||
332 | ChartDataSet dataSet; |
|
|||
333 | QLineSeries* series1 = new QLineSeries(); |
|
|||
334 | series1->add(domain1.m_minX, domain1.m_minY); |
|
|||
335 | series1->add(domain1.m_maxX, domain1.m_maxY); |
|
|||
336 | QLineSeries* series2 = new QLineSeries(); |
|
|||
337 | series2->add(domain2.m_minX, domain2.m_minY); |
|
|||
338 | series2->add(domain2.m_maxX, domain2.m_maxY); |
|
|||
339 | QLineSeries* series3 = new QLineSeries(); |
|
|||
340 | series3->add(domain3.m_minX, domain3.m_minY); |
|
|||
341 | series3->add(domain3.m_maxX, domain3.m_maxY); |
|
|||
342 |
|
||||
343 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
|||
344 | QSignalSpy spy1(&dataSet, |
|
|||
345 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); |
|
|||
346 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
|||
347 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); |
|
|||
348 | QSignalSpy spy4(&dataSet, |
|
|||
349 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
|||
350 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
|||
351 |
|
||||
352 | dataSet.addSeries(series1); |
|
|||
353 | dataSet.addSeries(series2); |
|
|||
354 | dataSet.addSeries(series3); |
|
|||
355 |
|
||||
356 | QCOMPARE(dataSet.domainIndex(), 0); |
|
|||
357 | QVERIFY2(dataSet.domain(dataSet.axisY()) == domain, "Domain not equal"); |
|
|||
358 |
|
||||
359 | QCOMPARE(spy0.count(), 2); |
|
|||
360 | QCOMPARE(spy1.count(), 6); |
|
|||
361 |
|
|
175 | QCOMPARE(spy2.count(), 0); | |
362 |
|
|
176 | QCOMPARE(spy3.count(), 3); | |
363 | QCOMPARE(spy4.count(), 6); |
|
|||
364 | QCOMPARE(spy5.count(), 0); |
|
|||
365 | } |
|
177 | } | |
366 |
|
178 | |||
367 |
void tst_ChartDataSet:: |
|
179 | void tst_ChartDataSet::removeAllSeries_data() | |
368 | { |
|
180 | { | |
369 |
|
|
181 | QTest::addColumn<QLineSeries*>("series0"); | |
370 |
|
|
182 | QTest::addColumn<QChartAxis*>("axis0"); | |
371 | QTest::newRow("400x400,1000x1000") << QRectF(200, 200, 600, 600) |
|
183 | QTest::addColumn<QLineSeries*>("series1"); | |
372 | << QRectF(0, 0, 1000, 1000); |
|
184 | QTest::addColumn<QChartAxis*>("axis1"); | |
373 | QTest::newRow("600x600,1000x1000") << QRectF(100, 100, 700, 700) |
|
185 | QTest::addColumn<QLineSeries*>("series2"); | |
374 | << QRectF(0, 0, 1000, 1000); |
|
186 | QTest::addColumn<QChartAxis*>("axis2"); | |
375 | QTest::newRow("200x200,1000x1000") << QRectF(400, 400, 600, 600) |
|
187 | QTest::addColumn<int>("axisCount"); | |
376 | << QRectF(0, 0, 1000, 1000); |
|
188 | ||
|
189 | QLineSeries* series0 = new QLineSeries(this); | |||
|
190 | QLineSeries* series1 = new QLineSeries(this); | |||
|
191 | QLineSeries* series2 = new QLineSeries(this); | |||
|
192 | ||||
|
193 | QChartAxis* axis0 = new QChartAxis(this); | |||
|
194 | QChartAxis* axis1 = new QChartAxis(this); | |||
|
195 | QChartAxis* axis2 = new QChartAxis(this); | |||
|
196 | ||||
|
197 | QTest::newRow("default axis Y: series0,series1,series2") << series0 << (QChartAxis*) 0 | |||
|
198 | << series1 << (QChartAxis*) 0 << series2 << (QChartAxis*) 0 << 2; | |||
|
199 | QTest::newRow("default axis Y: series0, axis 0: series1,series2") << series0 << (QChartAxis*) 0 | |||
|
200 | << series1 << axis0 << series2 << axis0 << 3; | |||
|
201 | QTest::newRow("axis0: series0, axis1: series1, axis2: series2") << series0 << axis0 << series1 | |||
|
202 | << axis1 << series2 << axis2 << 4; | |||
377 | } |
|
203 | } | |
378 |
|
204 | |||
379 |
void tst_ChartDataSet:: |
|
205 | void tst_ChartDataSet::removeAllSeries() | |
380 | { |
|
206 | { | |
381 |
|
207 | QFETCH(QLineSeries*, series0); | ||
382 | QFETCH(QRectF, rect); |
|
208 | QFETCH(QChartAxis*, axis0); | |
383 | QFETCH(QRectF, viewport); |
|
209 | QFETCH(QLineSeries*, series1); | |
|
210 | QFETCH(QChartAxis*, axis1); | |||
|
211 | QFETCH(QLineSeries*, series2); | |||
|
212 | QFETCH(QChartAxis*, axis2); | |||
|
213 | QFETCH(int, axisCount); | |||
384 |
|
214 | |||
385 |
|
|
215 | ChartDataSet dataSet; | |
386 |
|
216 | |||
387 | Domain domain1(0, 1000, 0, 1000); |
|
217 | dataSet.addSeries(series0,axis0); | |
388 | QLineSeries* series = new QLineSeries(); |
|
218 | dataSet.addSeries(series1,axis1); | |
389 | series->add(0, 0); |
|
219 | dataSet.addSeries(series2,axis2); | |
390 | series->add(1000, 1000); |
|
|||
391 |
|
||||
392 | dataSet.addSeries(series); |
|
|||
393 |
|
||||
394 | QCOMPARE(dataSet.domainIndex(), 0); |
|
|||
395 |
|
||||
396 | Domain domain2 = dataSet.domain(dataSet.axisY()); |
|
|||
397 | QVERIFY(domain1 == domain2); |
|
|||
398 |
|
||||
399 | dataSet.addDomain(rect, viewport); |
|
|||
400 | QCOMPARE(dataSet.domainIndex(), 1); |
|
|||
401 | Domain domain3 = dataSet.domain(dataSet.axisY()); |
|
|||
402 | Domain domain4 = domain1.subDomain(rect, viewport.width(), |
|
|||
403 | viewport.height()); |
|
|||
404 | QVERIFY(domain3 == domain4); |
|
|||
405 |
|
||||
406 | dataSet.addDomain(rect, viewport); |
|
|||
407 | QCOMPARE(dataSet.domainIndex(), 2); |
|
|||
408 | Domain domain5 = dataSet.domain(dataSet.axisY()); |
|
|||
409 | Domain domain6 = domain3.subDomain(rect, viewport.width(), |
|
|||
410 | viewport.height()); |
|
|||
411 | QVERIFY(domain5 == domain6); |
|
|||
412 |
|
||||
413 | dataSet.addDomain(rect, viewport); |
|
|||
414 | QCOMPARE(dataSet.domainIndex(), 3); |
|
|||
415 | Domain domain7 = dataSet.domain(dataSet.axisY()); |
|
|||
416 | Domain domain8 = domain5.subDomain(rect, viewport.width(), |
|
|||
417 | viewport.height()); |
|
|||
418 | QVERIFY(domain7 == domain8); |
|
|||
419 |
|
||||
420 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
|||
421 | QSignalSpy spy1(&dataSet, |
|
|||
422 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); |
|
|||
423 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
|||
424 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); |
|
|||
425 | QSignalSpy spy4(&dataSet, |
|
|||
426 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
|||
427 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
|||
428 |
|
||||
429 | Domain domain; |
|
|||
430 |
|
||||
431 | bool previous = dataSet.previousDomain(); |
|
|||
432 | QCOMPARE(previous, true); |
|
|||
433 | QCOMPARE(dataSet.domainIndex(), 2); |
|
|||
434 | domain = dataSet.domain(dataSet.axisY()); |
|
|||
435 | QVERIFY(domain == domain5); |
|
|||
436 | previous = dataSet.previousDomain(); |
|
|||
437 | QCOMPARE(previous, true); |
|
|||
438 | QCOMPARE(dataSet.domainIndex(), 1); |
|
|||
439 | domain = dataSet.domain(dataSet.axisY()); |
|
|||
440 | QVERIFY(domain == domain3); |
|
|||
441 | previous = dataSet.previousDomain(); |
|
|||
442 | QCOMPARE(previous, true); |
|
|||
443 | QCOMPARE(dataSet.domainIndex(), 0); |
|
|||
444 | domain = dataSet.domain(dataSet.axisY()); |
|
|||
445 | QVERIFY(domain == domain1); |
|
|||
446 | previous = dataSet.previousDomain(); |
|
|||
447 | QCOMPARE(previous, false); |
|
|||
448 | QCOMPARE(dataSet.domainIndex(), 0); |
|
|||
449 | domain = dataSet.domain(dataSet.axisY()); |
|
|||
450 | QVERIFY(domain == domain1); |
|
|||
451 |
|
||||
452 | bool next = dataSet.nextDomain(); |
|
|||
453 | QCOMPARE(next, true); |
|
|||
454 | QCOMPARE(dataSet.domainIndex(),1); |
|
|||
455 | next = dataSet.nextDomain(); |
|
|||
456 | QCOMPARE(next, true); |
|
|||
457 | QCOMPARE(dataSet.domainIndex(),2); |
|
|||
458 | next = dataSet.nextDomain(); |
|
|||
459 | QCOMPARE(next, true); |
|
|||
460 | QCOMPARE(dataSet.domainIndex(),3); |
|
|||
461 | next = dataSet.nextDomain(); |
|
|||
462 | QCOMPARE(next, false); |
|
|||
463 | QCOMPARE(dataSet.domainIndex(),3); |
|
|||
464 |
|
220 | |||
|
221 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*,Domain*))); | |||
|
222 | QSignalSpy spy1(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); | |||
|
223 | QSignalSpy spy2(&dataSet, SIGNAL(seriesAdded(QSeries*,Domain*))); | |||
|
224 | QSignalSpy spy3(&dataSet, SIGNAL(seriesRemoved(QSeries*))); | |||
|
225 | ||||
|
226 | dataSet.removeAllSeries(); | |||
465 |
|
227 | |||
466 |
|
|
228 | QCOMPARE(spy0.count(), 0); | |
467 |
|
|
229 | QCOMPARE(spy1.count(), axisCount); | |
468 |
|
|
230 | QCOMPARE(spy2.count(), 0); | |
469 |
|
|
231 | QCOMPARE(spy3.count(), 3); | |
470 | QCOMPARE(spy4.count(), 6); |
|
|||
471 | QCOMPARE(spy5.count(), 0); |
|
|||
472 | } |
|
|||
473 |
|
||||
474 | void tst_ChartDataSet::removeSeries_data() |
|
|||
475 | { |
|
|||
476 | QTest::addColumn<int>("seriesCount"); |
|
|||
477 | QTest::addColumn<int>("axisYCount"); |
|
|||
478 | QTest::newRow("2 series, default axis") << 2 << 0; |
|
|||
479 | QTest::newRow("2 series, 2 new axis") << 2 << 2; |
|
|||
480 | QTest::newRow("2 series, 1 new axis") << 2 << 2; |
|
|||
481 | QTest::newRow("3 series, 3 new axis") << 3 << 3; |
|
|||
482 | QTest::newRow("3 series, 2 new axis") << 3 << 2; |
|
|||
483 | QTest::newRow("3 series, 1 new axis") << 3 << 1; |
|
|||
484 | } |
|
|||
485 |
|
||||
486 | void tst_ChartDataSet::removeSeries() |
|
|||
487 | { |
|
|||
488 | QFETCH(int, seriesCount); |
|
|||
489 | QFETCH(int, axisYCount); |
|
|||
490 |
|
||||
491 | ChartDataSet dataSet; |
|
|||
492 |
|
||||
493 | QList<QChartAxis*> axisList; |
|
|||
494 | QList<QSeries*> seriesList; |
|
|||
495 |
|
||||
496 | for (int i = 0; i < axisYCount; i++) { |
|
|||
497 | QChartAxis* axis = new QChartAxis(); |
|
|||
498 | axisList << axis; |
|
|||
499 | } |
|
|||
500 |
|
||||
501 | QList<QChartAxis*>::iterator iterator = axisList.begin(); |
|
|||
502 |
|
||||
503 | for (int i = 0; i < seriesCount; i++) { |
|
|||
504 | QChartAxis* axisY = 0; |
|
|||
505 | QLineSeries* series = new QLineSeries(); |
|
|||
506 | if (iterator != axisList.end()) { |
|
|||
507 | axisY = *iterator; |
|
|||
508 | iterator++; |
|
|||
509 | } else if (axisList.count() > 0) { |
|
|||
510 | iterator--; |
|
|||
511 | axisY = *iterator; |
|
|||
512 | iterator++; |
|
|||
513 | } |
|
|||
514 | dataSet.addSeries(series, axisY); |
|
|||
515 | seriesList << series; |
|
|||
516 | } |
|
|||
517 |
|
||||
518 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
|||
519 | QSignalSpy spy1(&dataSet, |
|
|||
520 | SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); |
|
|||
521 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
|||
522 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); |
|
|||
523 | QSignalSpy spy4(&dataSet, |
|
|||
524 | SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
|||
525 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
|||
526 |
|
||||
527 | for (int i = 0; i < seriesCount; i++) { |
|
|||
528 | dataSet.removeSeries(seriesList.at(i)); |
|
|||
529 |
|
|
232 | } | |
530 |
|
233 | |||
531 | //default axis |
|
|||
532 | if (axisYCount == 0) |
|
|||
533 | axisYCount++; |
|
|||
534 |
|
234 | |||
535 | QCOMPARE(spy0.count(), 0); |
|
235 | void tst_ChartDataSet::axisY_data() | |
536 | QCOMPARE(spy1.count(), 0); |
|
|||
537 | QCOMPARE(spy2.count(), axisYCount); |
|
|||
538 | QCOMPARE(spy3.count(), 0); |
|
|||
539 | QCOMPARE(spy4.count(), 0); |
|
|||
540 | QCOMPARE(spy5.count(), seriesCount); |
|
|||
541 |
|
||||
542 | QCOMPARE(dataSet.domainIndex(), 0); |
|
|||
543 |
|
||||
544 | qDeleteAll(seriesList); |
|
|||
545 | } |
|
|||
546 |
|
||||
547 | void tst_ChartDataSet::removeAllSeries_data() |
|
|||
548 | { |
|
236 | { | |
549 |
QTest::addColumn< |
|
237 | QTest::addColumn<QChartAxis*>("axis0"); | |
550 |
QTest::addColumn< |
|
238 | QTest::addColumn<QChartAxis*>("axis1"); | |
551 | QTest::newRow("2 series, default axis") << 2 << 0; |
|
239 | QTest::addColumn<QChartAxis*>("axis2"); | |
552 | QTest::newRow("2 series, 2 new axis") << 2 << 2; |
|
240 | QTest::newRow("1 defualt, 2 optional") << (QChartAxis*)0 << new QChartAxis() << new QChartAxis(); | |
553 | QTest::newRow("2 series, 1 new axis") << 2 << 2; |
|
241 | QTest::newRow("3 optional") << new QChartAxis() << new QChartAxis() << new QChartAxis(); | |
554 | QTest::newRow("3 series, 3 new axis") << 3 << 3; |
|
|||
555 | QTest::newRow("3 series, 2 new axis") << 3 << 2; |
|
|||
556 | QTest::newRow("3 series, 1 new axis") << 3 << 1; |
|
|||
557 | } |
|
242 | } | |
558 |
|
243 | |||
559 |
void tst_ChartDataSet:: |
|
244 | void tst_ChartDataSet::axisY() | |
560 | { |
|
245 | { | |
561 | QFETCH(int, seriesCount); |
|
246 | QFETCH(QChartAxis*, axis0); | |
562 |
QFETCH( |
|
247 | QFETCH(QChartAxis*, axis1); | |
|
248 | QFETCH(QChartAxis*, axis2); | |||
563 |
|
249 | |||
564 | ChartDataSet dataSet; |
|
250 | ChartDataSet dataSet; | |
565 |
|
251 | |||
566 | QList<QChartAxis*> axisList; |
|
252 | QChartAxis* defaultAxisY = dataSet.axisY(); | |
567 |
|
253 | |||
568 | for (int i = 0; i < axisYCount; i++) { |
|
254 | QVERIFY2(defaultAxisY, "Missing axisY."); | |
569 | QChartAxis* axis = new QChartAxis(); |
|
|||
570 | axisList << axis; |
|
|||
571 | } |
|
|||
572 |
|
255 | |||
573 | QList<QChartAxis*>::iterator iterator = axisList.begin(); |
|
256 | QLineSeries* series0 = new QLineSeries(); | |
574 |
|
257 | dataSet.addSeries(series0,axis0); | ||
575 | for (int i = 0; i < seriesCount; i++) { |
|
|||
576 | QChartAxis* axisY = 0; |
|
|||
577 | QLineSeries* series = new QLineSeries(); |
|
|||
578 | if (iterator != axisList.end()) { |
|
|||
579 | axisY = *iterator; |
|
|||
580 | iterator++; |
|
|||
581 | } else if (axisList.count() > 0) { |
|
|||
582 | iterator--; |
|
|||
583 | axisY = *iterator; |
|
|||
584 | iterator++; |
|
|||
585 | } |
|
|||
586 | dataSet.addSeries(series, axisY); |
|
|||
587 | } |
|
|||
588 |
|
258 | |||
589 | QSignalSpy spy0(&dataSet, SIGNAL(axisAdded(QChartAxis*))); |
|
259 | QLineSeries* series1 = new QLineSeries(); | |
590 | QSignalSpy spy1(&dataSet, SIGNAL(axisRangeChanged(QChartAxis*, QStringList const&))); |
|
260 | dataSet.addSeries(series1,axis1); | |
591 | QSignalSpy spy2(&dataSet, SIGNAL(axisRemoved(QChartAxis*))); |
|
|||
592 | QSignalSpy spy3(&dataSet, SIGNAL(seriesAdded(QSeries*))); |
|
|||
593 | QSignalSpy spy4(&dataSet, SIGNAL(seriesDomainChanged(QSeries*, Domain const&))); |
|
|||
594 | QSignalSpy spy5(&dataSet, SIGNAL(seriesRemoved(QSeries*))); |
|
|||
595 |
|
261 | |||
596 | dataSet.removeAllSeries(); |
|
262 | QLineSeries* series2 = new QLineSeries(); | |
597 | //default axis |
|
263 | dataSet.addSeries(series2,axis2); | |
598 | if (axisYCount == 0) |
|
|||
599 | axisYCount++; |
|
|||
600 |
|
264 | |||
601 | QCOMPARE(spy0.count(), 0); |
|
265 | if(!axis0) axis0=defaultAxisY ; | |
602 | QCOMPARE(spy1.count(), 0); |
|
266 | if(!axis1) axis1=defaultAxisY ; | |
603 | QCOMPARE(spy2.count(), axisYCount); |
|
267 | if(!axis2) axis2=defaultAxisY ; | |
604 | QCOMPARE(spy3.count(), 0); |
|
|||
605 | QCOMPARE(spy4.count(), 0); |
|
|||
606 | QCOMPARE(spy5.count(), seriesCount); |
|
|||
607 |
|
268 | |||
608 | QCOMPARE(dataSet.domainIndex(), 0); |
|
269 | QVERIFY(dataSet.axisY(series0) == axis0); | |
609 | } |
|
270 | QVERIFY(dataSet.axisY(series1) == axis1); | |
|
271 | QVERIFY(dataSet.axisY(series2) == axis2); | |||
610 |
|
272 | |||
|
273 | } | |||
611 |
|
274 | |||
612 | QTEST_MAIN(tst_ChartDataSet) |
|
275 | QTEST_MAIN(tst_ChartDataSet) | |
613 | #include "tst_chartdataset.moc" |
|
276 | #include "tst_chartdataset.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now