summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippo Cucchetto <f.cucchetto@asem.it>2016-02-08 11:23:21 +0100
committerFilippo Cucchetto <filippocucchetto@gmail.com>2016-02-12 14:35:19 +0000
commit93d06fb27d7eae9290db33b6684916a225939f0b (patch)
tree1c89b8f078976c8a190389a746af6c8779d72893
parent5394bade0e2d3248ba5a7eea380936e2dd05144d (diff)
downloadqtquickcontrols-93d06fb27d7eae9290db33b6684916a225939f0b.tar.gz
TreeView should update selection on release with ExtendedSelection
The selection shouldn't change on press if multiple items are selected and the user presses on an already selected item. This is the correct behavior on Windows and OSX where selection changes on release. Furthermore reacting on press prevents the end user to implement dragging. In fact if we react on press the selection changes before the dragging event starts. Change-Id: Iff5bca8efa5f0701c479f63ff8b1f442268a98d5 Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
-rw-r--r--src/controls/TreeView.qml34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/controls/TreeView.qml b/src/controls/TreeView.qml
index 637c46c3..e152e810 100644
--- a/src/controls/TreeView.qml
+++ b/src/controls/TreeView.qml
@@ -121,6 +121,7 @@ BasicTableView {
property var clickedIndex: undefined
property var pressedIndex: undefined
+ property bool selectOnRelease: false
property int pressedColumn: -1
readonly property alias currentRow: root.__currentRow
readonly property alias currentIndex: root.currentIndex
@@ -237,22 +238,37 @@ BasicTableView {
var pressedRow = __listView.indexAt(0, mouseY + __listView.contentY)
pressedIndex = modelAdaptor.mapRowToModelIndex(pressedRow)
pressedColumn = __listView.columnAt(mouseX)
+ selectOnRelease = false
__listView.forceActiveFocus()
- if (pressedRow > -1 && !Settings.hasTouchScreen
- && !branchDecorationContains(mouse.x, mouse.y)) {
- __listView.currentIndex = pressedRow
- if (!clickedIndex)
- clickedIndex = pressedIndex
- mouseSelect(pressedIndex, mouse.modifiers, false)
- if (!mouse.modifiers)
- clickedIndex = pressedIndex
+ if (pressedRow === -1
+ || Settings.hasTouchScreen
+ || branchDecorationContains(mouse.x, mouse.y)) {
+ return
+ }
+ if (selectionMode === SelectionMode.ExtendedSelection
+ && selection.isSelected(pressedIndex)) {
+ selectOnRelease = true
+ return
}
+ __listView.currentIndex = pressedRow
+ if (!clickedIndex)
+ clickedIndex = pressedIndex
+ mouseSelect(pressedIndex, mouse.modifiers, false)
+ if (!mouse.modifiers)
+ clickedIndex = pressedIndex
}
onReleased: {
+ if (selectOnRelease) {
+ var releasedRow = __listView.indexAt(0, mouseY + __listView.contentY)
+ var releasedIndex = modelAdaptor.mapRowToModelIndex(releasedRow)
+ if (releasedRow >= 0 && releasedIndex === pressedIndex)
+ mouseSelect(pressedIndex, mouse.modifiers, false)
+ }
pressedIndex = undefined
pressedColumn = -1
autoScroll = 0
+ selectOnRelease = false
}
onPositionChanged: {
@@ -283,12 +299,14 @@ BasicTableView {
onExited: {
pressedIndex = undefined
pressedColumn = -1
+ selectOnRelease = false
}
onCanceled: {
pressedIndex = undefined
pressedColumn = -1
autoScroll = 0
+ selectOnRelease = false
}
onClicked: {