summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kelly <stephen@kdab.com>2010-08-19 16:41:40 (GMT)
committerGabriel de Dietrich <gabriel.dietrich-de@nokia.com>2010-08-19 16:41:40 (GMT)
commit6e24bef57683b26f7cc1c4cddacace413d181d00 (patch)
tree00edc3ad4c8fe64f40ab09550e039e52c05b5d09
parent9b4c6ab8e27873c133f16ea655d7220b1ba348cf (diff)
downloadQt-6e24bef57683b26f7cc1c4cddacace413d181d00.zip
Qt-6e24bef57683b26f7cc1c4cddacace413d181d00.tar.gz
Qt-6e24bef57683b26f7cc1c4cddacace413d181d00.tar.bz2
Make the QItemSelectionRange and QItemSelectionModel ensure that the model is correct.
Merge-request: 720 Reviewed-by: Gabriel de Dietrich <gabriel.dietrich-de@nokia.com>
-rw-r--r--src/gui/itemviews/qitemselectionmodel.cpp3
-rw-r--r--tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp28
2 files changed, 30 insertions, 1 deletions
diff --git a/src/gui/itemviews/qitemselectionmodel.cpp b/src/gui/itemviews/qitemselectionmodel.cpp
index 4979db6..7156b87 100644
--- a/src/gui/itemviews/qitemselectionmodel.cpp
+++ b/src/gui/itemviews/qitemselectionmodel.cpp
@@ -212,6 +212,7 @@ bool QItemSelectionRange::intersects(const QItemSelectionRange &other) const
{
return (isValid() && other.isValid()
&& parent() == other.parent()
+ && model() == other.model()
&& ((top() <= other.top() && bottom() >= other.top())
|| (top() >= other.top() && top() <= other.bottom()))
&& ((left() <= other.left() && right() >= other.left())
@@ -508,7 +509,7 @@ void QItemSelection::merge(const QItemSelection &other, QItemSelectionModel::Sel
void QItemSelection::split(const QItemSelectionRange &range,
const QItemSelectionRange &other, QItemSelection *result)
{
- if (range.parent() != other.parent())
+ if (range.parent() != other.parent() || range.model() != other.model())
return;
QModelIndex parent = other.parent();
diff --git a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
index 46bd4a2..69b1390 100644
--- a/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
+++ b/tests/auto/qitemselectionmodel/tst_qitemselectionmodel.cpp
@@ -98,6 +98,8 @@ private slots:
void rangeOperatorLessThan_data();
void rangeOperatorLessThan();
+ void testDifferentModels();
+
private:
QAbstractItemModel *model;
QItemSelectionModel *selection;
@@ -2561,5 +2563,31 @@ void tst_QItemSelectionModel::rangeOperatorLessThan()
QVERIFY(r4 < r2);
}
+void tst_QItemSelectionModel::testDifferentModels()
+{
+ QStandardItemModel model1;
+ QStandardItemModel model2;
+ QStandardItem top11("Child1"), top12("Child2"), top13("Child3");
+ QStandardItem top21("Child1"), top22("Child2"), top23("Child3");
+
+ model1.appendColumn(QList<QStandardItem*>() << &top11 << &top12 << &top13);
+ model2.appendColumn(QList<QStandardItem*>() << &top21 << &top22 << &top23);
+
+
+ QModelIndex topIndex1 = model1.index(0, 0);
+ QModelIndex bottomIndex1 = model1.index(2, 0);
+ QModelIndex topIndex2 = model2.index(0, 0);
+
+ QItemSelectionRange range(topIndex1, bottomIndex1);
+
+ QVERIFY(range.intersects(QItemSelectionRange(topIndex1, topIndex1)));
+ QVERIFY(!range.intersects(QItemSelectionRange(topIndex2, topIndex2)));
+
+ QItemSelection newSelection;
+ QItemSelection::split(range, QItemSelectionRange(topIndex2, topIndex2), &newSelection);
+
+ QVERIFY(newSelection.isEmpty());
+}
+
QTEST_MAIN(tst_QItemSelectionModel)
#include "tst_qitemselectionmodel.moc"