summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Kudryavtsev <a.kudryavtsev@netris.ru>2015-12-24 14:15:07 +0300
committerAnton Kudryavtsev <a.kudryavtsev@netris.ru>2016-01-11 11:40:38 +0000
commit2a2c58230655b174728a02c389b33b6b3bb248fd (patch)
tree3c0153e0e6ef00c11c4bd7a6d7e5c7d452853b6e
parent2ccacfb5c9a013fb8d32dfc90e55f0890e7b7a3a (diff)
QListView: use erase and std::remove_if with QVector
... instead of using erase in a loop, with quadratic complexity. Change-Id: I9686d117e092f5d74c6e74a462adf503a7b7ae79 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
-rw-r--r--src/widgets/itemviews/qlistview.cpp12
-rw-r--r--src/widgets/itemviews/qlistview_p.h10
2 files changed, 13 insertions, 9 deletions
diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp
index 985b347bbc..6e432a9ad7 100644
--- a/src/widgets/itemviews/qlistview.cpp
+++ b/src/widgets/itemviews/qlistview.cpp
@@ -52,6 +52,8 @@
#include <qaccessible.h>
#endif
+#include <algorithm>
+
QT_BEGIN_NAMESPACE
extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event);
@@ -1844,6 +1846,16 @@ bool QListViewPrivate::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QMo
}
#endif
+void QListViewPrivate::removeCurrentAndDisabled(QVector<QModelIndex> *indexes, const QModelIndex &current) const
+{
+ auto isCurrentOrDisabled = [=](const QModelIndex &index) {
+ return !isIndexEnabled(index) || index == current;
+ };
+ indexes->erase(std::remove_if(indexes->begin(), indexes->end(),
+ isCurrentOrDisabled),
+ indexes->end());
+}
+
/*
* Common ListView Implementation
*/
diff --git a/src/widgets/itemviews/qlistview_p.h b/src/widgets/itemviews/qlistview_p.h
index 506af311c3..2aa34256d2 100644
--- a/src/widgets/itemviews/qlistview_p.h
+++ b/src/widgets/itemviews/qlistview_p.h
@@ -372,15 +372,7 @@ public:
}
inline bool isHiddenOrDisabled(int row) const { return isHidden(row) || !isIndexEnabled(modelIndex(row)); }
- inline void removeCurrentAndDisabled(QVector<QModelIndex> *indexes, const QModelIndex &current) const {
- QVector<QModelIndex>::iterator it = indexes->begin();
- while (it != indexes->end()) {
- if (!isIndexEnabled(*it) || (*it) == current)
- indexes->erase(it);
- else
- ++it;
- }
- }
+ void removeCurrentAndDisabled(QVector<QModelIndex> *indexes, const QModelIndex &current) const;
void scrollElasticBandBy(int dx, int dy);