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