aboutsummaryrefslogtreecommitdiffstats
path: root/tests/manual/treeview/sidebyside/data/treeview.qml
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/treeview/sidebyside/data/treeview.qml')
-rw-r--r--tests/manual/treeview/sidebyside/data/treeview.qml50
1 files changed, 32 insertions, 18 deletions
diff --git a/tests/manual/treeview/sidebyside/data/treeview.qml b/tests/manual/treeview/sidebyside/data/treeview.qml
index 7d265c44e1..6cd3af662f 100644
--- a/tests/manual/treeview/sidebyside/data/treeview.qml
+++ b/tests/manual/treeview/sidebyside/data/treeview.qml
@@ -1,5 +1,5 @@
// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
import QtQuick
import QtQuick.Window
@@ -12,7 +12,6 @@ ApplicationWindow {
visible: true
property alias treeView: treeView
- property var selectedIndex: undefined
UICallback { id: callback }
@@ -37,6 +36,11 @@ ApplicationWindow {
text: "Use file system model"
}
+ CheckBox {
+ id: interactiveMode
+ text: "Interactive"
+ }
+
Button {
text: "Show QTreeView"
onClicked: callback.showQTreeView(treeView.model)
@@ -45,7 +49,7 @@ ApplicationWindow {
Button {
text: "Insert row"
onClicked: {
- let index = treeView.modelIndex(1, 0)
+ let index = treeView.index(1, 0)
treeView.model.insertRows(index.row, 1, index.parent);
}
}
@@ -53,20 +57,31 @@ ApplicationWindow {
Button {
text: "Remove row"
onClicked: {
- let index = treeView.modelIndex(1, 0)
+ let index = treeView.index(1, 0)
treeView.model.removeRows(index.row, 1, index.parent);
}
}
Button {
text: "Expand to"
- enabled: selectedIndex != undefined
onClicked: {
- treeView.expandToIndex(selectedIndex);
+ treeView.expandToIndex(treeView.selectionModel.currentIndex);
treeView.forceLayout()
- let row = treeView.rowAtIndex(selectedIndex)
+ let row = treeView.rowAtIndex(treeView.selectionModel.currentIndex)
treeView.positionViewAtRow(row, Qt.AlignVCenter)
}
}
+ Button {
+ text: "Set root"
+ onClicked: {
+ treeView.rootIndex = treeView.selectionModel.currentIndex
+ }
+ }
+ Button {
+ text: "Reset root"
+ onClicked: {
+ treeView.rootIndex = undefined
+ }
+ }
}
TreeView {
@@ -78,6 +93,7 @@ ApplicationWindow {
anchors.bottom: parent.bottom
anchors.leftMargin: 100
anchors.topMargin: 100
+ interactive: interactiveMode.checked
clip: true
selectionModel: ItemSelectionModel {}
@@ -85,6 +101,10 @@ ApplicationWindow {
model: useFileSystemModel.checked ? fileSystemModel : testModel
delegate: useCustomDelegate.checked ? customDelegate : treeViewDelegate
}
+
+ SelectionRectangle {
+ target: treeView
+ }
}
TestModel {
@@ -103,27 +123,19 @@ ApplicationWindow {
treeView.expandRecursively(row)
}
}
- TapHandler {
- acceptedModifiers: Qt.ShiftModifier
- onTapped: selectedIndex = treeView.modelIndex(row, 0)
- }
- Rectangle {
- anchors.fill: parent
- border.color: "red"
- border.width: 1
- visible: treeView.modelIndex(row, column) === selectedIndex
- }
}
}
Component {
id: customDelegate
- Item {
+ Rectangle {
id: root
implicitWidth: padding + label.x + label.implicitWidth + padding
implicitHeight: label.implicitHeight * 1.5
+ required property bool selected
+
readonly property real indentation: 20
readonly property real padding: 5
@@ -134,6 +146,8 @@ ApplicationWindow {
required property int hasChildren
required property int depth
+ color: selected ? "lightblue" : "transparent"
+
Text {
id: indicator
visible: root.isTreeNode && root.hasChildren