summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Bache-Wiig <jens.bache-wiig@digia.com>2013-05-31 13:10:02 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-31 14:06:47 +0200
commit33850881a074f93622869cc4dc6bc77fbbc1fa0c (patch)
tree894d206769d84eaf188b5a497ee03d7cd99e78ac
parent0155e0833c56ccd21ca5668eb1be8b359400535b (diff)
downloadqtquickcontrols-33850881a074f93622869cc4dc6bc77fbbc1fa0c.tar.gz
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: Caroline Chao <caroline.chao@digia.com>
-rw-r--r--src/controls/TableView.qml14
-rw-r--r--src/controls/TableViewColumn.qml10
-rw-r--r--tests/auto/controls/data/tst_tableview.qml17
3 files changed, 35 insertions, 6 deletions
diff --git a/src/controls/TableView.qml b/src/controls/TableView.qml
index d0417bfa..88a897e1 100644
--- a/src/controls/TableView.qml
+++ b/src/controls/TableView.qml
@@ -303,7 +303,12 @@ ScrollView {
if (typeof column['createObject'] === 'function')
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) {
+ object.__view = root
columnModel.insert(index, {columnItem: object})
return object
}
@@ -616,7 +621,7 @@ ScrollView {
delegate: Item {
z:-index
- width: modelData.width
+ width: columnCount == 1 ? viewport.width + __verticalScrollBar.width : modelData.width
visible: modelData.visible
height: headerVisible ? headerStyle.height : 0
@@ -655,7 +660,7 @@ ScrollView {
// NOTE: the direction is different from the master branch
// so this indicates that I am using an invalid assumption on item ordering
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) {
if (drag.target.x > headerrow.children[h].x) {
repeater.targetIndex = h
@@ -680,7 +685,7 @@ ScrollView {
}
drag.maximumX: 1000
drag.minimumX: -1000
- drag.target: draghandle
+ drag.target: columnCount > 1 ? draghandle : null
}
Loader {
@@ -708,6 +713,7 @@ ScrollView {
anchors.rightMargin: -width/2
width: 16 ; height: parent.height
anchors.right: parent.right
+ enabled: columnCount > 1
onPositionChanged: {
var newHeaderWidth = modelData.width + (mouseX - offset)
modelData.width = Math.max(minimumSize, newHeaderWidth)
@@ -728,7 +734,7 @@ ScrollView {
modelData.width = minWidth
}
onPressedChanged: if (pressed) offset=mouseX
- cursorShape: Qt.SplitHCursor
+ cursorShape: enabled ? Qt.SplitHCursor : Qt.ArrowCursor
}
}
}
diff --git a/src/controls/TableViewColumn.qml b/src/controls/TableViewColumn.qml
index 2c629dfb..f1abc553 100644
--- a/src/controls/TableViewColumn.qml
+++ b/src/controls/TableViewColumn.qml
@@ -49,6 +49,10 @@ import QtQuick 2.1
*/
QtObject {
+
+ /*! \internal */
+ property Item __view: null
+
/*! The title text of the column. */
property string title
@@ -56,8 +60,10 @@ QtObject {
property string role
/*! The current width of the column
- The default value depends on platform. */
- property int width: 160
+ The default value depends on platform. If only one
+ 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. */
property bool visible: true
diff --git a/tests/auto/controls/data/tst_tableview.qml b/tests/auto/controls/data/tst_tableview.qml
index d092ae9d..8763900e 100644
--- a/tests/auto/controls/data/tst_tableview.qml
+++ b/tests/auto/controls/data/tst_tableview.qml
@@ -240,6 +240,23 @@ TestCase {
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() {
var component = Qt.createComponent("tableview/table_dynamiccolumns.qml")
compare(component.status, Component.Ready)