summaryrefslogtreecommitdiff
path: root/tests/auto/controls/data/tst_treeview.qml
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>2015-06-29 12:30:57 +0200
committerGabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>2015-07-04 16:41:22 +0000
commitb27c2ed888788f91db33d2ccea962a3815006858 (patch)
treeceaa5189529bd5284e449ab1bafce8b8b4f71652 /tests/auto/controls/data/tst_treeview.qml
parent56dfb59237f902cebd480d92912ad572f000e2ba (diff)
downloadqtquickcontrols-b27c2ed888788f91db33d2ccea962a3815006858.tar.gz
TreeView: Track model indexes during selection
As we keep track of the previous user-selected row, it can happen that that row is no longer part of the TreeModelAdaptor items if the user collapses it or any of its ancestors (collapsing a node doesn't update the current selection). This will result on the row index pointing to the wrong entry in the model (or a completely invalid one). Instead, we now track the selection with QModelIndexes making it more robust to branch expansion and collapse in the view. We'll still need to account for model changes which means that, in the future, we should invalidate the previous user-selected item. Change-Id: I54ba2582e65515eef95d5f8ad755a8c68568d7ad Task-number: QTBUG-46891 Reviewed-by: Caroline Chao <caroline.chao@theqtcompany.com>
Diffstat (limited to 'tests/auto/controls/data/tst_treeview.qml')
-rw-r--r--tests/auto/controls/data/tst_treeview.qml29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_treeview.qml b/tests/auto/controls/data/tst_treeview.qml
index 9db58f14..6e17e318 100644
--- a/tests/auto/controls/data/tst_treeview.qml
+++ b/tests/auto/controls/data/tst_treeview.qml
@@ -785,5 +785,34 @@ Item {
compare(treeIndex.column, modelIndex.column)
compare(treeIndex.internalId, modelIndex.internalId)
}
+
+ function test_QTBUG_46891_selection_collapse_parent()
+ {
+ var component = Qt.createComponent("treeview/treeview_1.qml")
+ compare(component.status, Component.Ready)
+ var tree = component.createObject(container);
+ verify(tree !== null, "tree created is null")
+ var model = tree.model
+ model.removeRows(1, 9)
+ model.removeRows(1, 9, model.index(0, 0))
+ waitForRendering(tree)
+
+ var selectionModel = Qt.createQmlObject(testCase.instance_selectionModel, container, '')
+ selectionModel.model = tree.model
+ tree.selection = selectionModel
+ tree.selectionMode = SelectionMode.ExtendedSelection
+
+ var parentItem = tree.model.index(0, 0)
+ tree.expand(parentItem)
+ verify(tree.isExpanded(parentItem))
+
+ wait(100)
+ mouseClick(tree, semiIndent + 50, 20 + 100, Qt.LeftButton)
+ verify(selectionModel.isSelected(tree.currentIndex))
+
+ tree.collapse(parentItem)
+ mouseClick(tree, semiIndent + 50, 20 + 50, Qt.LeftButton)
+ verify(selectionModel.isSelected(parentItem))
+ }
}
}