From 8b029ef142526722a0931ae02b681ad57d7fd99a Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Mon, 11 Jul 2022 17:37:31 +0200 Subject: [PATCH] Do not use QTextFormat::FontFamily when building with QT_DISABLE_DEPRECATED_BEFORE >= 0x060000 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The QTextFormat::FontFamily enum is deprecated since Qt 6.0, however it is still used in the code. To retain backward compatibility with the old data stream formats, we introduce a new internal QTextFormat::OldFontFamily enum value, which has exactly the same value as QTextFormat::FontFamily, and use it instead. Task-number: QTBUG-104857 Pick-to: 6.4 6.3 6.2 Change-Id: Ibf5258b621c2b0aa507005dfe2c1e80c26ddb0d4 Reviewed-by: Volker Hilsheimer Reviewed-by: Tor Arne Vestbø --- src/gui/text/qtextformat.cpp | 5 +++-- src/gui/text/qtextformat.h | 1 + src/gui/text/qtextodfwriter.cpp | 2 +- tests/auto/gui/text/qtextformat/tst_qtextformat.cpp | 10 +++++----- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index fa83212033..be38aba368 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -425,7 +425,7 @@ Q_GUI_EXPORT QDataStream &operator<<(QDataStream &stream, const QTextFormat &fmt it = properties.find(QTextFormat::FontFamilies); if (it != properties.end()) { - properties[QTextFormat::FontFamily] = QVariant(it.value().toStringList().first()); + properties[QTextFormat::OldFontFamily] = QVariant(it.value().toStringList().first()); properties.erase(it); } } @@ -453,7 +453,7 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextFormat &fmt) key = QTextFormat::FontStretch; else if (key == QTextFormat::OldTextUnderlineColor) key = QTextFormat::TextUnderlineColor; - else if (key == QTextFormat::FontFamily) + else if (key == QTextFormat::OldFontFamily) key = QTextFormat::FontFamilies; fmt.d->insertProperty(key, it.value()); } @@ -625,6 +625,7 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &stream, QTextTableCellFormat & Character properties \value FontFamily e{This property has been deprecated.} Use QTextFormat::FontFamilies instead. + \omitvalue OldFontFamily \value FontFamilies \value FontStyleName \value FontPointSize diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h index 95bc9da334..02c66279e2 100644 --- a/src/gui/text/qtextformat.h +++ b/src/gui/text/qtextformat.h @@ -179,6 +179,7 @@ public: OldFontLetterSpacingType = 0x2033, OldFontStretch = 0x2034, OldTextUnderlineColor = 0x2010, + OldFontFamily = 0x2000, // same as FontFamily ObjectType = 0x2f00, diff --git a/src/gui/text/qtextodfwriter.cpp b/src/gui/text/qtextodfwriter.cpp index 4214dd11dc..af1015883a 100644 --- a/src/gui/text/qtextodfwriter.cpp +++ b/src/gui/text/qtextodfwriter.cpp @@ -644,7 +644,7 @@ void QTextOdfWriter::writeCharacterFormat(QXmlStreamWriter &writer, QTextCharFor value = QString::number(format.fontWeight()); writer.writeAttribute(foNS, QString::fromLatin1("font-weight"), value); } - if (format.hasProperty(QTextFormat::FontFamily)) + if (format.hasProperty(QTextFormat::OldFontFamily)) writer.writeAttribute(foNS, QString::fromLatin1("font-family"), format.fontFamilies().toStringList().value(0, QString())); else writer.writeAttribute(foNS, QString::fromLatin1("font-family"), QString::fromLatin1("Sans")); // Qt default diff --git a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp index a998bbd482..9ef5842803 100644 --- a/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp +++ b/tests/auto/gui/text/qtextformat/tst_qtextformat.cpp @@ -679,7 +679,7 @@ void tst_QTextFormat::dataStreamCompatibility() QVERIFY(properties.contains(QTextFormat::FontFamilies)); QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType)); QVERIFY(!properties.contains(QTextFormat::OldFontStretch)); - QVERIFY(!properties.contains(QTextFormat::FontFamily)); + QVERIFY(!properties.contains(QTextFormat::OldFontFamily)); } QByteArray memory; @@ -710,7 +710,7 @@ void tst_QTextFormat::dataStreamCompatibility() QVERIFY(properties.contains(QTextFormat::FontFamilies)); QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType)); QVERIFY(!properties.contains(QTextFormat::OldFontStretch)); - QVERIFY(!properties.contains(QTextFormat::FontFamily)); + QVERIFY(!properties.contains(QTextFormat::OldFontFamily)); } } @@ -730,7 +730,7 @@ void tst_QTextFormat::dataStreamCompatibility() QVERIFY(properties.contains(QTextFormat::FontFamilies)); QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType)); QVERIFY(!properties.contains(QTextFormat::OldFontStretch)); - QVERIFY(!properties.contains(QTextFormat::FontFamily)); + QVERIFY(!properties.contains(QTextFormat::OldFontFamily)); } } @@ -763,7 +763,7 @@ void tst_QTextFormat::dataStreamCompatibility() QVERIFY(properties.contains(QTextFormat::FontFamilies)); QVERIFY(!properties.contains(QTextFormat::OldFontLetterSpacingType)); QVERIFY(!properties.contains(QTextFormat::OldFontStretch)); - QVERIFY(!properties.contains(QTextFormat::FontFamily)); + QVERIFY(!properties.contains(QTextFormat::OldFontFamily)); } } @@ -785,7 +785,7 @@ void tst_QTextFormat::dataStreamCompatibility() QVERIFY(!properties.contains(QTextFormat::FontFamilies)); QVERIFY(properties.contains(QTextFormat::OldFontLetterSpacingType)); QVERIFY(properties.contains(QTextFormat::OldFontStretch)); - QVERIFY(properties.contains(QTextFormat::FontFamily)); + QVERIFY(properties.contains(QTextFormat::OldFontFamily)); } }