From efe0bec9468d75b768d1e26d2a8b440ade5ba632 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Thu, 15 Aug 2019 15:19:31 +0200 Subject: Allow Connections to handle signals using JavaScript functions Requiring full function definitions as signal handlers has two advantages: 1, We don't need a custom parser that magically recognizes properties which would otherwise be an error in other components. 2, The user is forced to specify the full signature of the handler, including any parameters. This helps when the functions will eventually be compiled to C++ The old behavior is retained, generating a warning if any of the magic bindings are still set in a Connections element. Only if no magic bindings are found, the functions are connected. This is because there might be functions named onFoo in old-style Connections elements and silently connecting those to any matching signals would be a change in behavior. Change-Id: I8c78d8994fdcddd355fe822cde9a0702dc8c75de Reviewed-by: Fabian Kosmale Reviewed-by: Simon Hausmann --- .../data/bindings/connection-no-signal-name.qml | 15 +++++ .../data/bindings/connection-targetchange.qml | 25 ++++++++ .../bindings/connection-unknownsignals-ignored.qml | 8 +++ .../connection-unknownsignals-notarget.qml | 5 ++ .../bindings/connection-unknownsignals-parent.qml | 5 ++ .../data/bindings/connection-unknownsignals.qml | 7 +++ .../data/bindings/disabled-at-start.qml | 14 +++++ .../data/bindings/override-proxy-type.qml | 13 ++++ .../data/bindings/rewriteError-global.qml | 8 +++ .../data/bindings/rewriteError-unnamed.qml | 8 +++ .../data/bindings/singletontype-target.qml | 22 +++++++ .../data/bindings/test-connection-implicit.qml | 9 +++ .../data/bindings/test-connection.qml | 10 ++++ .../qml/qqmlconnections/data/bindings/trimming.qml | 10 ++++ .../data/connection-no-signal-name.qml | 15 ----- .../data/connection-targetchange.qml | 25 -------- .../data/connection-unknownsignals-ignored.qml | 8 --- .../data/connection-unknownsignals-notarget.qml | 5 -- .../data/connection-unknownsignals-parent.qml | 5 -- .../data/connection-unknownsignals.qml | 7 --- .../qml/qqmlconnections/data/disabled-at-start.qml | 14 ----- .../data/functions/connection-no-signal-name.qml | 15 +++++ .../data/functions/connection-targetchange.qml | 25 ++++++++ .../connection-unknownsignals-ignored.qml | 17 ++++++ .../connection-unknownsignals-notarget.qml | 9 +++ .../functions/connection-unknownsignals-parent.qml | 8 +++ .../data/functions/connection-unknownsignals.qml | 11 ++++ .../data/functions/disabled-at-start.qml | 14 +++++ .../data/functions/override-proxy-type.qml | 13 ++++ .../data/functions/rewriteError-global.qml | 8 +++ .../data/functions/rewriteError-unnamed.qml | 8 +++ .../data/functions/singletontype-target.qml | 22 +++++++ .../data/functions/test-connection-implicit.qml | 9 +++ .../data/functions/test-connection.qml | 14 +++++ .../qqmlconnections/data/functions/trimming.qml | 13 ++++ .../qqmlconnections/data/override-proxy-type.qml | 13 ---- .../qqmlconnections/data/rewriteError-global.qml | 8 --- .../qqmlconnections/data/rewriteError-unnamed.qml | 8 --- .../qqmlconnections/data/singletontype-target.qml | 22 ------- .../data/test-connection-implicit.qml | 9 --- .../qml/qqmlconnections/data/test-connection.qml | 10 ---- tests/auto/qml/qqmlconnections/data/trimming.qml | 10 ---- .../qml/qqmlconnections/tst_qqmlconnections.cpp | 70 +++++++++++++++++----- 43 files changed, 401 insertions(+), 173 deletions(-) create mode 100644 tests/auto/qml/qqmlconnections/data/bindings/connection-no-signal-name.qml create mode 100644 tests/auto/qml/qqmlconnections/data/bindings/connection-targetchange.qml create mode 100644 tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals-ignored.qml create mode 100644 tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals-notarget.qml create mode 100644 tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals-parent.qml create mode 100644 tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals.qml create mode 100644 tests/auto/qml/qqmlconnections/data/bindings/disabled-at-start.qml create mode 100644 tests/auto/qml/qqmlconnections/data/bindings/override-proxy-type.qml create mode 100644 tests/auto/qml/qqmlconnections/data/bindings/rewriteError-global.qml create mode 100644 tests/auto/qml/qqmlconnections/data/bindings/rewriteError-unnamed.qml create mode 100644 tests/auto/qml/qqmlconnections/data/bindings/singletontype-target.qml create mode 100644 tests/auto/qml/qqmlconnections/data/bindings/test-connection-implicit.qml create mode 100644 tests/auto/qml/qqmlconnections/data/bindings/test-connection.qml create mode 100644 tests/auto/qml/qqmlconnections/data/bindings/trimming.qml delete mode 100644 tests/auto/qml/qqmlconnections/data/connection-no-signal-name.qml delete mode 100644 tests/auto/qml/qqmlconnections/data/connection-targetchange.qml delete mode 100644 tests/auto/qml/qqmlconnections/data/connection-unknownsignals-ignored.qml delete mode 100644 tests/auto/qml/qqmlconnections/data/connection-unknownsignals-notarget.qml delete mode 100644 tests/auto/qml/qqmlconnections/data/connection-unknownsignals-parent.qml delete mode 100644 tests/auto/qml/qqmlconnections/data/connection-unknownsignals.qml delete mode 100644 tests/auto/qml/qqmlconnections/data/disabled-at-start.qml create mode 100644 tests/auto/qml/qqmlconnections/data/functions/connection-no-signal-name.qml create mode 100644 tests/auto/qml/qqmlconnections/data/functions/connection-targetchange.qml create mode 100644 tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals-ignored.qml create mode 100644 tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals-notarget.qml create mode 100644 tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals-parent.qml create mode 100644 tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals.qml create mode 100644 tests/auto/qml/qqmlconnections/data/functions/disabled-at-start.qml create mode 100644 tests/auto/qml/qqmlconnections/data/functions/override-proxy-type.qml create mode 100644 tests/auto/qml/qqmlconnections/data/functions/rewriteError-global.qml create mode 100644 tests/auto/qml/qqmlconnections/data/functions/rewriteError-unnamed.qml create mode 100644 tests/auto/qml/qqmlconnections/data/functions/singletontype-target.qml create mode 100644 tests/auto/qml/qqmlconnections/data/functions/test-connection-implicit.qml create mode 100644 tests/auto/qml/qqmlconnections/data/functions/test-connection.qml create mode 100644 tests/auto/qml/qqmlconnections/data/functions/trimming.qml delete mode 100644 tests/auto/qml/qqmlconnections/data/override-proxy-type.qml delete mode 100644 tests/auto/qml/qqmlconnections/data/rewriteError-global.qml delete mode 100644 tests/auto/qml/qqmlconnections/data/rewriteError-unnamed.qml delete mode 100644 tests/auto/qml/qqmlconnections/data/singletontype-target.qml delete mode 100644 tests/auto/qml/qqmlconnections/data/test-connection-implicit.qml delete mode 100644 tests/auto/qml/qqmlconnections/data/test-connection.qml delete mode 100644 tests/auto/qml/qqmlconnections/data/trimming.qml (limited to 'tests/auto/qml/qqmlconnections') diff --git a/tests/auto/qml/qqmlconnections/data/bindings/connection-no-signal-name.qml b/tests/auto/qml/qqmlconnections/data/bindings/connection-no-signal-name.qml new file mode 100644 index 0000000000..462a9577ff --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/bindings/connection-no-signal-name.qml @@ -0,0 +1,15 @@ +import QtQuick 2.4 + +Item { + id: blaBlaBla + function hint() { + } + + Connections { + //target: blaBlaBla + //onHint: hint(); + on: true + } +} + + diff --git a/tests/auto/qml/qqmlconnections/data/bindings/connection-targetchange.qml b/tests/auto/qml/qqmlconnections/data/bindings/connection-targetchange.qml new file mode 100644 index 0000000000..154c309c9c --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/bindings/connection-targetchange.qml @@ -0,0 +1,25 @@ +import QtQuick 2.0 + +Item { + Component { + id: item1 + Item { + objectName: "item1" + } + } + Component { + id: item2 + Item { + objectName: "item2" + } + } + Loader { + id: loader + sourceComponent: item1 + } + Connections { + objectName: "connections" + target: loader.item + onWidthChanged: loader.sourceComponent = item2 + } +} diff --git a/tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals-ignored.qml b/tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals-ignored.qml new file mode 100644 index 0000000000..0780dd1509 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals-ignored.qml @@ -0,0 +1,8 @@ +import QtQml 2.0 + +QtObject { + id: root + + property Connections c1: Connections { target: root; onNotFooBar1: {} ignoreUnknownSignals: true } + property Connections c2: Connections { objectName: "connections"; onNotFooBar2: {} ignoreUnknownSignals: true } +} diff --git a/tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals-notarget.qml b/tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals-notarget.qml new file mode 100644 index 0000000000..3da3e0f5d1 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals-notarget.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 + +QtObject { + property Connections c1: Connections { objectName: "connections"; target: null; onNotFooBar: {} } +} diff --git a/tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals-parent.qml b/tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals-parent.qml new file mode 100644 index 0000000000..2c55215579 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals-parent.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 + +QtObject { + property Connections c1: Connections { objectName: "connections"; onFooBar: {} } +} diff --git a/tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals.qml b/tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals.qml new file mode 100644 index 0000000000..a351016b4a --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/bindings/connection-unknownsignals.qml @@ -0,0 +1,7 @@ +import QtQml 2.0 + +QtObject { + id: screen + + property Connections c1: Connections { objectName: "connections"; target: screen; onFooBar: {} } +} diff --git a/tests/auto/qml/qqmlconnections/data/bindings/disabled-at-start.qml b/tests/auto/qml/qqmlconnections/data/bindings/disabled-at-start.qml new file mode 100644 index 0000000000..1a823f87f6 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/bindings/disabled-at-start.qml @@ -0,0 +1,14 @@ +import QtQuick 2.9 + +Item { + id: root + + property bool tested: false + signal testMe() + + Connections { + target: root + enabled: false + onTestMe: root.tested = true; + } +} diff --git a/tests/auto/qml/qqmlconnections/data/bindings/override-proxy-type.qml b/tests/auto/qml/qqmlconnections/data/bindings/override-proxy-type.qml new file mode 100644 index 0000000000..80e459966b --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/bindings/override-proxy-type.qml @@ -0,0 +1,13 @@ +import QtQml 2.12 +import test.proxy 1.0 + +Proxy { + property int testEnum: 0; + id: proxy + property Connections connections: Connections { + target: proxy + onSomeSignal: testEnum = Proxy.EnumValue; + } + + Component.onCompleted: someSignal() +} diff --git a/tests/auto/qml/qqmlconnections/data/bindings/rewriteError-global.qml b/tests/auto/qml/qqmlconnections/data/bindings/rewriteError-global.qml new file mode 100644 index 0000000000..1d0b557069 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/bindings/rewriteError-global.qml @@ -0,0 +1,8 @@ +import QtQml 2.0 +import Test 1.0 + +TestObject { + property QtObject connection: Connections { + onSignalWithGlobalName: { ran = true } + } +} diff --git a/tests/auto/qml/qqmlconnections/data/bindings/rewriteError-unnamed.qml b/tests/auto/qml/qqmlconnections/data/bindings/rewriteError-unnamed.qml new file mode 100644 index 0000000000..a4849e994b --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/bindings/rewriteError-unnamed.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 +import Test 1.0 + +TestObject { + property QtObject connection: Connections { + onUnnamedArgumentSignal: { ran = true } + } +} diff --git a/tests/auto/qml/qqmlconnections/data/bindings/singletontype-target.qml b/tests/auto/qml/qqmlconnections/data/bindings/singletontype-target.qml new file mode 100644 index 0000000000..7de488c2dd --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/bindings/singletontype-target.qml @@ -0,0 +1,22 @@ +import QtQml 2.0 +import MyTestSingletonType 1.0 as MyTestSingletonType + +QtObject { + id: rootObject + objectName: "rootObject" + property int newIntPropValue: 12 + + property int moduleIntPropChangedCount: 0 + property int moduleOtherSignalCount: 0 + + function setModuleIntProp() { + MyTestSingletonType.Api.intProp = newIntPropValue; + newIntPropValue = newIntPropValue + 1; + } + + property Connections c: Connections { + target: MyTestSingletonType.Api + onIntPropChanged: moduleIntPropChangedCount = moduleIntPropChangedCount + 1; + onOtherSignal: moduleOtherSignalCount = moduleOtherSignalCount + 1; + } +} diff --git a/tests/auto/qml/qqmlconnections/data/bindings/test-connection-implicit.qml b/tests/auto/qml/qqmlconnections/data/bindings/test-connection-implicit.qml new file mode 100644 index 0000000000..d5aa0f102a --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/bindings/test-connection-implicit.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +Item { + width: 50 + + property bool tested: false + + Connections { onWidthChanged: tested = true } +} diff --git a/tests/auto/qml/qqmlconnections/data/bindings/test-connection.qml b/tests/auto/qml/qqmlconnections/data/bindings/test-connection.qml new file mode 100644 index 0000000000..f44cbc047f --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/bindings/test-connection.qml @@ -0,0 +1,10 @@ +import QtQuick 2.0 + +Item { + id: screen; width: 50 + + property bool tested: false + signal testMe + + Connections { objectName: "connections"; target: screen; onWidthChanged: screen.tested = true } +} diff --git a/tests/auto/qml/qqmlconnections/data/bindings/trimming.qml b/tests/auto/qml/qqmlconnections/data/bindings/trimming.qml new file mode 100644 index 0000000000..4c37eb22af --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/bindings/trimming.qml @@ -0,0 +1,10 @@ +import QtQml 2.0 + +QtObject { + id: root + + property string tested + signal testMe(int param1, string param2) + + property Connections c: Connections { target: root; onTestMe: root.tested = param2 + param1 } +} diff --git a/tests/auto/qml/qqmlconnections/data/connection-no-signal-name.qml b/tests/auto/qml/qqmlconnections/data/connection-no-signal-name.qml deleted file mode 100644 index 462a9577ff..0000000000 --- a/tests/auto/qml/qqmlconnections/data/connection-no-signal-name.qml +++ /dev/null @@ -1,15 +0,0 @@ -import QtQuick 2.4 - -Item { - id: blaBlaBla - function hint() { - } - - Connections { - //target: blaBlaBla - //onHint: hint(); - on: true - } -} - - diff --git a/tests/auto/qml/qqmlconnections/data/connection-targetchange.qml b/tests/auto/qml/qqmlconnections/data/connection-targetchange.qml deleted file mode 100644 index 154c309c9c..0000000000 --- a/tests/auto/qml/qqmlconnections/data/connection-targetchange.qml +++ /dev/null @@ -1,25 +0,0 @@ -import QtQuick 2.0 - -Item { - Component { - id: item1 - Item { - objectName: "item1" - } - } - Component { - id: item2 - Item { - objectName: "item2" - } - } - Loader { - id: loader - sourceComponent: item1 - } - Connections { - objectName: "connections" - target: loader.item - onWidthChanged: loader.sourceComponent = item2 - } -} diff --git a/tests/auto/qml/qqmlconnections/data/connection-unknownsignals-ignored.qml b/tests/auto/qml/qqmlconnections/data/connection-unknownsignals-ignored.qml deleted file mode 100644 index 0780dd1509..0000000000 --- a/tests/auto/qml/qqmlconnections/data/connection-unknownsignals-ignored.qml +++ /dev/null @@ -1,8 +0,0 @@ -import QtQml 2.0 - -QtObject { - id: root - - property Connections c1: Connections { target: root; onNotFooBar1: {} ignoreUnknownSignals: true } - property Connections c2: Connections { objectName: "connections"; onNotFooBar2: {} ignoreUnknownSignals: true } -} diff --git a/tests/auto/qml/qqmlconnections/data/connection-unknownsignals-notarget.qml b/tests/auto/qml/qqmlconnections/data/connection-unknownsignals-notarget.qml deleted file mode 100644 index 3da3e0f5d1..0000000000 --- a/tests/auto/qml/qqmlconnections/data/connection-unknownsignals-notarget.qml +++ /dev/null @@ -1,5 +0,0 @@ -import QtQml 2.0 - -QtObject { - property Connections c1: Connections { objectName: "connections"; target: null; onNotFooBar: {} } -} diff --git a/tests/auto/qml/qqmlconnections/data/connection-unknownsignals-parent.qml b/tests/auto/qml/qqmlconnections/data/connection-unknownsignals-parent.qml deleted file mode 100644 index 2c55215579..0000000000 --- a/tests/auto/qml/qqmlconnections/data/connection-unknownsignals-parent.qml +++ /dev/null @@ -1,5 +0,0 @@ -import QtQml 2.0 - -QtObject { - property Connections c1: Connections { objectName: "connections"; onFooBar: {} } -} diff --git a/tests/auto/qml/qqmlconnections/data/connection-unknownsignals.qml b/tests/auto/qml/qqmlconnections/data/connection-unknownsignals.qml deleted file mode 100644 index a351016b4a..0000000000 --- a/tests/auto/qml/qqmlconnections/data/connection-unknownsignals.qml +++ /dev/null @@ -1,7 +0,0 @@ -import QtQml 2.0 - -QtObject { - id: screen - - property Connections c1: Connections { objectName: "connections"; target: screen; onFooBar: {} } -} diff --git a/tests/auto/qml/qqmlconnections/data/disabled-at-start.qml b/tests/auto/qml/qqmlconnections/data/disabled-at-start.qml deleted file mode 100644 index 1a823f87f6..0000000000 --- a/tests/auto/qml/qqmlconnections/data/disabled-at-start.qml +++ /dev/null @@ -1,14 +0,0 @@ -import QtQuick 2.9 - -Item { - id: root - - property bool tested: false - signal testMe() - - Connections { - target: root - enabled: false - onTestMe: root.tested = true; - } -} diff --git a/tests/auto/qml/qqmlconnections/data/functions/connection-no-signal-name.qml b/tests/auto/qml/qqmlconnections/data/functions/connection-no-signal-name.qml new file mode 100644 index 0000000000..04cc36b3c5 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/functions/connection-no-signal-name.qml @@ -0,0 +1,15 @@ +import QtQuick 2.4 + +Item { + id: blaBlaBla + function hint() { + } + + Connections { + //target: blaBlaBla + // function onHint() { hint() }; + on: true + } +} + + diff --git a/tests/auto/qml/qqmlconnections/data/functions/connection-targetchange.qml b/tests/auto/qml/qqmlconnections/data/functions/connection-targetchange.qml new file mode 100644 index 0000000000..692194e837 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/functions/connection-targetchange.qml @@ -0,0 +1,25 @@ +import QtQuick 2.0 + +Item { + Component { + id: item1 + Item { + objectName: "item1" + } + } + Component { + id: item2 + Item { + objectName: "item2" + } + } + Loader { + id: loader + sourceComponent: item1 + } + Connections { + objectName: "connections" + target: loader.item + function onWidthChanged() { loader.sourceComponent = item2 } + } +} diff --git a/tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals-ignored.qml b/tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals-ignored.qml new file mode 100644 index 0000000000..f70d8cdb15 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals-ignored.qml @@ -0,0 +1,17 @@ +import QtQml 2.0 + +QtObject { + id: root + + property Connections c1: Connections { + target: root; + function onNotFooBar1() {} + ignoreUnknownSignals: true + } + + property Connections c2: Connections { + objectName: "connections" + function onNotFooBar2() {} + ignoreUnknownSignals: true + } +} diff --git a/tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals-notarget.qml b/tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals-notarget.qml new file mode 100644 index 0000000000..7658728dd9 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals-notarget.qml @@ -0,0 +1,9 @@ +import QtQml 2.0 + +QtObject { + property Connections c1: Connections { + objectName: "connections" + target: null + function onNotFooBar() {} + } +} diff --git a/tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals-parent.qml b/tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals-parent.qml new file mode 100644 index 0000000000..ece76b0cf7 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals-parent.qml @@ -0,0 +1,8 @@ +import QtQml 2.0 + +QtObject { + property Connections c1: Connections { + objectName: "connections" + function onFooBar() {} + } +} diff --git a/tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals.qml b/tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals.qml new file mode 100644 index 0000000000..a198a724d0 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/functions/connection-unknownsignals.qml @@ -0,0 +1,11 @@ +import QtQml 2.0 + +QtObject { + id: screen + + property Connections c1: Connections { + objectName: "connections" + target: screen + function onFooBar() {} + } +} diff --git a/tests/auto/qml/qqmlconnections/data/functions/disabled-at-start.qml b/tests/auto/qml/qqmlconnections/data/functions/disabled-at-start.qml new file mode 100644 index 0000000000..981437fe8c --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/functions/disabled-at-start.qml @@ -0,0 +1,14 @@ +import QtQuick 2.9 + +Item { + id: root + + property bool tested: false + signal testMe() + + Connections { + target: root + enabled: false + function onTestMe() { root.tested = true; } + } +} diff --git a/tests/auto/qml/qqmlconnections/data/functions/override-proxy-type.qml b/tests/auto/qml/qqmlconnections/data/functions/override-proxy-type.qml new file mode 100644 index 0000000000..b83f0baa11 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/functions/override-proxy-type.qml @@ -0,0 +1,13 @@ +import QtQml 2.12 +import test.proxy 1.0 + +Proxy { + property int testEnum: 0; + id: proxy + property Connections connections: Connections { + target: proxy + function onSomeSignal() { testEnum = Proxy.EnumValue } + } + + Component.onCompleted: someSignal() +} diff --git a/tests/auto/qml/qqmlconnections/data/functions/rewriteError-global.qml b/tests/auto/qml/qqmlconnections/data/functions/rewriteError-global.qml new file mode 100644 index 0000000000..de3154c431 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/functions/rewriteError-global.qml @@ -0,0 +1,8 @@ +import QtQml 2.0 +import Test 1.0 + +TestObject { + property QtObject connection: Connections { + function onSignalWithGlobalName() { ran = true } + } +} diff --git a/tests/auto/qml/qqmlconnections/data/functions/rewriteError-unnamed.qml b/tests/auto/qml/qqmlconnections/data/functions/rewriteError-unnamed.qml new file mode 100644 index 0000000000..fa1d1b17d7 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/functions/rewriteError-unnamed.qml @@ -0,0 +1,8 @@ +import QtQuick 2.0 +import Test 1.0 + +TestObject { + property QtObject connection: Connections { + function onUnnamedArgumentSignal() { ran = true } + } +} diff --git a/tests/auto/qml/qqmlconnections/data/functions/singletontype-target.qml b/tests/auto/qml/qqmlconnections/data/functions/singletontype-target.qml new file mode 100644 index 0000000000..935b610351 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/functions/singletontype-target.qml @@ -0,0 +1,22 @@ +import QtQml 2.0 +import MyTestSingletonType 1.0 as MyTestSingletonType + +QtObject { + id: rootObject + objectName: "rootObject" + property int newIntPropValue: 12 + + property int moduleIntPropChangedCount: 0 + property int moduleOtherSignalCount: 0 + + function setModuleIntProp() { + MyTestSingletonType.Api.intProp = newIntPropValue; + newIntPropValue = newIntPropValue + 1; + } + + property Connections c: Connections { + target: MyTestSingletonType.Api + function onIntPropChanged() { moduleIntPropChangedCount = moduleIntPropChangedCount + 1 } + function onOtherSignal() { moduleOtherSignalCount = moduleOtherSignalCount + 1 } + } +} diff --git a/tests/auto/qml/qqmlconnections/data/functions/test-connection-implicit.qml b/tests/auto/qml/qqmlconnections/data/functions/test-connection-implicit.qml new file mode 100644 index 0000000000..2ed5278636 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/functions/test-connection-implicit.qml @@ -0,0 +1,9 @@ +import QtQuick 2.0 + +Item { + width: 50 + + property bool tested: false + + Connections { function onWidthChanged() { tested = true } } +} diff --git a/tests/auto/qml/qqmlconnections/data/functions/test-connection.qml b/tests/auto/qml/qqmlconnections/data/functions/test-connection.qml new file mode 100644 index 0000000000..c706797ea4 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/functions/test-connection.qml @@ -0,0 +1,14 @@ +import QtQuick 2.0 + +Item { + id: screen; width: 50 + + property bool tested: false + signal testMe + + Connections { + objectName: "connections" + target: screen; + function onWidthChanged() { screen.tested = true } + } +} diff --git a/tests/auto/qml/qqmlconnections/data/functions/trimming.qml b/tests/auto/qml/qqmlconnections/data/functions/trimming.qml new file mode 100644 index 0000000000..7dfd673539 --- /dev/null +++ b/tests/auto/qml/qqmlconnections/data/functions/trimming.qml @@ -0,0 +1,13 @@ +import QtQml 2.0 + +QtObject { + id: root + + property string tested + signal testMe(int param1, string param2) + + property Connections c: Connections { + target: root + function onTestMe(param1, param2) { root.tested = param2 + param1 } + } +} diff --git a/tests/auto/qml/qqmlconnections/data/override-proxy-type.qml b/tests/auto/qml/qqmlconnections/data/override-proxy-type.qml deleted file mode 100644 index 80e459966b..0000000000 --- a/tests/auto/qml/qqmlconnections/data/override-proxy-type.qml +++ /dev/null @@ -1,13 +0,0 @@ -import QtQml 2.12 -import test.proxy 1.0 - -Proxy { - property int testEnum: 0; - id: proxy - property Connections connections: Connections { - target: proxy - onSomeSignal: testEnum = Proxy.EnumValue; - } - - Component.onCompleted: someSignal() -} diff --git a/tests/auto/qml/qqmlconnections/data/rewriteError-global.qml b/tests/auto/qml/qqmlconnections/data/rewriteError-global.qml deleted file mode 100644 index 1d0b557069..0000000000 --- a/tests/auto/qml/qqmlconnections/data/rewriteError-global.qml +++ /dev/null @@ -1,8 +0,0 @@ -import QtQml 2.0 -import Test 1.0 - -TestObject { - property QtObject connection: Connections { - onSignalWithGlobalName: { ran = true } - } -} diff --git a/tests/auto/qml/qqmlconnections/data/rewriteError-unnamed.qml b/tests/auto/qml/qqmlconnections/data/rewriteError-unnamed.qml deleted file mode 100644 index a4849e994b..0000000000 --- a/tests/auto/qml/qqmlconnections/data/rewriteError-unnamed.qml +++ /dev/null @@ -1,8 +0,0 @@ -import QtQuick 2.0 -import Test 1.0 - -TestObject { - property QtObject connection: Connections { - onUnnamedArgumentSignal: { ran = true } - } -} diff --git a/tests/auto/qml/qqmlconnections/data/singletontype-target.qml b/tests/auto/qml/qqmlconnections/data/singletontype-target.qml deleted file mode 100644 index 7de488c2dd..0000000000 --- a/tests/auto/qml/qqmlconnections/data/singletontype-target.qml +++ /dev/null @@ -1,22 +0,0 @@ -import QtQml 2.0 -import MyTestSingletonType 1.0 as MyTestSingletonType - -QtObject { - id: rootObject - objectName: "rootObject" - property int newIntPropValue: 12 - - property int moduleIntPropChangedCount: 0 - property int moduleOtherSignalCount: 0 - - function setModuleIntProp() { - MyTestSingletonType.Api.intProp = newIntPropValue; - newIntPropValue = newIntPropValue + 1; - } - - property Connections c: Connections { - target: MyTestSingletonType.Api - onIntPropChanged: moduleIntPropChangedCount = moduleIntPropChangedCount + 1; - onOtherSignal: moduleOtherSignalCount = moduleOtherSignalCount + 1; - } -} diff --git a/tests/auto/qml/qqmlconnections/data/test-connection-implicit.qml b/tests/auto/qml/qqmlconnections/data/test-connection-implicit.qml deleted file mode 100644 index d5aa0f102a..0000000000 --- a/tests/auto/qml/qqmlconnections/data/test-connection-implicit.qml +++ /dev/null @@ -1,9 +0,0 @@ -import QtQuick 2.0 - -Item { - width: 50 - - property bool tested: false - - Connections { onWidthChanged: tested = true } -} diff --git a/tests/auto/qml/qqmlconnections/data/test-connection.qml b/tests/auto/qml/qqmlconnections/data/test-connection.qml deleted file mode 100644 index f44cbc047f..0000000000 --- a/tests/auto/qml/qqmlconnections/data/test-connection.qml +++ /dev/null @@ -1,10 +0,0 @@ -import QtQuick 2.0 - -Item { - id: screen; width: 50 - - property bool tested: false - signal testMe - - Connections { objectName: "connections"; target: screen; onWidthChanged: screen.tested = true } -} diff --git a/tests/auto/qml/qqmlconnections/data/trimming.qml b/tests/auto/qml/qqmlconnections/data/trimming.qml deleted file mode 100644 index 4c37eb22af..0000000000 --- a/tests/auto/qml/qqmlconnections/data/trimming.qml +++ /dev/null @@ -1,10 +0,0 @@ -import QtQml 2.0 - -QtObject { - id: root - - property string tested - signal testMe(int param1, string param2) - - property Connections c: Connections { target: root; onTestMe: root.tested = param2 + param1 } -} diff --git a/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp b/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp index 7e6a0f79f9..cf0f3c7bb3 100644 --- a/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp +++ b/tests/auto/qml/qqmlconnections/tst_qqmlconnections.cpp @@ -42,29 +42,57 @@ public: private slots: void defaultValues(); void properties(); + + void connection_data() { prefixes(); } void connection(); + + void trimming_data() { prefixes(); } void trimming(); + + void targetChanged_data() { prefixes(); }; void targetChanged(); + void unknownSignals_data(); void unknownSignals(); + void errors_data(); void errors(); + + void rewriteErrors_data() { prefixes(); } void rewriteErrors(); + + void singletonTypeTarget_data() { prefixes(); } void singletonTypeTarget(); + + void enableDisable_QTBUG_36350_data() { prefixes(); } void enableDisable_QTBUG_36350(); + + void disabledAtStart_data() { prefixes(); } void disabledAtStart(); + + void clearImplicitTarget_data() { prefixes(); } void clearImplicitTarget(); void onWithoutASignal(); + + void noAcceleratedGlobalLookup_data() { prefixes(); } void noAcceleratedGlobalLookup(); private: QQmlEngine engine; + void prefixes(); }; tst_qqmlconnections::tst_qqmlconnections() { } +void tst_qqmlconnections::prefixes() +{ + QTest::addColumn("prefix"); + QTest::newRow("functions") << QString("functions"); + QTest::newRow("bindings") << QString("bindings"); +} + void tst_qqmlconnections::defaultValues() { QQmlEngine engine; @@ -93,8 +121,9 @@ void tst_qqmlconnections::properties() void tst_qqmlconnections::connection() { + QFETCH(QString, prefix); QQmlEngine engine; - QQmlComponent c(&engine, testFileUrl("test-connection.qml")); + QQmlComponent c(&engine, testFileUrl(prefix + "/test-connection.qml")); QQuickItem *item = qobject_cast(c.create()); QVERIFY(item != nullptr); @@ -110,8 +139,9 @@ void tst_qqmlconnections::connection() void tst_qqmlconnections::trimming() { + QFETCH(QString, prefix); QQmlEngine engine; - QQmlComponent c(&engine, testFileUrl("trimming.qml")); + QQmlComponent c(&engine, testFileUrl(prefix + "/trimming.qml")); QObject *object = c.create(); QVERIFY(object != nullptr); @@ -131,8 +161,9 @@ void tst_qqmlconnections::trimming() // Confirm that target can be changed by one of our signal handlers void tst_qqmlconnections::targetChanged() { + QFETCH(QString, prefix); QQmlEngine engine; - QQmlComponent c(&engine, testFileUrl("connection-targetchange.qml")); + QQmlComponent c(&engine, testFileUrl(prefix + "/connection-targetchange.qml")); QQuickItem *item = qobject_cast(c.create()); QVERIFY(item != nullptr); @@ -158,10 +189,15 @@ void tst_qqmlconnections::unknownSignals_data() QTest::addColumn("file"); QTest::addColumn("error"); - QTest::newRow("basic") << "connection-unknownsignals.qml" << ":6:30: QML Connections: Cannot assign to non-existent property \"onFooBar\""; - QTest::newRow("parent") << "connection-unknownsignals-parent.qml" << ":4:30: QML Connections: Cannot assign to non-existent property \"onFooBar\""; - QTest::newRow("ignored") << "connection-unknownsignals-ignored.qml" << ""; // should be NO error - QTest::newRow("notarget") << "connection-unknownsignals-notarget.qml" << ""; // should be NO error + QTest::newRow("functions/basic") << "functions/connection-unknownsignals.qml" << ":6:30: QML Connections: Detected function \"onFooBar\" in Connections element. This is probably intended to be a signal handler but no signal of the target matches the name."; + QTest::newRow("functions/parent") << "functions/connection-unknownsignals-parent.qml" << ":4:30: QML Connections: Detected function \"onFooBar\" in Connections element. This is probably intended to be a signal handler but no signal of the target matches the name."; + QTest::newRow("functions/ignored") << "functions/connection-unknownsignals-ignored.qml" << ""; // should be NO error + QTest::newRow("functions/notarget") << "functions/connection-unknownsignals-notarget.qml" << ""; // should be NO error + + QTest::newRow("bindings/basic") << "bindings/connection-unknownsignals.qml" << ":6:30: QML Connections: Cannot assign to non-existent property \"onFooBar\""; + QTest::newRow("bindings/parent") << "bindings/connection-unknownsignals-parent.qml" << ":4:30: QML Connections: Cannot assign to non-existent property \"onFooBar\""; + QTest::newRow("bindings/ignored") << "bindings/connection-unknownsignals-ignored.qml" << ""; // should be NO error + QTest::newRow("bindings/notarget") << "bindings/connection-unknownsignals-notarget.qml" << ""; // should be NO error } void tst_qqmlconnections::unknownSignals() @@ -239,10 +275,11 @@ private: void tst_qqmlconnections::rewriteErrors() { + QFETCH(QString, prefix); qmlRegisterType("Test", 1, 0, "TestObject"); { QQmlEngine engine; - QQmlComponent c(&engine, testFileUrl("rewriteError-unnamed.qml")); + QQmlComponent c(&engine, testFileUrl(prefix + "/rewriteError-unnamed.qml")); QTest::ignoreMessage(QtWarningMsg, (c.url().toString() + ":5:35: QML Connections: Signal uses unnamed parameter followed by named parameter.").toLatin1()); TestObject *obj = qobject_cast(c.create()); QVERIFY(obj != nullptr); @@ -254,7 +291,7 @@ void tst_qqmlconnections::rewriteErrors() { QQmlEngine engine; - QQmlComponent c(&engine, testFileUrl("rewriteError-global.qml")); + QQmlComponent c(&engine, testFileUrl(prefix + "/rewriteError-global.qml")); QTest::ignoreMessage(QtWarningMsg, (c.url().toString() + ":5:35: QML Connections: Signal parameter \"parseInt\" hides global variable.").toLatin1()); TestObject *obj = qobject_cast(c.create()); QVERIFY(obj != nullptr); @@ -305,8 +342,9 @@ static QObject *module_api_factory(QQmlEngine *engine, QJSEngine *scriptEngine) // QTBUG-20937 void tst_qqmlconnections::singletonTypeTarget() { + QFETCH(QString, prefix); qmlRegisterSingletonType("MyTestSingletonType", 1, 0, "Api", module_api_factory); - QQmlComponent component(&engine, testFileUrl("singletontype-target.qml")); + QQmlComponent component(&engine, testFileUrl(prefix + "/singletontype-target.qml")); QObject *object = component.create(); QVERIFY(object != nullptr); @@ -331,8 +369,9 @@ void tst_qqmlconnections::singletonTypeTarget() void tst_qqmlconnections::enableDisable_QTBUG_36350() { + QFETCH(QString, prefix); QQmlEngine engine; - QQmlComponent c(&engine, testFileUrl("test-connection.qml")); + QQmlComponent c(&engine, testFileUrl(prefix + "/test-connection.qml")); QQuickItem *item = qobject_cast(c.create()); QVERIFY(item != nullptr); @@ -358,8 +397,9 @@ void tst_qqmlconnections::enableDisable_QTBUG_36350() void tst_qqmlconnections::disabledAtStart() { + QFETCH(QString, prefix); QQmlEngine engine; - QQmlComponent c(&engine, testFileUrl("disabled-at-start.qml")); + QQmlComponent c(&engine, testFileUrl(prefix + "/disabled-at-start.qml")); QObject * const object = c.create(); QVERIFY(object != nullptr); @@ -376,8 +416,9 @@ void tst_qqmlconnections::disabledAtStart() //QTBUG-56499 void tst_qqmlconnections::clearImplicitTarget() { + QFETCH(QString, prefix); QQmlEngine engine; - QQmlComponent c(&engine, testFileUrl("test-connection-implicit.qml")); + QQmlComponent c(&engine, testFileUrl(prefix + "/test-connection-implicit.qml")); QQuickItem *item = qobject_cast(c.create()); QVERIFY(item != nullptr); @@ -421,10 +462,11 @@ signals: void tst_qqmlconnections::noAcceleratedGlobalLookup() { + QFETCH(QString, prefix); qRegisterMetaType(); qmlRegisterType("test.proxy", 1, 0, "Proxy"); QQmlEngine engine; - QQmlComponent c(&engine, testFileUrl("override-proxy-type.qml")); + QQmlComponent c(&engine, testFileUrl(prefix + "/override-proxy-type.qml")); QVERIFY(c.isReady()); QScopedPointer object(c.create()); const QVariant val = object->property("testEnum"); -- cgit v1.2.3