Commit 2a2c5823 authored by Anton Kudryavtsev's avatar Anton Kudryavtsev
Browse files

QListView: use erase and std::remove_if with QVector


... instead of using erase in a loop, with quadratic complexity.

Change-Id: I9686d117e092f5d74c6e74a462adf503a7b7ae79
Reviewed-by: default avatarMarc Mutz <marc.mutz@kdab.com>
Showing with 13 additions and 9 deletions
...@@ -52,6 +52,8 @@ ...@@ -52,6 +52,8 @@
#include <qaccessible.h> #include <qaccessible.h>
#endif #endif
#include <algorithm>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event); extern bool qt_sendSpontaneousEvent(QObject *receiver, QEvent *event);
...@@ -1844,6 +1846,16 @@ bool QListViewPrivate::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QMo ...@@ -1844,6 +1846,16 @@ bool QListViewPrivate::dropOn(QDropEvent *event, int *dropRow, int *dropCol, QMo
} }
#endif #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 * Common ListView Implementation
*/ */
......
...@@ -372,15 +372,7 @@ public: ...@@ -372,15 +372,7 @@ public:
} }
inline bool isHiddenOrDisabled(int row) const { return isHidden(row) || !isIndexEnabled(modelIndex(row)); } inline bool isHiddenOrDisabled(int row) const { return isHidden(row) || !isIndexEnabled(modelIndex(row)); }
inline void removeCurrentAndDisabled(QVector<QModelIndex> *indexes, const QModelIndex &current) const { 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 scrollElasticBandBy(int dx, int dy); void scrollElasticBandBy(int dx, int dy);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment