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 <allan.jensen@qt.io>
This commit is contained in:
Volker Hilsheimer 2020-10-27 23:54:08 +01:00
parent 9b35f22b58
commit a3d71792ca
3 changed files with 24 additions and 15 deletions

View File

@ -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

View File

@ -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:

View File

@ -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