Commit 76937540 authored by J-P Nurmi's avatar J-P Nurmi Committed by The Qt Project
Browse files

TableView: optimize bindings


Change-Id: I11096da2efdebf2a3a2e003c90e48e120f8ba5fd
Reviewed-by: default avatarJens Bache-Wiig <jens.bache-wiig@digia.com>
parent 57cb0961
6.2 5.10 5.11 5.12 5.12.1 5.12.10 5.12.11 5.12.12 5.12.2 5.12.3 5.12.4 5.12.5 5.12.6 5.12.7 5.12.8 5.12.9 5.13 5.13.0 5.13.1 5.13.2 5.14 5.14.0 5.14.1 5.14.2 5.15 5.15.0 5.15.1 5.15.2 5.3 5.4 5.5 5.6 5.7 5.8 5.9 5.9.8 dev old/5.1 old/5.2 wip/calendar wip/tizen v5.15.0-alpha1 v5.14.1 v5.14.0 v5.14.0-rc2 v5.14.0-rc1 v5.14.0-beta3 v5.14.0-beta2 v5.14.0-beta1 v5.14.0-alpha1 v5.13.2 v5.13.1 v5.13.0 v5.13.0-rc3 v5.13.0-rc2 v5.13.0-rc1 v5.13.0-beta4 v5.13.0-beta3 v5.13.0-beta2 v5.13.0-beta1 v5.13.0-alpha1 v5.12.7 v5.12.6 v5.12.5 v5.12.4 v5.12.3 v5.12.2 v5.12.1 v5.12.0 v5.12.0-rc2 v5.12.0-rc1 v5.12.0-beta4 v5.12.0-beta3 v5.12.0-beta2 v5.12.0-beta1 v5.12.0-alpha1 v5.11.3 v5.11.2 v5.11.1 v5.11.0 v5.11.0-rc2 v5.11.0-rc1 v5.11.0-beta4 v5.11.0-beta3 v5.11.0-beta2 v5.11.0-beta1 v5.11.0-alpha1 v5.10.1 v5.10.0 v5.10.0-rc3 v5.10.0-rc2 v5.10.0-rc1 v5.10.0-beta4 v5.10.0-beta3 v5.10.0-beta2 v5.10.0-beta1 v5.10.0-alpha1 v5.9.9 v5.9.8 v5.9.7 v5.9.6 v5.9.5 v5.9.4 v5.9.3 v5.9.2 v5.9.1 v5.9.0 v5.9.0-rc2 v5.9.0-rc1 v5.9.0-beta4 v5.9.0-beta3 v5.9.0-beta2 v5.9.0-beta1 v5.9.0-alpha1 v5.8.0 v5.8.0-rc1 v5.8.0-beta1 v5.8.0-alpha1 v5.7.1 v5.7.0 v5.7.0-rc1 v5.7.0-beta1 v5.7.0-alpha1 v5.6.3 v5.6.2 v5.6.1 v5.6.1-1 v5.6.0 v5.6.0-rc1 v5.6.0-beta1 v5.6.0-alpha1 v5.5.1 v5.5.0 v5.5.0-rc1 v5.5.0-beta1 v5.5.0-alpha1 v5.4.2 v5.4.1 v5.4.0 v5.4.0-rc1 v5.4.0-beta1 v5.4.0-alpha1 v5.3.2 v5.3.1 v5.3.0 v5.3.0-rc1 v5.3.0-beta1 v5.3.0-alpha1 v5.2.1 v5.2.0 v5.2.0-rc1 v5.2.0-beta1 v5.2.0-alpha1 v5.1.1 v5.1.0 v5.1.0-rc2 v5.1.0-rc1
No related merge requests found
Showing with 52 additions and 57 deletions
...@@ -315,7 +315,7 @@ ScrollView { ...@@ -315,7 +315,7 @@ ScrollView {
anchors.topMargin: tableHeader.height anchors.topMargin: tableHeader.height
anchors.fill: parent anchors.fill: parent
currentIndex: -1 currentIndex: -1
visible: columns.length > 0 visible: columnCount > 0
interactive: false interactive: false
SystemPalette { SystemPalette {
...@@ -346,8 +346,8 @@ ScrollView { ...@@ -346,8 +346,8 @@ ScrollView {
} }
// Handle vertical scrolling whem dragging mouse outside boundraries // Handle vertical scrolling whem dragging mouse outside boundraries
Timer { running: mousearea.autoincrement && __scroller.verticalScrollBar.visible; repeat: true; interval: 20 ; onTriggered: __incrementCurrentIndex()} Timer { running: mousearea.autoincrement && __verticalScrollBar.visible; repeat: true; interval: 20 ; onTriggered: __incrementCurrentIndex()}
Timer { running: mousearea.autodecrement && __scroller.verticalScrollBar.visible; repeat: true; interval: 20 ; onTriggered: __decrementCurrentIndex()} Timer { running: mousearea.autodecrement && __verticalScrollBar.visible; repeat: true; interval: 20 ; onTriggered: __decrementCurrentIndex()}
onPositionChanged: { onPositionChanged: {
if (mouseY > listView.height && pressed) { if (mouseY > listView.height && pressed) {
...@@ -362,7 +362,7 @@ ScrollView { ...@@ -362,7 +362,7 @@ ScrollView {
autoincrement = false; autoincrement = false;
autodecrement = false; autodecrement = false;
} }
var y = Math.min(flickableItem.contentY + listView.height - 5, Math.max(mouseY + flickableItem.contentY, flickableItem.contentY)); var y = Math.min(listView.contentY + listView.height - 5, Math.max(mouseY + listView.contentY, listView.contentY));
var newIndex = listView.indexAt(0, y); var newIndex = listView.indexAt(0, y);
if (newIndex >= 0) if (newIndex >= 0)
listView.currentIndex = listView.indexAt(0, y); listView.currentIndex = listView.indexAt(0, y);
...@@ -376,8 +376,8 @@ ScrollView { ...@@ -376,8 +376,8 @@ ScrollView {
onPressed: { onPressed: {
listView.forceActiveFocus() listView.forceActiveFocus()
var x = Math.min(flickableItem.contentWidth - 5, Math.max(mouseX + flickableItem.contentX, 0)) var x = Math.min(listView.contentWidth - 5, Math.max(mouseX + listView.contentX, 0))
var y = Math.min(flickableItem.contentHeight - 5, Math.max(mouseY + flickableItem.contentY, 0)) var y = Math.min(listView.contentHeight - 5, Math.max(mouseY + listView.contentY, 0))
listView.currentIndex = listView.indexAt(x, y) listView.currentIndex = listView.indexAt(x, y)
} }
...@@ -395,13 +395,13 @@ ScrollView { ...@@ -395,13 +395,13 @@ ScrollView {
// Fills extra rows with alternate color // Fills extra rows with alternate color
Column { Column {
id: rowfiller id: rowfiller
property int rowHeight: flickableItem.contentHeight/count property int rowHeight: listView.contentHeight/count
property int paddedRowCount: height/rowHeight property int paddedRowCount: height/rowHeight
property int count: flickableItem.count property int count: listView.count
y: flickableItem.contentHeight y: listView.contentHeight
width: parent.width width: parent.width
visible: flickableItem.contentHeight > 0 && alternatingRowColors visible: listView.contentHeight > 0 && alternatingRowColors
height: viewport.height - flickableItem.contentHeight height: viewport.height - listView.contentHeight
Repeater { Repeater {
model: visible ? parent.paddedRowCount : 0 model: visible ? parent.paddedRowCount : 0
Loader { Loader {
...@@ -426,9 +426,9 @@ ScrollView { ...@@ -426,9 +426,9 @@ ScrollView {
Keys.onPressed: { Keys.onPressed: {
if (event.key === Qt.Key_PageUp) { if (event.key === Qt.Key_PageUp) {
verticalScrollBar.value = __scroller.verticalScrollBar.value - listView.height verticalScrollBar.value = __verticalScrollBar.value - listView.height
} else if (event.key === Qt.Key_PageDown) } else if (event.key === Qt.Key_PageDown)
verticalScrollBar.value = __scroller.verticalScrollBar.value + listView.height verticalScrollBar.value = __verticalScrollBar.value + listView.height
} }
Keys.onReturnPressed: root.activated(); Keys.onReturnPressed: root.activated();
...@@ -438,10 +438,12 @@ ScrollView { ...@@ -438,10 +438,12 @@ ScrollView {
width: itemrow.width width: itemrow.width
height: rowstyle.height height: rowstyle.height
property int rowIndex: model.index readonly property int rowIndex: model.index
property bool alternateBackground: alternatingRowColors && rowIndex % 2 == 1 readonly property bool alternateBackground: alternatingRowColors && rowIndex % 2 == 1
property var itemModelData: typeof modelData == "undefined" ? null : modelData readonly property var itemModelData: typeof modelData == "undefined" ? null : modelData
property var itemModel: model readonly property var itemModel: model
readonly property bool itemSelected: ListView.isCurrentItem
readonly property color itemTextColor: itemSelected ? __style.highlightedTextColor : __style.textColor
Loader { Loader {
id: rowstyle id: rowstyle
...@@ -450,57 +452,50 @@ ScrollView { ...@@ -450,57 +452,50 @@ ScrollView {
// Row fills the view width regardless of item size // Row fills the view width regardless of item size
// But scrollbar should not adjust to it // But scrollbar should not adjust to it
height: item ? item.height : 16 height: item ? item.height : 16
width: parent.width + __scroller.horizontalScrollBar.width width: parent.width + __horizontalScrollBar.width
x: flickableItem.contentX x: listView.contentX
// these properties are exposed to the row delegate // these properties are exposed to the row delegate
// Note: these properties should be mirrored in the row filler as well // Note: these properties should be mirrored in the row filler as well
readonly property bool alternateBackground: rowitem.alternateBackground readonly property bool alternateBackground: rowitem.alternateBackground
readonly property bool rowSelected: rowitem.ListView.isCurrentItem readonly property bool rowSelected: rowitem.itemSelected
readonly property int row: rowitem.rowIndex readonly property int row: rowitem.rowIndex
readonly property var model: listView.model readonly property var model: listView.model
readonly property var modelData: rowitem.itemModelData readonly property var modelData: rowitem.itemModelData
readonly property var itemModel: rowitem.itemModel
readonly property bool hasActiveFocus: root.activeFocus readonly property bool hasActiveFocus: root.activeFocus
} }
Row { Row {
id: itemrow id: itemrow
anchors.left: parent.left
height: parent.height height: parent.height
Repeater { Repeater {
id: repeater id: repeater
model: root.columns.length model: root.columnCount
Loader { Loader {
id: itemDelegateLoader id: itemDelegateLoader
width: columns[index].width width: __column.width
height: parent ? parent.height : 0 height: parent ? parent.height : 0
visible: columns[index].visible visible: __column.visible
sourceComponent: columns[index].delegate ? columns[index].delegate : itemDelegate sourceComponent: __column.delegate ? __column.delegate : itemDelegate
// these properties are exposed to the item delegate // these properties are exposed to the item delegate
property var model: listView.model readonly property var model: listView.model
property var modelData: itemModelData readonly property var modelData: itemModelData
property var itemValue: __getValue() readonly property var itemValue: __hasModelRole ? itemModel[role] // Qml ListModel and QAbstractItemModel
property bool itemSelected: rowitem.ListView.isCurrentItem : __hasModelDataRole ? modelData[role] // QObjectList / QObject
property color itemTextColor: itemSelected ? __style.highlightedTextColor : __style.textColor : modelData != undefined ? modelData : "" // Models without role
property int row: rowitem.rowIndex readonly property bool itemSelected: rowitem.itemSelected
property int column: index readonly property color itemTextColor: rowitem.itemTextColor
property int itemElideMode: columns[index].elideMode readonly property int row: rowitem.rowIndex
property int itemTextAlignment: columns[index].horizontalAlignment readonly property int column: index
property string role: columns[index].role readonly property int itemElideMode: __column.elideMode
readonly property int itemTextAlignment: __column.horizontalAlignment
function __getValue() { readonly property string role: __column.role
var role = columns[index].role
if (role.length && itemModel.hasOwnProperty(role)) readonly property TableViewColumn __column: columns[index]
return itemModel[role] // Qml ListModel and QAbstractItemModel readonly property bool __hasModelRole: role && itemModel.hasOwnProperty(role)
else if (modelData != undefined && modelData.hasOwnProperty(role)) readonly property bool __hasModelDataRole: role && modelData && modelData.hasOwnProperty(role)
return modelData[role] // QObjectList / QObject
else if (modelData != undefined)
return modelData // Models without role
else
return ""
}
} }
} }
onWidthChanged: listView.contentWidth = width onWidthChanged: listView.contentWidth = width
...@@ -519,7 +514,7 @@ ScrollView { ...@@ -519,7 +514,7 @@ ScrollView {
anchors.leftMargin: viewport.anchors.leftMargin anchors.leftMargin: viewport.anchors.leftMargin
anchors.margins: viewport.anchors.margins anchors.margins: viewport.anchors.margins
anchors.rightMargin: __scroller.rightMargin + anchors.rightMargin: __scroller.rightMargin +
(__scroller.outerFrame && __scrollBarTopMargin ? 0 : __scroller.verticalScrollBar.width (__scroller.outerFrame && __scrollBarTopMargin ? 0 : __verticalScrollBar.width
+ __scroller.scrollBarSpacing) + __scroller.scrollBarSpacing)
anchors.left: parent.left anchors.left: parent.left
...@@ -537,7 +532,7 @@ ScrollView { ...@@ -537,7 +532,7 @@ ScrollView {
property int targetIndex: -1 property int targetIndex: -1
property int dragIndex: -1 property int dragIndex: -1
model: columns.length model: columnCount
delegate: Item { delegate: Item {
z:-index z:-index
...@@ -554,8 +549,8 @@ ScrollView { ...@@ -554,8 +549,8 @@ ScrollView {
property string itemSort: (sortIndicatorVisible && index == sortIndicatorColumn) ? (sortIndicatorOrder == Qt.AscendingOrder ? "up" : "down") : ""; property string itemSort: (sortIndicatorVisible && index == sortIndicatorColumn) ? (sortIndicatorOrder == Qt.AscendingOrder ? "up" : "down") : "";
property bool itemPressed: headerClickArea.pressed property bool itemPressed: headerClickArea.pressed
property bool itemContainsMouse: headerClickArea.containsMouse property bool itemContainsMouse: headerClickArea.containsMouse
property string itemPosition: columns.length === 1 ? "only" : property string itemPosition: columnCount === 1 ? "only" :
index===columns.length-1 ? "end" : index===columnCount-1 ? "end" :
index===0 ? "beginning" : "" index===0 ? "beginning" : ""
} }
Rectangle{ Rectangle{
...@@ -582,7 +577,7 @@ ScrollView { ...@@ -582,7 +577,7 @@ ScrollView {
// so this indicates that I am using an invalid assumption on item ordering // so this indicates that I am using an invalid assumption on item ordering
onPositionChanged: { onPositionChanged: {
if (pressed) { // only do this while dragging if (pressed) { // only do this while dragging
for (var h = columns.length-1 ; h >= 0 ; --h) { for (var h = columnCount-1 ; h >= 0 ; --h) {
if (drag.target.x > headerrow.children[h].x) { if (drag.target.x > headerrow.children[h].x) {
repeater.targetIndex = h repeater.targetIndex = h
break break
...@@ -600,7 +595,7 @@ ScrollView { ...@@ -600,7 +595,7 @@ ScrollView {
if (repeater.targetIndex >= 0 && repeater.targetIndex != index ) { if (repeater.targetIndex >= 0 && repeater.targetIndex != index ) {
// Rearrange the header sections // Rearrange the header sections
var items = new Array var items = new Array
for (var i = 0 ; i< columns.length ; ++i) for (var i = 0 ; i< columnCount ; ++i)
items.push(columns[i]) items.push(columns[i])
items.splice(index, 1); items.splice(index, 1);
items.splice(repeater.targetIndex, 0, columns[index]); items.splice(repeater.targetIndex, 0, columns[index]);
...@@ -678,7 +673,7 @@ ScrollView { ...@@ -678,7 +673,7 @@ ScrollView {
anchors.rightMargin: -2 anchors.rightMargin: -2
sourceComponent: root.headerDelegate sourceComponent: root.headerDelegate
width: root.width - headerrow.width + 2 width: root.width - headerrow.width + 2
visible: root.columns.length visible: root.columnCount
z:-1 z:-1
} }
} }
......
...@@ -130,7 +130,7 @@ Item { ...@@ -130,7 +130,7 @@ Item {
} }
onPositionChanged: { onPositionChanged: {
if (pressed && __panel.activeControl === "handle") { if (handlePressed) {
if (!horizontal) if (!horizontal)
slider.position = oldPosition + (mouseY - pressedY) slider.position = oldPosition + (mouseY - pressedY)
else else
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment