summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-03-01 08:47:20 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-06 19:21:26 +0100
commit47cdc50bbcdab874e5cbd11ae3a91eb2b5abab54 (patch)
treea3cf0ce2685edc6a4ba3b22adeb40bdd3ff6c057 /src/gui
parentf5433b9666a4a10779f2244c8c7399c8f794baa4 (diff)
QTouchEvent::TouchPoint: make it a proper value class
This includes: - Marking it as Q_MOVABLE_TYPE - adding move ctor and move assignment operator - add member-swap - use the copy-swap idiom in the copy-assignment operator This required making the destructor safe for d == nullptr. Change-Id: I8a77ffcb8e4a395a7e103d1df610561b6ae4c001 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qevent.cpp19
-rw-r--r--src/gui/kernel/qevent.h15
2 files changed, 21 insertions, 13 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index 60e754b289..f1bf07635c 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -3621,7 +3621,7 @@ QTouchEvent::TouchPoint::TouchPoint(const QTouchEvent::TouchPoint &other)
*/
QTouchEvent::TouchPoint::~TouchPoint()
{
- if (!d->ref.deref())
+ if (d && !d->ref.deref())
delete d;
}
@@ -4043,16 +4043,15 @@ void QTouchEvent::TouchPoint::setFlags(InfoFlags flags)
d->flags = flags;
}
-/*! \internal */
-QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::TouchPoint &other)
-{
- other.d->ref.ref();
- if (!d->ref.deref())
- delete d;
- d = other.d;
- return *this;
-}
+/*!
+ \fn QTouchEvent::TouchPoint &QTouchEvent::TouchPoint::operator=(const QTouchEvent::TouchPoint &other)
+ \internal
+ */
+/*!
+ \fn void QTouchEvent::TouchPoint::swap(TouchPoint &other);
+ \internal
+*/
/*!
\class QScrollPrepareEvent
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index d70f6be201..7c871b0dda 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -713,9 +713,19 @@ public:
Q_DECLARE_FLAGS(InfoFlags, InfoFlag)
explicit TouchPoint(int id = -1);
- TouchPoint(const QTouchEvent::TouchPoint &other);
+ TouchPoint(const TouchPoint &other);
+#ifdef Q_COMPILER_RVALUE_REFS
+ TouchPoint(TouchPoint &&other) : d(other.d) { other.d = 0; }
+ TouchPoint &operator=(TouchPoint &&other)
+ { qSwap(d, other.d); return *this; }
+#endif
~TouchPoint();
+ TouchPoint &operator=(const TouchPoint &other)
+ { if ( d != other.d ) { TouchPoint copy(other); swap(copy); } return *this; }
+
+ void swap(TouchPoint &other) { qSwap(d, other.d); }
+
int id() const;
Qt::TouchPointState state() const;
@@ -767,7 +777,6 @@ public:
void setVelocity(const QVector2D &v);
void setFlags(InfoFlags flags);
void setRawScreenPositions(const QList<QPointF> &positions);
- QTouchEvent::TouchPoint &operator=(const QTouchEvent::TouchPoint &other);
private:
QTouchEventTouchPointPrivate *d;
@@ -819,7 +828,7 @@ protected:
friend class QApplication;
friend class QApplicationPrivate;
};
-
+Q_DECLARE_TYPEINFO(QTouchEvent::TouchPoint, Q_MOVABLE_TYPE);
Q_DECLARE_OPERATORS_FOR_FLAGS(QTouchEvent::TouchPoint::InfoFlags)
class QScrollPrepareEventPrivate;