Commit 33850881 authored by Jens Bache-Wiig's avatar Jens Bache-Wiig Committed by The Qt Project
Browse files

TableView: Expand to single column and prevent multiple use


This fix ensures that we can only add a TableViewColumn exactly
once. It also automatically expands the column with to the viewport
when only one column is in use.

In addition I have disabled dragging when columnCount == 1
as it was pointless.

Change-Id: Ief6011c3e58166907836bf55b0fa6643698192d2
Reviewed-by: default avatarCaroline Chao <caroline.chao@digia.com>
parent 0155e083
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 35 additions and 6 deletions
...@@ -303,7 +303,12 @@ ScrollView { ...@@ -303,7 +303,12 @@ ScrollView {
if (typeof column['createObject'] === 'function') if (typeof column['createObject'] === 'function')
object = column.createObject(root) object = column.createObject(root)
else if (object.__view) {
console.warn("TableView::insertColumn(): you cannot add a column to multiple views")
return null
}
if (index >= 0 && index <= columnCount && object.Accessible.role === Accessible.ColumnHeader) { if (index >= 0 && index <= columnCount && object.Accessible.role === Accessible.ColumnHeader) {
object.__view = root
columnModel.insert(index, {columnItem: object}) columnModel.insert(index, {columnItem: object})
return object return object
} }
...@@ -616,7 +621,7 @@ ScrollView { ...@@ -616,7 +621,7 @@ ScrollView {
delegate: Item { delegate: Item {
z:-index z:-index
width: modelData.width width: columnCount == 1 ? viewport.width + __verticalScrollBar.width : modelData.width
visible: modelData.visible visible: modelData.visible
height: headerVisible ? headerStyle.height : 0 height: headerVisible ? headerStyle.height : 0
...@@ -655,7 +660,7 @@ ScrollView { ...@@ -655,7 +660,7 @@ ScrollView {
// NOTE: the direction is different from the master branch // NOTE: the direction is different from the master branch
// 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 && columnCount > 1) { // only do this while dragging
for (var h = columnCount-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
...@@ -680,7 +685,7 @@ ScrollView { ...@@ -680,7 +685,7 @@ ScrollView {
} }
drag.maximumX: 1000 drag.maximumX: 1000
drag.minimumX: -1000 drag.minimumX: -1000
drag.target: draghandle drag.target: columnCount > 1 ? draghandle : null
} }
Loader { Loader {
...@@ -708,6 +713,7 @@ ScrollView { ...@@ -708,6 +713,7 @@ ScrollView {
anchors.rightMargin: -width/2 anchors.rightMargin: -width/2
width: 16 ; height: parent.height width: 16 ; height: parent.height
anchors.right: parent.right anchors.right: parent.right
enabled: columnCount > 1
onPositionChanged: { onPositionChanged: {
var newHeaderWidth = modelData.width + (mouseX - offset) var newHeaderWidth = modelData.width + (mouseX - offset)
modelData.width = Math.max(minimumSize, newHeaderWidth) modelData.width = Math.max(minimumSize, newHeaderWidth)
...@@ -728,7 +734,7 @@ ScrollView { ...@@ -728,7 +734,7 @@ ScrollView {
modelData.width = minWidth modelData.width = minWidth
} }
onPressedChanged: if (pressed) offset=mouseX onPressedChanged: if (pressed) offset=mouseX
cursorShape: Qt.SplitHCursor cursorShape: enabled ? Qt.SplitHCursor : Qt.ArrowCursor
} }
} }
} }
......
...@@ -49,6 +49,10 @@ import QtQuick 2.1 ...@@ -49,6 +49,10 @@ import QtQuick 2.1
*/ */
QtObject { QtObject {
/*! \internal */
property Item __view: null
/*! The title text of the column. */ /*! The title text of the column. */
property string title property string title
...@@ -56,8 +60,10 @@ QtObject { ...@@ -56,8 +60,10 @@ QtObject {
property string role property string role
/*! The current width of the column /*! The current width of the column
The default value depends on platform. */ The default value depends on platform. If only one
property int width: 160 column is defined, the width expands to the viewport.
*/
property int width: (__view && __view.columnCount === 1) ? __view.viewport.width : 160
/*! The visible status of the column. */ /*! The visible status of the column. */
property bool visible: true property bool visible: true
......
...@@ -240,6 +240,23 @@ TestCase { ...@@ -240,6 +240,23 @@ TestCase {
table.destroy() table.destroy()
} }
function test_columnWidth() {
var tableView = Qt.createQmlObject('import QtQuick 2.1; import QtQuick.Controls 1.0; TableView { }', testCase, '');
compare(tableView.columnCount, 0)
var column = newColumn.createObject(testCase, {title: "title 1"});
verify(column.__view === null)
compare(column.width, 160)
compare(column.title, "title 1")
tableView.addColumn(column)
compare(column.__view, tableView)
compare(column.width, tableView.viewport.width)
var tableView2 = Qt.createQmlObject('import QtQuick 2.1; import QtQuick.Controls 1.0; TableView { }', testCase, '');
tableView2.addColumn(column) // should not work
compare(column.__view, tableView) //same as before
tableView2.destroy()
tableView.destroy()
}
function test_dynamicColumns() { function test_dynamicColumns() {
var component = Qt.createComponent("tableview/table_dynamiccolumns.qml") var component = Qt.createComponent("tableview/table_dynamiccolumns.qml")
compare(component.status, Component.Ready) compare(component.status, Component.Ready)
......
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