summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qevent.h
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-09-08 10:10:12 +0200
committerJani Heikkinen <jani.heikkinen@qt.io>2016-12-01 13:02:47 +0000
commit048447346bc1b78992be3ce4bf3292fc272f7e1a (patch)
treefeb3a31098cba1ee7c6d090ac85e51778494c7ba /src/gui/kernel/qevent.h
parentf4a33e345eb658996e171daa6478fdc2ef62ff17 (diff)
QPointerUniqueId: make fit for release
- Declare as Q_MOVABLE_TYPE - Prevent QList<QPointerUniqueId> 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 <shawn.rutledge@qt.io>
Diffstat (limited to 'src/gui/kernel/qevent.h')
-rw-r--r--src/gui/kernel/qevent.h36
1 files changed, 30 insertions, 6 deletions
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<QPointerUniqueId> {}; // 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