@@ -0,0 +1,8 | |||
|
1 | !include( ../auto.pri ) { | |
|
2 | error( "Couldn't find the auto.pri file!" ) | |
|
3 | } | |
|
4 | ||
|
5 | SOURCES += \ | |
|
6 | tst_qpiemodelmapper.cpp | |
|
7 | ||
|
8 | !system_build:mac: QMAKE_POST_LINK += "$$MAC_POST_LINK_PREFIX $$MAC_AUTOTESTS_BIN_DIR" |
@@ -0,0 +1,241 | |||
|
1 | #include <QtCore/QString> | |
|
2 | #include <QtTest/QtTest> | |
|
3 | ||
|
4 | #include <qchart.h> | |
|
5 | #include <qchartview.h> | |
|
6 | #include <qpieseries.h> | |
|
7 | #include <qvpiemodelmapper.h> | |
|
8 | #include <qhpiemodelmapper.h> | |
|
9 | #include <QStandardItemModel> | |
|
10 | ||
|
11 | QTCOMMERCIALCHART_USE_NAMESPACE | |
|
12 | ||
|
13 | class tst_piemodelmapper : public QObject | |
|
14 | { | |
|
15 | Q_OBJECT | |
|
16 | ||
|
17 | public: | |
|
18 | tst_piemodelmapper(); | |
|
19 | ||
|
20 | private Q_SLOTS: | |
|
21 | void initTestCase(); | |
|
22 | void cleanupTestCase(); | |
|
23 | void init(); | |
|
24 | void cleanup(); | |
|
25 | void verticalMapper_data(); | |
|
26 | void verticalMapper(); | |
|
27 | void verticalMapperCustomMapping_data(); | |
|
28 | void verticalMapperCustomMapping(); | |
|
29 | void horizontalMapper_data(); | |
|
30 | void horizontalMapper(); | |
|
31 | void horizontalMapperCustomMapping_data(); | |
|
32 | void horizontalMapperCustomMapping(); | |
|
33 | ||
|
34 | ||
|
35 | private: | |
|
36 | QStandardItemModel *m_model; | |
|
37 | int m_modelRowCount; | |
|
38 | int m_modelColumnCount; | |
|
39 | ||
|
40 | QPieSeries *m_series; | |
|
41 | QChart *m_chart; | |
|
42 | }; | |
|
43 | ||
|
44 | tst_piemodelmapper::tst_piemodelmapper(): | |
|
45 | m_model(0), | |
|
46 | m_modelRowCount(10), | |
|
47 | m_modelColumnCount(8) | |
|
48 | { | |
|
49 | } | |
|
50 | ||
|
51 | void tst_piemodelmapper::init() | |
|
52 | { | |
|
53 | m_series = new QPieSeries; | |
|
54 | m_chart->addSeries(m_series); | |
|
55 | } | |
|
56 | ||
|
57 | void tst_piemodelmapper::cleanup() | |
|
58 | { | |
|
59 | m_chart->removeSeries(m_series); | |
|
60 | delete m_series; | |
|
61 | m_series = 0; | |
|
62 | } | |
|
63 | ||
|
64 | void tst_piemodelmapper::initTestCase() | |
|
65 | { | |
|
66 | m_chart = new QChart; | |
|
67 | QChartView *chartView = new QChartView(m_chart); | |
|
68 | chartView->show(); | |
|
69 | ||
|
70 | m_model = new QStandardItemModel(this); | |
|
71 | for (int row = 0; row < m_modelRowCount; ++row) { | |
|
72 | for (int column = 0; column < m_modelColumnCount; column++) { | |
|
73 | QStandardItem *item = new QStandardItem(row * column); | |
|
74 | m_model->setItem(row, column, item); | |
|
75 | } | |
|
76 | } | |
|
77 | } | |
|
78 | ||
|
79 | void tst_piemodelmapper::cleanupTestCase() | |
|
80 | { | |
|
81 | m_model->clear(); | |
|
82 | } | |
|
83 | ||
|
84 | void tst_piemodelmapper::verticalMapper_data() | |
|
85 | { | |
|
86 | QTest::addColumn<int>("valuesColumn"); | |
|
87 | QTest::addColumn<int>("labelsColumn"); | |
|
88 | QTest::addColumn<int>("expectedCount"); | |
|
89 | QTest::newRow("different values and labels columns") << 0 << 1 << m_modelRowCount; | |
|
90 | QTest::newRow("same values and labels columns") << 1 << 1 << m_modelRowCount; | |
|
91 | QTest::newRow("invalid values column and correct labels column") << -3 << 1 << 0; | |
|
92 | QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << 1 << 0; | |
|
93 | QTest::newRow("values column beyond the size of model and correct labels column") << m_modelColumnCount << -1 << 0; | |
|
94 | } | |
|
95 | ||
|
96 | void tst_piemodelmapper::verticalMapper() | |
|
97 | { | |
|
98 | QFETCH(int, valuesColumn); | |
|
99 | QFETCH(int, labelsColumn); | |
|
100 | QFETCH(int, expectedCount); | |
|
101 | ||
|
102 | QVPieModelMapper *mapper = new QVPieModelMapper; | |
|
103 | mapper->setValuesColumn(valuesColumn); | |
|
104 | mapper->setLabelsColumn(labelsColumn); | |
|
105 | mapper->setModel(m_model); | |
|
106 | mapper->setSeries(m_series); | |
|
107 | ||
|
108 | QCOMPARE(m_series->count(), expectedCount); | |
|
109 | QCOMPARE(mapper->valuesColumn(), qMax(-1, valuesColumn)); | |
|
110 | QCOMPARE(mapper->labelsColumn(), qMax(-1, labelsColumn)); | |
|
111 | ||
|
112 | delete mapper; | |
|
113 | mapper = 0; | |
|
114 | } | |
|
115 | ||
|
116 | void tst_piemodelmapper::verticalMapperCustomMapping_data() | |
|
117 | { | |
|
118 | QTest::addColumn<int>("first"); | |
|
119 | QTest::addColumn<int>("countLimit"); | |
|
120 | QTest::addColumn<int>("expectedCount"); | |
|
121 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelRowCount; | |
|
122 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelRowCount - 3; | |
|
123 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelRowCount); | |
|
124 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelRowCount - 3); | |
|
125 | QTest::newRow("first: +1 greater then the number of rows in the model, unlimited count") << m_modelRowCount + 1 << -1 << 0; | |
|
126 | QTest::newRow("first: +1 greater then the number of rows in the model, count: 5") << m_modelRowCount + 1 << 5 << 0; | |
|
127 | 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; | |
|
128 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelRowCount; | |
|
129 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelRowCount; | |
|
130 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelRowCount; | |
|
131 | ||
|
132 | } | |
|
133 | ||
|
134 | void tst_piemodelmapper::verticalMapperCustomMapping() | |
|
135 | { | |
|
136 | QFETCH(int, first); | |
|
137 | QFETCH(int, countLimit); | |
|
138 | QFETCH(int, expectedCount); | |
|
139 | ||
|
140 | QCOMPARE(m_series->count(), 0); | |
|
141 | ||
|
142 | QVPieModelMapper *mapper = new QVPieModelMapper; | |
|
143 | mapper->setValuesColumn(0); | |
|
144 | mapper->setLabelsColumn(1); | |
|
145 | mapper->setModel(m_model); | |
|
146 | mapper->setSeries(m_series); | |
|
147 | mapper->setFirst(first); | |
|
148 | mapper->setCount(countLimit); | |
|
149 | ||
|
150 | QCOMPARE(m_series->count(), expectedCount); | |
|
151 | ||
|
152 | // change values column mappings to invalid | |
|
153 | mapper->setValuesColumn(-1); | |
|
154 | mapper->setLabelsColumn(1); | |
|
155 | ||
|
156 | QCOMPARE(m_series->count(), 0); | |
|
157 | ||
|
158 | delete mapper; | |
|
159 | mapper = 0; | |
|
160 | } | |
|
161 | ||
|
162 | void tst_piemodelmapper::horizontalMapper_data() | |
|
163 | { | |
|
164 | QTest::addColumn<int>("valuesRow"); | |
|
165 | QTest::addColumn<int>("labelsRow"); | |
|
166 | QTest::addColumn<int>("expectedCount"); | |
|
167 | QTest::newRow("different values and labels rows") << 0 << 1 << m_modelColumnCount; | |
|
168 | QTest::newRow("same values and labels rows") << 1 << 1 << m_modelColumnCount; | |
|
169 | QTest::newRow("invalid values row and correct labels row") << -3 << 1 << 0; | |
|
170 | QTest::newRow("values row beyond the size of model and correct labels row") << m_modelRowCount << 1 << 0; | |
|
171 | QTest::newRow("values row beyond the size of model and invalid labels row") << m_modelRowCount << -1 << 0; | |
|
172 | } | |
|
173 | ||
|
174 | void tst_piemodelmapper::horizontalMapper() | |
|
175 | { | |
|
176 | QFETCH(int, valuesRow); | |
|
177 | QFETCH(int, labelsRow); | |
|
178 | QFETCH(int, expectedCount); | |
|
179 | ||
|
180 | QHPieModelMapper *mapper = new QHPieModelMapper; | |
|
181 | mapper->setValuesRow(valuesRow); | |
|
182 | mapper->setLabelsRow(labelsRow); | |
|
183 | mapper->setModel(m_model); | |
|
184 | mapper->setSeries(m_series); | |
|
185 | ||
|
186 | QCOMPARE(m_series->count(), expectedCount); | |
|
187 | QCOMPARE(mapper->valuesRow(), qMax(-1, valuesRow)); | |
|
188 | QCOMPARE(mapper->labelsRow(), qMax(-1, labelsRow)); | |
|
189 | ||
|
190 | delete mapper; | |
|
191 | mapper = 0; | |
|
192 | } | |
|
193 | ||
|
194 | void tst_piemodelmapper::horizontalMapperCustomMapping_data() | |
|
195 | { | |
|
196 | QTest::addColumn<int>("first"); | |
|
197 | QTest::addColumn<int>("countLimit"); | |
|
198 | QTest::addColumn<int>("expectedCount"); | |
|
199 | QTest::newRow("first: 0, unlimited count") << 0 << -1 << m_modelColumnCount; | |
|
200 | QTest::newRow("first: 3, unlimited count") << 3 << -1 << m_modelColumnCount - 3; | |
|
201 | QTest::newRow("first: 0, count: 5") << 0 << 5 << qMin(5, m_modelColumnCount); | |
|
202 | QTest::newRow("first: 3, count: 5") << 3 << 5 << qMin(5, m_modelColumnCount - 3); | |
|
203 | QTest::newRow("first: +1 greater then the number of columns in the model, unlimited count") << m_modelColumnCount + 1 << -1 << 0; | |
|
204 | QTest::newRow("first: +1 greater then the number of columns in the model, count: 5") << m_modelColumnCount + 1 << 5 << 0; | |
|
205 | 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; | |
|
206 | QTest::newRow("first: -3(invalid - should default to 0), unlimited count") << -3 << -1 << m_modelColumnCount; | |
|
207 | QTest::newRow("first: 0, count: -3 (invalid - shlould default to -1)") << 0 << -3 << m_modelColumnCount; | |
|
208 | QTest::newRow("first: -3(invalid - should default to 0), count: -3 (invalid - shlould default to -1)") << -3 << -3 << m_modelColumnCount; | |
|
209 | } | |
|
210 | ||
|
211 | void tst_piemodelmapper::horizontalMapperCustomMapping() | |
|
212 | { | |
|
213 | QFETCH(int, first); | |
|
214 | QFETCH(int, countLimit); | |
|
215 | QFETCH(int, expectedCount); | |
|
216 | ||
|
217 | QCOMPARE(m_series->count(), 0); | |
|
218 | ||
|
219 | QHPieModelMapper *mapper = new QHPieModelMapper; | |
|
220 | mapper->setValuesRow(0); | |
|
221 | mapper->setLabelsRow(1); | |
|
222 | mapper->setModel(m_model); | |
|
223 | mapper->setSeries(m_series); | |
|
224 | mapper->setFirst(first); | |
|
225 | mapper->setCount(countLimit); | |
|
226 | ||
|
227 | QCOMPARE(m_series->count(), expectedCount); | |
|
228 | ||
|
229 | // change values column mappings to invalid | |
|
230 | mapper->setValuesRow(-1); | |
|
231 | mapper->setLabelsRow(1); | |
|
232 | ||
|
233 | QCOMPARE(m_series->count(), 0); | |
|
234 | ||
|
235 | delete mapper; | |
|
236 | mapper = 0; | |
|
237 | } | |
|
238 | ||
|
239 | QTEST_MAIN(tst_piemodelmapper) | |
|
240 | ||
|
241 | #include "tst_qpiemodelmapper.moc" |
@@ -73,7 +73,6 void QPieModelMapper::setFirst(int first) | |||
|
73 | 73 | Q_D(QPieModelMapper); |
|
74 | 74 | d->m_first = qMax(first, 0); |
|
75 | 75 | d->initializePieFromModel(); |
|
76 | // emit updated(); | |
|
77 | 76 | } |
|
78 | 77 | |
|
79 | 78 | int QPieModelMapper::count() const |
@@ -87,7 +86,6 void QPieModelMapper::setCount(int count) | |||
|
87 | 86 | Q_D(QPieModelMapper); |
|
88 | 87 | d->m_count = qMax(count, -1); |
|
89 | 88 | d->initializePieFromModel(); |
|
90 | // emit updated(); | |
|
91 | 89 | } |
|
92 | 90 | |
|
93 | 91 | Qt::Orientation QPieModelMapper::orientation() const |
@@ -101,7 +99,6 void QPieModelMapper::setOrientation(Qt::Orientation orientation) | |||
|
101 | 99 | Q_D(QPieModelMapper); |
|
102 | 100 | d->m_orientation = orientation; |
|
103 | 101 | d->initializePieFromModel(); |
|
104 | // emit updated(); | |
|
105 | 102 | } |
|
106 | 103 | |
|
107 | 104 | int QPieModelMapper::valuesIndex() const |
@@ -110,12 +107,11 int QPieModelMapper::valuesIndex() const | |||
|
110 | 107 | return d->m_valuesIndex; |
|
111 | 108 | } |
|
112 | 109 | |
|
113 |
void QPieModelMapper::setValuesIndex(int |
|
|
110 | void QPieModelMapper::setValuesIndex(int valuesIndex) | |
|
114 | 111 | { |
|
115 | 112 | Q_D(QPieModelMapper); |
|
116 |
d->m_valuesIndex = |
|
|
113 | d->m_valuesIndex = qMax(-1, valuesIndex); | |
|
117 | 114 | d->initializePieFromModel(); |
|
118 | // emit updated(); | |
|
119 | 115 | } |
|
120 | 116 | |
|
121 | 117 | int QPieModelMapper::labelsIndex() const |
@@ -124,12 +120,11 int QPieModelMapper::labelsIndex() const | |||
|
124 | 120 | return d->m_labelsIndex; |
|
125 | 121 | } |
|
126 | 122 | |
|
127 |
void QPieModelMapper::setLabelsIndex(int |
|
|
123 | void QPieModelMapper::setLabelsIndex(int labelsIndex) | |
|
128 | 124 | { |
|
129 | 125 | Q_D(QPieModelMapper); |
|
130 |
d->m_labelsIndex = |
|
|
126 | d->m_labelsIndex = qMax(-1, labelsIndex); | |
|
131 | 127 | d->initializePieFromModel(); |
|
132 | // emit updated(); | |
|
133 | 128 | } |
|
134 | 129 | |
|
135 | 130 | void QPieModelMapper::reset() |
@@ -140,7 +135,6 void QPieModelMapper::reset() | |||
|
140 | 135 | d->m_orientation = Qt::Vertical; |
|
141 | 136 | d->m_valuesIndex = -1; |
|
142 | 137 | d->m_labelsIndex = -1; |
|
143 | // emit updated(); | |
|
144 | 138 | } |
|
145 | 139 | |
|
146 | 140 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
@@ -439,10 +433,6 void QPieModelMapperPrivate::initializePieFromModel() | |||
|
439 | 433 | if (m_model == 0 || m_series == 0) |
|
440 | 434 | return; |
|
441 | 435 | |
|
442 | // check if mappings are set | |
|
443 | if (m_valuesIndex == -1 || m_labelsIndex == -1) | |
|
444 | return; | |
|
445 | ||
|
446 | 436 | blockSeriesSignals(); |
|
447 | 437 | // clear current content |
|
448 | 438 | m_series->clear(); |
@@ -3,7 +3,7 | |||
|
3 | 3 | } |
|
4 | 4 | |
|
5 | 5 | TEMPLATE = subdirs |
|
6 | SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qstackedbarseries qpercentbarseries qgroupedbarseries qpieslice qpieseries | |
|
6 | SUBDIRS += qchartview qchart qlineseries qbarset qbarseries qstackedbarseries qpercentbarseries qgroupedbarseries qpieslice qpieseries qpiemodelmapper | |
|
7 | 7 | |
|
8 | 8 | test_private:{ |
|
9 | 9 | SUBDIRS += chartdataset domain |
@@ -355,7 +355,7 void TableWidget::updateChartType(bool toggle) | |||
|
355 | 355 | m_pieMapper->setSeries(m_pieSeries); |
|
356 | 356 | m_pieMapper->setModel(m_model); |
|
357 | 357 | m_pieMapper->setFirst(2); |
|
358 | m_pieMapper->setCount(5); | |
|
358 | // m_pieMapper->setCount(5); | |
|
359 | 359 | // pieSeries->setModelMapper(mapper); |
|
360 | 360 | |
|
361 | 361 | m_pieSeries->setLabelsVisible(true); |
General Comments 0
You need to be logged in to leave comments.
Login now