summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@qt.io>2019-10-14 13:40:14 +0300
committerMiikka Heikkinen <miikka.heikkinen@qt.io>2019-10-15 09:56:08 +0300
commit73f81ac479eb5ce48716c491abfe7a875a047edb (patch)
treeae21c679002eac13cede4bb1dde47a049bcdfca2 /src
parenta692d9a826d864e91b668415aea266228c2ae323 (diff)
Fix removing rows from candlestick model mapper
There is no guarantee removed rows are in correct order or that they are sequential, so don't assume so. Fixes: QTBUG-79188 Change-Id: I6ee6851ce881872d01486c600d4204faeb162d87 Reviewed-by: Tomi Korpipää <tomi.korpipaa@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/charts/candlestickchart/qcandlestickmodelmapper.cpp33
1 files changed, 24 insertions, 9 deletions
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();
}