aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items/qquickitem.cpp
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2018-11-22 14:00:39 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2018-12-07 20:45:10 +0000
commitee2ac69595d3f854f7bf7158e600091f2675fa18 (patch)
tree50ef6ecedadd96ac1c563e65f16f28dd1ded2943 /src/quick/items/qquickitem.cpp
parent1cd3b2acfeb041ef54fe546b07a5e9efb5a2099b (diff)
Add dynamically-created Event Handlers to the relevant handlers vector
If any kind of Pointer Handler is created dynamically in JS by calling Component.createObject(), QObject::setParent() is called rather than passing the parent to the constructor, so QQuickItemPrivate::data_append() did not take care of adding the handler to QQuickItemPrivate's extra->pointerHandlers vector. We need to use the auto-parent mechanism (just as we did with handling dynamic creation of nested Windows in 8cb02e23abbefc9d020707fc1a2d8b6eb4e103b6). Added QQuickItemPrivate::addPointerHandler() to put the prepend() and implied setAcceptedMouseButtons() in one place. Fixes: QTBUG-71427 Change-Id: I3be3dd033c1c89e6e5b5c3463e1a720bbe963281 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items/qquickitem.cpp')
-rw-r--r--src/quick/items/qquickitem.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/quick/items/qquickitem.cpp b/src/quick/items/qquickitem.cpp
index 064406ee3c..015fe66202 100644
--- a/src/quick/items/qquickitem.cpp
+++ b/src/quick/items/qquickitem.cpp
@@ -3281,11 +3281,7 @@ void QQuickItemPrivate::data_append(QQmlListProperty<QObject> *prop, QObject *o)
qWarning("Cannot add a QtQuick 1.0 item (%s) into a QtQuick 2.0 scene!", o->metaObject()->className());
else if (QQuickPointerHandler *pointerHandler = qmlobject_cast<QQuickPointerHandler *>(o)) {
Q_ASSERT(pointerHandler->parentItem() == that);
- // Accept all buttons, and leave filtering to pointerEvent() and/or user JS,
- // because there can be multiple handlers...
- that->setAcceptedMouseButtons(Qt::AllButtons);
- QQuickItemPrivate *p = QQuickItemPrivate::get(that);
- p->extra.value().pointerHandlers.prepend(pointerHandler);
+ QQuickItemPrivate::get(that)->addPointerHandler(pointerHandler);
} else {
QQuickWindow *thisWindow = qmlobject_cast<QQuickWindow *>(o);
QQuickItem *item = that;
@@ -8207,6 +8203,17 @@ bool QQuickItemPrivate::hasHoverHandlers() const
return false;
}
+void QQuickItemPrivate::addPointerHandler(QQuickPointerHandler *h)
+{
+ Q_Q(QQuickItem);
+ // Accept all buttons, and leave filtering to pointerEvent() and/or user JS,
+ // because there can be multiple handlers...
+ q->setAcceptedMouseButtons(Qt::AllButtons);
+ auto &handlers = extra.value().pointerHandlers;
+ if (!handlers.contains(h))
+ handlers.prepend(h);
+}
+
#if QT_CONFIG(quick_shadereffect)
QQuickItemLayer::QQuickItemLayer(QQuickItem *item)
: m_item(item)