summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qevent.cpp
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-10-16 11:23:57 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-10-17 08:21:52 +0200
commit833a6e18bfeda0e33963b1231c8ed9224332c4b3 (patch)
treea18fed2bc7520862ef39aa0a1695f70a573135c6 /src/gui/kernel/qevent.cpp
parenta9982e64eb5108e5c4b51a4e5738c08eff6d07e7 (diff)
Implement move and comparison operators for QEventPoint
QEventPoints are equal when all data values are equal, the refcount is ignored. Change-Id: I6ef70faf0b12129eaa22bfc1f0a45bab2422d421 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/gui/kernel/qevent.cpp')
-rw-r--r--src/gui/kernel/qevent.cpp52
1 files changed, 48 insertions, 4 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 38906df6cb..d34b74d9d0 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -243,24 +243,68 @@ QEventPoint::QEventPoint(int id, const QPointingDevice *device)
QEventPoint::QEventPoint(int pointId, State state, const QPointF &scenePosition, const QPointF &globalPosition)
: d(new QEventPointPrivate(pointId, state, scenePosition, globalPosition)) {}
+/*!
+ Constructs an event point by making a shallow copy of \a other.
+*/
QEventPoint::QEventPoint(const QEventPoint &other)
: d(other.d)
{
- d->refCount++;
+ if (d)
+ d->refCount++;
}
+/*!
+ Assigns \a other to this event point and returns a reference to this
+ event point.
+*/
QEventPoint &QEventPoint::operator=(const QEventPoint &other)
{
- other.d->refCount++;
- if (!(--d->refCount))
+ if (other.d)
+ other.d->refCount++;
+ if (d && !(--d->refCount))
delete d;
d = other.d;
return *this;
}
+/*!
+ \fn QEventPoint::QEventPoint(QEventPoint &&other) noexcept
+
+ Constructs an event point by moving \a other.
+*/
+
+/*!
+ \fn QEventPoint &QEventPoint QEventPoint::operator=(QEventPoint &&other) noexcept
+
+ Move-assigns \a other to this event point instance.
+*/
+
+/*!
+ Returns \c true if this event point is equal to \a other, otherwise
+ return \c false.
+*/
+bool QEventPoint::operator==(const QEventPoint &other) const noexcept
+{
+ if (d == other.d)
+ return true;
+ if (!d || !other.d)
+ return false;
+ return *d == *other.d;
+}
+
+/*!
+ \fn bool QEventPoint::operator!=(const QEventPoint &other) const noexcept
+
+ Returns \c true if this event point is not equal to \a other, otherwise
+ return \c false.
+*/
+
+/*!
+ Destroys the event point.
+*/
QEventPoint::~QEventPoint()
{
- if (!(--d->refCount))
+ if (d && !(--d->refCount))
delete d;
}