diff options
author | Jarkko Koivikko <jarkko.koivikko@code-q.fi> | 2023-10-26 17:17:06 +0300 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-11-14 11:48:52 +0000 |
commit | 8cdc89faf0ecf35bb52c68fa87d37fa2a9b6b176 (patch) | |
tree | f9aa4e657522ee41e5303f375aa804761e399cb5 | |
parent | ec9e256188e83adb0982a1e9246e4345c17c3251 (diff) |
Fix VirtualKeyboard attached properties
VirtualKeyboard attached type was missing QML_NAMED_ELEMENT and
QML_UNCREATABLE rendering it useless.
Add missing type definitions and also fix the documentation.
Add a simple automated test which checks the availability of the
existing attached properties.
Fixes: QTBUG-118565
Change-Id: I9297dfab9b7168e65e35f78738be3fb46b1fe8bc
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
(cherry picked from commit 13d007df695be24de6744468a66b00c92d25e212)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
6 files changed, 148 insertions, 2 deletions
diff --git a/src/virtualkeyboard/virtualkeyboard.cpp b/src/virtualkeyboard/virtualkeyboard.cpp index 8d46ef88..6b2fa50d 100644 --- a/src/virtualkeyboard/virtualkeyboard.cpp +++ b/src/virtualkeyboard/virtualkeyboard.cpp @@ -24,7 +24,7 @@ namespace QtVirtualKeyboard { For example: \code TextInput { - VirtualKeyboard.dictionaries: ["myDictionary"] + VirtualKeyboard.extraDictionaries: ["myDictionary"] } \endcode */ @@ -43,7 +43,7 @@ VirtualKeyboardAttachedType *VirtualKeyboard::qmlAttachedProperties(QObject *obj } /*! - \qmlattachedproperty list VirtualKeyboard::dictionaries + \qmlattachedproperty list VirtualKeyboard::extraDictionaries Sets active user dictionaries in this context. */ diff --git a/src/virtualkeyboard/virtualkeyboard_p.h b/src/virtualkeyboard/virtualkeyboard_p.h index ca1f197b..f00cbfdc 100644 --- a/src/virtualkeyboard/virtualkeyboard_p.h +++ b/src/virtualkeyboard/virtualkeyboard_p.h @@ -27,6 +27,8 @@ class VirtualKeyboardAttachedType; class Q_VIRTUALKEYBOARD_EXPORT VirtualKeyboard : public QObject { Q_OBJECT + QML_NAMED_ELEMENT(VirtualKeyboard) + QML_UNCREATABLE("VirtualKeyboard is an abstract type that is only available as an attached property.") QML_ATTACHED(VirtualKeyboardAttachedType) QML_ADDED_IN_VERSION(6, 1) diff --git a/tests/auto/virtualkeyboardattached/CMakeLists.txt b/tests/auto/virtualkeyboardattached/CMakeLists.txt new file mode 100644 index 00000000..b3221bd2 --- /dev/null +++ b/tests/auto/virtualkeyboardattached/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +# Collect test data +file(GLOB_RECURSE test_data_glob + RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/data/*) +list(APPEND test_data ${test_data_glob}) + +qt_internal_add_test(tst_virtualkeyboardattached + QMLTEST + SOURCES + tst_virtualkeyboardattached.cpp + LIBRARIES + Qt::Gui + TESTDATA ${test_data} +) diff --git a/tests/auto/virtualkeyboardattached/data/inputpanel/inputpanel.qml b/tests/auto/virtualkeyboardattached/data/inputpanel/inputpanel.qml new file mode 100644 index 00000000..80fe6265 --- /dev/null +++ b/tests/auto/virtualkeyboardattached/data/inputpanel/inputpanel.qml @@ -0,0 +1,16 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtTest +import QtQuick +import QtQuick.VirtualKeyboard +import QtQuick.VirtualKeyboard.Settings + +InputPanel { + id: inputPanel + z: 99 + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: parent.bottom + visible: active +} diff --git a/tests/auto/virtualkeyboardattached/data/tst_virtualkeyboardattached.qml b/tests/auto/virtualkeyboardattached/data/tst_virtualkeyboardattached.qml new file mode 100644 index 00000000..b158f603 --- /dev/null +++ b/tests/auto/virtualkeyboardattached/data/tst_virtualkeyboardattached.qml @@ -0,0 +1,99 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +import QtTest +import QtQuick +import QtQuick.Window +import QtQuick.VirtualKeyboard + +Rectangle { + id: container + width: 800 + height: 640 + color: "blue" + + TestCase { + id: testcase + name: "tst_virtualkeyboardattached" + when: windowShown + + property var inputPanel: null + + function initTestCase() { + var inputPanelComp = Qt.createComponent("inputpanel/inputpanel.qml") + compare(inputPanelComp.status, Component.Ready, "Failed to create component: "+inputPanelComp.errorString()) + inputPanel = inputPanelComp.createObject(container) + } + + function cleanupTestCase() { + if (inputPanel) + inputPanel.destroy() + } + + function prepareTest() { + var window = container.Window.window + verify(window) + window.raise() + window.requestActivate() + tryCompare(window, "active", true) + } + + Component { + id: textInputWithVirtualKeyboardAttachedComp + TextEdit { + anchors.fill: parent + visible: true + focus: true + color: "white" + VirtualKeyboard.extraDictionaries: ["example"] + } + } + + function test_virtualKeyboardAttached() { + prepareTest() + + container.forceActiveFocus() + waitForRendering(container) + + let textInput = textInputWithVirtualKeyboardAttachedComp.createObject(container) + + verify(textInput !== null) + + textInput.forceActiveFocus() + waitForRendering(inputPanel) + + verify(inputPanel.visible === true) + verify(textInput.activeFocus === true) + } + + Component { + id: textInputWithEnterKeyActionAttachedComp + TextEdit { + anchors.fill: parent + visible: true + focus: true + color: "white" + EnterKeyAction.actionId: EnterKeyAction.Done + EnterKeyAction.label: "hello" + EnterKeyAction.enabled: true + } + } + + function test_enterKeyActionAttached() { + prepareTest() + + container.forceActiveFocus() + waitForRendering(container) + + let textInput = textInputWithEnterKeyActionAttachedComp.createObject(container) + + verify(textInput !== null) + + textInput.forceActiveFocus() + waitForRendering(inputPanel) + + verify(inputPanel.visible === true) + verify(textInput.activeFocus === true) + } + } +} diff --git a/tests/auto/virtualkeyboardattached/tst_virtualkeyboardattached.cpp b/tests/auto/virtualkeyboardattached/tst_virtualkeyboardattached.cpp new file mode 100644 index 00000000..5bf71dfb --- /dev/null +++ b/tests/auto/virtualkeyboardattached/tst_virtualkeyboardattached.cpp @@ -0,0 +1,12 @@ +// Copyright (C) 2023 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include <QtQuickTest/quicktest.h> +#include <QByteArray> +#include <QStandardPaths> +#include <QFileInfo> +#include <QDir> + +static bool s_configEnv = qputenv("QT_IM_MODULE", QByteArray("qtvirtualkeyboard")); + +QUICK_TEST_MAIN(virtualkeyboardattached) |