summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaroline Chao <caroline.chao@digia.com>2013-05-06 16:16:13 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-07 14:32:56 +0200
commit533b45357246725efacf90b330a718d34a0cf3eb (patch)
tree8513856c771e3236a2afffcc316e665b374a517a
parenta6deb27ba0252bc06fd6f28fb76b552e6320853f (diff)
downloadqtquickcontrols-533b45357246725efacf90b330a718d34a0cf3eb.tar.gz
TableView: Fix activated() not emitted
The mousearea in TableView has to accept mouse event in onPressed to receive upcoming double click event. Regression introduced by Iff3e5c1. Instead of not accepting the event in onPressed, set the MouseArea property propagateComposedEvents to true and does not accept the onClicked event. Also uses QStyle::SH_ItemView_ActivateItemOnSingleClick to check if the table is activated on single or double-clicking. By default, it is activated on double-clicking. Change-Id: I744174d7b31efebfae5e8db4db7b99a544ecf50f Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
-rw-r--r--src/controls/TableView.qml23
-rw-r--r--src/private/qquickstyleitem.cpp2
-rw-r--r--src/styles/Desktop/TableViewStyle.qml1
-rw-r--r--src/styles/TableViewStyle.qml1
-rw-r--r--tests/auto/controls/data/tableview/table_activated.qml54
-rw-r--r--tests/auto/controls/data/tableview/table_delegate.qml3
-rw-r--r--tests/auto/controls/data/tst_tableview.qml30
7 files changed, 110 insertions, 4 deletions
diff --git a/src/controls/TableView.qml b/src/controls/TableView.qml
index 9ebf64e9..430c862d 100644
--- a/src/controls/TableView.qml
+++ b/src/controls/TableView.qml
@@ -41,6 +41,7 @@
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Controls.Private 1.0
+import QtQuick.Controls.Styles 1.0
/*!
\qmltype TableView
@@ -221,7 +222,8 @@ ScrollView {
property alias currentRow: listView.currentIndex
/*! \qmlsignal TableView::activated()
- Emitted when a new row is selected by the user. */
+ Emitted when the user activates an item by single or double-clicking (depending on the platform).
+ */
signal activated
@@ -238,6 +240,9 @@ ScrollView {
__viewTopMargin: headerrow.height
/*! \internal */
+ property bool __activateItemOnSingleClick: __style ? __style.activateItemOnSingleClick : false
+
+ /*! \internal */
function __decrementCurrentIndex() {
__scroller.blockUpdates = true;
listView.decrementCurrentIndex();
@@ -277,6 +282,7 @@ ScrollView {
id: mousearea
anchors.fill: listView
+ propagateComposedEvents: true
property bool autoincrement: false
property bool autodecrement: false
@@ -309,19 +315,28 @@ ScrollView {
listView.currentIndex = listView.indexAt(0, y);
}
- onPressed: {
+ onClicked: {
+ if (root.__activateItemOnSingleClick)
+ root.activated()
+ mouse.accepted = false
+ }
+
+ onPressed: {
listView.forceActiveFocus()
var x = Math.min(flickableItem.contentWidth - 5, Math.max(mouseX + flickableItem.contentX, 0))
var y = Math.min(flickableItem.contentHeight - 5, Math.max(mouseY + flickableItem.contentY, 0))
listView.currentIndex = listView.indexAt(x, y)
- mouse.accepted = false
}
- onDoubleClicked: { root.activated() }
+ onDoubleClicked: {
+ if (!root.__activateItemOnSingleClick)
+ root.activated()
+ }
// Note: with boolean preventStealing we are keeping the flickable from
// eating our mouse press events
preventStealing: true
+
}
// Fills extra rows with alternate color
diff --git a/src/private/qquickstyleitem.cpp b/src/private/qquickstyleitem.cpp
index 59c9eaac..bde25409 100644
--- a/src/private/qquickstyleitem.cpp
+++ b/src/private/qquickstyleitem.cpp
@@ -946,6 +946,8 @@ QVariant QQuickStyleItem::styleHint(const QString &metric)
return qApp->style()->styleHint(QStyle::SH_ScrollView_FrameOnlyAroundContents);
} else if (metric == "scrollToClickPosition")
return qApp->style()->styleHint(QStyle::SH_ScrollBar_LeftClickAbsolutePosition);
+ else if (metric == "activateItemOnSingleClick")
+ return qApp->style()->styleHint(QStyle::SH_ItemView_ActivateItemOnSingleClick);
else if (metric == "transientScrollBars")
return qApp->style()->styleHint(QStyle::SH_ScrollBar_Transient, m_styleoption);
return 0;
diff --git a/src/styles/Desktop/TableViewStyle.qml b/src/styles/Desktop/TableViewStyle.qml
index 26699270..716afa61 100644
--- a/src/styles/Desktop/TableViewStyle.qml
+++ b/src/styles/Desktop/TableViewStyle.qml
@@ -44,6 +44,7 @@ import QtQuick.Controls.Private 1.0
ScrollViewStyle {
id: root
+ property bool activateItemOnSingleClick: __styleitem.styleHint("activateItemOnSingleClick")
property color textColor: __styleitem.styleHint("textColor")
property color highlightedTextColor: __styleitem.styleHint("highlightedTextColor")
diff --git a/src/styles/TableViewStyle.qml b/src/styles/TableViewStyle.qml
index 88fc3743..86678f97 100644
--- a/src/styles/TableViewStyle.qml
+++ b/src/styles/TableViewStyle.qml
@@ -44,6 +44,7 @@ import QtQuick.Controls.Private 1.0
ScrollViewStyle {
id: root
+ property bool activateItemOnSingleClick: false
property color textColor: __syspal.text
property color highlightedTextColor: "white"
diff --git a/tests/auto/controls/data/tableview/table_activated.qml b/tests/auto/controls/data/tableview/table_activated.qml
new file mode 100644
index 00000000..52d420c4
--- /dev/null
+++ b/tests/auto/controls/data/tableview/table_activated.qml
@@ -0,0 +1,54 @@
+/****************************************************************************
+**
+** Copyright (C) 2013 Tasuku Suzuki <stasuku@gmail.com>
+** 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 {
+ height: 70
+ model: 10
+
+ property bool test: false
+ onActivated: test = true
+
+ TableViewColumn {
+ width: 100
+ }
+}
diff --git a/tests/auto/controls/data/tableview/table_delegate.qml b/tests/auto/controls/data/tableview/table_delegate.qml
index 38f4c1ce..a3ab621d 100644
--- a/tests/auto/controls/data/tableview/table_delegate.qml
+++ b/tests/auto/controls/data/tableview/table_delegate.qml
@@ -46,6 +46,9 @@ TableView {
model: [{"text": "text1"}, {"text": "text2"}, {"text": "text3"}]
property var test: 0
+ property bool activatedTest: false
+ onActivated: activatedTest = true
+
TableViewColumn {
title: "Text"
role: "text"
diff --git a/tests/auto/controls/data/tst_tableview.qml b/tests/auto/controls/data/tst_tableview.qml
index 65d7c72c..bc38ad46 100644
--- a/tests/auto/controls/data/tst_tableview.qml
+++ b/tests/auto/controls/data/tst_tableview.qml
@@ -180,6 +180,36 @@ TestCase {
table.destroy()
}
+ function test_activated() {
+ var component = Qt.createComponent("tableview/table_activated.qml")
+ compare(component.status, Component.Ready)
+ var table = component.createObject(container);
+ verify(table !== null, "table created is null")
+ table.forceActiveFocus();
+ compare(table.test, false)
+ if (!table.__activateItemOnSingleClick)
+ mouseDoubleClick(table, 15 , 15, Qt.LeftButton)
+ else
+ mouseClick(table, 15, 15, Qt.LeftButton)
+ compare(table.test, true)
+ 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)
+ 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)