diff options
author | Mitch Curtis <mitch.curtis@theqtcompany.com> | 2015-04-08 10:04:25 +0200 |
---|---|---|
committer | Simon Hausmann <simon.hausmann@theqtcompany.com> | 2015-04-08 14:32:41 +0000 |
commit | 360fcf3a99d84b038326d05f8ea8718b40bff2c0 (patch) | |
tree | cf1bd655ff9aa7c439cc7281105066def24a880c /tests/auto/quick/qquickitem/data | |
parent | 1a4719dd0d6c565fa97e6962c3686123ec02fd00 (diff) |
Return the correct type from Item::mapToItem/Item::mapFromItem.
Previously we were returning a JavaScript object with x/y/width/height
properties, instead of a point/rect. This meant that the type couldn't
be converted to a point/rect because we don't support duck typing,
where we would deduce the type based on the properties.
One example of a broken use case that this patch fixes is when QML is
unable to convert the return type to a point in a property declaration:
property point p: mouseArea.mapToItem(child, mouseArea.mouseX, mouseArea.mouseY)
Another is using the result of the function to pass to another function:
child.contains(mouseArea.mapToItem(child, mouseArea.mouseX, mouseArea.mouseY))
Change-Id: I3ce82f10175f904dd02c8af6b5e42cee14b2ebb2
Task-number: QTBUG-41452
Reviewed-by: Liang Qi <liang.qi@theqtcompany.com>
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tests/auto/quick/qquickitem/data')
-rw-r--r-- | tests/auto/quick/qquickitem/data/contains.qml | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickitem/data/contains.qml b/tests/auto/quick/qquickitem/data/contains.qml new file mode 100644 index 0000000000..72fd8bdc91 --- /dev/null +++ b/tests/auto/quick/qquickitem/data/contains.qml @@ -0,0 +1,26 @@ +import QtQuick 2.3 + +Item { + id: root + width: 300 + height: 300 + + function childContainsViaMapToItem(x, y) { + var childLocalPos = root.mapToItem(child, x, y); + return child.contains(childLocalPos); + } + + function childContainsViaMapFromItem(x, y) { + var childLocalPos = child.mapFromItem(root, x, y); + return child.contains(childLocalPos); + } + + Item { + id: child + x: 50 + y: 50 + width: 50 + height: 50 + } +} + |