From 08411a3ddfe2a3a392b1520e1283ce12208ebcb9 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 19 Jul 2021 12:51:46 +0200 Subject: QTextCharFormat: mark a couple of API mistakes to be fixed in Qt 7 The fontFamilies and fontStyleName have an asymmetric getter and setter. The setter takes QStringList, but the getter returns QVariant (?), for no reason whatsoever (the underlying QFont APIs take QStringList, and the docs say that they should return QStringList). It's not entirely obvious that we can fix this without introducing badly-named getters (getX) or somesuch, so for the time being, mark this to be fixed in Qt 7. Change-Id: I49706af00906a2c5d950ada4be3cbc76dbee432c Reviewed-by: Edward Welbourne Reviewed-by: David Faure --- src/gui/text/qtextformat.cpp | 30 ++++++++++++++++++++++++++++++ src/gui/text/qtextformat.h | 10 ++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index d31e17efc3..0166cd7ad2 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -1483,6 +1483,20 @@ QTextCharFormat::QTextCharFormat(const QTextFormat &fmt) \sa setFont() */ +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) +/*! + \fn QVariant QTextCharFormat::fontFamilies() const + \since 5.13 + + Returns the text format's font families. + + \note This function returns a QVariant for historical reasons. It will be + corrected to return QStringList in Qt 7. The variant contains a QStringList + object, which can be extracted by calling \c{toStringList()} on it. + + \sa font() +*/ +#else /*! \fn QStringList QTextCharFormat::fontFamilies() const \since 5.13 @@ -1491,6 +1505,7 @@ QTextCharFormat::QTextCharFormat(const QTextFormat &fmt) \sa font() */ +#endif /*! \fn void QTextCharFormat::setFontStyleName(const QString &styleName) @@ -1501,6 +1516,20 @@ QTextCharFormat::QTextCharFormat(const QTextFormat &fmt) \sa setFont(), QFont::setStyleName() */ +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) +/*! + \fn QVariant QTextCharFormat::fontStyleName() const + \since 5.13 + + Returns the text format's font style name. + + \note This function returns a QVariant for historical reasons. It will be + corrected to return QStringList in Qt 7. The variant contains a QStringList + object, which can be extracted by calling \c{toStringList()} on it. + + \sa font(), QFont::styleName() +*/ +#else /*! \fn QStringList QTextCharFormat::fontStyleName() const \since 5.13 @@ -1509,6 +1538,7 @@ QTextCharFormat::QTextCharFormat(const QTextFormat &fmt) \sa font(), QFont::styleName() */ +#endif /*! \fn void QTextCharFormat::setFontPointSize(qreal size) diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h index b297862b6f..45bf458cae 100644 --- a/src/gui/text/qtextformat.h +++ b/src/gui/text/qtextformat.h @@ -465,13 +465,23 @@ public: inline void setFontFamilies(const QStringList &families) { setProperty(FontFamilies, QVariant(families)); } +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) inline QVariant fontFamilies() const { return property(FontFamilies); } +#else + inline QStringList fontFamilies() const + { return property(FontFamilies).toStringList(); } +#endif inline void setFontStyleName(const QString &styleName) { setProperty(FontStyleName, styleName); } +#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) inline QVariant fontStyleName() const { return property(FontStyleName); } +#else + inline QStringList fontStyleName() const + { return property(FontStyleName).toStringList(); } +#endif inline void setFontPointSize(qreal size) { setProperty(FontPointSize, size); } -- cgit v1.2.3