diff options
author | Simon Hausmann <simon.hausmann@qt.io> | 2019-10-16 09:38:32 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@qt.io> | 2019-10-16 09:38:32 +0200 |
commit | 73d797cda0579f18ef4ef837a6384315619b50be (patch) | |
tree | d6ef7b983ff14f68a32808fd4b49c08730380092 | |
parent | 88e67e7686fa564e81a770a18879cc281e620222 (diff) | |
parent | fe9066461afd36fc9611db11f95f4c43f645b96e (diff) |
Merge remote-tracking branch 'origin/5.13' into 5.14v5.14.0-beta2
Change-Id: I2570b3c739857b2fc4ffb26e9ccf1101f2803d87
-rw-r--r-- | qtcharts.pro | 1 | ||||
-rw-r--r-- | src/charts/candlestickchart/qcandlestickmodelmapper.cpp | 33 | ||||
-rw-r--r-- | tests/auto/qcandlestickmodelmapper/tst_qcandlestickmodelmapper.cpp | 11 |
3 files changed, 35 insertions, 10 deletions
diff --git a/qtcharts.pro b/qtcharts.pro index fc2928f8..b5f519dc 100644 --- a/qtcharts.pro +++ b/qtcharts.pro @@ -3,6 +3,7 @@ requires(qtHaveModule(widgets)) qtHaveModule(widgets) { QT_FOR_CONFIG += widgets requires(qtConfig(graphicsview)) + requires(qtConfig(texthtmlparser)) } load(qt_parts) diff --git a/src/charts/candlestickchart/qcandlestickmodelmapper.cpp b/src/charts/candlestickchart/qcandlestickmodelmapper.cpp index 8f876cd3..95a53b52 100644 --- a/src/charts/candlestickchart/qcandlestickmodelmapper.cpp +++ b/src/charts/candlestickchart/qcandlestickmodelmapper.cpp @@ -33,6 +33,8 @@ #include <QtCore/QAbstractItemModel> #include <private/qcandlestickmodelmapper_p.h> +#include <algorithm> + QT_CHARTS_BEGIN_NAMESPACE /*! @@ -590,20 +592,33 @@ void QCandlestickModelMapperPrivate::candlestickSetsRemoved(const QList<QCandles if (sets.isEmpty()) return; - int firstIndex = m_sets.indexOf(sets.at(0)); - if (firstIndex == -1) + QVector<int> removedIndices; + for (auto &set : sets) { + int index = m_sets.indexOf(set); + if (index != -1) + removedIndices << index; + } + + if (removedIndices.isEmpty()) return; - m_lastSetSection -= sets.count(); + std::sort(removedIndices.begin(), removedIndices.end()); - for (int i = firstIndex + sets.count() - 1; i >= firstIndex; --i) - m_sets.removeAt(i); + for (int i = removedIndices.size() - 1; i >= 0; --i) { + m_sets.removeAt(removedIndices[i]); + --m_lastSetSection; + } blockModelSignals(); - if (q->orientation() == Qt::Vertical) - m_model->removeColumns(firstIndex + m_firstSetSection, sets.count()); - else - m_model->removeRows(firstIndex + m_firstSetSection, sets.count()); + + // There is no guarantee removed sets are continuous, so remove them one by one + for (int i = removedIndices.size() - 1; i >= 0; --i) { + if (q->orientation() == Qt::Vertical) + m_model->removeColumns(removedIndices[i] + m_firstSetSection, 1); + else + m_model->removeRows(removedIndices[i] + m_firstSetSection, 1); + } + blockModelSignals(false); initializeCandlestickFromModel(); } diff --git a/tests/auto/qcandlestickmodelmapper/tst_qcandlestickmodelmapper.cpp b/tests/auto/qcandlestickmodelmapper/tst_qcandlestickmodelmapper.cpp index cf3531ed..a9ac4837 100644 --- a/tests/auto/qcandlestickmodelmapper/tst_qcandlestickmodelmapper.cpp +++ b/tests/auto/qcandlestickmodelmapper/tst_qcandlestickmodelmapper.cpp @@ -425,14 +425,23 @@ void tst_qcandlestickmodelmapper::seriesUpdated() QList<QCandlestickSet *> newCandlestickSets; newCandlestickSets << new QCandlestickSet(3.0, 5.0, 2.0, 4.0, 1234); newCandlestickSets << new QCandlestickSet(5.0, 7.0, 4.0, 6.0, 5678); + newCandlestickSets << new QCandlestickSet(3.0, 8.0, 4.0, 6.0, 6789); m_series->append(newCandlestickSets); QCOMPARE(m_model->columnCount(), m_modelColumnCount + newCandlestickSets.count()); // remove sets newCandlestickSets.clear(); newCandlestickSets << m_series->sets().at(m_series->count() - 1); - newCandlestickSets << m_series->sets().at(m_series->count() - 2); + newCandlestickSets << m_series->sets().at(m_series->count() - 5); + newCandlestickSets << m_series->sets().at(m_series->count() - 3); m_series->remove(newCandlestickSets); + + // Make sure correct rows have been removed from model + for (int i = 0, end = m_series->sets().size(); i < end; ++i) { + QCOMPARE(m_model->data(m_model->index(m_vMapper->timestampRow(), i)).toReal(), + m_series->sets().at(i)->timestamp()); + } + QCOMPARE(m_model->columnCount(), m_modelColumnCount); } |