Do not use QTextFormat::FontFamily when building with QT_DISABLE_DEPRECATED_BEFORE >= 0x060000

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 <volker.hilsheimer@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Ivan Solovev 2022-07-11 17:37:31 +02:00
parent fc172e3093
commit 8b029ef142
4 changed files with 10 additions and 8 deletions

View File

@ -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

View File

@ -179,6 +179,7 @@ public:
OldFontLetterSpacingType = 0x2033,
OldFontStretch = 0x2034,
OldTextUnderlineColor = 0x2010,
OldFontFamily = 0x2000, // same as FontFamily
ObjectType = 0x2f00,

View File

@ -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

View File

@ -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));
}
}