aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/items
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2016-07-18 15:50:21 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2016-07-19 14:52:28 +0000
commit3fa5a9c0113f381cedb1b9d82d82bdd2289c57c0 (patch)
treee1c26195608fc7a4c2fdd68aab79b07096a7bb0d /src/quick/items
parent90de20f17fc1b3690a263372b222682e5292e857 (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')
-rw-r--r--src/quick/items/qquickevents.cpp16
-rw-r--r--src/quick/items/qquickevents_p_p.h11
2 files changed, 19 insertions, 8 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;
diff --git a/src/quick/items/qquickevents_p_p.h b/src/quick/items/qquickevents_p_p.h
index f9668eb434..ed75556d6a 100644
--- a/src/quick/items/qquickevents_p_p.h
+++ b/src/quick/items/qquickevents_p_p.h
@@ -238,6 +238,8 @@ private:
bool _accepted;
};
+class QQuickPointerEvent;
+
class Q_QUICK_PRIVATE_EXPORT QQuickEventPoint : public QObject
{
Q_OBJECT
@@ -248,11 +250,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickEventPoint : public QObject
Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
public:
- QQuickEventPoint() : QObject(), m_pointId(0), m_timestamp(0), m_pressTimestamp(0),
- m_state(Qt::TouchPointReleased), m_valid(false), m_accept(false)
- {
- Q_UNUSED(m_reserved);
- }
+ QQuickEventPoint(QQuickPointerEvent *parent);
void reset(Qt::TouchPointState state, QPointF scenePos, quint64 pointId, ulong timestamp)
{
@@ -269,6 +267,7 @@ public:
void invalidate() { m_valid = false; }
+ QQuickPointerEvent *pointerEvent() const;
QPointF scenePos() const { return m_scenePos; }
Qt::TouchPointState state() const { return m_state; }
quint64 pointId() const { return m_pointId; }
@@ -296,7 +295,7 @@ class Q_QUICK_PRIVATE_EXPORT QQuickEventTouchPoint : public QQuickEventPoint
Q_PROPERTY(QPointerUniqueId uniqueId READ uniqueId)
public:
- QQuickEventTouchPoint() : QQuickEventPoint(), m_rotation(0), m_pressure(0) { }
+ QQuickEventTouchPoint(QQuickPointerEvent *parent) : QQuickEventPoint(parent), m_rotation(0), m_pressure(0) { }
void reset(const QTouchEvent::TouchPoint &tp, ulong timestamp)
{