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