diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2016-07-18 15:50:21 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2016-07-19 14:52:28 +0000 |
commit | 3fa5a9c0113f381cedb1b9d82d82bdd2289c57c0 (patch) | |
tree | e1c26195608fc7a4c2fdd68aab79b07096a7bb0d /src/quick/items/qquickevents.cpp | |
parent | 90de20f17fc1b3690a263372b222682e5292e857 (diff) |
QQuickEventPoint: be a QObject-child of QQuickPointerEvent
The points are conceptually children, so this will help take care of
memory management. It's also useful to be able to emit or pass
a QQuickEventPoint without losing the context of the event it came from.
To this end, a pointerEvent() accessor is added, which simply does
the static_cast for you.
Change-Id: I71e57655cf1a0e7d741c4099c7eb9fc3a9a76446
Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
Diffstat (limited to 'src/quick/items/qquickevents.cpp')
-rw-r--r-- | src/quick/items/qquickevents.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/quick/items/qquickevents.cpp b/src/quick/items/qquickevents.cpp index 5f6cadaf00..c04fbeea6e 100644 --- a/src/quick/items/qquickevents.cpp +++ b/src/quick/items/qquickevents.cpp @@ -492,7 +492,7 @@ void QQuickPointerEvent::initFromMouse(QMouseEvent *ev) { } if (!m_mousePoint) - m_mousePoint = new QQuickEventPoint; + m_mousePoint = new QQuickEventPoint(this); m_pointCount = 1; m_mousePoint->reset(state, ev->windowPos(), 0, ev->timestamp()); // mouse is 0 } @@ -507,7 +507,7 @@ void QQuickPointerEvent::initFromTouch(QTouchEvent *ev) { m_pointCount = tps.count(); m_touchPoints.reserve(m_pointCount); for (int i = m_touchPoints.size(); i < m_pointCount; ++i) - m_touchPoints.insert(i, new QQuickEventTouchPoint); + m_touchPoints.insert(i, new QQuickEventTouchPoint(this)); for (int i = 0; i < m_pointCount; ++i) m_touchPoints.at(i)->reset(tps.at(i), ev->timestamp()); @@ -563,6 +563,18 @@ bool QQuickPointerEvent::isTabletEvent() const } } +QQuickEventPoint::QQuickEventPoint(QQuickPointerEvent *parent) + : QObject(parent), m_pointId(0), m_timestamp(0), m_pressTimestamp(0), + m_state(Qt::TouchPointReleased), m_valid(false), m_accept(false) +{ + Q_UNUSED(m_reserved); +} + +QQuickPointerEvent *QQuickEventPoint::pointerEvent() const +{ + return static_cast<QQuickPointerEvent *>(parent()); +} + QQuickEventPoint *QQuickPointerEvent::point(int i) const { if (Q_UNLIKELY(i < 0 || i >= m_pointCount)) return nullptr; |