diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 3ac63e9ee10..abbbf3296ee 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -2311,9 +2311,8 @@ void QFont::cacheStatistics() */ /*! - \fn bool QFont::Tag::operator==(QFont::Tag::Tag lhs, QFont::Tag::Tag rhs) noexcept - \fn bool QFont::Tag::operator!=(QFont::Tag::Tag lhs, QFont::Tag::Tag rhs) noexcept - \fn bool QFont::Tag::operator<(QFont::Tag::Tag lhs, QFont::Tag::Tag rhs) noexcept + \fn bool QFont::Tag::comparesEqual(const QFont::Tag &lhs, const QFont::Tag &rhs) noexcept + \fn Qt::strong_ordering QFont::Tag::compareThreeWay(const QFont::Tag &lhs, const QFont::Tag &rhs) noexcept Compare \a lhs with \a rhs for equality and ordering. */ diff --git a/src/gui/text/qfont.h b/src/gui/text/qfont.h index 3206c5c2ee4..653b123c946 100644 --- a/src/gui/text/qfont.h +++ b/src/gui/text/qfont.h @@ -4,6 +4,7 @@ #ifndef QFONT_H #define QFONT_H +#include #include #include #include @@ -221,12 +222,6 @@ public: static_assert(N == 5, "The tag name must be exactly 4 characters long!"); } - friend inline bool operator==(Tag lhs, Tag rhs) noexcept - { return lhs.m_value == rhs.m_value; } - friend inline bool operator!=(Tag lhs, Tag rhs) noexcept - { return lhs.m_value != rhs.m_value; } - friend inline bool operator<(Tag lhs, Tag rhs) noexcept - { return lhs.m_value < rhs.m_value; } constexpr bool isValid() const noexcept { return m_value != 0; } constexpr quint32 value() const noexcept { return m_value; } @@ -262,6 +257,12 @@ public: { return qHash(key.value(), seed); } private: + friend constexpr bool comparesEqual(const Tag &lhs, const Tag &rhs) noexcept + { return lhs.m_value == rhs.m_value; } + friend constexpr Qt::strong_ordering compareThreeWay(const Tag &lhs, const Tag &rhs) noexcept + { return Qt::compareThreeWay(lhs.m_value, rhs.m_value); } + Q_DECLARE_STRONGLY_ORDERED_LITERAL_TYPE(QFont::Tag) + quint32 m_value = 0; }; diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index bbcbf11d096..7ce0e2905f6 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -21,6 +21,7 @@ #endif #include #include +#include using namespace Qt::StringLiterals; @@ -59,6 +60,8 @@ private slots: void setFamiliesAndFamily_data(); void setFamiliesAndFamily(); void featureAccessors(); + void tagCompares_data(); + void tagCompares(); }; // Testing get/set functions @@ -899,5 +902,30 @@ void tst_QFont::featureAccessors() }; } +void tst_QFont::tagCompares_data() +{ + QTestPrivate::testAllComparisonOperatorsCompile(); + + QTest::addColumn("lhs"); + QTest::addColumn("rhs"); + QTest::addColumn("expectedOrder"); + + auto row = [](QFont::Tag left, QFont::Tag right) { + QTest::addRow("%s<=>%s", left.toString().constData(), right.toString().constData()) + << left << right << Qt::compareThreeWay(left.value(), right.value()); + }; + row("frac", "wght"); +} + +void tst_QFont::tagCompares() +{ + QFETCH(QFont::Tag, lhs); + QFETCH(QFont::Tag, rhs); + QFETCH(Qt::strong_ordering, expectedOrder); + + QVERIFY(comparesEqual(lhs, lhs)); + QCOMPARE(compareThreeWay(lhs, rhs), expectedOrder); +} + QTEST_MAIN(tst_QFont) #include "tst_qfont.moc"