Fix compiler warnings from deprecated method

QTextCharFormat::fontFamily is deprecated in favor of fontFamilies,
which returns a QStringList wrapped in a QVariant, whereas the setter
expects a QStringList.

Change-Id: I3333eaae4fc5ec3e3bdbec58047d6b3554b4a171
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
This commit is contained in:
Volker Hilsheimer 2020-11-26 21:26:29 +01:00 committed by Andy Shaw
parent 63c5d13885
commit c2dbc26893
3 changed files with 9 additions and 10 deletions

View File

@ -679,7 +679,7 @@ void QTextOdfWriter::writeCharacterFormat(QXmlStreamWriter &writer, QTextCharFor
writer.writeAttribute(foNS, QString::fromLatin1("font-weight"), value); writer.writeAttribute(foNS, QString::fromLatin1("font-weight"), value);
} }
if (format.hasProperty(QTextFormat::FontFamily)) if (format.hasProperty(QTextFormat::FontFamily))
writer.writeAttribute(foNS, QString::fromLatin1("font-family"), format.fontFamily()); writer.writeAttribute(foNS, QString::fromLatin1("font-family"), format.fontFamilies().toStringList().value(0, QString()));
else else
writer.writeAttribute(foNS, QString::fromLatin1("font-family"), QString::fromLatin1("Sans")); // Qt default writer.writeAttribute(foNS, QString::fromLatin1("font-family"), QString::fromLatin1("Sans")); // Qt default
if (format.hasProperty(QTextFormat::FontPointSize)) if (format.hasProperty(QTextFormat::FontPointSize))

View File

@ -686,7 +686,7 @@ qreal QTextEdit::fontPointSize() const
QString QTextEdit::fontFamily() const QString QTextEdit::fontFamily() const
{ {
Q_D(const QTextEdit); Q_D(const QTextEdit);
return d->control->textCursor().charFormat().fontFamily(); return d->control->textCursor().charFormat().fontFamilies().toStringList().value(0, QString());
} }
/*! /*!
@ -878,7 +878,7 @@ QTextCursor QTextEdit::textCursor() const
void QTextEdit::setFontFamily(const QString &fontFamily) void QTextEdit::setFontFamily(const QString &fontFamily)
{ {
QTextCharFormat fmt; QTextCharFormat fmt;
fmt.setFontFamily(fontFamily); fmt.setFontFamilies({fontFamily});
mergeCurrentCharFormat(fmt); mergeCurrentCharFormat(fmt);
} }

View File

@ -806,7 +806,7 @@ void tst_QTextDocument::toHtml_data()
CREATE_DOC_AND_CURSOR(); CREATE_DOC_AND_CURSOR();
QTextCharFormat fmt; QTextCharFormat fmt;
fmt.setFontFamily("Times"); fmt.setFontFamilies({QLatin1String("Times")});
cursor.insertText("Blah", fmt); cursor.insertText("Blah", fmt);
QTest::newRow("font-family") << QTextDocumentFragment(&doc) QTest::newRow("font-family") << QTextDocumentFragment(&doc)
@ -817,7 +817,7 @@ void tst_QTextDocument::toHtml_data()
CREATE_DOC_AND_CURSOR(); CREATE_DOC_AND_CURSOR();
QTextCharFormat fmt; QTextCharFormat fmt;
fmt.setFontFamily("Foo's Family"); fmt.setFontFamilies({QLatin1String("Foo's Family")});
cursor.insertText("Blah", fmt); cursor.insertText("Blah", fmt);
QTest::newRow("font-family-with-quotes1") << QTextDocumentFragment(&doc) QTest::newRow("font-family-with-quotes1") << QTextDocumentFragment(&doc)
@ -828,7 +828,7 @@ void tst_QTextDocument::toHtml_data()
CREATE_DOC_AND_CURSOR(); CREATE_DOC_AND_CURSOR();
QTextCharFormat fmt; QTextCharFormat fmt;
fmt.setFontFamily("Foo\"s Family"); fmt.setFontFamilies({QLatin1String("Foo\"s Family")});
cursor.insertText("Blah", fmt); cursor.insertText("Blah", fmt);
QTest::newRow("font-family-with-quotes2") << QTextDocumentFragment(&doc) QTest::newRow("font-family-with-quotes2") << QTextDocumentFragment(&doc)
@ -839,7 +839,6 @@ void tst_QTextDocument::toHtml_data()
CREATE_DOC_AND_CURSOR(); CREATE_DOC_AND_CURSOR();
QTextCharFormat fmt; QTextCharFormat fmt;
fmt.setFontFamily("Times");
fmt.setFontFamilies(QStringList{ "Times", "serif" }); fmt.setFontFamilies(QStringList{ "Times", "serif" });
cursor.insertText("Blah", fmt); cursor.insertText("Blah", fmt);
@ -3540,7 +3539,7 @@ void tst_QTextDocument::fontTagFace()
td.setHtml("<html><body><font face='Times'>Foobar</font></body></html>"); td.setHtml("<html><body><font face='Times'>Foobar</font></body></html>");
QTextFragment fragment = td.begin().begin().fragment(); QTextFragment fragment = td.begin().begin().fragment();
QTextCharFormat format = fragment.charFormat(); QTextCharFormat format = fragment.charFormat();
QCOMPARE(format.fontFamily(), QLatin1String("Times")); QCOMPARE(format.fontFamilies().toStringList().value(0, QString()), QLatin1String("Times"));
} }
{ {
@ -3548,7 +3547,7 @@ void tst_QTextDocument::fontTagFace()
td.setHtml("<html><body><font face='Times, serif'>Foobar</font></body></html>"); td.setHtml("<html><body><font face='Times, serif'>Foobar</font></body></html>");
QTextFragment fragment = td.begin().begin().fragment(); QTextFragment fragment = td.begin().begin().fragment();
QTextCharFormat format = fragment.charFormat(); QTextCharFormat format = fragment.charFormat();
QCOMPARE(format.fontFamily(), QLatin1String("Times")); QCOMPARE(format.fontFamilies().toStringList().value(0, QString()), QLatin1String("Times"));
QStringList expectedFamilies = { QLatin1String("Times"), QLatin1String("serif") }; QStringList expectedFamilies = { QLatin1String("Times"), QLatin1String("serif") };
QCOMPARE(format.fontFamilies().toStringList(), expectedFamilies); QCOMPARE(format.fontFamilies().toStringList(), expectedFamilies);
} }
@ -3563,7 +3562,7 @@ void tst_QTextDocument::mergeFontFamilies()
"</body></html>")); "</body></html>"));
QTextCharFormat newFormat; QTextCharFormat newFormat;
newFormat.setFontFamily(QLatin1String("Jokerman")); newFormat.setFontFamilies({QLatin1String("Jokerman")});
QTextCursor cursor = QTextCursor(&td); QTextCursor cursor = QTextCursor(&td);
cursor.setPosition(0); cursor.setPosition(0);