summaryrefslogtreecommitdiffstats
path: root/src/corelib/itemmodels
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2017-05-29 10:06:10 +0200
committerLiang Qi <liang.qi@qt.io>2017-05-29 10:54:41 +0200
commit6a772fd201ac738dc86e71bd82e98f65158e6335 (patch)
tree674007720f41d27b251bbcffd7a368a93f88eb96 /src/corelib/itemmodels
parent40206a9f6d7635bb19305d1c8d74908808e3529e (diff)
parent4c346b6e2bfab976bc9b16275b8382aee38aefa4 (diff)
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts: .qmake.conf mkspecs/common/msvc-desktop.conf mkspecs/win32-g++/qmake.conf mkspecs/win32-icc/qmake.conf src/platformsupport/fontdatabases/mac/coretext.pri src/plugins/platforms/cocoa/qcocoawindow.h src/plugins/platforms/cocoa/qcocoawindow.mm Change-Id: I74a6f7705c9547ed8bbac7260eb4645543e32655
Diffstat (limited to 'src/corelib/itemmodels')
-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;
}