summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text/qfont
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2020-10-19 11:39:24 +0200
committerAndy Shaw <andy.shaw@qt.io>2020-11-20 14:30:22 +0100
commitd8602ce58b6ef268be84b9aa0166b0c3fa6a96e8 (patch)
tree3665176e38aac64015213085f3d0e867ec11e612 /tests/auto/gui/text/qfont
parent13c460d0ff1a4eecfb7b1bc43a863783ed59a2bd (diff)
QFont: Prefer setFamilies() over setFamily()
By depending on setFamilies() then we can be sure that font names with spaces, commas, quotes and so on are correctly handled without being misinterpreted. For now it will split on the comma when a string containing one is passed to setFamily. But from Qt 6.2 this will be removed to preserve the family string as a convenience function. [ChangeLog][QtGui][QFont] Indicated that setFamilies/families is preferred over setFamily/family to ensure that font family names are preserved when spaces, commas and so on are used in the name. Change-Id: Id3c1a4e827756a4c928fed461a4aafa5a0f06633 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'tests/auto/gui/text/qfont')
-rw-r--r--tests/auto/gui/text/qfont/tst_qfont.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp
index 4cc5a81329..7af48eda01 100644
--- a/tests/auto/gui/text/qfont/tst_qfont.cpp
+++ b/tests/auto/gui/text/qfont/tst_qfont.cpp
@@ -311,10 +311,11 @@ void tst_QFont::resolve()
QCOMPARE(font6.families(), fontFamilies);
QFont font7, font8;
+ // This will call setFamilies() directly now
font7.setFamily(QLatin1String("Helvetica"));
font8.setFamilies(fontFamilies);
font7 = font7.resolve(font8);
- QCOMPARE(font7.families(), QStringList({"Helvetica", "Arial"}));
+ QCOMPARE(font7.families(), QStringList({"Helvetica"}));
QCOMPARE(font7.family(), "Helvetica");
}
@@ -710,6 +711,7 @@ void tst_QFont::sharing()
void tst_QFont::familyNameWithCommaQuote_data()
{
+ QTest::addColumn<QString>("enteredFamilyName");
QTest::addColumn<QString>("familyName");
QTest::addColumn<QString>("chosenFamilyName");
@@ -717,15 +719,16 @@ void tst_QFont::familyNameWithCommaQuote_data()
if (standardFont.isEmpty())
QSKIP("No default font available on the system");
const QString weirdFont(QLatin1String("'My, weird'' font name',"));
+ const QString bogusFont(QLatin1String("BogusFont"));
const QString commaSeparated(standardFont + QLatin1String(",Times New Roman"));
const QString commaSeparatedWeird(weirdFont + QLatin1String(",") + standardFont);
- const QString commaSeparatedBogus(QLatin1String("BogusFont,") + standardFont);
+ const QString commaSeparatedBogus(bogusFont + QLatin1String(",") + standardFont);
- QTest::newRow("standard") << standardFont << standardFont;
- QTest::newRow("weird") << weirdFont << weirdFont;
- QTest::newRow("commaSeparated") << commaSeparated << standardFont;
- QTest::newRow("commaSeparatedWeird") << commaSeparatedWeird << weirdFont;
- QTest::newRow("commaSeparatedBogus") << commaSeparatedBogus << standardFont;
+ QTest::newRow("standard") << standardFont << standardFont << standardFont;
+ QTest::newRow("weird") << weirdFont << QString("'My") << standardFont;
+ QTest::newRow("commaSeparated") << commaSeparated << standardFont << standardFont;
+ QTest::newRow("commaSeparatedWeird") << commaSeparatedWeird << QString("'My") << standardFont;
+ QTest::newRow("commaSeparatedBogus") << commaSeparatedBogus << bogusFont << standardFont;
}
void tst_QFont::familyNameWithCommaQuote()
@@ -804,8 +807,8 @@ void tst_QFont::setFamiliesAndFamily()
QVERIFY(weirdFontId != -1);
QFont f;
- f.setFamilies(families);
f.setFamily(family);
+ f.setFamilies(families);
QCOMPARE(QFontInfo(f).family(), chosenFamilyName);
QFontDatabase::removeApplicationFont(weirdFontId);