summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ-P Nurmi <jpnurmi@digia.com>2013-08-15 14:00:03 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-17 16:01:42 +0200
commit9cde5d427a1fc1c2d36b853e1261d08f8dbfa126 (patch)
treeaa96f86f11a3a4a6019d72c2933066b59997d63f
parentac39d220f2989286d871a16f064f4de69098f167 (diff)
Add TableViewColumn::movable
Change-Id: Ibf1b68d4c63ca02c603d5203128bb94984a809f2 Reviewed-by: Caroline Chao <caroline.chao@digia.com>
-rw-r--r--examples/quick/controls/gallery/content/ModelView.qml9
-rw-r--r--src/controls/TableView.qml14
-rw-r--r--src/controls/TableViewColumn.qml6
-rw-r--r--tests/manual/testbench/content/Components.qml2
-rw-r--r--tests/manual/testbench/main.qml1
5 files changed, 25 insertions, 7 deletions
diff --git a/examples/quick/controls/gallery/content/ModelView.qml b/examples/quick/controls/gallery/content/ModelView.qml
index e733793bd..5bbb34f4f 100644
--- a/examples/quick/controls/gallery/content/ModelView.qml
+++ b/examples/quick/controls/gallery/content/ModelView.qml
@@ -67,7 +67,7 @@ Item {
id: dummyModel
Component.onCompleted: {
for (var i = 0 ; i < 100 ; ++i) {
- append({"title": "A title " + i, "imagesource" :"http://someurl.com", "credit" : "N/A"})
+ append({"index": i, "title": "A title " + i, "imagesource" :"http://someurl.com", "credit" : "N/A"})
}
}
}
@@ -77,6 +77,13 @@ Item {
anchors.fill: parent
TableViewColumn {
+ role: "index"
+ title: "#"
+ width: 36
+ resizable: false
+ movable: false
+ }
+ TableViewColumn {
role: "title"
title: "Title"
width: 120
diff --git a/src/controls/TableView.qml b/src/controls/TableView.qml
index 9a53e019d..f96e4bf25 100644
--- a/src/controls/TableView.qml
+++ b/src/controls/TableView.qml
@@ -708,6 +708,7 @@ ScrollView {
opacity: (index == repeater.targetIndex && repeater.targetIndex != repeater.dragIndex) ? 0.5 : 0
Behavior on opacity { NumberAnimation{duration:160}}
color: palette.highlight
+ visible: modelData.movable
}
MouseArea{
@@ -724,7 +725,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 && columnCount > 1) { // only do this while dragging
+ if (modelData.movable && 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
@@ -741,15 +742,18 @@ ScrollView {
onReleased: {
if (repeater.targetIndex >= 0 && repeater.targetIndex != index ) {
- columnModel.move(index, repeater.targetIndex, 1)
- if (sortIndicatorColumn == index)
- sortIndicatorColumn = repeater.targetIndex
+ var targetColumn = columnModel.get(repeater.targetIndex).columnItem
+ if (targetColumn.movable) {
+ columnModel.move(index, repeater.targetIndex, 1)
+ if (sortIndicatorColumn == index)
+ sortIndicatorColumn = repeater.targetIndex
+ }
}
repeater.targetIndex = -1
}
drag.maximumX: 1000
drag.minimumX: -1000
- drag.target: columnCount > 1 ? draghandle : null
+ drag.target: modelData.movable && columnCount > 1 ? draghandle : null
}
Loader {
diff --git a/src/controls/TableViewColumn.qml b/src/controls/TableViewColumn.qml
index 81833c021..42a726984 100644
--- a/src/controls/TableViewColumn.qml
+++ b/src/controls/TableViewColumn.qml
@@ -72,6 +72,12 @@ QtObject {
\since QtQuick.Controls 1.1 */
property bool resizable: true
+ /*! Determines if the column should be movable.
+ The default value is \c true.
+ \note A non-movable column may get indirectly moved if adjacent columns are movable.
+ \since QtQuick.Controls 1.1 */
+ property bool movable: true
+
/*! \qmlproperty enumeration TableViewColumn::elideMode
The text elide mode of the column.
Allowed values are:
diff --git a/tests/manual/testbench/content/Components.qml b/tests/manual/testbench/content/Components.qml
index e9d91fa24..059a1f164 100644
--- a/tests/manual/testbench/content/Components.qml
+++ b/tests/manual/testbench/content/Components.qml
@@ -57,7 +57,7 @@ Item {
property Component toolbar: ToolBar { }
property Component statusbar: StatusBar { }
property Component label: Label {text: "I am a label" }
- property Component tableview: TableView { model: testDataModel ; TableViewColumn {title: "Column 1"}}
+ property Component tableview: TableView { property bool movableColumns: true; model: testDataModel ; TableViewColumn {title: "Column 1"; movable: movableColumns} TableViewColumn {title: "Column 2"; movable: movableColumns} }
property Component tabView: TabView { Repeater { model: 3 ; delegate:Tab { title: "Tab " + index } }}
property Component scrollview: ScrollView {
Rectangle {
diff --git a/tests/manual/testbench/main.qml b/tests/manual/testbench/main.qml
index 24acb1112..73ddf62be 100644
--- a/tests/manual/testbench/main.qml
+++ b/tests/manual/testbench/main.qml
@@ -212,6 +212,7 @@ ApplicationWindow {
case "isDefault":
case "partiallyCheckedEnabled":
case "alternatingRowColors":
+ case "movableColumns":
layout = layouts.boolLayout
typeName = "Boolean";
break