@@ -1,293 +1,333 | |||||
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 <qxyseries.h> |
|
26 | #include <qxyseries.h> | |
27 | #include <qlineseries.h> |
|
27 | #include <qlineseries.h> | |
28 | #include <qvxymodelmapper.h> |
|
28 | #include <qvxymodelmapper.h> | |
29 | #include <qhxymodelmapper.h> |
|
29 | #include <qhxymodelmapper.h> | |
30 | #include <QStandardItemModel> |
|
30 | #include <QStandardItemModel> | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
32 | QTCOMMERCIALCHART_USE_NAMESPACE | |
33 |
|
33 | |||
34 | class tst_qxymodelmapper : public QObject |
|
34 | class tst_qxymodelmapper : public QObject | |
35 | { |
|
35 | { | |
36 | Q_OBJECT |
|
36 | Q_OBJECT | |
37 |
|
37 | |||
38 | public: |
|
38 | public: | |
39 | tst_qxymodelmapper(); |
|
39 | tst_qxymodelmapper(); | |
40 |
|
40 | |||
41 | private Q_SLOTS: |
|
41 | private Q_SLOTS: | |
42 | void initTestCase(); |
|
42 | void initTestCase(); | |
43 | void cleanupTestCase(); |
|
43 | void cleanupTestCase(); | |
44 | void init(); |
|
44 | void init(); | |
45 | void cleanup(); |
|
45 | void cleanup(); | |
46 | void verticalMapper_data(); |
|
46 | void verticalMapper_data(); | |
47 | void verticalMapper(); |
|
47 | void verticalMapper(); | |
48 | void verticalMapperCustomMapping_data(); |
|
48 | void verticalMapperCustomMapping_data(); | |
49 | void verticalMapperCustomMapping(); |
|
49 | void verticalMapperCustomMapping(); | |
50 | void horizontalMapper_data(); |
|
50 | void horizontalMapper_data(); | |
51 | void horizontalMapper(); |
|
51 | void horizontalMapper(); | |
52 | void horizontalMapperCustomMapping_data(); |
|
52 | void horizontalMapperCustomMapping_data(); | |
53 | void horizontalMapperCustomMapping(); |
|
53 | void horizontalMapperCustomMapping(); | |
54 | void seriesUpdated(); |
|
54 | void seriesUpdated(); | |
|
55 | void modelUpdated(); | |||
55 |
|
56 | |||
56 | private: |
|
57 | private: | |
57 | QStandardItemModel *m_model; |
|
58 | QStandardItemModel *m_model; | |
58 | int m_modelRowCount; |
|
59 | int m_modelRowCount; | |
59 | int m_modelColumnCount; |
|
60 | int m_modelColumnCount; | |
60 |
|
61 | |||
61 | QXYSeries *m_series; |
|
62 | QXYSeries *m_series; | |
62 | QChart *m_chart; |
|
63 | QChart *m_chart; | |
63 | }; |
|
64 | }; | |
64 |
|
65 | |||
65 | tst_qxymodelmapper::tst_qxymodelmapper(): |
|
66 | tst_qxymodelmapper::tst_qxymodelmapper(): | |
66 | m_model(0), |
|
67 | m_model(0), | |
67 | m_modelRowCount(10), |
|
68 | m_modelRowCount(10), | |
68 | m_modelColumnCount(8) |
|
69 | m_modelColumnCount(8) | |
69 | { |
|
70 | { | |
70 | } |
|
71 | } | |
71 |
|
72 | |||
72 | void tst_qxymodelmapper::init() |
|
73 | void tst_qxymodelmapper::init() | |
73 | { |
|
74 | { | |
74 | m_series = new QLineSeries; |
|
75 | m_series = new QLineSeries; | |
75 | m_chart->addSeries(m_series); |
|
76 | m_chart->addSeries(m_series); | |
76 | } |
|
77 | } | |
77 |
|
78 | |||
78 | void tst_qxymodelmapper::cleanup() |
|
79 | void tst_qxymodelmapper::cleanup() | |
79 | { |
|
80 | { | |
80 | m_chart->removeSeries(m_series); |
|
81 | m_chart->removeSeries(m_series); | |
81 | delete m_series; |
|
82 | delete m_series; | |
82 | m_series = 0; |
|
83 | m_series = 0; | |
83 | } |
|
84 | } | |
84 |
|
85 | |||
85 | void tst_qxymodelmapper::initTestCase() |
|
86 | void tst_qxymodelmapper::initTestCase() | |
86 | { |
|
87 | { | |
87 | m_chart = new QChart; |
|
88 | m_chart = new QChart; | |
88 | QChartView *chartView = new QChartView(m_chart); |
|
89 | QChartView *chartView = new QChartView(m_chart); | |
89 | chartView->show(); |
|
90 | chartView->show(); | |
90 |
|
91 | |||
91 | m_model = new QStandardItemModel(this); |
|
92 | m_model = new QStandardItemModel(this); | |
92 | for (int row = 0; row < m_modelRowCount; ++row) { |
|
93 | for (int row = 0; row < m_modelRowCount; ++row) { | |
93 | for (int column = 0; column < m_modelColumnCount; column++) { |
|
94 | for (int column = 0; column < m_modelColumnCount; column++) { | |
94 | QStandardItem *item = new QStandardItem(row * column); |
|
95 | QStandardItem *item = new QStandardItem(row * column); | |
95 | m_model->setItem(row, column, item); |
|
96 | m_model->setItem(row, column, item); | |
96 | } |
|
97 | } | |
97 | } |
|
98 | } | |
98 | } |
|
99 | } | |
99 |
|
100 | |||
100 | void tst_qxymodelmapper::cleanupTestCase() |
|
101 | void tst_qxymodelmapper::cleanupTestCase() | |
101 | { |
|
102 | { | |
102 | m_model->clear(); |
|
103 | m_model->clear(); | |
103 | } |
|
104 | } | |
104 |
|
105 | |||
105 | void tst_qxymodelmapper::verticalMapper_data() |
|
106 | void tst_qxymodelmapper::verticalMapper_data() | |
106 | { |
|
107 | { | |
107 | QTest::addColumn<int>("xColumn"); |
|
108 | QTest::addColumn<int>("xColumn"); | |
108 | QTest::addColumn<int>("yColumn"); |
|
109 | QTest::addColumn<int>("yColumn"); | |
109 | QTest::addColumn<int>("expectedCount"); |
|
110 | QTest::addColumn<int>("expectedCount"); | |
110 | QTest::newRow("different x and y columns") << 0 << 1 << m_modelRowCount; |
|
111 | QTest::newRow("different x and y columns") << 0 << 1 << m_modelRowCount; | |
111 | QTest::newRow("same x and y columns") << 1 << 1 << m_modelRowCount; |
|
112 | QTest::newRow("same x and y columns") << 1 << 1 << m_modelRowCount; | |
112 | QTest::newRow("invalid x column and correct y column") << -3 << 1 << 0; |
|
113 | QTest::newRow("invalid x column and correct y column") << -3 << 1 << 0; | |
113 | QTest::newRow("x column beyond the size of model and correct y column") << m_modelColumnCount << 1 << 0; |
|
114 | QTest::newRow("x column beyond the size of model and correct y column") << m_modelColumnCount << 1 << 0; | |
114 | QTest::newRow("x column beyond the size of model and invalid y column") << m_modelColumnCount << -1 << 0; |
|
115 | QTest::newRow("x column beyond the size of model and invalid y column") << m_modelColumnCount << -1 << 0; | |
115 | } |
|
116 | } | |
116 |
|
117 | |||
117 | void tst_qxymodelmapper::verticalMapper() |
|
118 | void tst_qxymodelmapper::verticalMapper() | |
118 | { |
|
119 | { | |
119 | QFETCH(int, xColumn); |
|
120 | QFETCH(int, xColumn); | |
120 | QFETCH(int, yColumn); |
|
121 | QFETCH(int, yColumn); | |
121 | QFETCH(int, expectedCount); |
|
122 | QFETCH(int, expectedCount); | |
122 |
|
123 | |||
123 | QVXYModelMapper *mapper = new QVXYModelMapper; |
|
124 | QVXYModelMapper *mapper = new QVXYModelMapper; | |
|
125 | QVERIFY(mapper->model() == 0); | |||
|
126 | ||||
124 | mapper->setXColumn(xColumn); |
|
127 | mapper->setXColumn(xColumn); | |
125 | mapper->setYColumn(yColumn); |
|
128 | mapper->setYColumn(yColumn); | |
126 | mapper->setModel(m_model); |
|
129 | mapper->setModel(m_model); | |
127 | mapper->setSeries(m_series); |
|
130 | mapper->setSeries(m_series); | |
128 |
|
131 | |||
129 | QCOMPARE(m_series->count(), expectedCount); |
|
132 | QCOMPARE(m_series->count(), expectedCount); | |
130 | QCOMPARE(mapper->xColumn(), qMax(-1, xColumn)); |
|
133 | QCOMPARE(mapper->xColumn(), qMax(-1, xColumn)); | |
131 | QCOMPARE(mapper->yColumn(), qMax(-1, yColumn)); |
|
134 | QCOMPARE(mapper->yColumn(), qMax(-1, yColumn)); | |
132 |
|
135 | |||
133 | delete mapper; |
|
136 | delete mapper; | |
134 | mapper = 0; |
|
137 | mapper = 0; | |
135 | } |
|
138 | } | |
136 |
|
139 | |||
137 | void tst_qxymodelmapper::verticalMapperCustomMapping_data() |
|
140 | void tst_qxymodelmapper::verticalMapperCustomMapping_data() | |
138 | { |
|
141 | { | |
139 | QTest::addColumn<int>("first"); |
|
142 | QTest::addColumn<int>("first"); | |
140 | QTest::addColumn<int>("countLimit"); |
|
143 | QTest::addColumn<int>("countLimit"); | |
141 | QTest::addColumn<int>("expectedCount"); |
|
144 | QTest::addColumn<int>("expectedCount"); | |
142 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount; |
|
145 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount; | |
143 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3; |
|
146 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3; | |
144 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount); |
|
147 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount); | |
145 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3); |
|
148 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3); | |
146 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0; |
|
149 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0; | |
147 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0; |
|
150 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0; | |
148 | 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 << m_modelRowCount; |
|
151 | 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 << m_modelRowCount; | |
149 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount; |
|
152 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount; | |
150 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount; |
|
153 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount; | |
151 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount; |
|
154 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount; | |
152 |
|
155 | |||
153 | } |
|
156 | } | |
154 |
|
157 | |||
155 | void tst_qxymodelmapper::verticalMapperCustomMapping() |
|
158 | void tst_qxymodelmapper::verticalMapperCustomMapping() | |
156 | { |
|
159 | { | |
157 | QFETCH(int, first); |
|
160 | QFETCH(int, first); | |
158 | QFETCH(int, countLimit); |
|
161 | QFETCH(int, countLimit); | |
159 | QFETCH(int, expectedCount); |
|
162 | QFETCH(int, expectedCount); | |
160 |
|
163 | |||
161 | QCOMPARE(m_series->count(), 0); |
|
164 | QCOMPARE(m_series->count(), 0); | |
162 |
|
165 | |||
163 | QVXYModelMapper *mapper = new QVXYModelMapper; |
|
166 | QVXYModelMapper *mapper = new QVXYModelMapper; | |
164 | mapper->setXColumn(0); |
|
167 | mapper->setXColumn(0); | |
165 | mapper->setYColumn(1); |
|
168 | mapper->setYColumn(1); | |
166 | mapper->setModel(m_model); |
|
169 | mapper->setModel(m_model); | |
167 | mapper->setSeries(m_series); |
|
170 | mapper->setSeries(m_series); | |
168 | mapper->setFirst(first); |
|
171 | mapper->setFirst(first); | |
169 | mapper->setCount(countLimit); |
|
172 | mapper->setCount(countLimit); | |
170 |
|
173 | |||
171 | QCOMPARE(m_series->count(), expectedCount); |
|
174 | QCOMPARE(m_series->count(), expectedCount); | |
172 |
|
175 | |||
173 | // change values column mapping to invalid |
|
176 | // change values column mapping to invalid | |
174 | mapper->setXColumn(-1); |
|
177 | mapper->setXColumn(-1); | |
175 | mapper->setYColumn(1); |
|
178 | mapper->setYColumn(1); | |
176 |
|
179 | |||
177 | QCOMPARE(m_series->count(), 0); |
|
180 | QCOMPARE(m_series->count(), 0); | |
178 |
|
181 | |||
179 | delete mapper; |
|
182 | delete mapper; | |
180 | mapper = 0; |
|
183 | mapper = 0; | |
181 | } |
|
184 | } | |
182 |
|
185 | |||
183 | void tst_qxymodelmapper::horizontalMapper_data() |
|
186 | void tst_qxymodelmapper::horizontalMapper_data() | |
184 | { |
|
187 | { | |
185 | QTest::addColumn<int>("xRow"); |
|
188 | QTest::addColumn<int>("xRow"); | |
186 | QTest::addColumn<int>("yRow"); |
|
189 | QTest::addColumn<int>("yRow"); | |
187 | QTest::addColumn<int>("expectedCount"); |
|
190 | QTest::addColumn<int>("expectedCount"); | |
188 | QTest::newRow("different x and y rows") << 0 << 1 << m_modelColumnCount; |
|
191 | QTest::newRow("different x and y rows") << 0 << 1 << m_modelColumnCount; | |
189 | QTest::newRow("same x and y rows") << 1 << 1 << m_modelColumnCount; |
|
192 | QTest::newRow("same x and y rows") << 1 << 1 << m_modelColumnCount; | |
190 | QTest::newRow("invalid x row and correct y row") << -3 << 1 << 0; |
|
193 | QTest::newRow("invalid x row and correct y row") << -3 << 1 << 0; | |
191 | QTest::newRow("x row beyond the size of model and correct y row") << m_modelRowCount << 1 << 0; |
|
194 | QTest::newRow("x row beyond the size of model and correct y row") << m_modelRowCount << 1 << 0; | |
192 | QTest::newRow("x row beyond the size of model and invalid y row") << m_modelRowCount << -1 << 0; |
|
195 | QTest::newRow("x row beyond the size of model and invalid y row") << m_modelRowCount << -1 << 0; | |
193 | } |
|
196 | } | |
194 |
|
197 | |||
195 | void tst_qxymodelmapper::horizontalMapper() |
|
198 | void tst_qxymodelmapper::horizontalMapper() | |
196 | { |
|
199 | { | |
197 | QFETCH(int, xRow); |
|
200 | QFETCH(int, xRow); | |
198 | QFETCH(int, yRow); |
|
201 | QFETCH(int, yRow); | |
199 | QFETCH(int, expectedCount); |
|
202 | QFETCH(int, expectedCount); | |
200 |
|
203 | |||
201 | QHXYModelMapper *mapper = new QHXYModelMapper; |
|
204 | QHXYModelMapper *mapper = new QHXYModelMapper; | |
202 | mapper->setXRow(xRow); |
|
205 | mapper->setXRow(xRow); | |
203 | mapper->setYRow(yRow); |
|
206 | mapper->setYRow(yRow); | |
204 | mapper->setModel(m_model); |
|
207 | mapper->setModel(m_model); | |
205 | mapper->setSeries(m_series); |
|
208 | mapper->setSeries(m_series); | |
206 |
|
209 | |||
207 | QCOMPARE(m_series->count(), expectedCount); |
|
210 | QCOMPARE(m_series->count(), expectedCount); | |
208 | QCOMPARE(mapper->xRow(), qMax(-1, xRow)); |
|
211 | QCOMPARE(mapper->xRow(), qMax(-1, xRow)); | |
209 | QCOMPARE(mapper->yRow(), qMax(-1, yRow)); |
|
212 | QCOMPARE(mapper->yRow(), qMax(-1, yRow)); | |
210 |
|
213 | |||
211 | delete mapper; |
|
214 | delete mapper; | |
212 | mapper = 0; |
|
215 | mapper = 0; | |
213 | } |
|
216 | } | |
214 |
|
217 | |||
215 | void tst_qxymodelmapper::horizontalMapperCustomMapping_data() |
|
218 | void tst_qxymodelmapper::horizontalMapperCustomMapping_data() | |
216 | { |
|
219 | { | |
217 | QTest::addColumn<int>("first"); |
|
220 | QTest::addColumn<int>("first"); | |
218 | QTest::addColumn<int>("countLimit"); |
|
221 | QTest::addColumn<int>("countLimit"); | |
219 | QTest::addColumn<int>("expectedCount"); |
|
222 | QTest::addColumn<int>("expectedCount"); | |
220 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount; |
|
223 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount; | |
221 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3; |
|
224 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3; | |
222 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount); |
|
225 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount); | |
223 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3); |
|
226 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3); | |
224 | QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0; |
|
227 | QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0; | |
225 | QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0; |
|
228 | QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0; | |
226 | QTest::newRow("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; |
|
229 | QTest::newRow("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; | |
227 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount; |
|
230 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount; | |
228 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount; |
|
231 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount; | |
229 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount; |
|
232 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount; | |
230 | } |
|
233 | } | |
231 |
|
234 | |||
232 | void tst_qxymodelmapper::horizontalMapperCustomMapping() |
|
235 | void tst_qxymodelmapper::horizontalMapperCustomMapping() | |
233 | { |
|
236 | { | |
234 | QFETCH(int, first); |
|
237 | QFETCH(int, first); | |
235 | QFETCH(int, countLimit); |
|
238 | QFETCH(int, countLimit); | |
236 | QFETCH(int, expectedCount); |
|
239 | QFETCH(int, expectedCount); | |
237 |
|
240 | |||
238 | QCOMPARE(m_series->count(), 0); |
|
241 | QCOMPARE(m_series->count(), 0); | |
239 |
|
242 | |||
240 | QHXYModelMapper *mapper = new QHXYModelMapper; |
|
243 | QHXYModelMapper *mapper = new QHXYModelMapper; | |
241 | mapper->setXRow(0); |
|
244 | mapper->setXRow(0); | |
242 | mapper->setYRow(1); |
|
245 | mapper->setYRow(1); | |
243 | mapper->setModel(m_model); |
|
246 | mapper->setModel(m_model); | |
244 | mapper->setSeries(m_series); |
|
247 | mapper->setSeries(m_series); | |
245 | mapper->setFirst(first); |
|
248 | mapper->setFirst(first); | |
246 | mapper->setCount(countLimit); |
|
249 | mapper->setCount(countLimit); | |
247 |
|
250 | |||
248 | QCOMPARE(m_series->count(), expectedCount); |
|
251 | QCOMPARE(m_series->count(), expectedCount); | |
249 |
|
252 | |||
250 | // change values row mapping to invalid |
|
253 | // change values row mapping to invalid | |
251 | mapper->setXRow(-1); |
|
254 | mapper->setXRow(-1); | |
252 | mapper->setYRow(1); |
|
255 | mapper->setYRow(1); | |
253 |
|
256 | |||
254 | QCOMPARE(m_series->count(), 0); |
|
257 | QCOMPARE(m_series->count(), 0); | |
255 |
|
258 | |||
256 | delete mapper; |
|
259 | delete mapper; | |
257 | mapper = 0; |
|
260 | mapper = 0; | |
258 | } |
|
261 | } | |
259 |
|
262 | |||
260 | void tst_qxymodelmapper::seriesUpdated() |
|
263 | void tst_qxymodelmapper::seriesUpdated() | |
261 | { |
|
264 | { | |
262 | QStandardItemModel *otherModel = new QStandardItemModel; |
|
265 | QStandardItemModel *otherModel = new QStandardItemModel; | |
263 | for (int row = 0; row < m_modelRowCount; ++row) { |
|
266 | for (int row = 0; row < m_modelRowCount; ++row) { | |
264 | for (int column = 0; column < m_modelColumnCount; column++) { |
|
267 | for (int column = 0; column < m_modelColumnCount; column++) { | |
265 | QStandardItem *item = new QStandardItem(row * column); |
|
268 | QStandardItem *item = new QStandardItem(row * column); | |
266 | otherModel->setItem(row, column, item); |
|
269 | otherModel->setItem(row, column, item); | |
267 | } |
|
270 | } | |
268 | } |
|
271 | } | |
269 |
|
272 | |||
270 | QVXYModelMapper *mapper = new QVXYModelMapper; |
|
273 | QVXYModelMapper *mapper = new QVXYModelMapper; | |
271 | mapper->setXColumn(0); |
|
274 | mapper->setXColumn(0); | |
272 | mapper->setYColumn(1); |
|
275 | mapper->setYColumn(1); | |
273 | mapper->setModel(otherModel); |
|
276 | mapper->setModel(otherModel); | |
274 | mapper->setSeries(m_series); |
|
277 | mapper->setSeries(m_series); | |
275 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
278 | QCOMPARE(m_series->count(), m_modelRowCount); | |
276 | QCOMPARE(mapper->count(), -1); |
|
279 | QCOMPARE(mapper->count(), -1); | |
277 |
|
280 | |||
278 | m_series->append(QPointF(100, 100)); |
|
281 | m_series->append(QPointF(100, 100)); | |
279 | QCOMPARE(m_series->count(), m_modelRowCount + 1); |
|
282 | QCOMPARE(m_series->count(), m_modelRowCount + 1); | |
280 | QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model |
|
283 | QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model | |
281 |
|
284 | |||
282 | m_series->remove(m_series->points().last()); |
|
285 | m_series->remove(m_series->points().last()); | |
283 | QCOMPARE(m_series->count(), m_modelRowCount); |
|
286 | QCOMPARE(m_series->count(), m_modelRowCount); | |
284 | QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model |
|
287 | QCOMPARE(mapper->count(), -1); // the value should not change as it indicates 'all' items there are in the model | |
285 |
|
288 | |||
|
289 | delete mapper; | |||
|
290 | mapper = 0; | |||
|
291 | ||||
|
292 | otherModel->clear(); | |||
|
293 | delete otherModel; | |||
|
294 | otherModel = 0; | |||
|
295 | } | |||
|
296 | ||||
|
297 | void tst_qxymodelmapper::modelUpdated() | |||
|
298 | { | |||
|
299 | QStandardItemModel *otherModel = new QStandardItemModel; | |||
|
300 | for (int row = 0; row < m_modelRowCount; ++row) { | |||
|
301 | for (int column = 0; column < m_modelColumnCount; column++) { | |||
|
302 | QStandardItem *item = new QStandardItem(row * column); | |||
|
303 | otherModel->setItem(row, column, item); | |||
|
304 | } | |||
|
305 | } | |||
|
306 | ||||
|
307 | QVXYModelMapper *mapper = new QVXYModelMapper; | |||
|
308 | QVERIFY(mapper->model() == 0); | |||
|
309 | mapper->setXColumn(0); | |||
|
310 | mapper->setYColumn(1); | |||
|
311 | mapper->setModel(otherModel); | |||
|
312 | mapper->setSeries(m_series); | |||
|
313 | QCOMPARE(m_series->count(), m_modelRowCount); | |||
|
314 | ||||
|
315 | QVERIFY(mapper->model() != 0); | |||
|
316 | ||||
|
317 | if (otherModel->insertRows(3, 4)) | |||
|
318 | QCOMPARE(m_series->count(), m_modelRowCount + 4); | |||
|
319 | ||||
|
320 | if (otherModel->removeRows(1, 5)) | |||
|
321 | QCOMPARE(m_series->count(), m_modelRowCount - 1); | |||
|
322 | ||||
|
323 | delete mapper; | |||
|
324 | mapper = 0; | |||
|
325 | ||||
286 | otherModel->clear(); |
|
326 | otherModel->clear(); | |
287 | delete otherModel; |
|
327 | delete otherModel; | |
288 | otherModel = 0; |
|
328 | otherModel = 0; | |
289 | } |
|
329 | } | |
290 |
|
330 | |||
291 | QTEST_MAIN(tst_qxymodelmapper) |
|
331 | QTEST_MAIN(tst_qxymodelmapper) | |
292 |
|
332 | |||
293 | #include "tst_qxymodelmapper.moc" |
|
333 | #include "tst_qxymodelmapper.moc" |
General Comments 0
You need to be logged in to leave comments.
Login now