##// END OF EJS Templates
Added more test for QBarModelMapper
Marek Rosa -
r1428:72f73c9d280d
parent child
Show More
@@ -1,286 +1,571
1 1 /****************************************************************************
2 2 **
3 3 ** Copyright (C) 2012 Digia Plc
4 4 ** All rights reserved.
5 5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 6 **
7 7 ** This file is part of the Qt Commercial Charts Add-on.
8 8 **
9 9 ** $QT_BEGIN_LICENSE$
10 10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 11 ** accordance with the Qt Commercial License Agreement provided with the
12 12 ** Software or, alternatively, in accordance with the terms contained in
13 13 ** a written agreement between you and Digia.
14 14 **
15 15 ** If you have questions regarding the use of this file, please use
16 16 ** contact form at http://qt.digia.com
17 17 ** $QT_END_LICENSE$
18 18 **
19 19 ****************************************************************************/
20 20
21 21 #include <QtCore/QString>
22 22 #include <QtTest/QtTest>
23 23
24 24 #include <qchart.h>
25 25 #include <qchartview.h>
26 26 #include <qgroupedbarseries.h>
27 27 #include <qbarset.h>
28 28 #include <qvbarmodelmapper.h>
29 29 #include <qhbarmodelmapper.h>
30 30 #include <QStandardItemModel>
31 31
32 32 QTCOMMERCIALCHART_USE_NAMESPACE
33 33
34 34 class tst_qbarmodelmapper : public QObject
35 35 {
36 36 Q_OBJECT
37 37
38 38 public:
39 39 tst_qbarmodelmapper();
40 void createVerticalMapper();
41 void createHorizontalMapper();
40 42
41 43 private Q_SLOTS:
42 44 void initTestCase();
43 45 void cleanupTestCase();
44 46 void init();
45 47 void cleanup();
46 48 void verticalMapper_data();
47 49 void verticalMapper();
48 50 void verticalMapperCustomMapping_data();
49 51 void verticalMapperCustomMapping();
50 52 void horizontalMapper_data();
51 53 void horizontalMapper();
52 54 void horizontalMapperCustomMapping_data();
53 55 void horizontalMapperCustomMapping();
54 56
57 void verticalModelInsertRows();
58 void verticalModelRemoveRows();
59 void verticalModelInsertColumns();
60 void verticalModelRemoveColumns();
61 void horizontalModelInsertRows();
62 void horizontalModelRemoveRows();
63 void horizontalModelInsertColumns();
64 void horizontalModelRemoveColumns();
65 void modelUpdateCell();
66
55 67 private:
56 68 QStandardItemModel *m_model;
57 69 int m_modelRowCount;
58 70 int m_modelColumnCount;
59 71
72 QVBarModelMapper *m_vMapper;
73 QHBarModelMapper *m_hMapper;
74
60 75 QGroupedBarSeries *m_series;
61 76 QChart *m_chart;
62 77 };
63 78
64 79 tst_qbarmodelmapper::tst_qbarmodelmapper():
65 80 m_model(0),
66 81 m_modelRowCount(10),
67 m_modelColumnCount(8)
82 m_modelColumnCount(8),
83 m_vMapper(0),
84 m_hMapper(0),
85 m_series(0),
86 m_chart(0)
87 {
88 }
89
90 void tst_qbarmodelmapper::createVerticalMapper()
91 {
92 m_vMapper = new QVBarModelMapper;
93 QVERIFY(m_vMapper->model() == 0);
94 m_vMapper->setFirstBarSetColumn(0);
95 m_vMapper->setLastBarSetColumn(4);
96 m_vMapper->setModel(m_model);
97 m_vMapper->setSeries(m_series);
98 }
99
100 void tst_qbarmodelmapper::createHorizontalMapper()
68 101 {
102 m_hMapper = new QHBarModelMapper;
103 QVERIFY(m_hMapper->model() == 0);
104 m_hMapper->setFirstBarSetRow(0);
105 m_hMapper->setLastBarSetRow(4);
106 m_hMapper->setModel(m_model);
107 m_hMapper->setSeries(m_series);
69 108 }
70 109
71 110 void tst_qbarmodelmapper::init()
72 111 {
73 // m_series = new QGroupedBarSeries;
74 // m_chart->addSeries(m_series);
112 m_series = new QGroupedBarSeries;
113 m_chart->addSeries(m_series);
114
115 m_model = new QStandardItemModel(m_modelRowCount, m_modelColumnCount, this);
116 for (int row = 0; row < m_modelRowCount; ++row) {
117 for (int column = 0; column < m_modelColumnCount; column++) {
118 m_model->setData(m_model->index(row, column), row * column);
119 }
120 }
75 121 }
76 122
77 123 void tst_qbarmodelmapper::cleanup()
78 124 {
79 125 m_chart->removeSeries(m_series);
80 126 delete m_series;
81 127 m_series = 0;
128
129 m_model->clear();
130 m_model->deleteLater();
131 m_model = 0;
132
133 if (m_vMapper) {
134 m_vMapper->deleteLater();
135 m_vMapper = 0;
136 }
137
138 if (m_hMapper) {
139 m_hMapper->deleteLater();
140 m_hMapper = 0;
141 }
82 142 }
83 143
84 144 void tst_qbarmodelmapper::initTestCase()
85 145 {
86 146 m_chart = new QChart;
87 147 QChartView *chartView = new QChartView(m_chart);
88 148 chartView->show();
89
90 m_model = new QStandardItemModel(this);
91 for (int row = 0; row < m_modelRowCount; ++row) {
92 for (int column = 0; column < m_modelColumnCount; column++) {
93 QStandardItem *item = new QStandardItem(row * column);
94 m_model->setItem(row, column, item);
95 }
96 }
97 149 }
98 150
99 151 void tst_qbarmodelmapper::cleanupTestCase()
100 152 {
101 m_model->clear();
102 153 }
103 154
104 155 void tst_qbarmodelmapper::verticalMapper_data()
105 156 {
106 157 QTest::addColumn<int>("firstBarSetColumn");
107 158 QTest::addColumn<int>("lastBarSetColumn");
108 159 QTest::addColumn<int>("expectedBarSetCount");
109 160 QTest::newRow("lastBarSetColumn greater than firstBarSetColumn") << 0 << 1 << 2;
110 161 QTest::newRow("lastBarSetColumn equal to firstBarSetColumn") << 1 << 1 << 1;
111 162 QTest::newRow("lastBarSetColumn lesser than firstBarSetColumn") << 1 << 0 << 0;
112 163 QTest::newRow("invalid firstBarSetColumn and correct lastBarSetColumn") << -3 << 1 << 0;
113 164 QTest::newRow("firstBarSetColumn beyond the size of model and correct lastBarSetColumn") << m_modelColumnCount << 1 << 0;
114 165 QTest::newRow("firstBarSetColumn beyond the size of model and invalid lastBarSetColumn") << m_modelColumnCount << -1 << 0;
115 166 }
116 167
117 168 void tst_qbarmodelmapper::verticalMapper()
118 169 {
119 170 QFETCH(int, firstBarSetColumn);
120 171 QFETCH(int, lastBarSetColumn);
121 172 QFETCH(int, expectedBarSetCount);
122 173
123 174 m_series = new QGroupedBarSeries;
124 175
125 176 QVBarModelMapper *mapper = new QVBarModelMapper;
126 177 mapper->setFirstBarSetColumn(firstBarSetColumn);
127 178 mapper->setLastBarSetColumn(lastBarSetColumn);
128 179 mapper->setModel(m_model);
129 180 mapper->setSeries(m_series);
130 181
131 182 m_chart->addSeries(m_series);
132 183
133 184 QCOMPARE(m_series->barsetCount(), expectedBarSetCount);
134 185 QCOMPARE(mapper->firstBarSetColumn(), qMax(-1, firstBarSetColumn));
135 186 QCOMPARE(mapper->lastBarSetColumn(), qMax(-1, lastBarSetColumn));
136 187
137 188 delete mapper;
138 189 mapper = 0;
139 190 }
140 191
141 192 void tst_qbarmodelmapper::verticalMapperCustomMapping_data()
142 193 {
143 194 QTest::addColumn<int>("first");
144 195 QTest::addColumn<int>("countLimit");
145 196 QTest::addColumn<int>("expectedBarSetCount");
146 197 QTest::addColumn<int>("expectedCount");
147 198 QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelRowCount;
148 199 QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelRowCount - 3;
149 200 QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelRowCount);
150 201 QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelRowCount - 3);
151 202 QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0 << 0;
152 203 QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0 << 0;
153 204 QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelRowCount + 3 << 2 << m_modelRowCount;
154 205 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelRowCount;
155 206 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelRowCount;
156 207 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelRowCount;
157 208 }
158 209
159 210 void tst_qbarmodelmapper::verticalMapperCustomMapping()
160 211 {
161 212 QFETCH(int, first);
162 213 QFETCH(int, countLimit);
163 214 QFETCH(int, expectedBarSetCount);
164 215 QFETCH(int, expectedCount);
165 216
166 217 m_series = new QGroupedBarSeries;
167 218
168 219 QCOMPARE(m_series->barsetCount(), 0);
169 220
170 221 QVBarModelMapper *mapper = new QVBarModelMapper;
171 222 mapper->setFirstBarSetColumn(0);
172 223 mapper->setLastBarSetColumn(1);
173 224 mapper->setModel(m_model);
174 225 mapper->setSeries(m_series);
175 226 mapper->setFirst(first);
176 227 mapper->setCount(countLimit);
177 228 m_chart->addSeries(m_series);
178 229
179 230 QCOMPARE(m_series->barsetCount(), expectedBarSetCount);
180 231
181 232 if (expectedBarSetCount > 0)
182 233 QCOMPARE(m_series->barSets().first()->count(), expectedCount);
183 234
184 235 // change values column mapping to invalid
185 236 mapper->setFirstBarSetColumn(-1);
186 237 mapper->setLastBarSetColumn(1);
187 238
188 239 QCOMPARE(m_series->barsetCount(), 0);
189 240
190 241 delete mapper;
191 242 mapper = 0;
192 243 }
193 244
194 245 void tst_qbarmodelmapper::horizontalMapper_data()
195 246 {
196 247 QTest::addColumn<int>("firstBarSetRow");
197 248 QTest::addColumn<int>("lastBarSetRow");
198 249 QTest::addColumn<int>("expectedBarSetCount");
199 250 QTest::newRow("lastBarSetRow greater than firstBarSetRow") << 0 << 1 << 2;
200 251 QTest::newRow("lastBarSetRow equal to firstBarSetRow") << 1 << 1 << 1;
201 252 QTest::newRow("lastBarSetRow lesser than firstBarSetRow") << 1 << 0 << 0;
202 253 QTest::newRow("invalid firstBarSetRow and correct lastBarSetRow") << -3 << 1 << 0;
203 254 QTest::newRow("firstBarSetRow beyond the size of model and correct lastBarSetRow") << m_modelRowCount << 1 << 0;
204 255 QTest::newRow("firstBarSetRow beyond the size of model and invalid lastBarSetRow") << m_modelRowCount << -1 << 0;
205 256 }
206 257
207 258 void tst_qbarmodelmapper::horizontalMapper()
208 259 {
209 260 QFETCH(int, firstBarSetRow);
210 261 QFETCH(int, lastBarSetRow);
211 262 QFETCH(int, expectedBarSetCount);
212 263
213 264 m_series = new QGroupedBarSeries;
214 265
215 266 QHBarModelMapper *mapper = new QHBarModelMapper;
216 267 mapper->setFirstBarSetRow(firstBarSetRow);
217 268 mapper->setLastBarSetRow(lastBarSetRow);
218 269 mapper->setModel(m_model);
219 270 mapper->setSeries(m_series);
220 271
221 272 m_chart->addSeries(m_series);
222 273
223 274 QCOMPARE(m_series->barsetCount(), expectedBarSetCount);
224 275 QCOMPARE(mapper->firstBarSetRow(), qMax(-1, firstBarSetRow));
225 276 QCOMPARE(mapper->lastBarSetRow(), qMax(-1, lastBarSetRow));
226 277
227 278 delete mapper;
228 279 mapper = 0;
229 280 }
230 281
231 282 void tst_qbarmodelmapper::horizontalMapperCustomMapping_data()
232 283 {
233 284 QTest::addColumn<int>("first");
234 285 QTest::addColumn<int>("countLimit");
235 286 QTest::addColumn<int>("expectedBarSetCount");
236 287 QTest::addColumn<int>("expectedCount");
237 288 QTest::newRow("first: 0, unlimited count") << 0 << -1 << 2 << m_modelColumnCount;
238 289 QTest::newRow("first: 3, unlimited count") << 3 << -1 << 2 << m_modelColumnCount - 3;
239 290 QTest::newRow("first: 0, count: 5") << 0 << 5 << 2 << qMin(5, m_modelColumnCount);
240 291 QTest::newRow("first: 3, count: 5") << 3 << 5 << 2 << qMin(5, m_modelColumnCount - 3);
241 292 QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0 << 0;
242 293 QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0 << 0;
243 294 QTest::newRow("first: 0, count: +3 greater than the number of rows in the model (should limit to the size of model)") << 0 << m_modelColumnCount + 3 << 2 << m_modelColumnCount;
244 295 QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << 2 << m_modelColumnCount;
245 296 QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << 2 << m_modelColumnCount;
246 297 QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << 2 << m_modelColumnCount;
247 298 }
248 299
249 300 void tst_qbarmodelmapper::horizontalMapperCustomMapping()
250 301 {
251 302 QFETCH(int, first);
252 303 QFETCH(int, countLimit);
253 304 QFETCH(int, expectedBarSetCount);
254 305 QFETCH(int, expectedCount);
255 306
256 307 m_series = new QGroupedBarSeries;
257 308
258 309 QCOMPARE(m_series->barsetCount(), 0);
259 310
260 311 QHBarModelMapper *mapper = new QHBarModelMapper;
261 312 mapper->setFirstBarSetRow(0);
262 313 mapper->setLastBarSetRow(1);
263 314 mapper->setModel(m_model);
264 315 mapper->setSeries(m_series);
265 316 mapper->setFirst(first);
266 317 mapper->setCount(countLimit);
267 318 m_chart->addSeries(m_series);
268 319
269 320 QCOMPARE(m_series->barsetCount(), expectedBarSetCount);
270 321
271 322 if (expectedBarSetCount > 0)
272 323 QCOMPARE(m_series->barSets().first()->count(), expectedCount);
273 324
274 325 // change values column mapping to invalid
275 326 mapper->setFirstBarSetRow(-1);
276 327 mapper->setLastBarSetRow(1);
277 328
278 329 QCOMPARE(m_series->barsetCount(), 0);
279 330
280 331 delete mapper;
281 332 mapper = 0;
282 333 }
283 334
335 void tst_qbarmodelmapper::verticalModelInsertRows()
336 {
337 // setup the mapper
338 createVerticalMapper();
339 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
340 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount);
341 QVERIFY(m_vMapper->model() != 0);
342
343 int insertCount = 4;
344 m_model->insertRows(3, insertCount);
345 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
346 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount);
347
348 int first = 3;
349 m_vMapper->setFirst(3);
350 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
351 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + insertCount - first);
352
353 m_model->insertRows(3, insertCount);
354 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
355 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 2 * insertCount - first);
356
357 int countLimit = 6;
358 m_vMapper->setCount(countLimit);
359 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
360 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 2 * insertCount - first));
361
362 m_model->insertRows(3, insertCount);
363 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
364 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount - first));
365
366 m_vMapper->setFirst(0);
367 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
368 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount + 3 * insertCount));
369
370 m_vMapper->setCount(-1);
371 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
372 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount + 3 * insertCount);
373 }
374
375 void tst_qbarmodelmapper::verticalModelRemoveRows()
376 {
377 // setup the mapper
378 createVerticalMapper();
379 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
380 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount);
381 QVERIFY(m_vMapper->model() != 0);
382
383 int removeCount = 2;
384 m_model->removeRows(1, removeCount);
385 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
386 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount);
387
388 int first = 1;
389 m_vMapper->setFirst(first);
390 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
391 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - removeCount - first);
392
393 m_model->removeRows(1, removeCount);
394 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
395 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 2 * removeCount - first);
396
397 int countLimit = 3;
398 m_vMapper->setCount(countLimit);
399 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
400 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 2 * removeCount - first));
401
402 m_model->removeRows(1, removeCount);
403 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
404 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount - first));
405
406 m_vMapper->setFirst(0);
407 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
408 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelRowCount - 3 * removeCount));
409
410 m_vMapper->setCount(-1);
411 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
412 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount - 3 * removeCount);
413 }
414
415 void tst_qbarmodelmapper::verticalModelInsertColumns()
416 {
417 // setup the mapper
418 createVerticalMapper();
419 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
420 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount);
421 QVERIFY(m_vMapper->model() != 0);
422
423 int insertCount = 4;
424 m_model->insertColumns(3, insertCount);
425 QCOMPARE(m_series->barsetCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1);
426 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount);
427 }
428
429 void tst_qbarmodelmapper::verticalModelRemoveColumns()
430 {
431 // setup the mapper
432 createVerticalMapper();
433 QCOMPARE(m_series->barsetCount(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1));
434 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount);
435 QVERIFY(m_vMapper->model() != 0);
436
437 int removeCount = m_modelColumnCount - 2;
438 m_model->removeColumns(0, removeCount);
439 QCOMPARE(m_series->barsetCount(), qMin(m_model->columnCount(), m_vMapper->lastBarSetColumn() - m_vMapper->firstBarSetColumn() + 1));
440 QCOMPARE(m_series->barSets().first()->count(), m_modelRowCount);
441
442 // leave all the columns
443 m_model->removeColumns(0, m_modelColumnCount - removeCount);
444 QCOMPARE(m_series->barsetCount(), 0);
445 }
446
447 void tst_qbarmodelmapper::horizontalModelInsertRows()
448 {
449 // setup the mapper
450 createHorizontalMapper();
451 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
452 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount);
453 QVERIFY(m_hMapper->model() != 0);
454
455 int insertCount = 4;
456 m_model->insertRows(3, insertCount);
457 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
458 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount);
459 }
460
461 void tst_qbarmodelmapper::horizontalModelRemoveRows()
462 {
463 // setup the mapper
464 createHorizontalMapper();
465 QCOMPARE(m_series->barsetCount(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1));
466 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount);
467 QVERIFY(m_hMapper->model() != 0);
468
469 int removeCount = m_modelRowCount - 2;
470 m_model->removeRows(0, removeCount);
471 QCOMPARE(m_series->barsetCount(), qMin(m_model->rowCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1));
472 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount);
473
474 // leave all the columns
475 m_model->removeRows(0, m_modelRowCount - removeCount);
476 QCOMPARE(m_series->barsetCount(), 0);
477 }
478
479 void tst_qbarmodelmapper::horizontalModelInsertColumns()
480 {
481 // setup the mapper
482 createHorizontalMapper();
483 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
484 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount);
485 QVERIFY(m_hMapper->model() != 0);
486
487 int insertCount = 4;
488 m_model->insertColumns(3, insertCount);
489 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
490 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount);
491
492 int first = 3;
493 m_hMapper->setFirst(3);
494 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
495 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + insertCount - first);
496
497 m_model->insertColumns(3, insertCount);
498 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
499 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 2 * insertCount - first);
500
501 int countLimit = 6;
502 m_hMapper->setCount(countLimit);
503 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
504 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 2 * insertCount - first));
505
506 m_model->insertColumns(3, insertCount);
507 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
508 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount - first));
509
510 m_hMapper->setFirst(0);
511 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
512 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount + 3 * insertCount));
513
514 m_hMapper->setCount(-1);
515 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
516 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount + 3 * insertCount);
517 }
518
519 void tst_qbarmodelmapper::horizontalModelRemoveColumns()
520 {
521 // setup the mapper
522 createHorizontalMapper();
523 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
524 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount);
525 QVERIFY(m_hMapper->model() != 0);
526
527 int removeCount = 2;
528 m_model->removeColumns(1, removeCount);
529 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
530 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount);
531
532 int first = 1;
533 m_hMapper->setFirst(first);
534 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
535 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - removeCount - first);
536
537 m_model->removeColumns(1, removeCount);
538 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
539 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 2 * removeCount - first);
540
541 int countLimit = 3;
542 m_hMapper->setCount(countLimit);
543 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
544 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 2 * removeCount - first));
545
546 m_model->removeColumns(1, removeCount);
547 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
548 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount - first));
549
550 m_hMapper->setFirst(0);
551 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
552 QCOMPARE(m_series->barSets().first()->count(), qMin(countLimit, m_modelColumnCount - 3 * removeCount));
553
554 m_hMapper->setCount(-1);
555 QCOMPARE(m_series->barsetCount(), m_hMapper->lastBarSetRow() - m_hMapper->firstBarSetRow() + 1);
556 QCOMPARE(m_series->barSets().first()->count(), m_modelColumnCount - 3 * removeCount);
557 }
558
559 void tst_qbarmodelmapper::modelUpdateCell()
560 {
561 // setup the mapper
562 createVerticalMapper();
563
564 QVERIFY(m_model->setData(m_model->index(1, 0), 44));
565 QCOMPARE(m_series->barSets().at(0)->at(1).y(), 44.0);
566 QCOMPARE(m_model->data(m_model->index(1, 0)).toReal(), 44.0);
567 }
568
284 569 QTEST_MAIN(tst_qbarmodelmapper)
285 570
286 571 #include "tst_qbarmodelmapper.moc"
General Comments 0
You need to be logged in to leave comments. Login now