diff options
author | Andy Shaw <andy.shaw@qt.io> | 2019-10-29 09:44:50 +0100 |
---|---|---|
committer | Andy Shaw <andy.shaw@qt.io> | 2019-11-05 09:46:29 +0100 |
commit | b1004c7d0a5d7abbacd687fd41a5b2683e62b27d (patch) | |
tree | f2ad983ceccb6bbcfdc24c1581bed8691a8c7a0b | |
parent | 99e43db7cea1c838993c151d2d40fc2874a94256 (diff) |
If only family is set, prefer that in the families list after resolving
If a font with only a family set is resolved with one that has been setup
with setFamilies() then the family needs to be prepended to the families
list after resolving. This is so that the font still prefers the one set
as just a family with no famillies set.
This also amends the QFontDialog test to account for this too.
[ChangeLog][QtGui][Text] Resolving a font that just has a family set
with families set will prepend the family to the families so that it
is still the first preference for the font.
Task-number: QTBUG-46322
Change-Id: Icc4005732f95b2b4c684e592b06b31e133270e44
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
-rw-r--r-- | src/gui/text/qfont.cpp | 7 | ||||
-rw-r--r-- | tests/auto/gui/text/qfont/tst_qfont.cpp | 7 | ||||
-rw-r--r-- | tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp | 1 |
3 files changed, 14 insertions, 1 deletions
diff --git a/src/gui/text/qfont.cpp b/src/gui/text/qfont.cpp index 84c5be60b1..f5dbec3a3e 100644 --- a/src/gui/text/qfont.cpp +++ b/src/gui/text/qfont.cpp @@ -271,8 +271,13 @@ void QFontPrivate::resolve(uint mask, const QFontPrivate *other) if (! (mask & QFont::FamilyResolved)) request.family = other->request.family; - if (!(mask & QFont::FamiliesResolved)) + if (!(mask & QFont::FamiliesResolved)) { request.families = other->request.families; + // Prepend the family explicitly set so it will be given + // preference in this case + if (mask & QFont::FamilyResolved) + request.families.prepend(request.family); + } if (! (mask & QFont::StyleNameResolved)) request.styleName = other->request.styleName; diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index 66f3ee0d2c..bb047d5461 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -299,6 +299,13 @@ void tst_QFont::resolve() font5.setFamilies(fontFamilies); font6 = font6.resolve(font5); QCOMPARE(font6.families(), fontFamilies); + + QFont font7, font8; + font7.setFamily(QLatin1String("Helvetica")); + font8.setFamilies(fontFamilies); + font7 = font7.resolve(font8); + QCOMPARE(font7.families(), QStringList({"Helvetica", "Arial"})); + QCOMPARE(font7.family(), "Helvetica"); } #ifndef QT_NO_WIDGETS diff --git a/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp b/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp index a5aaf62855..c8e6e8fcd0 100644 --- a/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp +++ b/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp @@ -225,6 +225,7 @@ void tst_QFontDialog::qtbug_41513_stylesheetStyle() // The fontdialog sets the styleName, when the fontdatabase knows the style name. resultFont.setStyleName(testFont.styleName()); + testFont.setFamilies(QStringList(testFont.family())); QCOMPARE(resultFont, testFont); // reset stylesheet |