From e6e63e749088d3a6057bcb18f0f241ab1eb603f6 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Mon, 1 Apr 2019 22:47:12 +0200 Subject: QQuickMultiPointHandler::moveTarget(): work with interceptors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As with WheelHandler, DragHandler also needs to allow the target movements to be constrained with interceptors like BoundaryRule. Also do a null pointer check in moveTarget(): we haven't needed it before, but we are becoming more open to subclassing, so need to prevent user foot-shooting. Change-Id: I6b39b6dd2ca8245c56ecb3812e6de9624b36fa50 Reviewed-by: Jan Arve Sæther --- src/quick/handlers/qquickmultipointhandler.cpp | 29 ++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/quick/handlers/qquickmultipointhandler.cpp') diff --git a/src/quick/handlers/qquickmultipointhandler.cpp b/src/quick/handlers/qquickmultipointhandler.cpp index ceadbf3ada..5c10ecce75 100644 --- a/src/quick/handlers/qquickmultipointhandler.cpp +++ b/src/quick/handlers/qquickmultipointhandler.cpp @@ -384,8 +384,13 @@ bool QQuickMultiPointHandler::grabPoints(QVector points) void QQuickMultiPointHandler::moveTarget(QPointF pos) { Q_D(QQuickMultiPointHandler); - target()->setPosition(pos); - d->centroid.m_position = target()->mapFromScene(d->centroid.m_scenePosition); + if (QQuickItem *t = target()) { + d->xMetaProperty().write(t, pos.x()); + d->yMetaProperty().write(t, pos.y()); + d->centroid.m_position = t->mapFromScene(d->centroid.m_scenePosition); + } else { + qWarning() << "moveTarget: target is null"; + } } QQuickMultiPointHandlerPrivate::QQuickMultiPointHandlerPrivate(int minPointCount, int maxPointCount) @@ -395,4 +400,24 @@ QQuickMultiPointHandlerPrivate::QQuickMultiPointHandlerPrivate(int minPointCount { } +QMetaProperty &QQuickMultiPointHandlerPrivate::xMetaProperty() const +{ + Q_Q(const QQuickMultiPointHandler); + if (!xProperty.isValid() && q->target()) { + const QMetaObject *targetMeta = q->target()->metaObject(); + xProperty = targetMeta->property(targetMeta->indexOfProperty("x")); + } + return xProperty; +} + +QMetaProperty &QQuickMultiPointHandlerPrivate::yMetaProperty() const +{ + Q_Q(const QQuickMultiPointHandler); + if (!yProperty.isValid() && q->target()) { + const QMetaObject *targetMeta = q->target()->metaObject(); + yProperty = targetMeta->property(targetMeta->indexOfProperty("y")); + } + return yProperty; +} + QT_END_NAMESPACE -- cgit v1.2.3