1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Charts module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 or (at your option) any later version |
20 | ** approved by the KDE Free Qt Foundation. The licenses are as published by |
21 | ** the Free Software Foundation and appearing in the file LICENSE.GPL3 |
22 | ** included in the packaging of this file. Please review the following |
23 | ** information to ensure the GNU General Public License requirements will |
24 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
25 | ** |
26 | ** $QT_END_LICENSE$ |
27 | ** |
28 | ****************************************************************************/ |
29 | |
30 | #include <QtCore/QString> |
31 | #include <QtTest/QtTest> |
32 | |
33 | #include <QtCharts/QChart> |
34 | #include <QtCharts/QChartView> |
35 | #include <QtCharts/QPieSeries> |
36 | #include <QtCharts/QPieSlice> |
37 | #include <QtCharts/QVPieModelMapper> |
38 | #include <QtCharts/QHPieModelMapper> |
39 | #include <QtGui/QStandardItemModel> |
40 | |
41 | QT_CHARTS_USE_NAMESPACE |
42 | |
43 | class tst_qpiemodelmapper : public QObject |
44 | { |
45 | Q_OBJECT |
46 | |
47 | public: |
48 | tst_qpiemodelmapper(); |
49 | void createVerticalMapper(); |
50 | void createHorizontalMapper(); |
51 | |
52 | private Q_SLOTS: |
53 | void initTestCase(); |
54 | void cleanupTestCase(); |
55 | void init(); |
56 | void cleanup(); |
57 | void verticalMapper_data(); |
58 | void verticalMapper(); |
59 | void verticalMapperCustomMapping_data(); |
60 | void verticalMapperCustomMapping(); |
61 | void horizontalMapper_data(); |
62 | void horizontalMapper(); |
63 | void horizontalMapperCustomMapping_data(); |
64 | void horizontalMapperCustomMapping(); |
65 | void seriesUpdated(); |
66 | void verticalModelInsertRows(); |
67 | void verticalModelRemoveRows(); |
68 | void verticalModelInsertColumns(); |
69 | void verticalModelRemoveColumns(); |
70 | void horizontalModelInsertRows(); |
71 | void horizontalModelRemoveRows(); |
72 | void horizontalModelInsertColumns(); |
73 | void horizontalModelRemoveColumns(); |
74 | void modelUpdateCell(); |
75 | void verticalMapperSignals(); |
76 | void horizontalMapperSignals(); |
77 | |
78 | private: |
79 | QStandardItemModel *m_model; |
80 | int m_modelRowCount; |
81 | int m_modelColumnCount; |
82 | QVPieModelMapper *m_vMapper; |
83 | QHPieModelMapper *m_hMapper; |
84 | |
85 | QPieSeries *m_series; |
86 | QChart *m_chart; |
87 | QChartView *m_chartView; |
88 | }; |
89 | |
90 | tst_qpiemodelmapper::tst_qpiemodelmapper(): |
91 | m_model(0), |
92 | m_modelRowCount(10), |
93 | m_modelColumnCount(8), |
94 | m_vMapper(0), |
95 | m_hMapper(0), |
96 | m_series(0), |
97 | m_chart(0), |
98 | m_chartView(0) |
99 | { |
100 | } |
101 | |
102 | void tst_qpiemodelmapper::createVerticalMapper() |
103 | { |
104 | m_vMapper = new QVPieModelMapper; |
105 | QVERIFY(m_vMapper->model() == 0); |
106 | m_vMapper->setValuesColumn(0); |
107 | m_vMapper->setLabelsColumn(1); |
108 | m_vMapper->setModel(m_model); |
109 | m_vMapper->setSeries(m_series); |
110 | } |
111 | |
112 | void tst_qpiemodelmapper::createHorizontalMapper() |
113 | { |
114 | m_hMapper = new QHPieModelMapper; |
115 | QVERIFY(m_hMapper->model() == 0); |
116 | m_hMapper->setValuesRow(0); |
117 | m_hMapper->setLabelsRow(1); |
118 | m_hMapper->setModel(m_model); |
119 | m_hMapper->setSeries(m_series); |
120 | } |
121 | |
122 | void tst_qpiemodelmapper::init() |
123 | { |
124 | m_series = new QPieSeries; |
125 | m_chart->addSeries(series: m_series); |
126 | |
127 | m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this); |
128 | for (int row = 0; row < m_modelRowCount; ++row) { |
129 | for (int column = 0; column < m_modelColumnCount; column++) { |
130 | m_model->setData(index: m_model->index(row, column), value: row * column); |
131 | } |
132 | } |
133 | } |
134 | |
135 | void tst_qpiemodelmapper::cleanup() |
136 | { |
137 | m_chart->removeSeries(series: m_series); |
138 | m_series->deleteLater(); |
139 | m_series = 0; |
140 | |
141 | m_model->clear(); |
142 | m_model->deleteLater(); |
143 | m_model = 0; |
144 | |
145 | if (m_vMapper) { |
146 | m_vMapper->deleteLater(); |
147 | m_vMapper = 0; |
148 | } |
149 | |
150 | if (m_hMapper) { |
151 | m_hMapper->deleteLater(); |
152 | m_hMapper = 0; |
153 | } |
154 | } |
155 | |
156 | void tst_qpiemodelmapper::initTestCase() |
157 | { |
158 | m_chart = new QChart; |
159 | m_chartView = new QChartView(m_chart); |
160 | m_chartView->resize(w: 200, h: 200); |
161 | m_chartView->show(); |
162 | } |
163 | |
164 | void tst_qpiemodelmapper::cleanupTestCase() |
165 | { |
166 | delete m_chartView; |
167 | QTest::qWait(ms: 1); // Allow final deleteLaters to run |
168 | } |
169 | |
170 | void tst_qpiemodelmapper::verticalMapper_data() |
171 | { |
172 | QTest::addColumn<int>(name: "valuesColumn" ); |
173 | QTest::addColumn<int>(name: "labelsColumn" ); |
174 | QTest::addColumn<int>(name: "expectedCount" ); |
175 | QTest::newRow(dataTag: "different values and labels columns" ) << 0 << 1 << m_modelRowCount; |
176 | QTest::newRow(dataTag: "same values and labels columns" ) << 1 << 1 << m_modelRowCount; |
177 | QTest::newRow(dataTag: "invalid values column and correct labels column" ) << -3 << 1 << 0; |
178 | QTest::newRow(dataTag: "values column beyond the size of model and correct labels column" ) << m_modelColumnCount << 1 << 0; |
179 | QTest::newRow(dataTag: "values column beyond the size of model and invalid labels column" ) << m_modelColumnCount << -1 << 0; |
180 | } |
181 | |
182 | void tst_qpiemodelmapper::verticalMapper() |
183 | { |
184 | QFETCH(int, valuesColumn); |
185 | QFETCH(int, labelsColumn); |
186 | QFETCH(int, expectedCount); |
187 | |
188 | QVPieModelMapper *mapper = new QVPieModelMapper; |
189 | mapper->setValuesColumn(valuesColumn); |
190 | mapper->setLabelsColumn(labelsColumn); |
191 | mapper->setModel(m_model); |
192 | mapper->setSeries(m_series); |
193 | |
194 | QCOMPARE(m_series->count(), expectedCount); |
195 | QCOMPARE(mapper->valuesColumn(), qMax(-1, valuesColumn)); |
196 | QCOMPARE(mapper->labelsColumn(), qMax(-1, labelsColumn)); |
197 | |
198 | delete mapper; |
199 | mapper = 0; |
200 | } |
201 | |
202 | void tst_qpiemodelmapper::verticalMapperCustomMapping_data() |
203 | { |
204 | QTest::addColumn<int>(name: "first" ); |
205 | QTest::addColumn<int>(name: "countLimit" ); |
206 | QTest::addColumn<int>(name: "expectedCount" ); |
207 | QTest::newRow(dataTag: "first: 0, unlimited count" ) << 0 << -1 << m_modelRowCount; |
208 | QTest::newRow(dataTag: "first: 3, unlimited count" ) << 3 << -1 << m_modelRowCount - 3; |
209 | QTest::newRow(dataTag: "first: 0, count: 5" ) << 0 << 5 << qMin(a: 5, b: m_modelRowCount); |
210 | QTest::newRow(dataTag: "first: 3, count: 5" ) << 3 << 5 << qMin(a: 5, b: m_modelRowCount - 3); |
211 | QTest::newRow(dataTag: "first: +1 greater then the number of rows in the model, unlimited count" ) << m_modelRowCount + 1 << -1 << 0; |
212 | QTest::newRow(dataTag: "first: +1 greater then the number of rows in the model, count: 5" ) << m_modelRowCount + 1 << 5 << 0; |
213 | QTest::newRow(dataTag: "first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)" ) << 0 << m_modelRowCount + 3 << m_modelRowCount; |
214 | QTest::newRow(dataTag: "first: -3(invalid - should default to 0), unlimited count" ) << -3 << -1 << m_modelRowCount; |
215 | QTest::newRow(dataTag: "first: 0, count: -3 (invalid - shlould default to -1)" ) << 0 << -3 << m_modelRowCount; |
216 | QTest::newRow(dataTag: "first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)" ) << -3 << -3 << m_modelRowCount; |
217 | |
218 | } |
219 | |
220 | void tst_qpiemodelmapper::verticalMapperCustomMapping() |
221 | { |
222 | QFETCH(int, first); |
223 | QFETCH(int, countLimit); |
224 | QFETCH(int, expectedCount); |
225 | |
226 | QCOMPARE(m_series->count(), 0); |
227 | |
228 | QVPieModelMapper *mapper = new QVPieModelMapper; |
229 | mapper->setValuesColumn(0); |
230 | mapper->setLabelsColumn(1); |
231 | mapper->setModel(m_model); |
232 | mapper->setSeries(m_series); |
233 | mapper->setFirstRow(first); |
234 | mapper->setRowCount(countLimit); |
235 | |
236 | QCOMPARE(m_series->count(), expectedCount); |
237 | |
238 | // change values column mapping to invalid |
239 | mapper->setValuesColumn(-1); |
240 | mapper->setLabelsColumn(1); |
241 | |
242 | QCOMPARE(m_series->count(), 0); |
243 | |
244 | delete mapper; |
245 | mapper = 0; |
246 | } |
247 | |
248 | void tst_qpiemodelmapper::horizontalMapper_data() |
249 | { |
250 | QTest::addColumn<int>(name: "valuesRow" ); |
251 | QTest::addColumn<int>(name: "labelsRow" ); |
252 | QTest::addColumn<int>(name: "expectedCount" ); |
253 | QTest::newRow(dataTag: "different values and labels rows" ) << 0 << 1 << m_modelColumnCount; |
254 | QTest::newRow(dataTag: "same values and labels rows" ) << 1 << 1 << m_modelColumnCount; |
255 | QTest::newRow(dataTag: "invalid values row and correct labels row" ) << -3 << 1 << 0; |
256 | QTest::newRow(dataTag: "values row beyond the size of model and correct labels row" ) << m_modelRowCount << 1 << 0; |
257 | QTest::newRow(dataTag: "values row beyond the size of model and invalid labels row" ) << m_modelRowCount << -1 << 0; |
258 | } |
259 | |
260 | void tst_qpiemodelmapper::horizontalMapper() |
261 | { |
262 | QFETCH(int, valuesRow); |
263 | QFETCH(int, labelsRow); |
264 | QFETCH(int, expectedCount); |
265 | |
266 | QHPieModelMapper *mapper = new QHPieModelMapper; |
267 | mapper->setValuesRow(valuesRow); |
268 | mapper->setLabelsRow(labelsRow); |
269 | mapper->setModel(m_model); |
270 | mapper->setSeries(m_series); |
271 | |
272 | QCOMPARE(m_series->count(), expectedCount); |
273 | QCOMPARE(mapper->valuesRow(), qMax(-1, valuesRow)); |
274 | QCOMPARE(mapper->labelsRow(), qMax(-1, labelsRow)); |
275 | |
276 | delete mapper; |
277 | mapper = 0; |
278 | } |
279 | |
280 | void tst_qpiemodelmapper::horizontalMapperCustomMapping_data() |
281 | { |
282 | QTest::addColumn<int>(name: "first" ); |
283 | QTest::addColumn<int>(name: "countLimit" ); |
284 | QTest::addColumn<int>(name: "expectedCount" ); |
285 | QTest::newRow(dataTag: "first: 0, unlimited count" ) << 0 << -1 << m_modelColumnCount; |
286 | QTest::newRow(dataTag: "first: 3, unlimited count" ) << 3 << -1 << m_modelColumnCount - 3; |
287 | QTest::newRow(dataTag: "first: 0, count: 5" ) << 0 << 5 << qMin(a: 5, b: m_modelColumnCount); |
288 | QTest::newRow(dataTag: "first: 3, count: 5" ) << 3 << 5 << qMin(a: 5, b: m_modelColumnCount - 3); |
289 | QTest::newRow(dataTag: "first: +1 greater then the number of columns in the model, unlimited count" ) << m_modelColumnCount + 1 << -1 << 0; |
290 | QTest::newRow(dataTag: "first: +1 greater then the number of columns in the model, count: 5" ) << m_modelColumnCount + 1 << 5 << 0; |
291 | QTest::newRow(dataTag: "first: 0, count: +3 greater than the number of columns in the model (should limit to the size of model)" ) << 0 << m_modelColumnCount + 3 << m_modelColumnCount; |
292 | QTest::newRow(dataTag: "first: -3(invalid - should default to 0), unlimited count" ) << -3 << -1 << m_modelColumnCount; |
293 | QTest::newRow(dataTag: "first: 0, count: -3 (invalid - shlould default to -1)" ) << 0 << -3 << m_modelColumnCount; |
294 | QTest::newRow(dataTag: "first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)" ) << -3 << -3 << m_modelColumnCount; |
295 | } |
296 | |
297 | void tst_qpiemodelmapper::horizontalMapperCustomMapping() |
298 | { |
299 | QFETCH(int, first); |
300 | QFETCH(int, countLimit); |
301 | QFETCH(int, expectedCount); |
302 | |
303 | QCOMPARE(m_series->count(), 0); |
304 | |
305 | QHPieModelMapper *mapper = new QHPieModelMapper; |
306 | mapper->setValuesRow(0); |
307 | mapper->setLabelsRow(1); |
308 | mapper->setModel(m_model); |
309 | mapper->setSeries(m_series); |
310 | mapper->setFirstColumn(first); |
311 | mapper->setColumnCount(countLimit); |
312 | |
313 | QCOMPARE(m_series->count(), expectedCount); |
314 | |
315 | // change values row mapping to invalid |
316 | mapper->setValuesRow(-1); |
317 | mapper->setLabelsRow(1); |
318 | |
319 | QCOMPARE(m_series->count(), 0); |
320 | |
321 | delete mapper; |
322 | mapper = 0; |
323 | } |
324 | |
325 | void tst_qpiemodelmapper::seriesUpdated() |
326 | { |
327 | // setup the mapper |
328 | createVerticalMapper(); |
329 | QCOMPARE(m_series->count(), m_modelRowCount); |
330 | QCOMPARE(m_vMapper->rowCount(), -1); |
331 | |
332 | m_series->append(label: "1000" , value: 1000); |
333 | QCOMPARE(m_series->count(), m_modelRowCount + 1); |
334 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model |
335 | |
336 | m_series->remove(slice: m_series->slices().last()); |
337 | QCOMPARE(m_series->count(), m_modelRowCount); |
338 | QCOMPARE(m_vMapper->rowCount(), -1); // the value should not change as it indicates 'all' items there are in the model |
339 | |
340 | QPieSlice *slice = m_series->slices().first(); |
341 | slice->setValue(25.0); |
342 | slice->setLabel(QString("25.0" )); |
343 | QCOMPARE(m_model->data(m_model->index(0, 0)).toReal(), 25.0); |
344 | QCOMPARE(m_model->data(m_model->index(0, 1)).toString(), QString("25.0" )); |
345 | } |
346 | |
347 | void tst_qpiemodelmapper::verticalModelInsertRows() |
348 | { |
349 | // setup the mapper |
350 | createVerticalMapper(); |
351 | QCOMPARE(m_series->count(), m_modelRowCount); |
352 | QVERIFY(m_vMapper->model() != 0); |
353 | |
354 | int insertCount = 4; |
355 | m_model->insertRows(row: 3, count: insertCount); |
356 | QCOMPARE(m_series->count(), m_modelRowCount + insertCount); |
357 | |
358 | int first = 3; |
359 | m_vMapper->setFirstRow(3); |
360 | QCOMPARE(m_series->count(), m_modelRowCount + insertCount - first); |
361 | |
362 | m_model->insertRows(row: 3, count: insertCount); |
363 | QCOMPARE(m_series->count(), m_modelRowCount + 2 * insertCount - first); |
364 | |
365 | int countLimit = 6; |
366 | m_vMapper->setRowCount(countLimit); |
367 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first)); |
368 | |
369 | m_model->insertRows(row: 3, count: insertCount); |
370 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first)); |
371 | |
372 | m_vMapper->setFirstRow(0); |
373 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount)); |
374 | |
375 | m_vMapper->setRowCount(-1); |
376 | QCOMPARE(m_series->count(), m_modelRowCount + 3 * insertCount); |
377 | } |
378 | |
379 | void tst_qpiemodelmapper::verticalModelRemoveRows() |
380 | { |
381 | // setup the mapper |
382 | createVerticalMapper(); |
383 | QCOMPARE(m_series->count(), m_modelRowCount); |
384 | QVERIFY(m_vMapper->model() != 0); |
385 | |
386 | int removeCount = 2; |
387 | m_model->removeRows(row: 1, count: removeCount); |
388 | QCOMPARE(m_series->count(), m_modelRowCount - removeCount); |
389 | |
390 | int first = 1; |
391 | m_vMapper->setFirstRow(first); |
392 | QCOMPARE(m_series->count(), m_modelRowCount - removeCount - first); |
393 | |
394 | m_model->removeRows(row: 1, count: removeCount); |
395 | QCOMPARE(m_series->count(), m_modelRowCount - 2 * removeCount - first); |
396 | |
397 | int countLimit = 3; |
398 | m_vMapper->setRowCount(countLimit); |
399 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first)); |
400 | |
401 | m_model->removeRows(row: 1, count: removeCount); |
402 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first)); |
403 | |
404 | m_vMapper->setFirstRow(0); |
405 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount)); |
406 | |
407 | m_vMapper->setRowCount(-1); |
408 | QCOMPARE(m_series->count(), m_modelRowCount - 3 * removeCount); |
409 | } |
410 | |
411 | void tst_qpiemodelmapper::verticalModelInsertColumns() |
412 | { |
413 | // setup the mapper |
414 | createVerticalMapper(); |
415 | QCOMPARE(m_series->count(), m_modelRowCount); |
416 | QVERIFY(m_vMapper->model() != 0); |
417 | |
418 | int insertCount = 4; |
419 | m_model->insertColumns(column: 3, count: insertCount); |
420 | QCOMPARE(m_series->count(), m_modelRowCount); |
421 | } |
422 | |
423 | void tst_qpiemodelmapper::verticalModelRemoveColumns() |
424 | { |
425 | // setup the mapper |
426 | createVerticalMapper(); |
427 | QCOMPARE(m_series->count(), m_modelRowCount); |
428 | QVERIFY(m_vMapper->model() != 0); |
429 | |
430 | int removeCount = m_modelColumnCount - 2; |
431 | m_model->removeColumns(column: 0, count: removeCount); |
432 | QCOMPARE(m_series->count(), m_modelRowCount); |
433 | |
434 | // leave only one column |
435 | m_model->removeColumns(column: 0, count: m_modelColumnCount - removeCount - 1); |
436 | QCOMPARE(m_series->count(), 0); |
437 | } |
438 | |
439 | void tst_qpiemodelmapper::horizontalModelInsertRows() |
440 | { |
441 | // setup the mapper |
442 | createHorizontalMapper(); |
443 | QCOMPARE(m_series->count(), m_modelColumnCount); |
444 | QVERIFY(m_hMapper->model() != 0); |
445 | |
446 | int insertCount = 4; |
447 | m_model->insertRows(row: 3, count: insertCount); |
448 | QCOMPARE(m_series->count(), m_modelColumnCount); |
449 | } |
450 | |
451 | void tst_qpiemodelmapper::horizontalModelRemoveRows() |
452 | { |
453 | // setup the mapper |
454 | createHorizontalMapper(); |
455 | QCOMPARE(m_series->count(), m_modelColumnCount); |
456 | QVERIFY(m_hMapper->model() != 0); |
457 | |
458 | int removeCount = m_modelRowCount - 2; |
459 | m_model->removeRows(row: 0, count: removeCount); |
460 | QCOMPARE(m_series->count(), m_modelColumnCount); |
461 | |
462 | // leave only one column |
463 | m_model->removeRows(row: 0, count: m_modelRowCount - removeCount - 1); |
464 | QCOMPARE(m_series->count(), 0); |
465 | } |
466 | |
467 | void tst_qpiemodelmapper::horizontalModelInsertColumns() |
468 | { |
469 | // setup the mapper |
470 | createHorizontalMapper(); |
471 | QCOMPARE(m_series->count(), m_modelColumnCount); |
472 | QVERIFY(m_hMapper->model() != 0); |
473 | |
474 | int insertCount = 4; |
475 | m_model->insertColumns(column: 3, count: insertCount); |
476 | QCOMPARE(m_series->count(), m_modelColumnCount + insertCount); |
477 | |
478 | int first = 3; |
479 | m_hMapper->setFirstColumn(3); |
480 | QCOMPARE(m_series->count(), m_modelColumnCount + insertCount - first); |
481 | |
482 | m_model->insertColumns(column: 3, count: insertCount); |
483 | QCOMPARE(m_series->count(), m_modelColumnCount + 2 * insertCount - first); |
484 | |
485 | int countLimit = 6; |
486 | m_hMapper->setColumnCount(countLimit); |
487 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first)); |
488 | |
489 | m_model->insertColumns(column: 3, count: insertCount); |
490 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first)); |
491 | |
492 | m_hMapper->setFirstColumn(0); |
493 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount)); |
494 | |
495 | m_hMapper->setColumnCount(-1); |
496 | QCOMPARE(m_series->count(), m_modelColumnCount + 3 * insertCount); |
497 | } |
498 | |
499 | void tst_qpiemodelmapper::horizontalModelRemoveColumns() |
500 | { |
501 | // setup the mapper |
502 | createHorizontalMapper(); |
503 | QCOMPARE(m_series->count(), m_modelColumnCount); |
504 | QVERIFY(m_hMapper->model() != 0); |
505 | |
506 | int removeCount = 2; |
507 | m_model->removeColumns(column: 1, count: removeCount); |
508 | QCOMPARE(m_series->count(), m_modelColumnCount - removeCount); |
509 | |
510 | int first = 1; |
511 | m_hMapper->setFirstColumn(first); |
512 | QCOMPARE(m_series->count(), m_modelColumnCount - removeCount - first); |
513 | |
514 | m_model->removeColumns(column: 1, count: removeCount); |
515 | QCOMPARE(m_series->count(), m_modelColumnCount - 2 * removeCount - first); |
516 | |
517 | int countLimit = 3; |
518 | m_hMapper->setColumnCount(countLimit); |
519 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first)); |
520 | |
521 | m_model->removeColumns(column: 1, count: removeCount); |
522 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first)); |
523 | |
524 | m_hMapper->setFirstColumn(0); |
525 | QCOMPARE(m_series->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount)); |
526 | |
527 | m_hMapper->setColumnCount(-1); |
528 | QCOMPARE(m_series->count(), m_modelColumnCount - 3 * removeCount); |
529 | } |
530 | |
531 | void tst_qpiemodelmapper::modelUpdateCell() |
532 | { |
533 | // setup the mapper |
534 | createVerticalMapper(); |
535 | |
536 | QVERIFY(m_model->setData(m_model->index(1, 0), 44)); |
537 | QCOMPARE(m_series->slices().at(1)->value(), 44.0); |
538 | QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0); |
539 | } |
540 | |
541 | void tst_qpiemodelmapper::verticalMapperSignals() |
542 | { |
543 | QVPieModelMapper *mapper = new QVPieModelMapper; |
544 | |
545 | QSignalSpy spy0(mapper, SIGNAL(firstRowChanged())); |
546 | QSignalSpy spy1(mapper, SIGNAL(rowCountChanged())); |
547 | QSignalSpy spy2(mapper, SIGNAL(valuesColumnChanged())); |
548 | QSignalSpy spy3(mapper, SIGNAL(labelsColumnChanged())); |
549 | QSignalSpy spy4(mapper, SIGNAL(modelReplaced())); |
550 | QSignalSpy spy5(mapper, SIGNAL(seriesReplaced())); |
551 | |
552 | mapper->setValuesColumn(0); |
553 | mapper->setLabelsColumn(1); |
554 | mapper->setModel(m_model); |
555 | mapper->setSeries(m_series); |
556 | mapper->setFirstRow(1); |
557 | mapper->setRowCount(5); |
558 | |
559 | QCOMPARE(spy0.count(), 1); |
560 | QCOMPARE(spy1.count(), 1); |
561 | QCOMPARE(spy2.count(), 1); |
562 | QCOMPARE(spy3.count(), 1); |
563 | QCOMPARE(spy4.count(), 1); |
564 | QCOMPARE(spy5.count(), 1); |
565 | |
566 | delete mapper; |
567 | } |
568 | |
569 | void tst_qpiemodelmapper::horizontalMapperSignals() |
570 | { |
571 | QHPieModelMapper *mapper = new QHPieModelMapper; |
572 | |
573 | QSignalSpy spy0(mapper, SIGNAL(firstColumnChanged())); |
574 | QSignalSpy spy1(mapper, SIGNAL(columnCountChanged())); |
575 | QSignalSpy spy2(mapper, SIGNAL(valuesRowChanged())); |
576 | QSignalSpy spy3(mapper, SIGNAL(labelsRowChanged())); |
577 | QSignalSpy spy4(mapper, SIGNAL(modelReplaced())); |
578 | QSignalSpy spy5(mapper, SIGNAL(seriesReplaced())); |
579 | |
580 | mapper->setValuesRow(0); |
581 | mapper->setLabelsRow(1); |
582 | mapper->setModel(m_model); |
583 | mapper->setSeries(m_series); |
584 | mapper->setFirstColumn(1); |
585 | mapper->setColumnCount(5); |
586 | |
587 | QCOMPARE(spy0.count(), 1); |
588 | QCOMPARE(spy1.count(), 1); |
589 | QCOMPARE(spy2.count(), 1); |
590 | QCOMPARE(spy3.count(), 1); |
591 | QCOMPARE(spy4.count(), 1); |
592 | QCOMPARE(spy5.count(), 1); |
593 | } |
594 | |
595 | QTEST_MAIN(tst_qpiemodelmapper) |
596 | |
597 | #include "tst_qpiemodelmapper.moc" |
598 | |