@@ -1,648 +1,649 | |||||
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 <qpiemodelmapper.h> |
|
26 | #include <qpiemodelmapper.h> | |
27 | #include <QStandardItemModel> |
|
27 | #include <QStandardItemModel> | |
28 | #include <tst_definitions.h> |
|
28 | #include <tst_definitions.h> | |
29 |
|
29 | |||
30 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
30 | QTCOMMERCIALCHART_USE_NAMESPACE | |
31 |
|
31 | |||
32 | Q_DECLARE_METATYPE(QPieSlice*) |
|
32 | Q_DECLARE_METATYPE(QPieSlice*) | |
33 | Q_DECLARE_METATYPE(QList<QPieSlice*>) |
|
33 | Q_DECLARE_METATYPE(QList<QPieSlice*>) | |
34 |
|
34 | |||
35 | class tst_qpieseries : public QObject |
|
35 | class tst_qpieseries : public QObject | |
36 | { |
|
36 | { | |
37 | Q_OBJECT |
|
37 | Q_OBJECT | |
38 |
|
38 | |||
39 | public slots: |
|
39 | public slots: | |
40 | void initTestCase(); |
|
40 | void initTestCase(); | |
41 | void cleanupTestCase(); |
|
41 | void cleanupTestCase(); | |
42 | void init(); |
|
42 | void init(); | |
43 | void cleanup(); |
|
43 | void cleanup(); | |
44 |
|
44 | |||
45 | private slots: |
|
45 | private slots: | |
46 | void properties(); |
|
46 | void properties(); | |
47 | void append(); |
|
47 | void append(); | |
48 | void appendAnimated(); |
|
48 | void appendAnimated(); | |
49 | void insert(); |
|
49 | void insert(); | |
50 | void insertAnimated(); |
|
50 | void insertAnimated(); | |
51 | void remove(); |
|
51 | void remove(); | |
52 | void removeAnimated(); |
|
52 | void removeAnimated(); | |
53 | void take(); |
|
53 | void take(); | |
54 | void takeAnimated(); |
|
54 | void takeAnimated(); | |
55 | void calculatedValues(); |
|
55 | void calculatedValues(); | |
56 | void clickedSignal(); |
|
56 | void clickedSignal(); | |
57 | void hoverSignal(); |
|
57 | void hoverSignal(); | |
58 | void sliceSeries(); |
|
58 | void sliceSeries(); | |
59 | void destruction(); |
|
59 | void destruction(); | |
60 |
|
60 | |||
61 | private: |
|
61 | private: | |
62 | void verifyCalculatedData(const QPieSeries &series, bool *ok); |
|
62 | void verifyCalculatedData(const QPieSeries &series, bool *ok); | |
63 | QList<QPoint> slicePoints(QRectF rect); |
|
63 | QList<QPoint> slicePoints(QRectF rect); | |
64 |
|
64 | |||
65 | private: |
|
65 | private: | |
66 | QChartView *m_view; |
|
66 | QChartView *m_view; | |
67 | QPieSeries *m_series; |
|
67 | QPieSeries *m_series; | |
68 | }; |
|
68 | }; | |
69 |
|
69 | |||
70 | void tst_qpieseries::initTestCase() |
|
70 | void tst_qpieseries::initTestCase() | |
71 | { |
|
71 | { | |
72 | qRegisterMetaType<QPieSlice*>("QPieSlice*"); |
|
72 | qRegisterMetaType<QPieSlice*>("QPieSlice*"); | |
73 | qRegisterMetaType<QList<QPieSlice*> >("QList<QPieSlice*>"); |
|
73 | qRegisterMetaType<QList<QPieSlice*> >("QList<QPieSlice*>"); | |
74 | } |
|
74 | } | |
75 |
|
75 | |||
76 | void tst_qpieseries::cleanupTestCase() |
|
76 | void tst_qpieseries::cleanupTestCase() | |
77 | { |
|
77 | { | |
78 | } |
|
78 | } | |
79 |
|
79 | |||
80 | void tst_qpieseries::init() |
|
80 | void tst_qpieseries::init() | |
81 | { |
|
81 | { | |
82 | m_view = new QChartView(); |
|
82 | m_view = new QChartView(); | |
83 | m_series = new QPieSeries(m_view); |
|
83 | m_series = new QPieSeries(m_view); | |
84 | m_view->show(); |
|
84 | m_view->show(); | |
85 | QTest::qWaitForWindowShown(m_view); |
|
85 | QTest::qWaitForWindowShown(m_view); | |
86 |
|
86 | |||
87 | } |
|
87 | } | |
88 |
|
88 | |||
89 | void tst_qpieseries::cleanup() |
|
89 | void tst_qpieseries::cleanup() | |
90 | { |
|
90 | { | |
91 | delete m_view; |
|
91 | delete m_view; | |
92 | m_view = 0; |
|
92 | m_view = 0; | |
93 | m_series = 0; |
|
93 | m_series = 0; | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | void tst_qpieseries::properties() |
|
96 | void tst_qpieseries::properties() | |
97 | { |
|
97 | { | |
98 | QSignalSpy countSpy(m_series, SIGNAL(countChanged())); |
|
98 | QSignalSpy countSpy(m_series, SIGNAL(countChanged())); | |
99 | QSignalSpy sumSpy(m_series, SIGNAL(sumChanged())); |
|
99 | QSignalSpy sumSpy(m_series, SIGNAL(sumChanged())); | |
100 | QSignalSpy opacitySpy(m_series, SIGNAL(opacityChanged())); |
|
100 | QSignalSpy opacitySpy(m_series, SIGNAL(opacityChanged())); | |
101 |
|
101 | |||
102 | QVERIFY(m_series->type() == QAbstractSeries::SeriesTypePie); |
|
102 | QVERIFY(m_series->type() == QAbstractSeries::SeriesTypePie); | |
103 | QVERIFY(m_series->count() == 0); |
|
103 | QVERIFY(m_series->count() == 0); | |
104 | QVERIFY(m_series->isEmpty()); |
|
104 | QVERIFY(m_series->isEmpty()); | |
105 | QCOMPARE(m_series->sum(), 0.0); |
|
105 | QCOMPARE(m_series->sum(), 0.0); | |
106 | QCOMPARE(m_series->horizontalPosition(), 0.5); |
|
106 | QCOMPARE(m_series->horizontalPosition(), 0.5); | |
107 | QCOMPARE(m_series->verticalPosition(), 0.5); |
|
107 | QCOMPARE(m_series->verticalPosition(), 0.5); | |
108 | QCOMPARE(m_series->pieSize(), 0.7); |
|
108 | QCOMPARE(m_series->pieSize(), 0.7); | |
109 | QCOMPARE(m_series->pieStartAngle(), 0.0); |
|
109 | QCOMPARE(m_series->pieStartAngle(), 0.0); | |
110 | QCOMPARE(m_series->pieEndAngle(), 360.0); |
|
110 | QCOMPARE(m_series->pieEndAngle(), 360.0); | |
111 | QCOMPARE(m_series->opacity(), 1.0); |
|
111 | QCOMPARE(m_series->opacity(), 1.0); | |
112 |
|
112 | |||
113 | m_series->append("s1", 1); |
|
113 | m_series->append("s1", 1); | |
114 | m_series->append("s2", 1); |
|
114 | m_series->append("s2", 1); | |
115 | m_series->append("s3", 1); |
|
115 | m_series->append("s3", 1); | |
116 | m_series->insert(1, new QPieSlice("s4", 1)); |
|
116 | m_series->insert(1, new QPieSlice("s4", 1)); | |
117 | m_series->remove(m_series->slices().first()); |
|
117 | m_series->remove(m_series->slices().first()); | |
118 | QCOMPARE(m_series->count(), 3); |
|
118 | QCOMPARE(m_series->count(), 3); | |
119 | QCOMPARE(m_series->sum(), 3.0); |
|
119 | QCOMPARE(m_series->sum(), 3.0); | |
120 | m_series->clear(); |
|
120 | m_series->clear(); | |
121 | QCOMPARE(m_series->count(), 0); |
|
121 | QCOMPARE(m_series->count(), 0); | |
122 | QCOMPARE(m_series->sum(), 0.0); |
|
122 | QCOMPARE(m_series->sum(), 0.0); | |
123 | QCOMPARE(countSpy.count(), 6); |
|
123 | QCOMPARE(countSpy.count(), 6); | |
124 | QCOMPARE(sumSpy.count(), 6); |
|
124 | QCOMPARE(sumSpy.count(), 6); | |
125 |
|
125 | |||
126 | m_series->setPieSize(-1.0); |
|
126 | m_series->setPieSize(-1.0); | |
127 | QCOMPARE(m_series->pieSize(), 0.0); |
|
127 | QCOMPARE(m_series->pieSize(), 0.0); | |
128 | m_series->setPieSize(0.0); |
|
128 | m_series->setPieSize(0.0); | |
129 | m_series->setPieSize(0.9); |
|
129 | m_series->setPieSize(0.9); | |
130 | m_series->setPieSize(2.0); |
|
130 | m_series->setPieSize(2.0); | |
131 | QCOMPARE(m_series->pieSize(), 1.0); |
|
131 | QCOMPARE(m_series->pieSize(), 1.0); | |
132 |
|
132 | |||
133 | m_series->setPieSize(0.7); |
|
133 | m_series->setPieSize(0.7); | |
134 | QCOMPARE(m_series->pieSize(), 0.7); |
|
134 | QCOMPARE(m_series->pieSize(), 0.7); | |
135 |
|
135 | |||
136 | m_series->setHoleSize(-1.0); |
|
136 | m_series->setHoleSize(-1.0); | |
137 | QCOMPARE(m_series->holeSize(), 0.0); |
|
137 | QCOMPARE(m_series->holeSize(), 0.0); | |
138 | m_series->setHoleSize(0.5); |
|
138 | m_series->setHoleSize(0.5); | |
139 | QCOMPARE(m_series->holeSize(), 0.5); |
|
139 | QCOMPARE(m_series->holeSize(), 0.5); | |
140 |
|
140 | |||
141 | m_series->setHoleSize(0.8); |
|
141 | m_series->setHoleSize(0.8); | |
142 | QCOMPARE(m_series->holeSize(), 0.8); |
|
142 | QCOMPARE(m_series->holeSize(), 0.8); | |
143 | QCOMPARE(m_series->pieSize(), 0.8); |
|
143 | QCOMPARE(m_series->pieSize(), 0.8); | |
144 |
|
144 | |||
145 | m_series->setPieSize(0.4); |
|
145 | m_series->setPieSize(0.4); | |
146 | QCOMPARE(m_series->pieSize(), 0.4); |
|
146 | QCOMPARE(m_series->pieSize(), 0.4); | |
147 | QCOMPARE(m_series->holeSize(), 0.4); |
|
147 | QCOMPARE(m_series->holeSize(), 0.4); | |
148 |
|
148 | |||
149 | m_series->setPieStartAngle(0); |
|
149 | m_series->setPieStartAngle(0); | |
150 | m_series->setPieStartAngle(-180); |
|
150 | m_series->setPieStartAngle(-180); | |
151 | m_series->setPieStartAngle(180); |
|
151 | m_series->setPieStartAngle(180); | |
152 | QCOMPARE(m_series->pieStartAngle(), 180.0); |
|
152 | QCOMPARE(m_series->pieStartAngle(), 180.0); | |
153 |
|
153 | |||
154 | m_series->setPieEndAngle(360); |
|
154 | m_series->setPieEndAngle(360); | |
155 | m_series->setPieEndAngle(-180); |
|
155 | m_series->setPieEndAngle(-180); | |
156 | m_series->setPieEndAngle(180); |
|
156 | m_series->setPieEndAngle(180); | |
157 | QCOMPARE(m_series->pieEndAngle(), 180.0); |
|
157 | QCOMPARE(m_series->pieEndAngle(), 180.0); | |
158 |
|
158 | |||
159 | m_series->setHorizontalPosition(0.5); |
|
159 | m_series->setHorizontalPosition(0.5); | |
160 | m_series->setHorizontalPosition(-1.0); |
|
160 | m_series->setHorizontalPosition(-1.0); | |
161 | QCOMPARE(m_series->horizontalPosition(), 0.0); |
|
161 | QCOMPARE(m_series->horizontalPosition(), 0.0); | |
162 | m_series->setHorizontalPosition(1.0); |
|
162 | m_series->setHorizontalPosition(1.0); | |
163 | m_series->setHorizontalPosition(2.0); |
|
163 | m_series->setHorizontalPosition(2.0); | |
164 | QCOMPARE(m_series->horizontalPosition(), 1.0); |
|
164 | QCOMPARE(m_series->horizontalPosition(), 1.0); | |
165 |
|
165 | |||
166 | m_series->setVerticalPosition(0.5); |
|
166 | m_series->setVerticalPosition(0.5); | |
167 | m_series->setVerticalPosition(-1.0); |
|
167 | m_series->setVerticalPosition(-1.0); | |
168 | QCOMPARE(m_series->verticalPosition(), 0.0); |
|
168 | QCOMPARE(m_series->verticalPosition(), 0.0); | |
169 | m_series->setVerticalPosition(1.0); |
|
169 | m_series->setVerticalPosition(1.0); | |
170 | m_series->setVerticalPosition(2.0); |
|
170 | m_series->setVerticalPosition(2.0); | |
171 | QCOMPARE(m_series->verticalPosition(), 1.0); |
|
171 | QCOMPARE(m_series->verticalPosition(), 1.0); | |
172 |
|
172 | |||
173 | m_series->setOpacity(0.5); |
|
173 | m_series->setOpacity(0.5); | |
174 | QCOMPARE(m_series->opacity(), 0.5); |
|
174 | QCOMPARE(m_series->opacity(), 0.5); | |
175 | QCOMPARE(opacitySpy.count(), 1); |
|
175 | QCOMPARE(opacitySpy.count(), 1); | |
176 | m_series->setOpacity(0.0); |
|
176 | m_series->setOpacity(0.0); | |
177 | QCOMPARE(m_series->opacity(), 0.0); |
|
177 | QCOMPARE(m_series->opacity(), 0.0); | |
178 | QCOMPARE(opacitySpy.count(), 2); |
|
178 | QCOMPARE(opacitySpy.count(), 2); | |
179 | m_series->setOpacity(1.0); |
|
179 | m_series->setOpacity(1.0); | |
180 | QCOMPARE(m_series->opacity(), 1.0); |
|
180 | QCOMPARE(m_series->opacity(), 1.0); | |
181 | QCOMPARE(opacitySpy.count(), 3); |
|
181 | QCOMPARE(opacitySpy.count(), 3); | |
182 | } |
|
182 | } | |
183 |
|
183 | |||
184 | void tst_qpieseries::append() |
|
184 | void tst_qpieseries::append() | |
185 | { |
|
185 | { | |
186 | m_view->chart()->addSeries(m_series); |
|
186 | m_view->chart()->addSeries(m_series); | |
187 | QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>))); |
|
187 | QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>))); | |
188 |
|
188 | |||
189 | // append pointer |
|
189 | // append pointer | |
190 | QPieSlice *slice1 = 0; |
|
190 | QPieSlice *slice1 = 0; | |
191 | QVERIFY(!m_series->append(slice1)); |
|
191 | QVERIFY(!m_series->append(slice1)); | |
192 | slice1 = new QPieSlice("slice 1", 1); |
|
192 | slice1 = new QPieSlice("slice 1", 1); | |
193 | QVERIFY(m_series->append(slice1)); |
|
193 | QVERIFY(m_series->append(slice1)); | |
194 | QVERIFY(!m_series->append(slice1)); |
|
194 | QVERIFY(!m_series->append(slice1)); | |
195 | QCOMPARE(m_series->count(), 1); |
|
195 | QCOMPARE(m_series->count(), 1); | |
196 | QCOMPARE(addedSpy.count(), 1); |
|
196 | QCOMPARE(addedSpy.count(), 1); | |
197 | QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); |
|
197 | QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); | |
198 | QCOMPARE(added.count(), 1); |
|
198 | QCOMPARE(added.count(), 1); | |
199 | QCOMPARE(added.first(), slice1); |
|
199 | QCOMPARE(added.first(), slice1); | |
200 |
|
200 | |||
201 | // try to append same slice to another series |
|
201 | // try to append same slice to another series | |
202 | QPieSeries series2; |
|
202 | QPieSeries series2; | |
203 | QVERIFY(!series2.append(slice1)); |
|
203 | QVERIFY(!series2.append(slice1)); | |
204 |
|
204 | |||
205 | // append pointer list |
|
205 | // append pointer list | |
206 | QList<QPieSlice *> list; |
|
206 | QList<QPieSlice *> list; | |
207 | QVERIFY(!m_series->append(list)); |
|
207 | QVERIFY(!m_series->append(list)); | |
208 | list << (QPieSlice *) 0; |
|
208 | list << (QPieSlice *) 0; | |
209 | QVERIFY(!m_series->append(list)); |
|
209 | QVERIFY(!m_series->append(list)); | |
210 | list.clear(); |
|
210 | list.clear(); | |
211 | list << new QPieSlice("slice 2", 2); |
|
211 | list << new QPieSlice("slice 2", 2); | |
212 | list << new QPieSlice("slice 3", 3); |
|
212 | list << new QPieSlice("slice 3", 3); | |
213 | QVERIFY(m_series->append(list)); |
|
213 | QVERIFY(m_series->append(list)); | |
214 | QVERIFY(!m_series->append(list)); |
|
214 | QVERIFY(!m_series->append(list)); | |
215 | QCOMPARE(m_series->count(), 3); |
|
215 | QCOMPARE(m_series->count(), 3); | |
216 | QCOMPARE(addedSpy.count(), 2); |
|
216 | QCOMPARE(addedSpy.count(), 2); | |
217 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); |
|
217 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); | |
218 | QCOMPARE(added.count(), 2); |
|
218 | QCOMPARE(added.count(), 2); | |
219 | QCOMPARE(added, list); |
|
219 | QCOMPARE(added, list); | |
220 |
|
220 | |||
221 | // append operator |
|
221 | // append operator | |
222 | QPieSlice *slice4 = new QPieSlice("slice 4", 4); |
|
222 | QPieSlice *slice4 = new QPieSlice("slice 4", 4); | |
223 | *m_series << slice4; |
|
223 | *m_series << slice4; | |
224 | *m_series << slice1; // fails because already added |
|
224 | *m_series << slice1; // fails because already added | |
225 | QCOMPARE(m_series->count(), 4); |
|
225 | QCOMPARE(m_series->count(), 4); | |
226 | QCOMPARE(addedSpy.count(), 3); |
|
226 | QCOMPARE(addedSpy.count(), 3); | |
227 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); |
|
227 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); | |
228 | QCOMPARE(added.count(), 1); |
|
228 | QCOMPARE(added.count(), 1); | |
229 | QCOMPARE(added.first(), slice4); |
|
229 | QCOMPARE(added.first(), slice4); | |
230 |
|
230 | |||
231 | // append with params |
|
231 | // append with params | |
232 | QPieSlice *slice5 = m_series->append("slice 5", 5); |
|
232 | QPieSlice *slice5 = m_series->append("slice 5", 5); | |
233 | QVERIFY(slice5 != 0); |
|
233 | QVERIFY(slice5 != 0); | |
234 | QCOMPARE(slice5->value(), 5.0); |
|
234 | QCOMPARE(slice5->value(), 5.0); | |
235 | QCOMPARE(slice5->label(), QString("slice 5")); |
|
235 | QCOMPARE(slice5->label(), QString("slice 5")); | |
236 | QCOMPARE(m_series->count(), 5); |
|
236 | QCOMPARE(m_series->count(), 5); | |
237 | QCOMPARE(addedSpy.count(), 4); |
|
237 | QCOMPARE(addedSpy.count(), 4); | |
238 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); |
|
238 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); | |
239 | QCOMPARE(added.count(), 1); |
|
239 | QCOMPARE(added.count(), 1); | |
240 | QCOMPARE(added.first(), slice5); |
|
240 | QCOMPARE(added.first(), slice5); | |
241 |
|
241 | |||
242 | // check slices |
|
242 | // check slices | |
243 | QVERIFY(!m_series->isEmpty()); |
|
243 | QVERIFY(!m_series->isEmpty()); | |
244 | for (int i=0; i<m_series->count(); i++) { |
|
244 | for (int i=0; i<m_series->count(); i++) { | |
245 | QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1); |
|
245 | QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1); | |
246 | QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1)); |
|
246 | QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1)); | |
247 | } |
|
247 | } | |
248 | } |
|
248 | } | |
249 |
|
249 | |||
250 | void tst_qpieseries::appendAnimated() |
|
250 | void tst_qpieseries::appendAnimated() | |
251 | { |
|
251 | { | |
252 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); |
|
252 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); | |
253 | append(); |
|
253 | append(); | |
254 | } |
|
254 | } | |
255 |
|
255 | |||
256 | void tst_qpieseries::insert() |
|
256 | void tst_qpieseries::insert() | |
257 | { |
|
257 | { | |
258 | m_view->chart()->addSeries(m_series); |
|
258 | m_view->chart()->addSeries(m_series); | |
259 | QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>))); |
|
259 | QSignalSpy addedSpy(m_series, SIGNAL(added(QList<QPieSlice*>))); | |
260 |
|
260 | |||
261 | // insert one slice |
|
261 | // insert one slice | |
262 | QPieSlice *slice1 = 0; |
|
262 | QPieSlice *slice1 = 0; | |
263 | QVERIFY(!m_series->insert(0, slice1)); |
|
263 | QVERIFY(!m_series->insert(0, slice1)); | |
264 | slice1 = new QPieSlice("slice 1", 1); |
|
264 | slice1 = new QPieSlice("slice 1", 1); | |
265 | QVERIFY(!m_series->insert(-1, slice1)); |
|
265 | QVERIFY(!m_series->insert(-1, slice1)); | |
266 | QVERIFY(!m_series->insert(5, slice1)); |
|
266 | QVERIFY(!m_series->insert(5, slice1)); | |
267 | QVERIFY(m_series->insert(0, slice1)); |
|
267 | QVERIFY(m_series->insert(0, slice1)); | |
268 | QVERIFY(!m_series->insert(0, slice1)); |
|
268 | QVERIFY(!m_series->insert(0, slice1)); | |
269 | QCOMPARE(m_series->count(), 1); |
|
269 | QCOMPARE(m_series->count(), 1); | |
270 | QCOMPARE(addedSpy.count(), 1); |
|
270 | QCOMPARE(addedSpy.count(), 1); | |
271 | QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); |
|
271 | QList<QPieSlice*> added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(0).at(0)); | |
272 | QCOMPARE(added.count(), 1); |
|
272 | QCOMPARE(added.count(), 1); | |
273 | QCOMPARE(added.first(), slice1); |
|
273 | QCOMPARE(added.first(), slice1); | |
274 |
|
274 | |||
275 | // try to insert same slice to another series |
|
275 | // try to insert same slice to another series | |
276 | QPieSeries series2; |
|
276 | QPieSeries series2; | |
277 | QVERIFY(!series2.insert(0, slice1)); |
|
277 | QVERIFY(!series2.insert(0, slice1)); | |
278 |
|
278 | |||
279 | // add some more slices |
|
279 | // add some more slices | |
280 | QPieSlice *slice2 = m_series->append("slice 2", 2); |
|
280 | QPieSlice *slice2 = m_series->append("slice 2", 2); | |
281 | QPieSlice *slice4 = m_series->append("slice 4", 4); |
|
281 | QPieSlice *slice4 = m_series->append("slice 4", 4); | |
282 | QCOMPARE(m_series->count(), 3); |
|
282 | QCOMPARE(m_series->count(), 3); | |
283 | QCOMPARE(addedSpy.count(), 3); |
|
283 | QCOMPARE(addedSpy.count(), 3); | |
284 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); |
|
284 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(1).at(0)); | |
285 | QCOMPARE(added.count(), 1); |
|
285 | QCOMPARE(added.count(), 1); | |
286 | QCOMPARE(added.first(), slice2); |
|
286 | QCOMPARE(added.first(), slice2); | |
287 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); |
|
287 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(2).at(0)); | |
288 | QCOMPARE(added.count(), 1); |
|
288 | QCOMPARE(added.count(), 1); | |
289 | QCOMPARE(added.first(), slice4); |
|
289 | QCOMPARE(added.first(), slice4); | |
290 |
|
290 | |||
291 | // insert between slices |
|
291 | // insert between slices | |
292 | QPieSlice *slice3 = new QPieSlice("slice 3", 3); |
|
292 | QPieSlice *slice3 = new QPieSlice("slice 3", 3); | |
293 | m_series->insert(2, slice3); |
|
293 | m_series->insert(2, slice3); | |
294 | QCOMPARE(m_series->count(), 4); |
|
294 | QCOMPARE(m_series->count(), 4); | |
295 | QCOMPARE(addedSpy.count(), 4); |
|
295 | QCOMPARE(addedSpy.count(), 4); | |
296 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); |
|
296 | added = qvariant_cast<QList<QPieSlice*> >(addedSpy.at(3).at(0)); | |
297 | QCOMPARE(added.count(), 1); |
|
297 | QCOMPARE(added.count(), 1); | |
298 | QCOMPARE(added.first(), slice3); |
|
298 | QCOMPARE(added.first(), slice3); | |
299 |
|
299 | |||
300 | // check slices |
|
300 | // check slices | |
301 | for (int i=0; i<m_series->count(); i++) { |
|
301 | for (int i=0; i<m_series->count(); i++) { | |
302 | QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1); |
|
302 | QCOMPARE(m_series->slices().at(i)->value(), (qreal) i+1); | |
303 | QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1)); |
|
303 | QCOMPARE(m_series->slices().at(i)->label(), QString("slice ") + QString::number(i+1)); | |
304 | QVERIFY(m_series->slices().at(i)->parent() == m_series); |
|
304 | QVERIFY(m_series->slices().at(i)->parent() == m_series); | |
305 | } |
|
305 | } | |
306 | } |
|
306 | } | |
307 |
|
307 | |||
308 | void tst_qpieseries::insertAnimated() |
|
308 | void tst_qpieseries::insertAnimated() | |
309 | { |
|
309 | { | |
310 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); |
|
310 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); | |
311 | insert(); |
|
311 | insert(); | |
312 | } |
|
312 | } | |
313 |
|
313 | |||
314 | void tst_qpieseries::remove() |
|
314 | void tst_qpieseries::remove() | |
315 | { |
|
315 | { | |
316 | m_view->chart()->addSeries(m_series); |
|
316 | m_view->chart()->addSeries(m_series); | |
317 | QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>))); |
|
317 | QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>))); | |
318 |
|
318 | |||
319 | // add some slices |
|
319 | // add some slices | |
320 | QPieSlice *slice1 = m_series->append("slice 1", 1); |
|
320 | QPieSlice *slice1 = m_series->append("slice 1", 1); | |
321 | QPieSlice *slice2 = m_series->append("slice 2", 2); |
|
321 | QPieSlice *slice2 = m_series->append("slice 2", 2); | |
322 | QPieSlice *slice3 = m_series->append("slice 3", 3); |
|
322 | QPieSlice *slice3 = m_series->append("slice 3", 3); | |
323 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); |
|
323 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); | |
324 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); |
|
324 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); | |
325 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); |
|
325 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); | |
326 | QCOMPARE(m_series->count(), 3); |
|
326 | QCOMPARE(m_series->count(), 3); | |
327 |
|
327 | |||
328 | // null pointer remove |
|
328 | // null pointer remove | |
329 | QVERIFY(!m_series->remove(0)); |
|
329 | QVERIFY(!m_series->remove(0)); | |
330 |
|
330 | |||
331 | // remove first |
|
331 | // remove first | |
332 | QVERIFY(m_series->remove(slice1)); |
|
332 | QVERIFY(m_series->remove(slice1)); | |
333 | QVERIFY(!m_series->remove(slice1)); |
|
333 | QVERIFY(!m_series->remove(slice1)); | |
334 | QCOMPARE(m_series->count(), 2); |
|
334 | QCOMPARE(m_series->count(), 2); | |
335 | QCOMPARE(m_series->slices().at(0)->label(), slice2->label()); |
|
335 | QCOMPARE(m_series->slices().at(0)->label(), slice2->label()); | |
336 | QCOMPARE(removedSpy.count(), 1); |
|
336 | QCOMPARE(removedSpy.count(), 1); | |
337 | QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0)); |
|
337 | QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0)); | |
338 | QCOMPARE(removed.count(), 1); |
|
338 | QCOMPARE(removed.count(), 1); | |
339 | QCOMPARE(removed.first(), slice1); |
|
339 | QCOMPARE(removed.first(), slice1); | |
340 |
|
340 | |||
341 | // remove all |
|
341 | // remove all | |
342 | m_series->clear(); |
|
342 | m_series->clear(); | |
343 | QVERIFY(m_series->isEmpty()); |
|
343 | QVERIFY(m_series->isEmpty()); | |
344 | QVERIFY(m_series->slices().isEmpty()); |
|
344 | QVERIFY(m_series->slices().isEmpty()); | |
345 | QCOMPARE(m_series->count(), 0); |
|
345 | QCOMPARE(m_series->count(), 0); | |
346 | QCOMPARE(removedSpy.count(), 2); |
|
346 | QCOMPARE(removedSpy.count(), 2); | |
347 | removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0)); |
|
347 | removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(1).at(0)); | |
348 | QCOMPARE(removed.count(), 2); |
|
348 | QCOMPARE(removed.count(), 2); | |
349 | QCOMPARE(removed.first(), slice2); |
|
349 | QCOMPARE(removed.first(), slice2); | |
350 | QCOMPARE(removed.last(), slice3); |
|
350 | QCOMPARE(removed.last(), slice3); | |
351 |
|
351 | |||
352 | // check that slices were actually destroyed |
|
352 | // check that slices were actually destroyed | |
353 | TRY_COMPARE(spy1.count(), 1); |
|
353 | TRY_COMPARE(spy1.count(), 1); | |
354 | TRY_COMPARE(spy2.count(), 1); |
|
354 | TRY_COMPARE(spy2.count(), 1); | |
355 | TRY_COMPARE(spy3.count(), 1); |
|
355 | TRY_COMPARE(spy3.count(), 1); | |
356 | } |
|
356 | } | |
357 |
|
357 | |||
358 | void tst_qpieseries::removeAnimated() |
|
358 | void tst_qpieseries::removeAnimated() | |
359 | { |
|
359 | { | |
360 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); |
|
360 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); | |
361 | remove(); |
|
361 | remove(); | |
362 | } |
|
362 | } | |
363 |
|
363 | |||
364 | void tst_qpieseries::take() |
|
364 | void tst_qpieseries::take() | |
365 | { |
|
365 | { | |
366 | m_view->chart()->addSeries(m_series); |
|
366 | m_view->chart()->addSeries(m_series); | |
367 | QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>))); |
|
367 | QSignalSpy removedSpy(m_series, SIGNAL(removed(QList<QPieSlice*>))); | |
368 |
|
368 | |||
369 | // add some slices |
|
369 | // add some slices | |
370 | QPieSlice *slice1 = m_series->append("slice 1", 1); |
|
370 | QPieSlice *slice1 = m_series->append("slice 1", 1); | |
371 | QPieSlice *slice2 = m_series->append("slice 2", 2); |
|
371 | QPieSlice *slice2 = m_series->append("slice 2", 2); | |
372 | m_series->append("slice 3", 3); |
|
372 | m_series->append("slice 3", 3); | |
373 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); |
|
373 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); | |
374 | QCOMPARE(m_series->count(), 3); |
|
374 | QCOMPARE(m_series->count(), 3); | |
375 |
|
375 | |||
376 | // null pointer remove |
|
376 | // null pointer remove | |
377 | QVERIFY(!m_series->take(0)); |
|
377 | QVERIFY(!m_series->take(0)); | |
378 |
|
378 | |||
379 | // take first |
|
379 | // take first | |
380 | QVERIFY(m_series->take(slice1)); |
|
380 | QVERIFY(m_series->take(slice1)); | |
381 | TRY_COMPARE(spy1.count(), 0); |
|
381 | TRY_COMPARE(spy1.count(), 0); | |
382 | QVERIFY(slice1->parent() == m_series); // series is still the parent object |
|
382 | QVERIFY(slice1->parent() == m_series); // series is still the parent object | |
383 | QVERIFY(!m_series->take(slice1)); |
|
383 | QVERIFY(!m_series->take(slice1)); | |
384 | QCOMPARE(m_series->count(), 2); |
|
384 | QCOMPARE(m_series->count(), 2); | |
385 | QCOMPARE(m_series->slices().at(0)->label(), slice2->label()); |
|
385 | QCOMPARE(m_series->slices().at(0)->label(), slice2->label()); | |
386 | QCOMPARE(removedSpy.count(), 1); |
|
386 | QCOMPARE(removedSpy.count(), 1); | |
387 | QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0)); |
|
387 | QList<QPieSlice*> removed = qvariant_cast<QList<QPieSlice*> >(removedSpy.at(0).at(0)); | |
388 | QCOMPARE(removed.count(), 1); |
|
388 | QCOMPARE(removed.count(), 1); | |
389 | QCOMPARE(removed.first(), slice1); |
|
389 | QCOMPARE(removed.first(), slice1); | |
390 | } |
|
390 | } | |
391 |
|
391 | |||
392 | void tst_qpieseries::takeAnimated() |
|
392 | void tst_qpieseries::takeAnimated() | |
393 | { |
|
393 | { | |
394 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); |
|
394 | m_view->chart()->setAnimationOptions(QChart::AllAnimations); | |
395 | take(); |
|
395 | take(); | |
396 | } |
|
396 | } | |
397 |
|
397 | |||
398 | void tst_qpieseries::calculatedValues() |
|
398 | void tst_qpieseries::calculatedValues() | |
399 | { |
|
399 | { | |
400 | m_view->chart()->addSeries(m_series); |
|
400 | m_view->chart()->addSeries(m_series); | |
401 |
|
401 | |||
402 | QPieSlice *slice1 = new QPieSlice("slice 1", 1); |
|
402 | QPieSlice *slice1 = new QPieSlice("slice 1", 1); | |
403 | QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged())); |
|
403 | QSignalSpy percentageSpy(slice1, SIGNAL(percentageChanged())); | |
404 | QSignalSpy startAngleSpy(slice1, SIGNAL(startAngleChanged())); |
|
404 | QSignalSpy startAngleSpy(slice1, SIGNAL(startAngleChanged())); | |
405 | QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged())); |
|
405 | QSignalSpy angleSpanSpy(slice1, SIGNAL(angleSpanChanged())); | |
406 |
|
406 | |||
407 | // add a slice |
|
407 | // add a slice | |
408 | m_series->append(slice1); |
|
408 | m_series->append(slice1); | |
409 | bool ok; |
|
409 | bool ok; | |
410 | verifyCalculatedData(*m_series, &ok); |
|
410 | verifyCalculatedData(*m_series, &ok); | |
411 | if (!ok) |
|
411 | if (!ok) | |
412 | return; |
|
412 | return; | |
413 | QCOMPARE(percentageSpy.count(), 1); |
|
413 | QCOMPARE(percentageSpy.count(), 1); | |
414 | QCOMPARE(startAngleSpy.count(), 0); |
|
414 | QCOMPARE(startAngleSpy.count(), 0); | |
415 | QCOMPARE(angleSpanSpy.count(), 1); |
|
415 | QCOMPARE(angleSpanSpy.count(), 1); | |
416 |
|
416 | |||
417 | // add some more slices |
|
417 | // add some more slices | |
418 | QList<QPieSlice *> list; |
|
418 | QList<QPieSlice *> list; | |
419 | list << new QPieSlice("slice 2", 2); |
|
419 | list << new QPieSlice("slice 2", 2); | |
420 | list << new QPieSlice("slice 3", 3); |
|
420 | list << new QPieSlice("slice 3", 3); | |
421 | m_series->append(list); |
|
421 | m_series->append(list); | |
422 | verifyCalculatedData(*m_series, &ok); |
|
422 | verifyCalculatedData(*m_series, &ok); | |
423 | if (!ok) |
|
423 | if (!ok) | |
424 | return; |
|
424 | return; | |
425 | QCOMPARE(percentageSpy.count(), 2); |
|
425 | QCOMPARE(percentageSpy.count(), 2); | |
426 | QCOMPARE(startAngleSpy.count(), 0); |
|
426 | QCOMPARE(startAngleSpy.count(), 0); | |
427 | QCOMPARE(angleSpanSpy.count(), 2); |
|
427 | QCOMPARE(angleSpanSpy.count(), 2); | |
428 |
|
428 | |||
429 | // remove a slice |
|
429 | // remove a slice | |
430 | m_series->remove(list.first()); // remove slice 2 |
|
430 | m_series->remove(list.first()); // remove slice 2 | |
431 | verifyCalculatedData(*m_series, &ok); |
|
431 | verifyCalculatedData(*m_series, &ok); | |
432 | if (!ok) |
|
432 | if (!ok) | |
433 | return; |
|
433 | return; | |
434 | QCOMPARE(percentageSpy.count(), 3); |
|
434 | QCOMPARE(percentageSpy.count(), 3); | |
435 | QCOMPARE(startAngleSpy.count(), 0); |
|
435 | QCOMPARE(startAngleSpy.count(), 0); | |
436 | QCOMPARE(angleSpanSpy.count(), 3); |
|
436 | QCOMPARE(angleSpanSpy.count(), 3); | |
437 |
|
437 | |||
438 | // insert a slice |
|
438 | // insert a slice | |
439 | m_series->insert(0, new QPieSlice("Slice 4", 4)); |
|
439 | m_series->insert(0, new QPieSlice("Slice 4", 4)); | |
440 | verifyCalculatedData(*m_series, &ok); |
|
440 | verifyCalculatedData(*m_series, &ok); | |
441 | if (!ok) |
|
441 | if (!ok) | |
442 | return; |
|
442 | return; | |
443 | QCOMPARE(percentageSpy.count(), 4); |
|
443 | QCOMPARE(percentageSpy.count(), 4); | |
444 | QCOMPARE(startAngleSpy.count(), 1); |
|
444 | QCOMPARE(startAngleSpy.count(), 1); | |
445 | QCOMPARE(angleSpanSpy.count(), 4); |
|
445 | QCOMPARE(angleSpanSpy.count(), 4); | |
446 |
|
446 | |||
447 | // modify pie angles |
|
447 | // modify pie angles | |
448 | m_series->setPieStartAngle(-90); |
|
448 | m_series->setPieStartAngle(-90); | |
449 | m_series->setPieEndAngle(90); |
|
449 | m_series->setPieEndAngle(90); | |
450 | verifyCalculatedData(*m_series, &ok); |
|
450 | verifyCalculatedData(*m_series, &ok); | |
451 | if (!ok) |
|
451 | if (!ok) | |
452 | return; |
|
452 | return; | |
453 | QCOMPARE(percentageSpy.count(), 4); |
|
453 | QCOMPARE(percentageSpy.count(), 4); | |
454 | QCOMPARE(startAngleSpy.count(), 3); |
|
454 | QCOMPARE(startAngleSpy.count(), 3); | |
455 | QCOMPARE(angleSpanSpy.count(), 6); |
|
455 | QCOMPARE(angleSpanSpy.count(), 6); | |
456 |
|
456 | |||
457 | // clear all |
|
457 | // clear all | |
458 | m_series->clear(); |
|
458 | m_series->clear(); | |
459 | verifyCalculatedData(*m_series, &ok); |
|
459 | verifyCalculatedData(*m_series, &ok); | |
460 | if (!ok) |
|
460 | if (!ok) | |
461 | return; |
|
461 | return; | |
462 | QCOMPARE(percentageSpy.count(), 4); |
|
462 | QCOMPARE(percentageSpy.count(), 4); | |
463 | QCOMPARE(startAngleSpy.count(), 3); |
|
463 | QCOMPARE(startAngleSpy.count(), 3); | |
464 | QCOMPARE(angleSpanSpy.count(), 6); |
|
464 | QCOMPARE(angleSpanSpy.count(), 6); | |
465 | } |
|
465 | } | |
466 |
|
466 | |||
467 | void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) |
|
467 | void tst_qpieseries::verifyCalculatedData(const QPieSeries &series, bool *ok) | |
468 | { |
|
468 | { | |
469 | *ok = false; |
|
469 | *ok = false; | |
470 |
|
470 | |||
471 | qreal sum = 0; |
|
471 | qreal sum = 0; | |
472 | foreach (const QPieSlice *slice, series.slices()) |
|
472 | foreach (const QPieSlice *slice, series.slices()) | |
473 | sum += slice->value(); |
|
473 | sum += slice->value(); | |
474 | QCOMPARE(series.sum(), sum); |
|
474 | QCOMPARE(series.sum(), sum); | |
475 |
|
475 | |||
476 | qreal startAngle = series.pieStartAngle(); |
|
476 | qreal startAngle = series.pieStartAngle(); | |
477 | qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle(); |
|
477 | qreal pieAngleSpan = series.pieEndAngle() - series.pieStartAngle(); | |
478 | foreach (const QPieSlice *slice, series.slices()) { |
|
478 | foreach (const QPieSlice *slice, series.slices()) { | |
479 | qreal ratio = slice->value() / sum; |
|
479 | qreal ratio = slice->value() / sum; | |
480 | qreal sliceSpan = pieAngleSpan * ratio; |
|
480 | qreal sliceSpan = pieAngleSpan * ratio; | |
481 | QCOMPARE(slice->startAngle(), startAngle); |
|
481 | QCOMPARE(slice->startAngle(), startAngle); | |
482 | QCOMPARE(slice->angleSpan(), sliceSpan); |
|
482 | QCOMPARE(slice->angleSpan(), sliceSpan); | |
483 | QCOMPARE(slice->percentage(), ratio); |
|
483 | QCOMPARE(slice->percentage(), ratio); | |
484 | startAngle += sliceSpan; |
|
484 | startAngle += sliceSpan; | |
485 | } |
|
485 | } | |
486 |
|
486 | |||
487 | if (!series.isEmpty()) |
|
487 | if (!series.isEmpty()) | |
488 | QCOMPARE(series.slices().last()->startAngle() + series.slices().last()->angleSpan(), series.pieEndAngle()); |
|
488 | QCOMPARE(series.slices().last()->startAngle() + series.slices().last()->angleSpan(), series.pieEndAngle()); | |
489 |
|
489 | |||
490 | *ok = true; |
|
490 | *ok = true; | |
491 | } |
|
491 | } | |
492 |
|
492 | |||
493 | void tst_qpieseries::clickedSignal() |
|
493 | void tst_qpieseries::clickedSignal() | |
494 | { |
|
494 | { | |
495 | // NOTE: |
|
495 | // NOTE: | |
496 | // This test is the same as tst_qpieslice::clickedSignal() |
|
496 | // This test is the same as tst_qpieslice::clickedSignal() | |
497 | // Just for different signals. |
|
497 | // Just for different signals. | |
498 |
|
498 | |||
499 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); |
|
499 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | |
500 |
|
500 | |||
501 | // add some slices |
|
501 | // add some slices | |
502 | QPieSlice *s1 = m_series->append("slice 1", 1); |
|
502 | QPieSlice *s1 = m_series->append("slice 1", 1); | |
503 | QPieSlice *s2 = m_series->append("slice 2", 1); |
|
503 | QPieSlice *s2 = m_series->append("slice 2", 1); | |
504 | QPieSlice *s3 = m_series->append("slice 3", 1); |
|
504 | QPieSlice *s3 = m_series->append("slice 3", 1); | |
505 | QPieSlice *s4 = m_series->append("slice 4", 1); |
|
505 | QPieSlice *s4 = m_series->append("slice 4", 1); | |
506 | QSignalSpy clickSpy(m_series, SIGNAL(clicked(QPieSlice*))); |
|
506 | QSignalSpy clickSpy(m_series, SIGNAL(clicked(QPieSlice*))); | |
507 |
|
507 | |||
508 | // add series to the chart |
|
508 | // add series to the chart | |
509 | m_view->chart()->legend()->setVisible(false); |
|
509 | m_view->chart()->legend()->setVisible(false); | |
510 | m_view->chart()->addSeries(m_series); |
|
510 | m_view->chart()->addSeries(m_series); | |
511 | m_view->show(); |
|
511 | m_view->show(); | |
512 | QTest::qWaitForWindowShown(m_view); |
|
512 | QTest::qWaitForWindowShown(m_view); | |
513 |
|
513 | |||
514 | // test maximum size |
|
514 | // test maximum size | |
515 | m_series->setPieSize(1.0); |
|
515 | m_series->setPieSize(1.0); | |
516 | QRectF pieRect = m_view->chart()->plotArea(); |
|
516 | QRectF pieRect = m_view->chart()->plotArea(); | |
517 | QList<QPoint> points = slicePoints(pieRect); |
|
517 | QList<QPoint> points = slicePoints(pieRect); | |
518 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0)); |
|
518 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0)); | |
519 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(1)); |
|
519 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(1)); | |
520 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(2)); |
|
520 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(2)); | |
521 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(3)); |
|
521 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(3)); | |
522 | TRY_COMPARE(clickSpy.count(), 4); |
|
522 | TRY_COMPARE(clickSpy.count(), 4); | |
523 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1); |
|
523 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1); | |
524 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s2); |
|
524 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s2); | |
525 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3); |
|
525 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3); | |
526 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s4); |
|
526 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s4); | |
527 | clickSpy.clear(); |
|
527 | clickSpy.clear(); | |
528 |
|
528 | |||
529 | // test half size |
|
529 | // test half size | |
530 | m_series->setPieSize(0.5); |
|
530 | m_series->setPieSize(0.5); | |
531 | m_series->setVerticalPosition(0.25); |
|
531 | m_series->setVerticalPosition(0.25); | |
532 | m_series->setHorizontalPosition(0.25); |
|
532 | m_series->setHorizontalPosition(0.25); | |
533 | pieRect = QRectF(m_view->chart()->plotArea().topLeft(), m_view->chart()->plotArea().center()); |
|
533 | pieRect = QRectF(m_view->chart()->plotArea().topLeft(), m_view->chart()->plotArea().center()); | |
534 | points = slicePoints(pieRect); |
|
534 | points = slicePoints(pieRect); | |
535 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0)); |
|
535 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(0)); | |
536 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(1)); |
|
536 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(1)); | |
537 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(2)); |
|
537 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(2)); | |
538 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(3)); |
|
538 | QTest::mouseClick(m_view->viewport(), Qt::LeftButton, 0, points.at(3)); | |
539 | TRY_COMPARE(clickSpy.count(), 4); |
|
539 | TRY_COMPARE(clickSpy.count(), 4); | |
540 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1); |
|
540 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(0).at(0)), s1); | |
541 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s2); |
|
541 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(1).at(0)), s2); | |
542 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3); |
|
542 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(2).at(0)), s3); | |
543 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s4); |
|
543 | QCOMPARE(qvariant_cast<QPieSlice*>(clickSpy.at(3).at(0)), s4); | |
544 | } |
|
544 | } | |
545 |
|
545 | |||
546 | void tst_qpieseries::hoverSignal() |
|
546 | void tst_qpieseries::hoverSignal() | |
547 | { |
|
547 | { | |
548 | // NOTE: |
|
548 | // NOTE: | |
549 | // This test is the same as tst_qpieslice::hoverSignal() |
|
549 | // This test is the same as tst_qpieslice::hoverSignal() | |
550 | // Just for different signals. |
|
550 | // Just for different signals. | |
551 |
|
551 | |||
552 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); |
|
552 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | |
553 |
|
553 | |||
554 | // add some slices |
|
554 | // add some slices | |
555 | m_series->append("slice 1", 1); |
|
555 | m_series->append("slice 1", 1); | |
556 | m_series->append("slice 2", 1); |
|
556 | m_series->append("slice 2", 1); | |
557 | m_series->append("slice 3", 1); |
|
557 | m_series->append("slice 3", 1); | |
558 | m_series->append("slice 4", 1); |
|
558 | m_series->append("slice 4", 1); | |
559 |
|
559 | |||
560 | // add series to the chart |
|
560 | // add series to the chart | |
561 | m_view->chart()->legend()->setVisible(false); |
|
561 | m_view->chart()->legend()->setVisible(false); | |
562 | m_view->chart()->addSeries(m_series); |
|
562 | m_view->chart()->addSeries(m_series); | |
563 | m_view->show(); |
|
563 | m_view->show(); | |
564 | QTest::qWaitForWindowShown(m_view); |
|
564 | QTest::qWaitForWindowShown(m_view); | |
565 |
|
565 | |||
566 | // move inside the slices |
|
566 | // move inside the slices | |
567 | m_series->setPieSize(1.0); |
|
567 | m_series->setPieSize(1.0); | |
568 | QRectF pieRect = m_view->chart()->plotArea(); |
|
568 | QRectF pieRect = m_view->chart()->plotArea(); | |
569 | QList<QPoint> points = slicePoints(pieRect); |
|
569 | QList<QPoint> points = slicePoints(pieRect); | |
570 | QTest::mouseMove(m_view->viewport(), pieRect.topRight().toPoint()); |
|
570 | QTest::mouseMove(m_view->viewport(), pieRect.topRight().toPoint()); | |
571 | QSignalSpy hoverSpy(m_series, SIGNAL(hovered(QPieSlice*,bool))); |
|
571 | QSignalSpy hoverSpy(m_series, SIGNAL(hovered(QPieSlice*,bool))); | |
572 | QTest::mouseMove(m_view->viewport(), points.at(0)); |
|
572 | QTest::mouseMove(m_view->viewport(), points.at(0)); | |
573 | QTest::mouseMove(m_view->viewport(), points.at(1)); |
|
573 | QTest::mouseMove(m_view->viewport(), points.at(1)); | |
574 | QTest::mouseMove(m_view->viewport(), points.at(2)); |
|
574 | QTest::mouseMove(m_view->viewport(), points.at(2)); | |
575 | QTest::mouseMove(m_view->viewport(), points.at(3)); |
|
575 | QTest::mouseMove(m_view->viewport(), points.at(3)); | |
576 | QTest::mouseMove(m_view->viewport(), pieRect.topLeft().toPoint()); |
|
576 | QTest::mouseMove(m_view->viewport(), pieRect.topLeft().toPoint()); | |
|
577 | QApplication::processEvents(); | |||
577 |
|
578 | |||
578 | // check |
|
579 | // check | |
579 | QCOMPARE(hoverSpy.count(), 8); |
|
580 | QCOMPARE(hoverSpy.count(), 8); | |
580 | int i = 0; |
|
581 | int i = 0; | |
581 | foreach (QPieSlice *s, m_series->slices()) { |
|
582 | foreach (QPieSlice *s, m_series->slices()) { | |
582 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(i).at(0)), s); |
|
583 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(i).at(0)), s); | |
583 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(i).at(1)), true); |
|
584 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(i).at(1)), true); | |
584 | i++; |
|
585 | i++; | |
585 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(i).at(0)), s); |
|
586 | QCOMPARE(qvariant_cast<QPieSlice*>(hoverSpy.at(i).at(0)), s); | |
586 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(i).at(1)), false); |
|
587 | QCOMPARE(qvariant_cast<bool>(hoverSpy.at(i).at(1)), false); | |
587 | i++; |
|
588 | i++; | |
588 | } |
|
589 | } | |
589 | } |
|
590 | } | |
590 |
|
591 | |||
591 | void tst_qpieseries::sliceSeries() |
|
592 | void tst_qpieseries::sliceSeries() | |
592 | { |
|
593 | { | |
593 | QPieSlice *slice = new QPieSlice(); |
|
594 | QPieSlice *slice = new QPieSlice(); | |
594 | QVERIFY(!slice->series()); |
|
595 | QVERIFY(!slice->series()); | |
595 | delete slice; |
|
596 | delete slice; | |
596 |
|
597 | |||
597 | slice = new QPieSlice(m_series); |
|
598 | slice = new QPieSlice(m_series); | |
598 | QVERIFY(!slice->series()); |
|
599 | QVERIFY(!slice->series()); | |
599 |
|
600 | |||
600 | m_series->append(slice); |
|
601 | m_series->append(slice); | |
601 | QCOMPARE(slice->series(), m_series); |
|
602 | QCOMPARE(slice->series(), m_series); | |
602 |
|
603 | |||
603 | slice = new QPieSlice(); |
|
604 | slice = new QPieSlice(); | |
604 | m_series->insert(0, slice); |
|
605 | m_series->insert(0, slice); | |
605 | QCOMPARE(slice->series(), m_series); |
|
606 | QCOMPARE(slice->series(), m_series); | |
606 |
|
607 | |||
607 | m_series->take(slice); |
|
608 | m_series->take(slice); | |
608 | QCOMPARE(slice->series(), (QPieSeries*) 0); |
|
609 | QCOMPARE(slice->series(), (QPieSeries*) 0); | |
609 | } |
|
610 | } | |
610 |
|
611 | |||
611 | void tst_qpieseries::destruction() |
|
612 | void tst_qpieseries::destruction() | |
612 | { |
|
613 | { | |
613 | // add some slices |
|
614 | // add some slices | |
614 | QPieSlice *slice1 = m_series->append("slice 1", 1); |
|
615 | QPieSlice *slice1 = m_series->append("slice 1", 1); | |
615 | QPieSlice *slice2 = m_series->append("slice 2", 2); |
|
616 | QPieSlice *slice2 = m_series->append("slice 2", 2); | |
616 | QPieSlice *slice3 = m_series->append("slice 3", 3); |
|
617 | QPieSlice *slice3 = m_series->append("slice 3", 3); | |
617 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); |
|
618 | QSignalSpy spy1(slice1, SIGNAL(destroyed())); | |
618 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); |
|
619 | QSignalSpy spy2(slice2, SIGNAL(destroyed())); | |
619 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); |
|
620 | QSignalSpy spy3(slice3, SIGNAL(destroyed())); | |
620 |
|
621 | |||
621 | // destroy series |
|
622 | // destroy series | |
622 | delete m_series; |
|
623 | delete m_series; | |
623 | m_series = 0; |
|
624 | m_series = 0; | |
624 |
|
625 | |||
625 | // check that series has destroyed its slices |
|
626 | // check that series has destroyed its slices | |
626 | QCOMPARE(spy1.count(), 1); |
|
627 | QCOMPARE(spy1.count(), 1); | |
627 | QCOMPARE(spy2.count(), 1); |
|
628 | QCOMPARE(spy2.count(), 1); | |
628 | QCOMPARE(spy3.count(), 1); |
|
629 | QCOMPARE(spy3.count(), 1); | |
629 | } |
|
630 | } | |
630 |
|
631 | |||
631 | QList<QPoint> tst_qpieseries::slicePoints(QRectF rect) |
|
632 | QList<QPoint> tst_qpieseries::slicePoints(QRectF rect) | |
632 | { |
|
633 | { | |
633 | qreal x1 = rect.topLeft().x() + (rect.width() / 4); |
|
634 | qreal x1 = rect.topLeft().x() + (rect.width() / 4); | |
634 | qreal x2 = rect.topLeft().x() + (rect.width() / 4) * 3; |
|
635 | qreal x2 = rect.topLeft().x() + (rect.width() / 4) * 3; | |
635 | qreal y1 = rect.topLeft().y() + (rect.height() / 4); |
|
636 | qreal y1 = rect.topLeft().y() + (rect.height() / 4); | |
636 | qreal y2 = rect.topLeft().y() + (rect.height() / 4) * 3; |
|
637 | qreal y2 = rect.topLeft().y() + (rect.height() / 4) * 3; | |
637 | QList<QPoint> points; |
|
638 | QList<QPoint> points; | |
638 | points << QPoint(x2, y1); |
|
639 | points << QPoint(x2, y1); | |
639 | points << QPoint(x2, y2); |
|
640 | points << QPoint(x2, y2); | |
640 | points << QPoint(x1, y2); |
|
641 | points << QPoint(x1, y2); | |
641 | points << QPoint(x1, y1); |
|
642 | points << QPoint(x1, y1); | |
642 | return points; |
|
643 | return points; | |
643 | } |
|
644 | } | |
644 |
|
645 | |||
645 | QTEST_MAIN(tst_qpieseries) |
|
646 | QTEST_MAIN(tst_qpieseries) | |
646 |
|
647 | |||
647 | #include "tst_qpieseries.moc" |
|
648 | #include "tst_qpieseries.moc" | |
648 |
|
649 |
@@ -1,331 +1,332 | |||||
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 clickedSignal(); |
|
44 | void clickedSignal(); | |
45 | void hoverSignal(); |
|
45 | void hoverSignal(); | |
46 |
|
46 | |||
47 | private: |
|
47 | private: | |
48 | QList<QPoint> slicePoints(QRectF rect); |
|
48 | QList<QPoint> slicePoints(QRectF rect); | |
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 | QCOMPARE(slice1.value(), 0.0); |
|
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.labelBrush(), QBrush()); |
|
82 | QCOMPARE(slice1.labelBrush(), QBrush()); | |
83 | QCOMPARE(slice1.labelFont(), QFont()); |
|
83 | QCOMPARE(slice1.labelFont(), QFont()); | |
84 | QCOMPARE(slice1.labelArmLengthFactor(), 0.15); // default value |
|
84 | QCOMPARE(slice1.labelArmLengthFactor(), 0.15); // default value | |
85 | QCOMPARE(slice1.explodeDistanceFactor(), 0.15); // default value |
|
85 | QCOMPARE(slice1.explodeDistanceFactor(), 0.15); // default value | |
86 | QCOMPARE(slice1.percentage(), 0.0); |
|
86 | QCOMPARE(slice1.percentage(), 0.0); | |
87 | QCOMPARE(slice1.startAngle(), 0.0); |
|
87 | QCOMPARE(slice1.startAngle(), 0.0); | |
88 | QCOMPARE(slice1.angleSpan(), 0.0); |
|
88 | QCOMPARE(slice1.angleSpan(), 0.0); | |
89 |
|
89 | |||
90 | // value and label params |
|
90 | // value and label params | |
91 | QPieSlice slice2("foobar", 1.0); |
|
91 | QPieSlice slice2("foobar", 1.0); | |
92 | QCOMPARE(slice2.value(), 1.0); |
|
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.labelBrush(), QBrush()); |
|
98 | QCOMPARE(slice2.labelBrush(), QBrush()); | |
99 | QCOMPARE(slice2.labelFont(), QFont()); |
|
99 | QCOMPARE(slice2.labelFont(), QFont()); | |
100 | QCOMPARE(slice2.labelArmLengthFactor(), 0.15); // default value |
|
100 | QCOMPARE(slice2.labelArmLengthFactor(), 0.15); // default value | |
101 | QCOMPARE(slice2.explodeDistanceFactor(), 0.15); // default value |
|
101 | QCOMPARE(slice2.explodeDistanceFactor(), 0.15); // default value | |
102 | QCOMPARE(slice2.percentage(), 0.0); |
|
102 | QCOMPARE(slice2.percentage(), 0.0); | |
103 | QCOMPARE(slice2.startAngle(), 0.0); |
|
103 | QCOMPARE(slice2.startAngle(), 0.0); | |
104 | QCOMPARE(slice2.angleSpan(), 0.0); |
|
104 | QCOMPARE(slice2.angleSpan(), 0.0); | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | void tst_qpieslice::changedSignals() |
|
107 | void tst_qpieslice::changedSignals() | |
108 | { |
|
108 | { | |
109 | QPieSlice slice; |
|
109 | QPieSlice slice; | |
110 |
|
110 | |||
111 | QSignalSpy valueSpy(&slice, SIGNAL(valueChanged())); |
|
111 | QSignalSpy valueSpy(&slice, SIGNAL(valueChanged())); | |
112 | QSignalSpy labelSpy(&slice, SIGNAL(labelChanged())); |
|
112 | QSignalSpy labelSpy(&slice, SIGNAL(labelChanged())); | |
113 | QSignalSpy penSpy(&slice, SIGNAL(penChanged())); |
|
113 | QSignalSpy penSpy(&slice, SIGNAL(penChanged())); | |
114 | QSignalSpy brushSpy(&slice, SIGNAL(brushChanged())); |
|
114 | QSignalSpy brushSpy(&slice, SIGNAL(brushChanged())); | |
115 | QSignalSpy labelBrushSpy(&slice, SIGNAL(labelBrushChanged())); |
|
115 | QSignalSpy labelBrushSpy(&slice, SIGNAL(labelBrushChanged())); | |
116 | QSignalSpy labelFontSpy(&slice, SIGNAL(labelFontChanged())); |
|
116 | QSignalSpy labelFontSpy(&slice, SIGNAL(labelFontChanged())); | |
117 | QSignalSpy colorSpy(&slice, SIGNAL(colorChanged())); |
|
117 | QSignalSpy colorSpy(&slice, SIGNAL(colorChanged())); | |
118 | QSignalSpy borderColorSpy(&slice, SIGNAL(borderColorChanged())); |
|
118 | QSignalSpy borderColorSpy(&slice, SIGNAL(borderColorChanged())); | |
119 | QSignalSpy borderWidthSpy(&slice, SIGNAL(borderWidthChanged())); |
|
119 | QSignalSpy borderWidthSpy(&slice, SIGNAL(borderWidthChanged())); | |
120 | QSignalSpy labelColorSpy(&slice, SIGNAL(labelColorChanged())); |
|
120 | QSignalSpy labelColorSpy(&slice, SIGNAL(labelColorChanged())); | |
121 |
|
121 | |||
122 | // percentageChanged(), startAngleChanged() and angleSpanChanged() signals tested at tst_qpieseries::calculatedValues() |
|
122 | // percentageChanged(), startAngleChanged() and angleSpanChanged() signals tested at tst_qpieseries::calculatedValues() | |
123 |
|
123 | |||
124 | // set everything twice to see we do not get unnecessary signals |
|
124 | // set everything twice to see we do not get unnecessary signals | |
125 | slice.setValue(1.0); |
|
125 | slice.setValue(1.0); | |
126 | slice.setValue(-1.0); |
|
126 | slice.setValue(-1.0); | |
127 | QCOMPARE(slice.value(), 1.0); |
|
127 | QCOMPARE(slice.value(), 1.0); | |
128 | slice.setLabel("foobar"); |
|
128 | slice.setLabel("foobar"); | |
129 | slice.setLabel("foobar"); |
|
129 | slice.setLabel("foobar"); | |
130 | slice.setLabelVisible(); |
|
130 | slice.setLabelVisible(); | |
131 | slice.setLabelVisible(); |
|
131 | slice.setLabelVisible(); | |
132 | slice.setExploded(); |
|
132 | slice.setExploded(); | |
133 | slice.setExploded(); |
|
133 | slice.setExploded(); | |
134 | slice.setPen(QPen(Qt::red)); |
|
134 | slice.setPen(QPen(Qt::red)); | |
135 | slice.setPen(QPen(QBrush(Qt::red), 3)); |
|
135 | slice.setPen(QPen(QBrush(Qt::red), 3)); | |
136 | slice.setBrush(QBrush(Qt::red)); |
|
136 | slice.setBrush(QBrush(Qt::red)); | |
137 | slice.setBrush(QBrush(Qt::red)); |
|
137 | slice.setBrush(QBrush(Qt::red)); | |
138 | slice.setLabelBrush(QBrush(Qt::green)); |
|
138 | slice.setLabelBrush(QBrush(Qt::green)); | |
139 | slice.setLabelBrush(QBrush(Qt::green)); |
|
139 | slice.setLabelBrush(QBrush(Qt::green)); | |
140 | slice.setLabelFont(QFont("Tahoma")); |
|
140 | slice.setLabelFont(QFont("Tahoma")); | |
141 | slice.setLabelFont(QFont("Tahoma")); |
|
141 | slice.setLabelFont(QFont("Tahoma")); | |
142 | slice.setLabelPosition(QPieSlice::LabelInsideHorizontal); |
|
142 | slice.setLabelPosition(QPieSlice::LabelInsideHorizontal); | |
143 | slice.setLabelPosition(QPieSlice::LabelInsideHorizontal); |
|
143 | slice.setLabelPosition(QPieSlice::LabelInsideHorizontal); | |
144 | slice.setLabelArmLengthFactor(0.1); |
|
144 | slice.setLabelArmLengthFactor(0.1); | |
145 | slice.setLabelArmLengthFactor(0.1); |
|
145 | slice.setLabelArmLengthFactor(0.1); | |
146 | slice.setExplodeDistanceFactor(0.1); |
|
146 | slice.setExplodeDistanceFactor(0.1); | |
147 | slice.setExplodeDistanceFactor(0.1); |
|
147 | slice.setExplodeDistanceFactor(0.1); | |
148 |
|
148 | |||
149 | TRY_COMPARE(valueSpy.count(), 1); |
|
149 | TRY_COMPARE(valueSpy.count(), 1); | |
150 | TRY_COMPARE(labelSpy.count(), 1); |
|
150 | TRY_COMPARE(labelSpy.count(), 1); | |
151 | TRY_COMPARE(penSpy.count(), 2); |
|
151 | TRY_COMPARE(penSpy.count(), 2); | |
152 | TRY_COMPARE(brushSpy.count(), 1); |
|
152 | TRY_COMPARE(brushSpy.count(), 1); | |
153 | TRY_COMPARE(labelBrushSpy.count(), 1); |
|
153 | TRY_COMPARE(labelBrushSpy.count(), 1); | |
154 | TRY_COMPARE(labelFontSpy.count(), 1); |
|
154 | TRY_COMPARE(labelFontSpy.count(), 1); | |
155 | TRY_COMPARE(colorSpy.count(), 1); |
|
155 | TRY_COMPARE(colorSpy.count(), 1); | |
156 | TRY_COMPARE(borderColorSpy.count(), 1); |
|
156 | TRY_COMPARE(borderColorSpy.count(), 1); | |
157 | TRY_COMPARE(borderWidthSpy.count(), 1); |
|
157 | TRY_COMPARE(borderWidthSpy.count(), 1); | |
158 | TRY_COMPARE(labelColorSpy.count(), 1); |
|
158 | TRY_COMPARE(labelColorSpy.count(), 1); | |
159 | } |
|
159 | } | |
160 |
|
160 | |||
161 | void tst_qpieslice::customize() |
|
161 | void tst_qpieslice::customize() | |
162 | { |
|
162 | { | |
163 | // create a pie series |
|
163 | // create a pie series | |
164 | QPieSeries *series = new QPieSeries(); |
|
164 | QPieSeries *series = new QPieSeries(); | |
165 | QPieSlice *s1 = series->append("slice 1", 1); |
|
165 | QPieSlice *s1 = series->append("slice 1", 1); | |
166 | QPieSlice *s2 = series->append("slice 2", 2); |
|
166 | QPieSlice *s2 = series->append("slice 2", 2); | |
167 | series->append("slice 3", 3); |
|
167 | series->append("slice 3", 3); | |
168 |
|
168 | |||
169 | // customize a slice |
|
169 | // customize a slice | |
170 | QPen p1(Qt::red); |
|
170 | QPen p1(Qt::red); | |
171 | s1->setPen(p1); |
|
171 | s1->setPen(p1); | |
172 | QBrush b1(Qt::red); |
|
172 | QBrush b1(Qt::red); | |
173 | s1->setBrush(b1); |
|
173 | s1->setBrush(b1); | |
174 | s1->setLabelBrush(b1); |
|
174 | s1->setLabelBrush(b1); | |
175 | QFont f1("Consolas"); |
|
175 | QFont f1("Consolas"); | |
176 | s1->setLabelFont(f1); |
|
176 | s1->setLabelFont(f1); | |
177 |
|
177 | |||
178 | // add series to the chart |
|
178 | // add series to the chart | |
179 | QChartView view(new QChart()); |
|
179 | QChartView view(new QChart()); | |
180 | view.resize(200, 200); |
|
180 | view.resize(200, 200); | |
181 | view.chart()->addSeries(series); |
|
181 | view.chart()->addSeries(series); | |
182 | view.show(); |
|
182 | view.show(); | |
183 | QTest::qWaitForWindowShown(&view); |
|
183 | QTest::qWaitForWindowShown(&view); | |
184 | //QTest::qWait(1000); |
|
184 | //QTest::qWait(1000); | |
185 |
|
185 | |||
186 | // check that customizations persist |
|
186 | // check that customizations persist | |
187 | QCOMPARE(s1->pen(), p1); |
|
187 | QCOMPARE(s1->pen(), p1); | |
188 | QCOMPARE(s1->brush(), b1); |
|
188 | QCOMPARE(s1->brush(), b1); | |
189 | QCOMPARE(s1->labelBrush(), b1); |
|
189 | QCOMPARE(s1->labelBrush(), b1); | |
190 | QCOMPARE(s1->labelFont(), f1); |
|
190 | QCOMPARE(s1->labelFont(), f1); | |
191 |
|
191 | |||
192 | // remove a slice |
|
192 | // remove a slice | |
193 | series->remove(s2); |
|
193 | series->remove(s2); | |
194 | QCOMPARE(s1->pen(), p1); |
|
194 | QCOMPARE(s1->pen(), p1); | |
195 | QCOMPARE(s1->brush(), b1); |
|
195 | QCOMPARE(s1->brush(), b1); | |
196 | QCOMPARE(s1->labelBrush(), b1); |
|
196 | QCOMPARE(s1->labelBrush(), b1); | |
197 | QCOMPARE(s1->labelFont(), f1); |
|
197 | QCOMPARE(s1->labelFont(), f1); | |
198 |
|
198 | |||
199 | // add a slice |
|
199 | // add a slice | |
200 | series->append("slice 4", 4); |
|
200 | series->append("slice 4", 4); | |
201 | QCOMPARE(s1->pen(), p1); |
|
201 | QCOMPARE(s1->pen(), p1); | |
202 | QCOMPARE(s1->brush(), b1); |
|
202 | QCOMPARE(s1->brush(), b1); | |
203 | QCOMPARE(s1->labelBrush(), b1); |
|
203 | QCOMPARE(s1->labelBrush(), b1); | |
204 | QCOMPARE(s1->labelFont(), f1); |
|
204 | QCOMPARE(s1->labelFont(), f1); | |
205 |
|
205 | |||
206 | // insert a slice |
|
206 | // insert a slice | |
207 | series->insert(0, new QPieSlice("slice 5", 5)); |
|
207 | series->insert(0, new QPieSlice("slice 5", 5)); | |
208 | QCOMPARE(s1->pen(), p1); |
|
208 | QCOMPARE(s1->pen(), p1); | |
209 | QCOMPARE(s1->brush(), b1); |
|
209 | QCOMPARE(s1->brush(), b1); | |
210 | QCOMPARE(s1->labelBrush(), b1); |
|
210 | QCOMPARE(s1->labelBrush(), b1); | |
211 | QCOMPARE(s1->labelFont(), f1); |
|
211 | QCOMPARE(s1->labelFont(), f1); | |
212 |
|
212 | |||
213 | // change theme |
|
213 | // change theme | |
214 | // theme will overwrite customizations |
|
214 | // theme will overwrite customizations | |
215 | view.chart()->setTheme(QChart::ChartThemeHighContrast); |
|
215 | view.chart()->setTheme(QChart::ChartThemeHighContrast); | |
216 | QVERIFY(s1->pen() != p1); |
|
216 | QVERIFY(s1->pen() != p1); | |
217 | QVERIFY(s1->brush() != b1); |
|
217 | QVERIFY(s1->brush() != b1); | |
218 | QVERIFY(s1->labelBrush() != b1); |
|
218 | QVERIFY(s1->labelBrush() != b1); | |
219 | QVERIFY(s1->labelFont() != f1); |
|
219 | QVERIFY(s1->labelFont() != f1); | |
220 | } |
|
220 | } | |
221 |
|
221 | |||
222 | void tst_qpieslice::clickedSignal() |
|
222 | void tst_qpieslice::clickedSignal() | |
223 | { |
|
223 | { | |
224 | // NOTE: |
|
224 | // NOTE: | |
225 | // This test is the same as tst_qpieseries::clickedSignal() |
|
225 | // This test is the same as tst_qpieseries::clickedSignal() | |
226 | // Just for different signals. |
|
226 | // Just for different signals. | |
227 |
|
227 | |||
228 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); |
|
228 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | |
229 |
|
229 | |||
230 | // create a pie series |
|
230 | // create a pie series | |
231 | QPieSeries *series = new QPieSeries(); |
|
231 | QPieSeries *series = new QPieSeries(); | |
232 | QPieSlice *s1 = series->append("slice 1", 1); |
|
232 | QPieSlice *s1 = series->append("slice 1", 1); | |
233 | QPieSlice *s2 = series->append("slice 2", 1); |
|
233 | QPieSlice *s2 = series->append("slice 2", 1); | |
234 | QPieSlice *s3 = series->append("slice 3", 1); |
|
234 | QPieSlice *s3 = series->append("slice 3", 1); | |
235 | QPieSlice *s4 = series->append("slice 4", 1); |
|
235 | QPieSlice *s4 = series->append("slice 4", 1); | |
236 | QSignalSpy clickSpy1(s1, SIGNAL(clicked())); |
|
236 | QSignalSpy clickSpy1(s1, SIGNAL(clicked())); | |
237 | QSignalSpy clickSpy2(s2, SIGNAL(clicked())); |
|
237 | QSignalSpy clickSpy2(s2, SIGNAL(clicked())); | |
238 | QSignalSpy clickSpy3(s3, SIGNAL(clicked())); |
|
238 | QSignalSpy clickSpy3(s3, SIGNAL(clicked())); | |
239 | QSignalSpy clickSpy4(s4, SIGNAL(clicked())); |
|
239 | QSignalSpy clickSpy4(s4, SIGNAL(clicked())); | |
240 |
|
240 | |||
241 | // add series to the chart |
|
241 | // add series to the chart | |
242 | QChartView view; |
|
242 | QChartView view; | |
243 | view.chart()->legend()->setVisible(false); |
|
243 | view.chart()->legend()->setVisible(false); | |
244 | view.chart()->addSeries(series); |
|
244 | view.chart()->addSeries(series); | |
245 | view.show(); |
|
245 | view.show(); | |
246 | QTest::qWaitForWindowShown(&view); |
|
246 | QTest::qWaitForWindowShown(&view); | |
247 |
|
247 | |||
248 | // simulate clicks |
|
248 | // simulate clicks | |
249 | series->setPieSize(1.0); |
|
249 | series->setPieSize(1.0); | |
250 | QRectF pieRect = view.chart()->plotArea(); |
|
250 | QRectF pieRect = view.chart()->plotArea(); | |
251 | QList<QPoint> points = slicePoints(pieRect); |
|
251 | QList<QPoint> points = slicePoints(pieRect); | |
252 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(0)); |
|
252 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(0)); | |
253 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(1)); |
|
253 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(1)); | |
254 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(2)); |
|
254 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(2)); | |
255 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(3)); |
|
255 | QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, points.at(3)); | |
256 | QCOMPARE(clickSpy1.count(), 1); |
|
256 | QCOMPARE(clickSpy1.count(), 1); | |
257 | QCOMPARE(clickSpy2.count(), 1); |
|
257 | QCOMPARE(clickSpy2.count(), 1); | |
258 | QCOMPARE(clickSpy3.count(), 1); |
|
258 | QCOMPARE(clickSpy3.count(), 1); | |
259 | QCOMPARE(clickSpy4.count(), 1); |
|
259 | QCOMPARE(clickSpy4.count(), 1); | |
260 | } |
|
260 | } | |
261 |
|
261 | |||
262 | void tst_qpieslice::hoverSignal() |
|
262 | void tst_qpieslice::hoverSignal() | |
263 | { |
|
263 | { | |
264 | // NOTE: |
|
264 | // NOTE: | |
265 | // This test is the same as tst_qpieseries::hoverSignal() |
|
265 | // This test is the same as tst_qpieseries::hoverSignal() | |
266 | // Just for different signals. |
|
266 | // Just for different signals. | |
267 |
|
267 | |||
268 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); |
|
268 | SKIP_IF_CANNOT_TEST_MOUSE_EVENTS(); | |
269 |
|
269 | |||
270 | // add some slices |
|
270 | // add some slices | |
271 | QPieSeries *series = new QPieSeries(); |
|
271 | QPieSeries *series = new QPieSeries(); | |
272 | QPieSlice *s1 = series->append("slice 1", 1); |
|
272 | QPieSlice *s1 = series->append("slice 1", 1); | |
273 | QPieSlice *s2 = series->append("slice 2", 1); |
|
273 | QPieSlice *s2 = series->append("slice 2", 1); | |
274 | QPieSlice *s3 = series->append("slice 3", 1); |
|
274 | QPieSlice *s3 = series->append("slice 3", 1); | |
275 | QPieSlice *s4 = series->append("slice 4", 1); |
|
275 | QPieSlice *s4 = series->append("slice 4", 1); | |
276 |
|
276 | |||
277 | // add series to the chart |
|
277 | // add series to the chart | |
278 | QChartView view; |
|
278 | QChartView view; | |
279 | view.chart()->legend()->setVisible(false); |
|
279 | view.chart()->legend()->setVisible(false); | |
280 | view.chart()->addSeries(series); |
|
280 | view.chart()->addSeries(series); | |
281 | view.show(); |
|
281 | view.show(); | |
282 | QTest::qWaitForWindowShown(&view); |
|
282 | QTest::qWaitForWindowShown(&view); | |
283 |
|
283 | |||
284 | // move inside the slices |
|
284 | // move inside the slices | |
285 | series->setPieSize(1.0); |
|
285 | series->setPieSize(1.0); | |
286 | QRectF pieRect = view.chart()->plotArea(); |
|
286 | QRectF pieRect = view.chart()->plotArea(); | |
287 | QList<QPoint> points = slicePoints(pieRect); |
|
287 | QList<QPoint> points = slicePoints(pieRect); | |
288 | QTest::mouseMove(view.viewport(), pieRect.topRight().toPoint()); |
|
288 | QTest::mouseMove(view.viewport(), pieRect.topRight().toPoint()); | |
289 | QSignalSpy hoverSpy1(s1, SIGNAL(hovered(bool))); |
|
289 | QSignalSpy hoverSpy1(s1, SIGNAL(hovered(bool))); | |
290 | QSignalSpy hoverSpy2(s2, SIGNAL(hovered(bool))); |
|
290 | QSignalSpy hoverSpy2(s2, SIGNAL(hovered(bool))); | |
291 | QSignalSpy hoverSpy3(s3, SIGNAL(hovered(bool))); |
|
291 | QSignalSpy hoverSpy3(s3, SIGNAL(hovered(bool))); | |
292 | QSignalSpy hoverSpy4(s4, SIGNAL(hovered(bool))); |
|
292 | QSignalSpy hoverSpy4(s4, SIGNAL(hovered(bool))); | |
293 | QTest::mouseMove(view.viewport(), points.at(0)); |
|
293 | QTest::mouseMove(view.viewport(), points.at(0)); | |
294 | QTest::mouseMove(view.viewport(), points.at(1)); |
|
294 | QTest::mouseMove(view.viewport(), points.at(1)); | |
295 | QTest::mouseMove(view.viewport(), points.at(2)); |
|
295 | QTest::mouseMove(view.viewport(), points.at(2)); | |
296 | QTest::mouseMove(view.viewport(), points.at(3)); |
|
296 | QTest::mouseMove(view.viewport(), points.at(3)); | |
297 | QTest::mouseMove(view.viewport(), pieRect.topLeft().toPoint()); |
|
297 | QTest::mouseMove(view.viewport(), pieRect.topLeft().toPoint()); | |
|
298 | QApplication::processEvents(); | |||
298 |
|
299 | |||
299 | // check |
|
300 | // check | |
300 | QCOMPARE(hoverSpy1.count(), 2); |
|
301 | QCOMPARE(hoverSpy1.count(), 2); | |
301 | QCOMPARE(qvariant_cast<bool>(hoverSpy1.at(0).at(0)), true); |
|
302 | QCOMPARE(qvariant_cast<bool>(hoverSpy1.at(0).at(0)), true); | |
302 | QCOMPARE(qvariant_cast<bool>(hoverSpy1.at(1).at(0)), false); |
|
303 | QCOMPARE(qvariant_cast<bool>(hoverSpy1.at(1).at(0)), false); | |
303 | QCOMPARE(hoverSpy2.count(), 2); |
|
304 | QCOMPARE(hoverSpy2.count(), 2); | |
304 | QCOMPARE(qvariant_cast<bool>(hoverSpy2.at(0).at(0)), true); |
|
305 | QCOMPARE(qvariant_cast<bool>(hoverSpy2.at(0).at(0)), true); | |
305 | QCOMPARE(qvariant_cast<bool>(hoverSpy2.at(1).at(0)), false); |
|
306 | QCOMPARE(qvariant_cast<bool>(hoverSpy2.at(1).at(0)), false); | |
306 | QCOMPARE(hoverSpy3.count(), 2); |
|
307 | QCOMPARE(hoverSpy3.count(), 2); | |
307 | QCOMPARE(qvariant_cast<bool>(hoverSpy3.at(0).at(0)), true); |
|
308 | QCOMPARE(qvariant_cast<bool>(hoverSpy3.at(0).at(0)), true); | |
308 | QCOMPARE(qvariant_cast<bool>(hoverSpy3.at(1).at(0)), false); |
|
309 | QCOMPARE(qvariant_cast<bool>(hoverSpy3.at(1).at(0)), false); | |
309 | QCOMPARE(hoverSpy4.count(), 2); |
|
310 | QCOMPARE(hoverSpy4.count(), 2); | |
310 | QCOMPARE(qvariant_cast<bool>(hoverSpy4.at(0).at(0)), true); |
|
311 | QCOMPARE(qvariant_cast<bool>(hoverSpy4.at(0).at(0)), true); | |
311 | QCOMPARE(qvariant_cast<bool>(hoverSpy4.at(1).at(0)), false); |
|
312 | QCOMPARE(qvariant_cast<bool>(hoverSpy4.at(1).at(0)), false); | |
312 | } |
|
313 | } | |
313 |
|
314 | |||
314 | QList<QPoint> tst_qpieslice::slicePoints(QRectF rect) |
|
315 | QList<QPoint> tst_qpieslice::slicePoints(QRectF rect) | |
315 | { |
|
316 | { | |
316 | qreal x1 = rect.topLeft().x() + (rect.width() / 4); |
|
317 | qreal x1 = rect.topLeft().x() + (rect.width() / 4); | |
317 | qreal x2 = rect.topLeft().x() + (rect.width() / 4) * 3; |
|
318 | qreal x2 = rect.topLeft().x() + (rect.width() / 4) * 3; | |
318 | qreal y1 = rect.topLeft().y() + (rect.height() / 4); |
|
319 | qreal y1 = rect.topLeft().y() + (rect.height() / 4); | |
319 | qreal y2 = rect.topLeft().y() + (rect.height() / 4) * 3; |
|
320 | qreal y2 = rect.topLeft().y() + (rect.height() / 4) * 3; | |
320 | QList<QPoint> points; |
|
321 | QList<QPoint> points; | |
321 | points << QPoint(x2, y1); |
|
322 | points << QPoint(x2, y1); | |
322 | points << QPoint(x2, y2); |
|
323 | points << QPoint(x2, y2); | |
323 | points << QPoint(x1, y2); |
|
324 | points << QPoint(x1, y2); | |
324 | points << QPoint(x1, y1); |
|
325 | points << QPoint(x1, y1); | |
325 | return points; |
|
326 | return points; | |
326 | } |
|
327 | } | |
327 |
|
328 | |||
328 | QTEST_MAIN(tst_qpieslice) |
|
329 | QTEST_MAIN(tst_qpieslice) | |
329 |
|
330 | |||
330 | #include "tst_qpieslice.moc" |
|
331 | #include "tst_qpieslice.moc" | |
331 |
|
332 |
General Comments 0
You need to be logged in to leave comments.
Login now