From 048447346bc1b78992be3ce4bf3292fc272f7e1a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 8 Sep 2016 10:10:12 +0200 Subject: QPointerUniqueId: make fit for release - Declare as Q_MOVABLE_TYPE - Prevent QList from being instantiated (use QVector instead) - Add equality relational operators - Add qHash() overload - Replace non-default ctor with named ctor. - Add Q_DECL_NOTHROW. - Add Q_DECL_CONSTEXPR. - Rename numeric() -> numericId(). - Update docs. The extension vector for this class calls for additional properties to be added later, but these are not user- settable. It thus suffices to rely on the only data member, a qint64, which can be reinterpreted to an index into an array or hash with actual objects. This allows to make the class a Trivial Type (ie. no overhead over an int) while still supporting later extension. Cf. QSslEllipticCurve as another example of such a class. The extension has to maintain the following invariants, encoded into user code by way of being used in inline functions: - m_numericId == -1 <=> !isValid() This is trivial to support. An extension could not and still cannot reinterpret the qint64 member as a d-pointer, but a d-pointer is only necessary for user-settable properties where updating a central private data structure would cause too much contention. Add a test. Since this type is used in other modules, keep the existing functions, but mark them as deprecated with the expectation that these compat functions be removed before 5.8.0 final. Task-number: QTBUG-54616 Change-Id: Ia3ede0ecaeeef4cd3ffa94a72b1050bd409713a5 Reviewed-by: Shawn Rutledge --- src/gui/kernel/qevent.h | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'src/gui/kernel/qevent.h') diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index a062331bd8..b7c0f3338e 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -793,21 +793,45 @@ inline bool operator==(QKeyEvent *e, QKeySequence::StandardKey key){return (e ? inline bool operator==(QKeySequence::StandardKey key, QKeyEvent *e){return (e ? e->matches(key) : false);} #endif // QT_NO_SHORTCUT -class QPointerUniqueIdPrivate; class Q_GUI_EXPORT QPointerUniqueId { Q_GADGET - Q_PROPERTY(qint64 numeric READ numeric CONSTANT) + // ### kept these to keep other modules compiling. Remove before 5.8.0 final! +#if QT_DEPRECATED_SINCE(5, 8) + Q_PROPERTY(qint64 numeric READ numericId CONSTANT) +#endif + Q_PROPERTY(qint64 numericId READ numericId CONSTANT) public: - explicit QPointerUniqueId(qint64 id = -1); + Q_ALWAYS_INLINE + Q_DECL_CONSTEXPR QPointerUniqueId() Q_DECL_NOTHROW : m_numericId(-1) {} + // compiler-generated copy/move ctor/assignment operators are ok! + // compiler-generated dtor is ok! + + static QPointerUniqueId fromNumericId(qint64 id); - qint64 numeric() const; + Q_ALWAYS_INLINE Q_DECL_CONSTEXPR bool isValid() const Q_DECL_NOTHROW { return m_numericId != -1; } + qint64 numericId() const Q_DECL_NOTHROW; + // ### kept these to keep other modules compiling. Remove before 5.8.0 final! +#if QT_DEPRECATED_SINCE(5, 8) + Q_ALWAYS_INLINE Q_DECL_DEPRECATED qint64 numeric() const { return numericId(); } + Q_ALWAYS_INLINE Q_DECL_DEPRECATED explicit QPointerUniqueId(qint64 id) : m_numericId(id) {} +#endif private: - // TODO for TUIO 2, or any other type of complex token ID, a d-pointer can replace - // m_numericId without changing the size of this class. + // TODO: for TUIO 2, or any other type of complex token ID, an internal + // array (or hash) can be added to hold additional properties. + // In this case, m_numericId will then turn into an index into that array (or hash). qint64 m_numericId; }; +Q_DECLARE_TYPEINFO(QPointerUniqueId, Q_MOVABLE_TYPE); +template <> class QList {}; // to prevent instantiation: use QVector instead + +Q_GUI_EXPORT bool operator==(QPointerUniqueId lhs, QPointerUniqueId rhs) Q_DECL_NOTHROW; +inline bool operator!=(QPointerUniqueId lhs, QPointerUniqueId rhs) Q_DECL_NOTHROW +{ return !operator==(lhs, rhs); } +Q_GUI_EXPORT uint qHash(QPointerUniqueId key, uint seed = 0) Q_DECL_NOTHROW; + + class QTouchEventTouchPointPrivate; class Q_GUI_EXPORT QTouchEvent : public QInputEvent -- cgit v1.2.3 From 7df0c7a309ada7f9ab70a2c20f86c0707288e31e Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 1 Dec 2016 12:47:55 +0100 Subject: rename QPointerUniqueId -> QPointingDeviceUniqueId Several people agreed that the name was confusing and that this one is better. Task-number: QTBUG-54616 Change-Id: I31cf057f4bc818332b0551a27d1711599440207c Reviewed-by: Marc Mutz Reviewed-by: Sune Vuorela --- src/gui/kernel/qevent.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/gui/kernel/qevent.h') diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index b7c0f3338e..7d5b719e09 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -793,7 +793,7 @@ inline bool operator==(QKeyEvent *e, QKeySequence::StandardKey key){return (e ? inline bool operator==(QKeySequence::StandardKey key, QKeyEvent *e){return (e ? e->matches(key) : false);} #endif // QT_NO_SHORTCUT -class Q_GUI_EXPORT QPointerUniqueId +class Q_GUI_EXPORT QPointingDeviceUniqueId { Q_GADGET // ### kept these to keep other modules compiling. Remove before 5.8.0 final! @@ -803,11 +803,11 @@ class Q_GUI_EXPORT QPointerUniqueId Q_PROPERTY(qint64 numericId READ numericId CONSTANT) public: Q_ALWAYS_INLINE - Q_DECL_CONSTEXPR QPointerUniqueId() Q_DECL_NOTHROW : m_numericId(-1) {} + Q_DECL_CONSTEXPR QPointingDeviceUniqueId() Q_DECL_NOTHROW : m_numericId(-1) {} // compiler-generated copy/move ctor/assignment operators are ok! // compiler-generated dtor is ok! - static QPointerUniqueId fromNumericId(qint64 id); + static QPointingDeviceUniqueId fromNumericId(qint64 id); Q_ALWAYS_INLINE Q_DECL_CONSTEXPR bool isValid() const Q_DECL_NOTHROW { return m_numericId != -1; } qint64 numericId() const Q_DECL_NOTHROW; @@ -815,7 +815,7 @@ public: // ### kept these to keep other modules compiling. Remove before 5.8.0 final! #if QT_DEPRECATED_SINCE(5, 8) Q_ALWAYS_INLINE Q_DECL_DEPRECATED qint64 numeric() const { return numericId(); } - Q_ALWAYS_INLINE Q_DECL_DEPRECATED explicit QPointerUniqueId(qint64 id) : m_numericId(id) {} + Q_ALWAYS_INLINE Q_DECL_DEPRECATED explicit QPointingDeviceUniqueId(qint64 id) : m_numericId(id) {} #endif private: // TODO: for TUIO 2, or any other type of complex token ID, an internal @@ -823,13 +823,13 @@ private: // In this case, m_numericId will then turn into an index into that array (or hash). qint64 m_numericId; }; -Q_DECLARE_TYPEINFO(QPointerUniqueId, Q_MOVABLE_TYPE); -template <> class QList {}; // to prevent instantiation: use QVector instead +Q_DECLARE_TYPEINFO(QPointingDeviceUniqueId, Q_MOVABLE_TYPE); +template <> class QList {}; // to prevent instantiation: use QVector instead -Q_GUI_EXPORT bool operator==(QPointerUniqueId lhs, QPointerUniqueId rhs) Q_DECL_NOTHROW; -inline bool operator!=(QPointerUniqueId lhs, QPointerUniqueId rhs) Q_DECL_NOTHROW +Q_GUI_EXPORT bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) Q_DECL_NOTHROW; +inline bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) Q_DECL_NOTHROW { return !operator==(lhs, rhs); } -Q_GUI_EXPORT uint qHash(QPointerUniqueId key, uint seed = 0) Q_DECL_NOTHROW; +Q_GUI_EXPORT uint qHash(QPointingDeviceUniqueId key, uint seed = 0) Q_DECL_NOTHROW; @@ -868,7 +868,7 @@ public: { qSwap(d, other.d); } int id() const; - QPointerUniqueId uniqueId() const; + QPointingDeviceUniqueId uniqueId() const; Qt::TouchPointState state() const; -- cgit v1.2.3 From 10143ea8030e6754b2021c84c30859ade79dc570 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Thu, 8 Dec 2016 10:00:21 +0100 Subject: QPointingDeviceUniqueId: remove deprecated numeric() and constructor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Followup to 0484473: this is all new stuff for 5.8 and we don't need to release it with pre-deprecated functions. Task-number: QTBUG-54616 Change-Id: If17a4bec6fc36ca78d87517992374f101ae13b4f Reviewed-by: Jan Arve Sæther --- src/gui/kernel/qevent.h | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/gui/kernel/qevent.h') diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 7d5b719e09..7881df205a 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -796,10 +796,6 @@ inline bool operator==(QKeySequence::StandardKey key, QKeyEvent *e){return (e ? class Q_GUI_EXPORT QPointingDeviceUniqueId { Q_GADGET - // ### kept these to keep other modules compiling. Remove before 5.8.0 final! -#if QT_DEPRECATED_SINCE(5, 8) - Q_PROPERTY(qint64 numeric READ numericId CONSTANT) -#endif Q_PROPERTY(qint64 numericId READ numericId CONSTANT) public: Q_ALWAYS_INLINE @@ -812,11 +808,6 @@ public: Q_ALWAYS_INLINE Q_DECL_CONSTEXPR bool isValid() const Q_DECL_NOTHROW { return m_numericId != -1; } qint64 numericId() const Q_DECL_NOTHROW; - // ### kept these to keep other modules compiling. Remove before 5.8.0 final! -#if QT_DEPRECATED_SINCE(5, 8) - Q_ALWAYS_INLINE Q_DECL_DEPRECATED qint64 numeric() const { return numericId(); } - Q_ALWAYS_INLINE Q_DECL_DEPRECATED explicit QPointingDeviceUniqueId(qint64 id) : m_numericId(id) {} -#endif private: // TODO: for TUIO 2, or any other type of complex token ID, an internal // array (or hash) can be added to hold additional properties. -- cgit v1.2.3