diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2020-06-04 19:44:03 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2020-06-07 22:43:37 +0200 |
commit | bd465695c306e04d2e91fb1aee03156da7ab86cc (patch) | |
tree | 3a58f48a8289d1e45ff256d198ce703df3208084 /src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h | |
parent | e0fc998e87dcf4acfb06cc5ff840498e4cbc3f6b (diff) |
QWindowsFontDatabase: replace a QPair with a dedicated struct
Pairs are easy to use, but they have no semantics attached: Two
QPair<QString, QString> compare equal, e.g., even though one is used
as a FontAndStyle and the other as, say, a type/subtype. It also
carries no information for the reader of the code.
So, write a minimal struct with equality and qHash() instead.
Change-Id: I9514c9b7d6c2cc6a4831f9ca83ca2ee466d91553
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h')
-rw-r--r-- | src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h index 38ddb178bd..0652685fc5 100644 --- a/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h +++ b/src/platformsupport/fontdatabases/windows/qwindowsfontdatabase_p.h @@ -56,6 +56,7 @@ #include <qpa/qplatformfontdatabase.h> #include <QtCore/QSharedPointer> #include <QtCore/QLoggingCategory> +#include <QtCore/qhashfunctions.h> #include <QtCore/qt_windows.h> QT_BEGIN_NAMESPACE @@ -154,6 +155,20 @@ bool qt_localizedName(const QString &name); QString qt_getEnglishName(const QString &familyName, bool includeStyle = false); QFontNames qt_getCanonicalFontNames(const LOGFONT &lf); +struct FontAndStyle { + QString font; + QString style; + + friend inline bool operator==(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept + { return lhs.font == rhs.font && lhs.style == rhs.style; } + friend inline bool operator!=(const FontAndStyle &lhs, const FontAndStyle &rhs) noexcept + { return !operator==(lhs, rhs); } +}; +inline size_t qHash(const FontAndStyle &key, size_t seed) noexcept +{ + return qHashMulti(seed, key.font, key.style); +} + QT_END_NAMESPACE #endif // QWINDOWSFONTDATABASE_H |