summaryrefslogtreecommitdiffstats
path: root/src/corelib/itemmodels/qitemselectionmodel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/itemmodels/qitemselectionmodel.cpp')
-rw-r--r--src/corelib/itemmodels/qitemselectionmodel.cpp37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp
index 7714aa5e46..8dcd80808b 100644
--- a/src/corelib/itemmodels/qitemselectionmodel.cpp
+++ b/src/corelib/itemmodels/qitemselectionmodel.cpp
@@ -42,6 +42,7 @@
#include <qdebug.h>
#include <algorithm>
+#include <functional>
#ifndef QT_NO_ITEMVIEWS
@@ -307,7 +308,9 @@ bool QItemSelectionRange::operator<(const QItemSelectionRange &other) const
}
return topLeftParent < otherTopLeftParent;
}
- return tl.model() < other.tl.model();
+
+ std::less<const QAbstractItemModel *> less;
+ return less(tl.model(), other.tl.model());
}
/*!
@@ -1264,6 +1267,21 @@ void QItemSelectionModel::select(const QModelIndex &index, QItemSelectionModel::
convenience.
*/
+namespace {
+namespace QtFunctionObjects {
+struct IsNotValid {
+ typedef bool result_type;
+ struct is_transparent : std::true_type {};
+ template <typename T>
+ Q_DECL_CONSTEXPR bool operator()(T &t) const Q_DECL_NOEXCEPT_EXPR(noexcept(t.isValid()))
+ { return !t.isValid(); }
+ template <typename T>
+ Q_DECL_CONSTEXPR bool operator()(T *t) const Q_DECL_NOEXCEPT_EXPR(noexcept(t->isValid()))
+ { return !t->isValid(); }
+};
+}
+} // unnamed namespace
+
/*!
Selects the item \a selection using the specified \a command, and emits
selectionChanged().
@@ -1287,13 +1305,9 @@ void QItemSelectionModel::select(const QItemSelection &selection, QItemSelection
// be too late if another model observer is connected to the same modelReset slot and is invoked first
// it might call select() on this selection model before any such QItemSelectionModelPrivate::_q_modelReset() slot
// is invoked, so it would not be cleared yet. We clear it invalid ranges in it here.
- QItemSelection::iterator it = d->ranges.begin();
- while (it != d->ranges.end()) {
- if (!it->isValid())
- it = d->ranges.erase(it);
- else
- ++it;
- }
+ using namespace QtFunctionObjects;
+ d->ranges.erase(std::remove_if(d->ranges.begin(), d->ranges.end(), IsNotValid()),
+ d->ranges.end());
QItemSelection old = d->ranges;
old.merge(d->currentSelection, d->currentCommand);
@@ -1745,12 +1759,9 @@ const QItemSelection QItemSelectionModel::selection() const
selected.merge(d->currentSelection, d->currentCommand);
// make sure we have no invalid ranges
// ### should probably be handled more generic somewhere else
- auto isNotValid = [](const QItemSelectionRange& range) {
- return !range.isValid();
- };
-
+ using namespace QtFunctionObjects;
selected.erase(std::remove_if(selected.begin(), selected.end(),
- isNotValid),
+ IsNotValid()),
selected.end());
return selected;
}