summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Bache-Wiig <jens.bache-wiig@digia.com>2013-06-03 12:47:40 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-06-10 10:56:58 +0200
commit5303f814746606a78198fec5c02746c2f3090460 (patch)
treecfbb07343e0093cb8dd7dbf46fa539e042e965b5
parentc7df1ebf207f99c7889c8834d16bf62fc99db75e (diff)
downloadqtquickcontrols-5303f814746606a78198fec5c02746c2f3090460.tar.gz
Updated activation signals in TableView
- Added row property to activated() - Added clicked(row) signal - Added doubleClicked(row) signal - We also fixed the behavior so that we do not emit activated if the user clicks outside of the available rows. - We fixed a problem where key events would not be seen outside of the control Change-Id: I13feba26e900daf85be7be88216f1a0a4a446c57 Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
-rw-r--r--src/controls/TableView.qml76
-rw-r--r--tests/auto/controls/data/tableview/table_activated.qml17
-rw-r--r--tests/auto/controls/data/tst_tableview.qml20
3 files changed, 91 insertions, 22 deletions
diff --git a/src/controls/TableView.qml b/src/controls/TableView.qml
index 17b2b186..44aecfc2 100644
--- a/src/controls/TableView.qml
+++ b/src/controls/TableView.qml
@@ -239,10 +239,30 @@ ScrollView {
/*! \internal */
property alias __currentRowItem: listView.currentItem
- /*! \qmlsignal TableView::activated()
- Emitted when the user activates an item by single or double-clicking (depending on the platform).
+ /*! \qmlsignal TableView::activated(int row)
+
+ Emitted when the user activates an item by mouse or keyboard interaction.
+ Mouse activation is triggered by single- or double-clicking, depending on the platform.
+
+ \a row int provides access to the activated row index.
+ */
+ signal activated(int row)
+
+ /*! \qmlsignal TableView::clicked(int row)
+
+ Emitted when the user clicks a valid row by single clicking
+
+ \a row int provides access to the clicked row index.
+ */
+ signal clicked(int row)
+
+ /*! \qmlsignal TableView::doubleClicked(int row)
+
+ Emitted when the user double clicks a valid row.
+
+ \a row int provides access to the clicked row index.
*/
- signal activated
+ signal doubleClicked(int row)
/*!
\qmlmethod TableView::positionViewAtRow( int row, PositionMode mode )
@@ -447,28 +467,39 @@ ScrollView {
autoincrement = false;
autodecrement = false;
}
- var y = Math.min(listView.contentY + listView.height - 5, Math.max(mouseY + listView.contentY, listView.contentY));
- var newIndex = listView.indexAt(0, y);
- if (newIndex >= 0)
- listView.currentIndex = listView.indexAt(0, y);
+
+ if (pressed) {
+ var newIndex = listView.indexAt(0, mouseY + listView.contentY)
+ if (newIndex >= 0)
+ listView.currentIndex = newIndex;
+ }
}
onClicked: {
- if (root.__activateItemOnSingleClick)
- root.activated()
+ var clickIndex = listView.indexAt(0, mouseY + listView.contentY)
+ if (clickIndex > -1) {
+ if (root.__activateItemOnSingleClick)
+ root.activated(clickIndex)
+ root.clicked(clickIndex)
+ }
mouse.accepted = false
}
onPressed: {
+ var newIndex = listView.indexAt(0, mouseY + listView.contentY)
listView.forceActiveFocus()
- var x = Math.min(listView.contentWidth - 5, Math.max(mouseX + listView.contentX, 0))
- var y = Math.min(listView.contentHeight - 5, Math.max(mouseY + listView.contentY, 0))
- listView.currentIndex = listView.indexAt(x, y)
+ if (newIndex > -1) {
+ listView.currentIndex = newIndex
+ }
}
onDoubleClicked: {
- if (!root.__activateItemOnSingleClick)
- root.activated()
+ var clickIndex = listView.indexAt(0, mouseY + listView.contentY)
+ if (clickIndex > -1) {
+ if (!root.__activateItemOnSingleClick)
+ root.activated(clickIndex)
+ root.doubleClicked(clickIndex)
+ }
}
// Note: with boolean preventStealing we are keeping the flickable from
@@ -511,8 +542,15 @@ ScrollView {
highlightFollowsCurrentItem: true
model: root.model
- Keys.onUpPressed: root.__decrementCurrentIndex()
- Keys.onDownPressed: root.__incrementCurrentIndex()
+ Keys.onUpPressed: {
+ event.accepted = false
+ root.__decrementCurrentIndex()
+ }
+
+ Keys.onDownPressed: {
+ event.accepted = false
+ root.__incrementCurrentIndex()
+ }
Keys.onPressed: {
if (event.key === Qt.Key_PageUp) {
@@ -521,7 +559,11 @@ ScrollView {
verticalScrollBar.value = __verticalScrollBar.value + listView.height
}
- Keys.onReturnPressed: root.activated();
+ Keys.onReturnPressed: {
+ event.accepted = false
+ if (currentRow > -1)
+ root.activated(currentRow);
+ }
delegate: Item {
id: rowitem
diff --git a/tests/auto/controls/data/tableview/table_activated.qml b/tests/auto/controls/data/tableview/table_activated.qml
index 52d420c4..227fbd88 100644
--- a/tests/auto/controls/data/tableview/table_activated.qml
+++ b/tests/auto/controls/data/tableview/table_activated.qml
@@ -42,11 +42,22 @@ import QtQuick 2.1
import QtQuick.Controls 1.0
TableView {
- height: 70
+ height: 120
model: 10
- property bool test: false
- onActivated: test = true
+ headerVisible: false
+ frameVisible: false
+ rowDelegate: Rectangle {
+ width: parent.width
+ height: 20
+ }
+
+ property int test: -1
+ property int testClick: -1
+ property int testDoubleClick: -1
+ onActivated: test = row
+ onClicked: testClick = row
+ onDoubleClicked: testDoubleClick = row
TableViewColumn {
width: 100
diff --git a/tests/auto/controls/data/tst_tableview.qml b/tests/auto/controls/data/tst_tableview.qml
index 8763900e..6779990c 100644
--- a/tests/auto/controls/data/tst_tableview.qml
+++ b/tests/auto/controls/data/tst_tableview.qml
@@ -198,12 +198,27 @@ TestCase {
var table = component.createObject(container);
verify(table !== null, "table created is null")
table.forceActiveFocus();
- compare(table.test, false)
+ compare(table.test, -1)
+ compare(table.testClick, table.currentRow)
+
+ if (!table.__activateItemOnSingleClick)
+ mouseDoubleClick(table, 15 , 45, Qt.LeftButton)
+ else
+ mouseClick(table, 15, 45, Qt.LeftButton)
+
+ compare(table.testDoubleClick, table.currentRow)
+ compare(table.test, table.currentRow)
+ compare(table.testClick, table.currentRow)
+
if (!table.__activateItemOnSingleClick)
mouseDoubleClick(table, 15 , 15, Qt.LeftButton)
else
mouseClick(table, 15, 15, Qt.LeftButton)
- compare(table.test, true)
+
+ compare(table.testDoubleClick, table.currentRow)
+ compare(table.testClick, table.currentRow)
+ compare(table.test, table.currentRow)
+
table.destroy()
}
@@ -214,6 +229,7 @@ TestCase {
verify(table !== null, "table created is null")
table.forceActiveFocus();
compare(table.activatedTest, false)
+ waitForRendering(table)
if (!table.__activateItemOnSingleClick)
mouseDoubleClick(table, 15 , 50, Qt.LeftButton)
else