diff options
| author | Caroline Chao <caroline.chao@digia.com> | 2013-06-18 15:00:52 +0200 |
|---|---|---|
| committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-06-19 17:38:23 +0200 |
| commit | d66245f1e8ebee65354a37c30d421a115dd0e383 (patch) | |
| tree | de900f667c17b9f125340094d4513961bf6c8dd1 /tests | |
| parent | b0f3a519289511ad89b99a449176a1aff72d2a99 (diff) | |
| download | qtquickcontrols-d66245f1e8ebee65354a37c30d421a115dd0e383.tar.gz | |
TableView: let delegates handle mouse events
Includes auto tests.
Task-number: QTBUG-31206
Change-Id: I683363f70f7e360cc70f84fd460cbde5e70a61af
Reviewed-by: Caroline Chao <caroline.chao@digia.com>
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/auto/controls/data/tableview/table_buttondelegate.qml (renamed from tests/auto/controls/data/tableview/table_delegate.qml) | 37 | ||||
| -rw-r--r-- | tests/auto/controls/data/tableview/table_delegate2.qml | 61 | ||||
| -rw-r--r-- | tests/auto/controls/data/tableview/table_delegate3.qml | 77 | ||||
| -rw-r--r-- | tests/auto/controls/data/tableview/table_mousearea.qml | 77 | ||||
| -rw-r--r-- | tests/auto/controls/data/tst_tableview.qml | 138 |
5 files changed, 353 insertions, 37 deletions
diff --git a/tests/auto/controls/data/tableview/table_delegate.qml b/tests/auto/controls/data/tableview/table_buttondelegate.qml index 82b08ba5..d5702524 100644 --- a/tests/auto/controls/data/tableview/table_delegate.qml +++ b/tests/auto/controls/data/tableview/table_buttondelegate.qml @@ -43,30 +43,35 @@ import QtQuick.Controls 1.0 TableView { id: table - model: [{"text": "text1"}, {"text": "text2"}, {"text": "text3"}] - property var test: 0 - property bool activatedTest: false - onActivated: activatedTest = true + headerVisible: false + model: ["text1", "text2", "text3"] + + property int tableClickCount: 0 + property int buttonPressCount: 0 + property int buttonReleaseCount: 0 + property int buttonClickCount: 0 + + onClicked: ++clickCount TableViewColumn { - title: "Text" - role: "text" width: 100 } - headerDelegate: Text { + rowDelegate: Item { height: 40 - text: styleData.value + width: parent.width } - itemDelegate: Text { + itemDelegate: Button { + height: 40 width: parent.width - anchors.left: parent.left - anchors.verticalCenter: parent.verticalCenter - text: styleData.value !== undefined ? styleData.value : "" - color: styleData.textColor - MouseArea { - anchors.fill: parent - onClicked: table.test = 1 + text: styleData.value + activeFocusOnPress: true + onClicked: ++table.buttonClickCount + onPressedChanged: { + if (pressed) + ++table.buttonPressCount + else + ++table.buttonReleaseCount } } } diff --git a/tests/auto/controls/data/tableview/table_delegate2.qml b/tests/auto/controls/data/tableview/table_delegate2.qml new file mode 100644 index 00000000..b55814ee --- /dev/null +++ b/tests/auto/controls/data/tableview/table_delegate2.qml @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.1 +import QtQuick.Controls 1.0 + +TableView { + id: table + model: 5 + property bool test: false + headerVisible: false + + TableViewColumn { + width: 100 + title: 'Title' + role: "text" + delegate: Item { + Button { + text: 'Click' + onClicked: test = true + } + } + } +} diff --git a/tests/auto/controls/data/tableview/table_delegate3.qml b/tests/auto/controls/data/tableview/table_delegate3.qml new file mode 100644 index 00000000..8ff37481 --- /dev/null +++ b/tests/auto/controls/data/tableview/table_delegate3.qml @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.1 +import QtQuick.Controls 1.0 + +TableView { + id: table + model: 5 + property bool _pressed: false + property bool _clicked: false + property bool _released: false + property bool _doubleClicked: false + + headerVisible: false + + function clearTestData() { + _pressed = false + _released = false + _clicked = false + _doubleClicked = false + } + + TableViewColumn { + id: column1 + title: 'Title' + role: "text" + delegate: Text { + text: "left" + MouseArea { + acceptedButtons: Qt.LeftButton + anchors.fill: parent + onPressed: table._pressed = true + onClicked: table._clicked = true + onReleased: table._released = true + onDoubleClicked: table._doubleClicked = true + } + } + } +} diff --git a/tests/auto/controls/data/tableview/table_mousearea.qml b/tests/auto/controls/data/tableview/table_mousearea.qml new file mode 100644 index 00000000..32f74e04 --- /dev/null +++ b/tests/auto/controls/data/tableview/table_mousearea.qml @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the Qt Quick Controls module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.1 +import QtQuick.Controls 1.0 + +TableView { + width:400 + id: table + model: [{"text": "text1"}, {"text": "text2"}, {"text": "text3"}] + property bool _pressed: false + property bool _clicked: false + property bool _released: false + property bool _doubleClicked: false + + headerVisible: false + + function clearTestData() { + _pressed = false + _released = false + _clicked = false + _doubleClicked = false + } + + TableViewColumn { + id: column1 + title: 'Text' + role: "text" + } + + MouseArea { + anchors.fill: parent + hoverEnabled: true + acceptedButtons: Qt.RightButton + onPressed: table._pressed = true + onClicked: table._clicked = true + onReleased: table._released = true + onDoubleClicked: table._doubleClicked = true + } +} diff --git a/tests/auto/controls/data/tst_tableview.qml b/tests/auto/controls/data/tst_tableview.qml index a54bbdcb..9a5e9c78 100644 --- a/tests/auto/controls/data/tst_tableview.qml +++ b/tests/auto/controls/data/tst_tableview.qml @@ -173,10 +173,104 @@ TestCase { table.destroy(); } - function test_forwardClickToChild() { - var component = Qt.createComponent("tableview/table_delegate.qml") + function test_buttonDelegate() { + var component = Qt.createComponent("tableview/table_buttondelegate.qml") + compare(component.status, Component.Ready) + var table = component.createObject(container) + verify(table !== null, "table created is null") + compare(table.currentRow, -1) + waitForRendering(table) + + // wait for items to be created + var timeout = 2000 + while (timeout >= 0 && table.rowAt(20, 50) === -1) { + timeout -= 50 + wait(50) + } + + mousePress(table, 50, 20, Qt.LeftButton) + compare(table.currentRow, 0) + compare(table.tableClickCount, 0) + compare(table.buttonPressCount, 1) + compare(table.buttonReleaseCount, 0) + + mouseRelease(table, 50, 20, Qt.LeftButton) + compare(table.currentRow, 0) + compare(table.tableClickCount, 0) + compare(table.buttonPressCount, 1) + compare(table.buttonReleaseCount, 1) + + mouseClick(table, 50, 60, Qt.LeftButton) + compare(table.currentRow, 1) + compare(table.tableClickCount, 0) + compare(table.buttonPressCount, 2) + compare(table.buttonReleaseCount, 2) + + table.destroy() + } + + function test_QTBUG_31206() { + var component = Qt.createComponent("tableview/table_delegate2.qml") + compare(component.status, Component.Ready) + var table = component.createObject(container); + verify(table !== null, "table created is null") + + // wait for items to be created + var timeout = 2000 + while (timeout >= 0 && table.rowAt(15, 55) === -1) { + timeout -= 50 + wait(50) + } + + compare(table.test, false) + mouseClick(table, 15 , 10, Qt.LeftButton) + compare(table.test, true) + table.destroy() + } + + function test_forwardMouseEventsToChildDelegate() { + var component = Qt.createComponent("tableview/table_delegate3.qml") + compare(component.status, Component.Ready) + var table = component.createObject(container); + table.forceActiveFocus(); + verify(table !== null, "table created is null") + + // wait for items to be created + var timeout = 2000 + while (timeout >= 0 && table.rowAt(15, 55) === -1) { + timeout -= 50 + wait(50) + } + + compare(table._pressed, false) + compare(table._clicked, false) + compare(table._released, false) + compare(table._doubleClicked, false) + + mousePress(table, 25 , 10, Qt.LeftButton) + compare(table._pressed, true) + table.clearTestData() + + mouseRelease(table, 25 , 10, Qt.LeftButton) + compare(table._released, true) + table.clearTestData() + + mouseClick(table, 25 , 10, Qt.LeftButton) + compare(table._clicked, true) + table.clearTestData() + + mouseDoubleClick(table, 25 , 10, Qt.LeftButton) + compare(table._doubleClicked, true) + table.clearTestData() + + table.destroy() + } + + function test_rightClickOnMouseAreaOverTableView() { + var component = Qt.createComponent("tableview/table_mousearea.qml") compare(component.status, Component.Ready) var table = component.createObject(container); + table.forceActiveFocus(); verify(table !== null, "table created is null") // wait for items to be created @@ -186,9 +280,27 @@ TestCase { wait(50) } - compare(table.test, 0) - mouseClick(table, 15 , 55, Qt.LeftButton) - compare(table.test, 1) + compare(table._pressed, false) + compare(table._clicked, false) + compare(table._released, false) + compare(table._doubleClicked, false) + + mousePress(table, 25, 10, Qt.RightButton) + compare(table._pressed, true) + table.clearTestData() + + mouseRelease(table, 25, 10, Qt.RightButton) + compare(table._released, true) + table.clearTestData() + + mouseClick(table, 25, 10, Qt.RightButton) + compare(table._clicked, true) + table.clearTestData() + + mouseDoubleClick(table, 25, 10, Qt.RightButton) + compare(table._doubleClicked, true) + table.clearTestData() + table.destroy() } @@ -222,22 +334,6 @@ TestCase { table.destroy() } - function test_activated_withItemDelegate() { - var component = Qt.createComponent("tableview/table_delegate.qml") - compare(component.status, Component.Ready) - var table = component.createObject(container); - 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 - mouseClick(table, 15, 50, Qt.LeftButton) - compare(table.activatedTest, true) - table.destroy() - } - function test_columnCount() { var component = Qt.createComponent("tableview/table_multicolumns.qml") compare(component.status, Component.Ready) |
