summaryrefslogtreecommitdiffstats
path: root/src/gui/itemmodels
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-06-10 16:46:54 +0200
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-06-11 13:29:23 +0000
commit56d62345ad34b8efb6a72a3c189542eb295ac2b9 (patch)
treeaaa002324fcbe36f13823e46be09135be125a4ff /src/gui/itemmodels
parent05dcc0499bfae43b8ae4100ab71902a13dd40f74 (diff)
Fix less-than comparison for QStandardItem and QSortFilterProxyModel with invalid data.
Previously, QStandardItem::operator<() returned true when both items had invalid data. With MSVC in debug mode (checked iterators/STL), this triggered an assert in tst_QStandardItem::sortChildren() since that verifies that !(b < a) when a < b: Debug Assertion Failed! Line: 3006 Expression: invalid operator< Introduce a stable sort order for invalid items such that other items are always less than invalid items and comparing invalid items returns false (indicating equivalence). Change-Id: Ica0f0d9f001c86973b1941dbcc1faf282e4c47df Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'src/gui/itemmodels')
-rw-r--r--src/gui/itemmodels/qstandarditemmodel.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp
index ed2479302e..8d848b662f 100644
--- a/src/gui/itemmodels/qstandarditemmodel.cpp
+++ b/src/gui/itemmodels/qstandarditemmodel.cpp
@@ -1811,9 +1811,11 @@ bool QStandardItem::operator<(const QStandardItem &other) const
const int role = model() ? model()->sortRole() : Qt::DisplayRole;
const QVariant l = data(role), r = other.data(role);
// this code is copied from QSortFilterProxyModel::lessThan()
+ if (l.userType() == QVariant::Invalid)
+ return false;
+ if (r.userType() == QVariant::Invalid)
+ return true;
switch (l.userType()) {
- case QVariant::Invalid:
- return (r.type() == QVariant::Invalid);
case QVariant::Int:
return l.toInt() < r.toInt();
case QVariant::UInt: