diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/controls/data/tst_treeview.qml | 29 | ||||
-rw-r--r-- | tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp | 35 | ||||
-rw-r--r-- | tests/auto/shared/testmodel.h | 4 |
3 files changed, 57 insertions, 11 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)) + } } } diff --git a/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp b/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp index 503b9e6f..b484665d 100644 --- a/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp +++ b/tests/auto/qquicktreemodeladaptor/tst_qquicktreemodeladaptor.cpp @@ -1138,7 +1138,8 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() for (int i = 0; i < ModelRowCount; i += ModelRowCountLoopStep) { // Single row selection - const QItemSelection &sel = tma.selectionForRowRange(i, i); + const QModelIndex &idx = model.index(i, 0); + const QItemSelection &sel = tma.selectionForRowRange(idx, idx); QCOMPARE(sel.count(), 1); const QItemSelectionRange &range = sel.first(); QCOMPARE(QModelIndex(range.topLeft()), model.index(i, 0)); @@ -1147,7 +1148,9 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() for (int i = 0; i < ModelRowCount - ModelRowCountLoopStep; i += ModelRowCountLoopStep) { // Single range selection - const QItemSelection &sel = tma.selectionForRowRange(i, i + ModelRowCountLoopStep); + const QModelIndex &from = model.index(i, 0); + const QModelIndex &to = model.index(i + ModelRowCountLoopStep, 0); + const QItemSelection &sel = tma.selectionForRowRange(from, to); QCOMPARE(sel.count(), 1); const QItemSelectionRange &range = sel.first(); QCOMPARE(QModelIndex(range.topLeft()), model.index(i, 0)); @@ -1155,7 +1158,9 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() } { // Select all, no branch expanded - const QItemSelection &sel = tma.selectionForRowRange(0, ModelRowCount - 1); + const QModelIndex &from = model.index(0, 0); + const QModelIndex &to = model.index(ModelRowCount - 1, 0); + const QItemSelection &sel = tma.selectionForRowRange(from, to); QCOMPARE(sel.count(), 1); const QItemSelectionRange &range = sel.first(); QCOMPARE(QModelIndex(range.topLeft()), model.index(0, 0)); @@ -1167,7 +1172,9 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() tma.expand(parent); { // 1st item expanded, select first 5 rows - const QItemSelection &sel = tma.selectionForRowRange(0, 4); + const QModelIndex &from = tma.mapRowToModelIndex(0); + const QModelIndex &to = tma.mapRowToModelIndex(4); + const QItemSelection &sel = tma.selectionForRowRange(from, to); QCOMPARE(sel.count(), 2); // We don't know in which order the selection ranges are // being added, so we iterate and try to find what we expect. @@ -1182,7 +1189,9 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() } { // 1st item expanded, select first 5 top-level items - const QItemSelection &sel = tma.selectionForRowRange(0, 4 + ModelRowCount); + const QModelIndex &from = tma.mapRowToModelIndex(0); + const QModelIndex &to = tma.mapRowToModelIndex(4 + ModelRowCount); + const QItemSelection &sel = tma.selectionForRowRange(from, to); QCOMPARE(sel.count(), 2); // We don't know in which order the selection ranges are // being added, so we iterate and try to find what we expect. @@ -1201,7 +1210,9 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() tma.expand(parent2); { // 1st two items expanded, select first 5 top-level items - const QItemSelection &sel = tma.selectionForRowRange(0, 4 + 2 * ModelRowCount); + const QModelIndex &from = tma.mapRowToModelIndex(0); + const QModelIndex &to = tma.mapRowToModelIndex(4 + 2 * ModelRowCount); + const QItemSelection &sel = tma.selectionForRowRange(from, to); QCOMPARE(sel.count(), 3); // We don't know in which order the selection ranges are // being added, so we iterate and try to find what we expect. @@ -1222,7 +1233,9 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() tma.expand(parent3); { // 1st two items, and 1st child of 1st item expanded, select first 5 rows - const QItemSelection &sel = tma.selectionForRowRange(0, 4); + const QModelIndex &from = tma.mapRowToModelIndex(0); + const QModelIndex &to = tma.mapRowToModelIndex(4); + const QItemSelection &sel = tma.selectionForRowRange(from, to); QCOMPARE(sel.count(), 3); // We don't know in which order the selection ranges are // being added, so we iterate and try to find what we expect. @@ -1239,7 +1252,9 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() } { // 1st two items, and 1st child of 1st item expanded, select all - const QItemSelection &sel = tma.selectionForRowRange(0, 4 * ModelRowCount - 1); + const QModelIndex &from = tma.mapRowToModelIndex(0); + const QModelIndex &to = tma.mapRowToModelIndex(4 * ModelRowCount - 1); + const QItemSelection &sel = tma.selectionForRowRange(from, to); QCOMPARE(sel.count(), 4); // We don't know in which order the selection ranges are // being added, so we iterate and try to find what we expect. @@ -1258,7 +1273,9 @@ void tst_QQuickTreeModelAdaptor::selectionForRowRange() } { // 1st two items, and 1st child of 1st item expanded, select rows across branches - const QItemSelection &sel = tma.selectionForRowRange(8, 23); + const QModelIndex &from = tma.mapRowToModelIndex(8); + const QModelIndex &to = tma.mapRowToModelIndex(23); + const QItemSelection &sel = tma.selectionForRowRange(from, to); QCOMPARE(sel.count(), 4); // We don't know in which order the selection ranges are // being added, so we iterate and try to find what we expect. diff --git a/tests/auto/shared/testmodel.h b/tests/auto/shared/testmodel.h index 0bc06757..00e74129 100644 --- a/tests/auto/shared/testmodel.h +++ b/tests/auto/shared/testmodel.h @@ -124,7 +124,7 @@ public: return false; } - Q_INVOKABLE QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const + QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const { if (row < 0 || column < 0 || (level(parent) > levels) || column >= cols) return QModelIndex(); @@ -199,7 +199,7 @@ public: emit layoutChanged(parents); } - bool removeRows(int row, int count, const QModelIndex &parent) + Q_INVOKABLE bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) { beginRemoveRows(parent, row, row + count - 1); Node *n = (Node *)parent.internalPointer(); |