Make rowIntersectsSelection take account of the parent argument.
authorStephen Kelly <stephen.kelly@kdab.com>
Fri, 10 Aug 2012 16:30:19 +0000 (18:30 +0200)
committerQt by Nokia <qt-info@nokia.com>
Fri, 10 Aug 2012 20:02:11 +0000 (22:02 +0200)
Task-number: QTBUG-22370

Change-Id: I497194793eab624b760deea93dac0df767850330
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
src/corelib/itemmodels/qitemselectionmodel.cpp
tests/auto/corelib/itemmodels/qitemselectionmodel/tst_qitemselectionmodel.cpp

index 9cc9502..a7aa404 100644 (file)
@@ -1379,10 +1379,13 @@ bool QItemSelectionModel::rowIntersectsSelection(int row, const QModelIndex &par
     QItemSelection sel = d->ranges;
     sel.merge(d->currentSelection, d->currentCommand);
     for (int i = 0; i < sel.count(); ++i) {
-        int top = sel.at(i).top();
-        int bottom = sel.at(i).bottom();
-        int left = sel.at(i).left();
-        int right = sel.at(i).right();
+        QItemSelectionRange range = sel.at(i);
+        if (range.parent() != parent)
+          return false;
+        int top = range.top();
+        int bottom = range.bottom();
+        int left = range.left();
+        int right = range.right();
         if (top <= row && bottom >= row) {
             for (int j = left; j <= right; j++) {
                 const Qt::ItemFlags flags = d->model->index(row, j, parent).flags();
index 94a81b9..2a7180c 100644 (file)
@@ -79,6 +79,7 @@ private slots:
     void splitOnInsert();
     void rowIntersectsSelection1();
     void rowIntersectsSelection2();
+    void rowIntersectsSelection3();
     void unselectable();
     void selectedIndexes();
     void layoutChanged();
@@ -2037,6 +2038,30 @@ void tst_QItemSelectionModel::rowIntersectsSelection2()
     QVERIFY(!selected.columnIntersectsSelection(5, QModelIndex()));
 }
 
+void tst_QItemSelectionModel::rowIntersectsSelection3()
+{
+    QStandardItemModel model;
+    QStandardItem *parentItem = model.invisibleRootItem();
+    for (int i = 0; i < 4; ++i) {
+        QStandardItem *item = new QStandardItem(QString("item %0").arg(i));
+        parentItem->appendRow(item);
+        parentItem = item;
+    }
+
+    QItemSelectionModel selectionModel(&model);
+
+    selectionModel.select(model.index(0, 0, model.index(0, 0)), QItemSelectionModel::Select);
+
+    QModelIndex parent;
+    QVERIFY(!selectionModel.rowIntersectsSelection(0, parent));
+    parent = model.index(0, 0, parent);
+    QVERIFY(selectionModel.rowIntersectsSelection(0, parent));
+    parent = model.index(0, 0, parent);
+    QVERIFY(!selectionModel.rowIntersectsSelection(0, parent));
+    parent = model.index(0, 0, parent);
+    QVERIFY(!selectionModel.rowIntersectsSelection(0, parent));
+}
+
 void tst_QItemSelectionModel::unselectable()
 {
     QTreeWidget w;