From a3d71792ca018b1cff06dbefde20f6f4e06ee704 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 27 Oct 2020 23:54:08 +0100 Subject: [PATCH] Make comparison operators hidden friends Reduce ADL noise from QKeyEvent, QKeySequence::StandardKey, and QPointingDeviceUniqueId. Task-number: QTBUG-87973 Change-Id: Ib4a3190d03046949acb25b3fe68c611689b82565 Reviewed-by: Allan Sandfeld Jensen --- src/gui/kernel/qevent.cpp | 17 ++++++++++------- src/gui/kernel/qevent.h | 12 +++++++----- src/gui/kernel/qpointingdevice.h | 10 +++++++--- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index b60672ce17..0c3b631608 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -5312,26 +5312,29 @@ qint64 QPointingDeviceUniqueId::numericId() const noexcept } /*! - \relates QPointingDeviceUniqueId + \fn bool QPointingDeviceUniqueId::operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) \since 5.8 Returns whether the two unique pointer IDs \a lhs and \a rhs identify the same pointer (\c true) or not (\c false). */ -bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept -{ - return lhs.numericId() == rhs.numericId(); -} /*! - \fn bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) - \relates QPointingDeviceUniqueId + \fn bool QPointingDeviceUniqueId::operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) \since 5.8 Returns whether the two unique pointer IDs \a lhs and \a rhs identify different pointers (\c true) or not (\c false). */ +/*! + \internal +*/ +bool QPointingDeviceUniqueId::equals(QPointingDeviceUniqueId other) const noexcept +{ + return numericId() == other.numericId(); +} + /*! \relates QPointingDeviceUniqueId \since 5.8 diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index fe728bc40c..f4cbf6f7af 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -534,6 +534,13 @@ public: inline quint32 nativeVirtualKey() const { return m_virtualKey; } inline quint32 nativeModifiers() const { return m_modifiers; } +#if QT_CONFIG(shortcut) + friend inline bool operator==(QKeyEvent *e, QKeySequence::StandardKey key) + { return (e ? e->matches(key) : false); } + friend inline bool operator==(QKeySequence::StandardKey key, QKeyEvent *e) + { return (e ? e->matches(key) : false); } +#endif // QT_CONFIG(shortcut) + protected: QString m_text; int m_key; @@ -984,11 +991,6 @@ private: Q_GUI_EXPORT QDebug operator<<(QDebug, const QEvent *); #endif -#if QT_CONFIG(shortcut) -inline bool operator==(QKeyEvent *e, QKeySequence::StandardKey key){return (e ? e->matches(key) : false);} -inline bool operator==(QKeySequence::StandardKey key, QKeyEvent *e){return (e ? e->matches(key) : false);} -#endif // QT_CONFIG(shortcut) - class Q_GUI_EXPORT QTouchEvent : public QPointerEvent { public: diff --git a/src/gui/kernel/qpointingdevice.h b/src/gui/kernel/qpointingdevice.h index 30c7c8ca1a..c68039e88f 100644 --- a/src/gui/kernel/qpointingdevice.h +++ b/src/gui/kernel/qpointingdevice.h @@ -69,6 +69,13 @@ public: qint64 numericId() const noexcept; private: + bool equals(QPointingDeviceUniqueId other) const noexcept; + + friend inline bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept + { return lhs.equals(rhs); } + friend inline bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept + { return !operator==(lhs, rhs); } + // 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). @@ -76,9 +83,6 @@ private: }; Q_DECLARE_TYPEINFO(QPointingDeviceUniqueId, Q_MOVABLE_TYPE); -Q_GUI_EXPORT bool operator==(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept; -inline bool operator!=(QPointingDeviceUniqueId lhs, QPointingDeviceUniqueId rhs) noexcept -{ return !operator==(lhs, rhs); } Q_GUI_EXPORT size_t qHash(QPointingDeviceUniqueId key, size_t seed = 0) noexcept; class Q_GUI_EXPORT QPointingDevice : public QInputDevice