@@ -1,328 +1,328 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <qchartview.h> |
|
22 | #include <qchartview.h> | |
23 | #include <qchart.h> |
|
23 | #include <qchart.h> | |
24 | #include <qpieseries.h> |
|
24 | #include <qpieseries.h> | |
25 | #include <qpieslice.h> |
|
25 | #include <qpieslice.h> | |
26 | #include <tst_definitions.h> |
|
26 | #include <tst_definitions.h> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | Q_DECLARE_METATYPE(QPieSlice*) |
|
30 | Q_DECLARE_METATYPE(QPieSlice*) | |
31 |
|
31 | |||
32 | class tst_qpieseries : public QObject |
|
32 | class tst_qpieseries : public QObject | |
33 | { |
|
33 | { | |
34 | Q_OBJECT |
|
34 | Q_OBJECT | |
35 |
|
35 | |||
36 | public slots: |
|
36 | public slots: | |
37 | void initTestCase(); |
|
37 | void initTestCase(); | |
38 | void cleanupTestCase(); |
|
38 | void cleanupTestCase(); | |
39 | void init(); |
|
39 | void init(); | |
40 | void cleanup(); |
|
40 | void cleanup(); | |
41 |
|
41 | |||
42 | private slots: |
|
42 | private slots: | |
43 | void construction(); |
|
43 | void construction(); | |
44 | void append(); |
|
44 | void append(); | |
45 | void insert(); |
|
45 | void insert(); | |
46 | void remove(); |
|
46 | void remove(); | |
47 | void calculatedValues(); |
|
47 | void calculatedValues(); | |
48 | void clickedSignal(); |
|
48 | void clickedSignal(); | |
49 | void hoverSignal(); |
|
49 | void hoverSignal(); | |
50 |
|
50 | |||
51 | private: |
|
51 | private: | |
52 | void verifyCalculatedData(const QPieSeries &series, bool *ok); |
|
52 | void verifyCalculatedData(const QPieSeries &series, bool *ok); | |
53 |
|
53 | |||
54 | private: |
|
54 | private: | |
55 |
|
55 | |||
56 | }; |
|
56 | }; | |
57 |
|
57 | |||
58 | void tst_qpieseries::initTestCase() |
|
58 | void tst_qpieseries::initTestCase() | |
59 | { |
|
59 | { | |
60 | qRegisterMetaType<QPieSlice*>("QPieSlice*"); |
|
60 | qRegisterMetaType<QPieSlice*>("QPieSlice*"); | |
61 | } |
|
61 | } | |
62 |
|
62 | |||
63 | void tst_qpieseries::cleanupTestCase() |
|
63 | void tst_qpieseries::cleanupTestCase() | |
64 | { |
|
64 | { | |
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | void tst_qpieseries::init() |
|
67 | void tst_qpieseries::init() | |
68 | { |
|
68 | { | |
69 |
|
69 | |||
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void tst_qpieseries::cleanup() |
|
72 | void tst_qpieseries::cleanup() | |
73 | { |
|
73 | { | |
74 |
|
74 | |||
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | void tst_qpieseries::construction() |
|
77 | void tst_qpieseries::construction() | |
78 | { |
|
78 | { | |
79 | // verify default values |
|
79 | // verify default values | |
80 | QPieSeries s; |
|
80 | QPieSeries s; | |
81 | QVERIFY(s.type() == QAbstractSeries::SeriesTypePie); |
|
81 | QVERIFY(s.type() == QAbstractSeries::SeriesTypePie); | |
82 | QVERIFY(s.count() == 0); |
|
82 | QVERIFY(s.count() == 0); | |
83 | QVERIFY(s.isEmpty()); |
|
83 | QVERIFY(s.isEmpty()); | |
84 | QVERIFY(qFuzzyIsNull(s.sum())); |
|
84 | QCOMPARE(s.sum(), 0.0); | |
85 |
Q |
|
85 | QCOMPARE(s.horizontalPosition(), 0.5); | |
86 |
Q |
|
86 | QCOMPARE(s.verticalPosition(), 0.5); | |
87 |
Q |
|
87 | QCOMPARE(s.pieSize(), 0.7); | |
88 |
Q |
|
88 | QCOMPARE(s.pieStartAngle(), 0.0); | |
89 |
Q |
|
89 | QCOMPARE(s.pieEndAngle(), 360.0); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void tst_qpieseries::append() |
|
92 | void tst_qpieseries::append() | |
93 | { |
|
93 | { | |
94 | QPieSeries s; |
|
94 | QPieSeries s; | |
95 |
|
95 | |||
96 | // append pointer |
|
96 | // append pointer | |
97 | QPieSlice *slice1 = 0; |
|
97 | QPieSlice *slice1 = 0; | |
98 | QVERIFY(!s.append(slice1)); |
|
98 | QVERIFY(!s.append(slice1)); | |
99 | slice1 = new QPieSlice(1, "slice 1"); |
|
99 | slice1 = new QPieSlice(1, "slice 1"); | |
100 | QVERIFY(s.append(slice1)); |
|
100 | QVERIFY(s.append(slice1)); | |
101 | QVERIFY(!s.append(slice1)); |
|
101 | QVERIFY(!s.append(slice1)); | |
102 | QCOMPARE(s.count(), 1); |
|
102 | QCOMPARE(s.count(), 1); | |
103 |
|
103 | |||
104 | // append pointer list |
|
104 | // append pointer list | |
105 | QList<QPieSlice *> list; |
|
105 | QList<QPieSlice *> list; | |
106 | QVERIFY(!s.append(list)); |
|
106 | QVERIFY(!s.append(list)); | |
107 | list << (QPieSlice *) 0; |
|
107 | list << (QPieSlice *) 0; | |
108 | QVERIFY(!s.append(list)); |
|
108 | QVERIFY(!s.append(list)); | |
109 | list.clear(); |
|
109 | list.clear(); | |
110 | list << new QPieSlice(2, "slice 2"); |
|
110 | list << new QPieSlice(2, "slice 2"); | |
111 | list << new QPieSlice(3, "slice 3"); |
|
111 | list << new QPieSlice(3, "slice 3"); | |
112 | QVERIFY(s.append(list)); |
|
112 | QVERIFY(s.append(list)); | |
113 | QVERIFY(!s.append(list)); |
|
113 | QVERIFY(!s.append(list)); | |
114 | QCOMPARE(s.count(), 3); |
|
114 | QCOMPARE(s.count(), 3); | |
115 |
|
115 | |||
116 | // append operator |
|
116 | // append operator | |
117 | s << new QPieSlice(4, "slice 4"); |
|
117 | s << new QPieSlice(4, "slice 4"); | |
118 | s << slice1; // fails because already added |
|
118 | s << slice1; // fails because already added | |
119 | QCOMPARE(s.count(), 4); |
|
119 | QCOMPARE(s.count(), 4); | |
120 |
|
120 | |||
121 | // append with params |
|
121 | // append with params | |
122 | QPieSlice *slice5 = s.append(5, "slice 5"); |
|
122 | QPieSlice *slice5 = s.append(5, "slice 5"); | |
123 | QVERIFY(slice5 != 0); |
|
123 | QVERIFY(slice5 != 0); | |
124 |
Q |
|
124 | QCOMPARE(slice5->value(), 5.0); | |
125 | QCOMPARE(slice5->label(), QString("slice 5")); |
|
125 | QCOMPARE(slice5->label(), QString("slice 5")); | |
126 | QCOMPARE(s.count(), 5); |
|
126 | QCOMPARE(s.count(), 5); | |
127 |
|
127 | |||
128 | // check slices |
|
128 | // check slices | |
129 | QVERIFY(!s.isEmpty()); |
|
129 | QVERIFY(!s.isEmpty()); | |
130 | for (int i=0; i<s.count(); i++) { |
|
130 | for (int i=0; i<s.count(); i++) { | |
131 |
Q |
|
131 | QCOMPARE(s.slices().at(i)->value(), (qreal) i+1); | |
132 | QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); |
|
132 | QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); | |
133 | } |
|
133 | } | |
134 | } |
|
134 | } | |
135 |
|
135 | |||
136 | void tst_qpieseries::insert() |
|
136 | void tst_qpieseries::insert() | |
137 | { |
|
137 | { | |
138 | QPieSeries s; |
|
138 | QPieSeries s; | |
139 |
|
139 | |||
140 | // insert one slice |
|
140 | // insert one slice | |
141 | QPieSlice *slice1 = 0; |
|
141 | QPieSlice *slice1 = 0; | |
142 | QVERIFY(!s.insert(0, slice1)); |
|
142 | QVERIFY(!s.insert(0, slice1)); | |
143 | slice1 = new QPieSlice(1, "slice 1"); |
|
143 | slice1 = new QPieSlice(1, "slice 1"); | |
144 | QVERIFY(!s.insert(-1, slice1)); |
|
144 | QVERIFY(!s.insert(-1, slice1)); | |
145 | QVERIFY(!s.insert(5, slice1)); |
|
145 | QVERIFY(!s.insert(5, slice1)); | |
146 | QVERIFY(s.insert(0, slice1)); |
|
146 | QVERIFY(s.insert(0, slice1)); | |
147 | QVERIFY(!s.insert(0, slice1)); |
|
147 | QVERIFY(!s.insert(0, slice1)); | |
148 | QCOMPARE(s.count(), 1); |
|
148 | QCOMPARE(s.count(), 1); | |
149 |
|
149 | |||
150 | // add some more slices |
|
150 | // add some more slices | |
151 | s.append(2, "slice 2"); |
|
151 | s.append(2, "slice 2"); | |
152 | s.append(4, "slice 4"); |
|
152 | s.append(4, "slice 4"); | |
153 | QCOMPARE(s.count(), 3); |
|
153 | QCOMPARE(s.count(), 3); | |
154 |
|
154 | |||
155 | // insert between slices |
|
155 | // insert between slices | |
156 | s.insert(2, new QPieSlice(3, "slice 3")); |
|
156 | s.insert(2, new QPieSlice(3, "slice 3")); | |
157 | QCOMPARE(s.count(), 4); |
|
157 | QCOMPARE(s.count(), 4); | |
158 |
|
158 | |||
159 | // check slices |
|
159 | // check slices | |
160 | for (int i=0; i<s.count(); i++) { |
|
160 | for (int i=0; i<s.count(); i++) { | |
161 |
Q |
|
161 | QCOMPARE(s.slices().at(i)->value(), (qreal) i+1); | |
162 | QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); |
|
162 | QCOMPARE(s.slices().at(i)->label(), QString("slice ") + QString::number(i+1)); | |
163 | } |
|
163 | } | |
164 | } |
|
164 | } | |
165 |
|
165 | |||
166 | void tst_qpieseries::remove() |
|
166 | void tst_qpieseries::remove() | |
167 | { |
|
167 | { | |
168 | QPieSeries s; |
|
168 | QPieSeries s; | |
169 |
|
169 | |||
170 | // add some slices |
|
170 | // add some slices | |
171 | QPieSlice *slice1 = s.append(1, "slice 1"); |
|
171 | QPieSlice *slice1 = s.append(1, "slice 1"); | |
172 | QPieSlice *slice2 = s.append(2, "slice 2"); |
|
172 | QPieSlice *slice2 = s.append(2, "slice 2"); | |
173 | QPieSlice *slice3 = s.append(3, "slice 3"); |
|
173 | QPieSlice *slice3 = s.append(3, "slice 3"); | |
174 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); |
|
174 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); | |
175 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); |
|
175 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); | |
176 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); |
|
176 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); | |
177 | QCOMPARE(s.count(), 3); |
|
177 | QCOMPARE(s.count(), 3); | |
178 |
|
178 | |||
179 | // null pointer remove |
|
179 | // null pointer remove | |
180 | QVERIFY(!s.remove(0)); |
|
180 | QVERIFY(!s.remove(0)); | |
181 |
|
181 | |||
182 | // remove first |
|
182 | // remove first | |
183 | QVERIFY(s.remove(slice1)); |
|
183 | QVERIFY(s.remove(slice1)); | |
184 | QVERIFY(!s.remove(slice1)); |
|
184 | QVERIFY(!s.remove(slice1)); | |
185 | QCOMPARE(s.count(), 2); |
|
185 | QCOMPARE(s.count(), 2); | |
186 | QCOMPARE(s.slices().at(0)->label(), slice2->label()); |
|
186 | QCOMPARE(s.slices().at(0)->label(), slice2->label()); | |
187 |
|
187 | |||
188 | // remove all |
|
188 | // remove all | |
189 | s.clear(); |
|
189 | s.clear(); | |
190 | QVERIFY(s.isEmpty()); |
|
190 | QVERIFY(s.isEmpty()); | |
191 | QVERIFY(s.slices().isEmpty()); |
|
191 | QVERIFY(s.slices().isEmpty()); | |
192 | QCOMPARE(s.count(), 0); |
|
192 | QCOMPARE(s.count(), 0); | |
193 |
|
193 | |||
194 | // check that slices were actually destroyed |
|
194 | // check that slices were actually destroyed | |
195 | TRY_COMPARE(spy1.count(), 1); |
|
195 | TRY_COMPARE(spy1.count(), 1); | |
196 | TRY_COMPARE(spy2.count(), 1); |
|
196 | TRY_COMPARE(spy2.count(), 1); | |
197 | TRY_COMPARE(spy3.count(), 1); |
|
197 | TRY_COMPARE(spy3.count(), 1); | |
198 | } |
|
198 | } | |
199 |
|
199 | |||
200 | void tst_qpieseries::calculatedValues() |
|
200 | void tst_qpieseries::calculatedValues() | |
201 | { |
|
201 | { | |
202 | bool ok; |
|
202 | bool ok; | |
203 | QPieSeries s; |
|
203 | QPieSeries s; | |
204 |
|
204 | |||
205 | // add a slice |
|
205 | // add a slice | |
206 | QPieSlice *slice1 = s.append(1, "slice 1"); |
|
206 | QPieSlice *slice1 = s.append(1, "slice 1"); | |
207 | verifyCalculatedData(s, &ok); |
|
207 | verifyCalculatedData(s, &ok); | |
208 | if (!ok) |
|
208 | if (!ok) | |
209 | return; |
|
209 | return; | |
210 |
|
210 | |||
211 | // add some more slices |
|
211 | // add some more slices | |
212 | QList<QPieSlice *> list; |
|
212 | QList<QPieSlice *> list; | |
213 | list << new QPieSlice(2, "slice 2"); |
|
213 | list << new QPieSlice(2, "slice 2"); | |
214 | list << new QPieSlice(3, "slice 3"); |
|
214 | list << new QPieSlice(3, "slice 3"); | |
215 | s.append(list); |
|
215 | s.append(list); | |
216 | verifyCalculatedData(s, &ok); |
|
216 | verifyCalculatedData(s, &ok); | |
217 | if (!ok) |
|
217 | if (!ok) | |
218 | return; |
|
218 | return; | |
219 |
|
219 | |||
220 | // remove a slice |
|
220 | // remove a slice | |
221 | s.remove(slice1); |
|
221 | s.remove(slice1); | |
222 | verifyCalculatedData(s, &ok); |
|
222 | verifyCalculatedData(s, &ok); | |
223 | if (!ok) |
|
223 | if (!ok) | |
224 | return; |
|
224 | return; | |
225 |
|
225 | |||
226 | // insert a slice |
|
226 | // insert a slice | |
227 | s.insert(0, new QPieSlice(1, "Slice 4")); |
|
227 | s.insert(0, new QPieSlice(1, "Slice 4")); | |
228 | verifyCalculatedData(s, &ok); |
|
228 | verifyCalculatedData(s, &ok); | |
229 | if (!ok) |
|
229 | if (!ok) | |
230 | return; |
|
230 | return; | |
231 |
|
231 | |||
232 | // clear all |
|
232 | // clear all | |
233 | s.clear(); |
|
233 | s.clear(); | |
234 | verifyCalculatedData(s, &ok); |
|
234 | verifyCalculatedData(s, &ok); | |
235 | } |
|
235 | } | |
236 |
|
236 | |||
237 | void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) |
|
237 | void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) | |
238 | { |
|
238 | { | |
239 | *ok = false; |
|
239 | *ok = false; | |
240 |
|
240 | |||
241 | qreal sum = 0; |
|
241 | qreal sum = 0; | |
242 | foreach (const QPieSlice *slice, series.slices()) |
|
242 | foreach (const QPieSlice *slice, series.slices()) | |
243 | sum += slice->value(); |
|
243 | sum += slice->value(); | |
244 | QCOMPARE(series.sum(), sum); |
|
244 | QCOMPARE(series.sum(), sum); | |
245 |
|
245 | |||
246 | qreal startAngle = series.pieStartAngle(); |
|
246 | qreal startAngle = series.pieStartAngle(); | |
247 | qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle(); |
|
247 | qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle(); | |
248 | foreach (const QPieSlice *slice, series.slices()) { |
|
248 | foreach (const QPieSlice *slice, series.slices()) { | |
249 | qreal ratio = slice->value() / sum; |
|
249 | qreal ratio = slice->value() / sum; | |
250 | qreal sliceSpan = pieAngleSpan * ratio; |
|
250 | qreal sliceSpan = pieAngleSpan * ratio; | |
251 | QCOMPARE(slice->startAngle(), startAngle); |
|
251 | QCOMPARE(slice->startAngle(), startAngle); | |
252 | QCOMPARE(slice->endAngle(), startAngle + sliceSpan); |
|
252 | QCOMPARE(slice->endAngle(), startAngle + sliceSpan); | |
253 | QCOMPARE(slice->percentage(), ratio); |
|
253 | QCOMPARE(slice->percentage(), ratio); | |
254 | startAngle += sliceSpan; |
|
254 | startAngle += sliceSpan; | |
255 | } |
|
255 | } | |
256 |
|
256 | |||
257 | if (!series.isEmpty()) |
|
257 | if (!series.isEmpty()) | |
258 | QCOMPARE(series.slices().last()->endAngle(), series.pieEndAngle()); |
|
258 | QCOMPARE(series.slices().last()->endAngle(), series.pieEndAngle()); | |
259 |
|
259 | |||
260 | *ok = true; |
|
260 | *ok = true; | |
261 | } |
|
261 | } | |
262 |
|
262 | |||
263 |
|
263 | |||
264 | void tst_qpieseries::clickedSignal() |
|
264 | void tst_qpieseries::clickedSignal() | |
265 | { |
|
265 | { | |
266 | // create a pie series |
|
266 | // create a pie series | |
267 | QPieSeries *series = new QPieSeries(); |
|
267 | QPieSeries *series = new QPieSeries(); | |
268 | series->setPieSize(1.0); |
|
268 | series->setPieSize(1.0); | |
269 | QPieSlice *s1 = series->append(1, "slice 1"); |
|
269 | QPieSlice *s1 = series->append(1, "slice 1"); | |
270 | series->append(2, "slice 2"); |
|
270 | series->append(2, "slice 2"); | |
271 | series->append(3, "slice 3"); |
|
271 | series->append(3, "slice 3"); | |
272 | QSignalSpy clickSpy1(series, SIGNAL(clicked(QPieSlice*))); |
|
272 | QSignalSpy clickSpy1(series, SIGNAL(clicked(QPieSlice*))); | |
273 |
|
273 | |||
274 | // add series to the chart |
|
274 | // add series to the chart | |
275 | QChartView view(new QChart()); |
|
275 | QChartView view(new QChart()); | |
276 | view.resize(200, 200); |
|
276 | view.resize(200, 200); | |
277 | view.chart()->addSeries(series); |
|
277 | view.chart()->addSeries(series); | |
278 | view.show(); |
|
278 | view.show(); | |
279 | QTest::qWaitForWindowShown(&view); |
|
279 | QTest::qWaitForWindowShown(&view); | |
280 |
|
280 | |||
281 | // simulate clicks |
|
281 | // simulate clicks | |
282 | // pie rectangle: QRectF(60,60 121x121) |
|
282 | // pie rectangle: QRectF(60,60 121x121) | |
283 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1 |
|
283 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1 | |
284 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
284 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
285 | QCOMPARE(clickSpy1.count(), 1); |
|
285 | QCOMPARE(clickSpy1.count(), 1); | |
286 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy1.at(0).at(0)), s1); |
|
286 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy1.at(0).at(0)), s1); | |
287 | } |
|
287 | } | |
288 |
|
288 | |||
289 | void tst_qpieseries::hoverSignal() |
|
289 | void tst_qpieseries::hoverSignal() | |
290 | { |
|
290 | { | |
291 | // create a pie series |
|
291 | // create a pie series | |
292 | QPieSeries *series = new QPieSeries(); |
|
292 | QPieSeries *series = new QPieSeries(); | |
293 | series->setPieSize(1.0); |
|
293 | series->setPieSize(1.0); | |
294 | QPieSlice *s1 = series->append(1, "slice 1"); |
|
294 | QPieSlice *s1 = series->append(1, "slice 1"); | |
295 | series->append(2, "slice 2"); |
|
295 | series->append(2, "slice 2"); | |
296 | series->append(3, "slice 3"); |
|
296 | series->append(3, "slice 3"); | |
297 |
|
297 | |||
298 | // add series to the chart |
|
298 | // add series to the chart | |
299 | QChartView view(new QChart()); |
|
299 | QChartView view(new QChart()); | |
300 | view.resize(200, 200); |
|
300 | view.resize(200, 200); | |
301 | view.chart()->addSeries(series); |
|
301 | view.chart()->addSeries(series); | |
302 | view.show(); |
|
302 | view.show(); | |
303 | QTest::qWaitForWindowShown(&view); |
|
303 | QTest::qWaitForWindowShown(&view); | |
304 |
|
304 | |||
305 | // first move to right top corner |
|
305 | // first move to right top corner | |
306 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); |
|
306 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |
307 |
|
307 | |||
308 | // move inside the slice |
|
308 | // move inside the slice | |
309 | // pie rectangle: QRectF(60,60 121x121) |
|
309 | // pie rectangle: QRectF(60,60 121x121) | |
310 | QSignalSpy hoverSpy(series, SIGNAL(hovered(QPieSlice*,bool))); |
|
310 | QSignalSpy hoverSpy(series, SIGNAL(hovered(QPieSlice*,bool))); | |
311 | QTest::mouseMove(view.viewport(), QPoint(139, 85)); |
|
311 | QTest::mouseMove(view.viewport(), QPoint(139, 85)); | |
312 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
312 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
313 | QCOMPARE(hoverSpy.count(), 1); |
|
313 | QCOMPARE(hoverSpy.count(), 1); | |
314 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1); |
|
314 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(0).at(0)), s1); | |
315 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true); |
|
315 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(1)), true); | |
316 |
|
316 | |||
317 | // move outside the slice |
|
317 | // move outside the slice | |
318 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); |
|
318 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |
319 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
319 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
320 | QCOMPARE(hoverSpy.count(), 2); |
|
320 | QCOMPARE(hoverSpy.count(), 2); | |
321 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1); |
|
321 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(1).at(0)), s1); | |
322 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false); |
|
322 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(1)), false); | |
323 | } |
|
323 | } | |
324 |
|
324 | |||
325 | QTEST_MAIN(tst_qpieseries) |
|
325 | QTEST_MAIN(tst_qpieseries) | |
326 |
|
326 | |||
327 | #include "tst_qpieseries.moc" |
|
327 | #include "tst_qpieseries.moc" | |
328 |
|
328 |
@@ -1,270 +1,270 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include <QtTest/QtTest> |
|
21 | #include <QtTest/QtTest> | |
22 | #include <tst_definitions.h> |
|
22 | #include <tst_definitions.h> | |
23 | #include <qchartview.h> |
|
23 | #include <qchartview.h> | |
24 | #include <qchart.h> |
|
24 | #include <qchart.h> | |
25 | #include <qpieslice.h> |
|
25 | #include <qpieslice.h> | |
26 | #include <qpieseries.h> |
|
26 | #include <qpieseries.h> | |
27 |
|
27 | |||
28 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
28 | QTCOMMERCIALCHART_USE_NAMESPACE | |
29 |
|
29 | |||
30 | class tst_qpieslice : public QObject |
|
30 | class tst_qpieslice : public QObject | |
31 | { |
|
31 | { | |
32 | Q_OBJECT |
|
32 | Q_OBJECT | |
33 |
|
33 | |||
34 | public slots: |
|
34 | public slots: | |
35 | void initTestCase(); |
|
35 | void initTestCase(); | |
36 | void cleanupTestCase(); |
|
36 | void cleanupTestCase(); | |
37 | void init(); |
|
37 | void init(); | |
38 | void cleanup(); |
|
38 | void cleanup(); | |
39 |
|
39 | |||
40 | private slots: |
|
40 | private slots: | |
41 | void construction(); |
|
41 | void construction(); | |
42 | void changedSignals(); |
|
42 | void changedSignals(); | |
43 | void customize(); |
|
43 | void customize(); | |
44 | void mouseClick(); |
|
44 | void mouseClick(); | |
45 | void mouseHover(); |
|
45 | void mouseHover(); | |
46 |
|
46 | |||
47 | private: |
|
47 | private: | |
48 |
|
48 | |||
49 |
|
49 | |||
50 | private: |
|
50 | private: | |
51 |
|
51 | |||
52 | }; |
|
52 | }; | |
53 |
|
53 | |||
54 | void tst_qpieslice::initTestCase() |
|
54 | void tst_qpieslice::initTestCase() | |
55 | { |
|
55 | { | |
56 | } |
|
56 | } | |
57 |
|
57 | |||
58 | void tst_qpieslice::cleanupTestCase() |
|
58 | void tst_qpieslice::cleanupTestCase() | |
59 | { |
|
59 | { | |
60 | } |
|
60 | } | |
61 |
|
61 | |||
62 | void tst_qpieslice::init() |
|
62 | void tst_qpieslice::init() | |
63 | { |
|
63 | { | |
64 |
|
64 | |||
65 | } |
|
65 | } | |
66 |
|
66 | |||
67 | void tst_qpieslice::cleanup() |
|
67 | void tst_qpieslice::cleanup() | |
68 | { |
|
68 | { | |
69 |
|
69 | |||
70 | } |
|
70 | } | |
71 |
|
71 | |||
72 | void tst_qpieslice::construction() |
|
72 | void tst_qpieslice::construction() | |
73 | { |
|
73 | { | |
74 | // no params |
|
74 | // no params | |
75 | QPieSlice slice1; |
|
75 | QPieSlice slice1; | |
76 |
Q |
|
76 | QCOMPARE(slice1.value(), 0.0); | |
77 | QVERIFY(slice1.label().isEmpty()); |
|
77 | QVERIFY(slice1.label().isEmpty()); | |
78 | QVERIFY(!slice1.isLabelVisible()); |
|
78 | QVERIFY(!slice1.isLabelVisible()); | |
79 | QVERIFY(!slice1.isExploded()); |
|
79 | QVERIFY(!slice1.isExploded()); | |
80 | QCOMPARE(slice1.pen(), QPen()); |
|
80 | QCOMPARE(slice1.pen(), QPen()); | |
81 | QCOMPARE(slice1.brush(), QBrush()); |
|
81 | QCOMPARE(slice1.brush(), QBrush()); | |
82 | QCOMPARE(slice1.labelPen(), QPen()); |
|
82 | QCOMPARE(slice1.labelPen(), QPen()); | |
83 | QCOMPARE(slice1.labelFont(), QFont()); |
|
83 | QCOMPARE(slice1.labelFont(), QFont()); | |
84 |
Q |
|
84 | QCOMPARE(slice1.labelArmLengthFactor(), 0.15); // default value | |
85 |
Q |
|
85 | QCOMPARE(slice1.explodeDistanceFactor(), 0.15); // default value | |
86 |
Q |
|
86 | QCOMPARE(slice1.percentage(), 0.0); | |
87 |
Q |
|
87 | QCOMPARE(slice1.startAngle(), 0.0); | |
88 |
Q |
|
88 | QCOMPARE(slice1.endAngle(), 0.0); | |
89 |
|
89 | |||
90 | // value and label params |
|
90 | // value and label params | |
91 | QPieSlice slice2(1.0, "foobar"); |
|
91 | QPieSlice slice2(1.0, "foobar"); | |
92 |
Q |
|
92 | QCOMPARE(slice2.value(), 1.0); | |
93 | QCOMPARE(slice2.label(), QString("foobar")); |
|
93 | QCOMPARE(slice2.label(), QString("foobar")); | |
94 | QVERIFY(!slice2.isLabelVisible()); |
|
94 | QVERIFY(!slice2.isLabelVisible()); | |
95 | QVERIFY(!slice2.isExploded()); |
|
95 | QVERIFY(!slice2.isExploded()); | |
96 | QCOMPARE(slice2.pen(), QPen()); |
|
96 | QCOMPARE(slice2.pen(), QPen()); | |
97 | QCOMPARE(slice2.brush(), QBrush()); |
|
97 | QCOMPARE(slice2.brush(), QBrush()); | |
98 | QCOMPARE(slice2.labelPen(), QPen()); |
|
98 | QCOMPARE(slice2.labelPen(), QPen()); | |
99 | QCOMPARE(slice2.labelFont(), QFont()); |
|
99 | QCOMPARE(slice2.labelFont(), QFont()); | |
100 |
Q |
|
100 | QCOMPARE(slice2.labelArmLengthFactor(), 0.15); // default value | |
101 |
Q |
|
101 | QCOMPARE(slice2.explodeDistanceFactor(), 0.15); // default value | |
102 |
Q |
|
102 | QCOMPARE(slice2.percentage(), 0.0); | |
103 |
Q |
|
103 | QCOMPARE(slice2.startAngle(), 0.0); | |
104 |
Q |
|
104 | QCOMPARE(slice2.endAngle(), 0.0); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void tst_qpieslice::changedSignals() |
|
107 | void tst_qpieslice::changedSignals() | |
108 | { |
|
108 | { | |
109 | // set everything twice to see we do not get unnecessary signals |
|
109 | // set everything twice to see we do not get unnecessary signals | |
110 | QPieSlice slice; |
|
110 | QPieSlice slice; | |
111 | QSignalSpy spy(&slice, SIGNAL(changed())); // TODO: this will be changed to something more refined |
|
111 | QSignalSpy spy(&slice, SIGNAL(changed())); // TODO: this will be changed to something more refined | |
112 | slice.setValue(1); |
|
112 | slice.setValue(1); | |
113 | slice.setValue(1); |
|
113 | slice.setValue(1); | |
114 | slice.setLabel("foobar"); |
|
114 | slice.setLabel("foobar"); | |
115 | slice.setLabel("foobar"); |
|
115 | slice.setLabel("foobar"); | |
116 | slice.setLabelVisible(); |
|
116 | slice.setLabelVisible(); | |
117 | slice.setLabelVisible(); |
|
117 | slice.setLabelVisible(); | |
118 | slice.setExploded(); |
|
118 | slice.setExploded(); | |
119 | slice.setExploded(); |
|
119 | slice.setExploded(); | |
120 | slice.setPen(QPen(Qt::red)); |
|
120 | slice.setPen(QPen(Qt::red)); | |
121 | slice.setPen(QPen(Qt::red)); |
|
121 | slice.setPen(QPen(Qt::red)); | |
122 | slice.setBrush(QBrush(Qt::red)); |
|
122 | slice.setBrush(QBrush(Qt::red)); | |
123 | slice.setBrush(QBrush(Qt::red)); |
|
123 | slice.setBrush(QBrush(Qt::red)); | |
124 | slice.setLabelPen(QPen(Qt::green)); |
|
124 | slice.setLabelPen(QPen(Qt::green)); | |
125 | slice.setLabelPen(QPen(Qt::green)); |
|
125 | slice.setLabelPen(QPen(Qt::green)); | |
126 | slice.setLabelFont(QFont("Tahoma")); |
|
126 | slice.setLabelFont(QFont("Tahoma")); | |
127 | slice.setLabelFont(QFont("Tahoma")); |
|
127 | slice.setLabelFont(QFont("Tahoma")); | |
128 | slice.setLabelArmLengthFactor(0.1); |
|
128 | slice.setLabelArmLengthFactor(0.1); | |
129 | slice.setLabelArmLengthFactor(0.1); |
|
129 | slice.setLabelArmLengthFactor(0.1); | |
130 | slice.setExplodeDistanceFactor(0.1); |
|
130 | slice.setExplodeDistanceFactor(0.1); | |
131 | slice.setExplodeDistanceFactor(0.1); |
|
131 | slice.setExplodeDistanceFactor(0.1); | |
132 | TRY_COMPARE(spy.count(), 10); |
|
132 | TRY_COMPARE(spy.count(), 10); | |
133 | } |
|
133 | } | |
134 |
|
134 | |||
135 | void tst_qpieslice::customize() |
|
135 | void tst_qpieslice::customize() | |
136 | { |
|
136 | { | |
137 | // create a pie series |
|
137 | // create a pie series | |
138 | QPieSeries *series = new QPieSeries(); |
|
138 | QPieSeries *series = new QPieSeries(); | |
139 | QPieSlice *s1 = series->append(1, "slice 1"); |
|
139 | QPieSlice *s1 = series->append(1, "slice 1"); | |
140 | QPieSlice *s2 = series->append(2, "slice 2"); |
|
140 | QPieSlice *s2 = series->append(2, "slice 2"); | |
141 | series->append(3, "slice 3"); |
|
141 | series->append(3, "slice 3"); | |
142 |
|
142 | |||
143 | // customize a slice |
|
143 | // customize a slice | |
144 | QPen p1(Qt::red); |
|
144 | QPen p1(Qt::red); | |
145 | s1->setPen(p1); |
|
145 | s1->setPen(p1); | |
146 | QBrush b1(Qt::red); |
|
146 | QBrush b1(Qt::red); | |
147 | s1->setBrush(b1); |
|
147 | s1->setBrush(b1); | |
148 | s1->setLabelPen(p1); |
|
148 | s1->setLabelPen(p1); | |
149 | QFont f1("Consolas"); |
|
149 | QFont f1("Consolas"); | |
150 | s1->setLabelFont(f1); |
|
150 | s1->setLabelFont(f1); | |
151 |
|
151 | |||
152 | // add series to the chart |
|
152 | // add series to the chart | |
153 | QChartView view(new QChart()); |
|
153 | QChartView view(new QChart()); | |
154 | view.resize(200, 200); |
|
154 | view.resize(200, 200); | |
155 | view.chart()->addSeries(series); |
|
155 | view.chart()->addSeries(series); | |
156 | view.show(); |
|
156 | view.show(); | |
157 | QTest::qWaitForWindowShown(&view); |
|
157 | QTest::qWaitForWindowShown(&view); | |
158 | //QTest::qWait(1000); |
|
158 | //QTest::qWait(1000); | |
159 |
|
159 | |||
160 | // check that customizations persist |
|
160 | // check that customizations persist | |
161 | QCOMPARE(s1->pen(), p1); |
|
161 | QCOMPARE(s1->pen(), p1); | |
162 | QCOMPARE(s1->brush(), b1); |
|
162 | QCOMPARE(s1->brush(), b1); | |
163 | QCOMPARE(s1->labelPen(), p1); |
|
163 | QCOMPARE(s1->labelPen(), p1); | |
164 | QCOMPARE(s1->labelFont(), f1); |
|
164 | QCOMPARE(s1->labelFont(), f1); | |
165 |
|
165 | |||
166 | // remove a slice |
|
166 | // remove a slice | |
167 | series->remove(s2); |
|
167 | series->remove(s2); | |
168 | QCOMPARE(s1->pen(), p1); |
|
168 | QCOMPARE(s1->pen(), p1); | |
169 | QCOMPARE(s1->brush(), b1); |
|
169 | QCOMPARE(s1->brush(), b1); | |
170 | QCOMPARE(s1->labelPen(), p1); |
|
170 | QCOMPARE(s1->labelPen(), p1); | |
171 | QCOMPARE(s1->labelFont(), f1); |
|
171 | QCOMPARE(s1->labelFont(), f1); | |
172 |
|
172 | |||
173 | // add a slice |
|
173 | // add a slice | |
174 | series->append(4, "slice 4"); |
|
174 | series->append(4, "slice 4"); | |
175 | QCOMPARE(s1->pen(), p1); |
|
175 | QCOMPARE(s1->pen(), p1); | |
176 | QCOMPARE(s1->brush(), b1); |
|
176 | QCOMPARE(s1->brush(), b1); | |
177 | QCOMPARE(s1->labelPen(), p1); |
|
177 | QCOMPARE(s1->labelPen(), p1); | |
178 | QCOMPARE(s1->labelFont(), f1); |
|
178 | QCOMPARE(s1->labelFont(), f1); | |
179 |
|
179 | |||
180 | // insert a slice |
|
180 | // insert a slice | |
181 | series->insert(0, new QPieSlice(5, "slice 5")); |
|
181 | series->insert(0, new QPieSlice(5, "slice 5")); | |
182 | QCOMPARE(s1->pen(), p1); |
|
182 | QCOMPARE(s1->pen(), p1); | |
183 | QCOMPARE(s1->brush(), b1); |
|
183 | QCOMPARE(s1->brush(), b1); | |
184 | QCOMPARE(s1->labelPen(), p1); |
|
184 | QCOMPARE(s1->labelPen(), p1); | |
185 | QCOMPARE(s1->labelFont(), f1); |
|
185 | QCOMPARE(s1->labelFont(), f1); | |
186 |
|
186 | |||
187 | // change theme |
|
187 | // change theme | |
188 | // theme will overwrite customizations |
|
188 | // theme will overwrite customizations | |
189 | view.chart()->setTheme(QChart::ChartThemeHighContrast); |
|
189 | view.chart()->setTheme(QChart::ChartThemeHighContrast); | |
190 | QVERIFY(s1->pen() != p1); |
|
190 | QVERIFY(s1->pen() != p1); | |
191 | QVERIFY(s1->brush() != b1); |
|
191 | QVERIFY(s1->brush() != b1); | |
192 | QVERIFY(s1->labelPen() != p1); |
|
192 | QVERIFY(s1->labelPen() != p1); | |
193 | QVERIFY(s1->labelFont() != f1); |
|
193 | QVERIFY(s1->labelFont() != f1); | |
194 | } |
|
194 | } | |
195 |
|
195 | |||
196 | void tst_qpieslice::mouseClick() |
|
196 | void tst_qpieslice::mouseClick() | |
197 | { |
|
197 | { | |
198 | // create a pie series |
|
198 | // create a pie series | |
199 | QPieSeries *series = new QPieSeries(); |
|
199 | QPieSeries *series = new QPieSeries(); | |
200 | series->setPieSize(1.0); |
|
200 | series->setPieSize(1.0); | |
201 | QPieSlice *s1 = series->append(1, "slice 1"); |
|
201 | QPieSlice *s1 = series->append(1, "slice 1"); | |
202 | QPieSlice *s2 = series->append(2, "slice 2"); |
|
202 | QPieSlice *s2 = series->append(2, "slice 2"); | |
203 | QPieSlice *s3 = series->append(3, "slice 3"); |
|
203 | QPieSlice *s3 = series->append(3, "slice 3"); | |
204 | QSignalSpy clickSpy1(s1, SIGNAL(clicked())); |
|
204 | QSignalSpy clickSpy1(s1, SIGNAL(clicked())); | |
205 | QSignalSpy clickSpy2(s2, SIGNAL(clicked())); |
|
205 | QSignalSpy clickSpy2(s2, SIGNAL(clicked())); | |
206 | QSignalSpy clickSpy3(s3, SIGNAL(clicked())); |
|
206 | QSignalSpy clickSpy3(s3, SIGNAL(clicked())); | |
207 |
|
207 | |||
208 | // add series to the chart |
|
208 | // add series to the chart | |
209 | QChartView view(new QChart()); |
|
209 | QChartView view(new QChart()); | |
210 | view.resize(200, 200); |
|
210 | view.resize(200, 200); | |
211 | view.chart()->addSeries(series); |
|
211 | view.chart()->addSeries(series); | |
212 | view.show(); |
|
212 | view.show(); | |
213 | QTest::qWaitForWindowShown(&view); |
|
213 | QTest::qWaitForWindowShown(&view); | |
214 |
|
214 | |||
215 | // simulate clicks |
|
215 | // simulate clicks | |
216 | // pie rectangle: QRectF(60,60 121x121) |
|
216 | // pie rectangle: QRectF(60,60 121x121) | |
217 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1 |
|
217 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(139, 85)); // inside slice 1 | |
218 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(146, 136)); // inside slice 2 |
|
218 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(146, 136)); // inside slice 2 | |
219 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(91, 119)); // inside slice 3 |
|
219 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(91, 119)); // inside slice 3 | |
220 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(70, 70)); // inside pie rectangle but not inside a slice |
|
220 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(70, 70)); // inside pie rectangle but not inside a slice | |
221 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(170, 170)); // inside pie rectangle but not inside a slice |
|
221 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, QPoint(170, 170)); // inside pie rectangle but not inside a slice | |
222 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
222 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
223 | QCOMPARE(clickSpy1.count(), 1); |
|
223 | QCOMPARE(clickSpy1.count(), 1); | |
224 | QCOMPARE(clickSpy2.count(), 1); |
|
224 | QCOMPARE(clickSpy2.count(), 1); | |
225 | QCOMPARE(clickSpy3.count(), 1); |
|
225 | QCOMPARE(clickSpy3.count(), 1); | |
226 | } |
|
226 | } | |
227 |
|
227 | |||
228 | void tst_qpieslice::mouseHover() |
|
228 | void tst_qpieslice::mouseHover() | |
229 | { |
|
229 | { | |
230 | // create a pie series |
|
230 | // create a pie series | |
231 | QPieSeries *series = new QPieSeries(); |
|
231 | QPieSeries *series = new QPieSeries(); | |
232 | series->setPieSize(1.0); |
|
232 | series->setPieSize(1.0); | |
233 | QPieSlice *s1 = series->append(1, "slice 1"); |
|
233 | QPieSlice *s1 = series->append(1, "slice 1"); | |
234 | series->append(2, "slice 2"); |
|
234 | series->append(2, "slice 2"); | |
235 | series->append(3, "slice 3"); |
|
235 | series->append(3, "slice 3"); | |
236 |
|
236 | |||
237 | // add series to the chart |
|
237 | // add series to the chart | |
238 | QChartView view(new QChart()); |
|
238 | QChartView view(new QChart()); | |
239 | view.resize(200, 200); |
|
239 | view.resize(200, 200); | |
240 | view.chart()->addSeries(series); |
|
240 | view.chart()->addSeries(series); | |
241 | view.show(); |
|
241 | view.show(); | |
242 | QTest::qWaitForWindowShown(&view); |
|
242 | QTest::qWaitForWindowShown(&view); | |
243 |
|
243 | |||
244 | // first move to right top corner |
|
244 | // first move to right top corner | |
245 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); |
|
245 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |
246 |
|
246 | |||
247 | // move inside slice rectangle but NOT the actual slice |
|
247 | // move inside slice rectangle but NOT the actual slice | |
248 | // pie rectangle: QRectF(60,60 121x121) |
|
248 | // pie rectangle: QRectF(60,60 121x121) | |
249 | QSignalSpy hoverSpy(s1, SIGNAL(hovered(bool))); |
|
249 | QSignalSpy hoverSpy(s1, SIGNAL(hovered(bool))); | |
250 | QTest::mouseMove(view.viewport(), QPoint(170, 70)); |
|
250 | QTest::mouseMove(view.viewport(), QPoint(170, 70)); | |
251 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
251 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
252 | QCOMPARE(hoverSpy.count(), 0); |
|
252 | QCOMPARE(hoverSpy.count(), 0); | |
253 |
|
253 | |||
254 | // move inside the slice |
|
254 | // move inside the slice | |
255 | QTest::mouseMove(view.viewport(), QPoint(139, 85)); |
|
255 | QTest::mouseMove(view.viewport(), QPoint(139, 85)); | |
256 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
256 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
257 | QCOMPARE(hoverSpy.count(), 1); |
|
257 | QCOMPARE(hoverSpy.count(), 1); | |
258 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(0)), true); |
|
258 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(0).at(0)), true); | |
259 |
|
259 | |||
260 | // move outside the slice |
|
260 | // move outside the slice | |
261 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); |
|
261 | QTest::mouseMove(view.viewport(), QPoint(200, 0)); | |
262 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); |
|
262 | QCoreApplication::processEvents(QEventLoop::AllEvents, 1000); | |
263 | QCOMPARE(hoverSpy.count(), 2); |
|
263 | QCOMPARE(hoverSpy.count(), 2); | |
264 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(0)), false); |
|
264 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(1).at(0)), false); | |
265 | } |
|
265 | } | |
266 |
|
266 | |||
267 | QTEST_MAIN(tst_qpieslice) |
|
267 | QTEST_MAIN(tst_qpieslice) | |
268 |
|
268 | |||
269 | #include "tst_qpieslice.moc" |
|
269 | #include "tst_qpieslice.moc" | |
270 |
|
270 |
General Comments 0
You need to be logged in to leave comments.
Login now