QColor: deprecate isValidColor, setNamedColor, string-ish ctors
[ChangeLog][QtGui][QColor] The constructors from string-ish type, as well as the setNamedColor() and isValidColor() functions, have been deprecated effective Qt 6.6 in favor of fromString() and isValidColorName(), resp. Fixes: QTBUG-101389 Change-Id: I002646bd48c1e4340dc6842fd136fc9f35bb9b61 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>bb10
parent
ee0908228f
commit
ce83a03cfd
|
|
@ -820,10 +820,11 @@ QColor::QColor(Spec spec) noexcept
|
|||
}
|
||||
}
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
/*!
|
||||
\fn QColor::QColor(const QString &name)
|
||||
|
||||
\obsolete
|
||||
\deprecated [6.6] Use fromString() instead.
|
||||
|
||||
Constructs a named color in the same way as setNamedColor() using
|
||||
the given \a name.
|
||||
|
|
@ -836,7 +837,7 @@ QColor::QColor(Spec spec) noexcept
|
|||
/*!
|
||||
\fn QColor::QColor(const char *name)
|
||||
|
||||
\obsolete
|
||||
\deprecated [6.6] Use fromString() instead.
|
||||
|
||||
Constructs a named color in the same way as setNamedColor() using
|
||||
the given \a name.
|
||||
|
|
@ -848,7 +849,7 @@ QColor::QColor(Spec spec) noexcept
|
|||
/*!
|
||||
\fn QColor::QColor(QLatin1String name)
|
||||
|
||||
\obsolete
|
||||
\deprecated [6.6] Use fromString() instead.
|
||||
|
||||
Constructs a named color in the same way as setNamedColor() using
|
||||
the given \a name.
|
||||
|
|
@ -857,6 +858,7 @@ QColor::QColor(Spec spec) noexcept
|
|||
\since 5.8
|
||||
\sa setNamedColor(), name(), isValid()
|
||||
*/
|
||||
#endif // QT_DEPRECATED_SINCE(6, 6)
|
||||
|
||||
/*!
|
||||
\fn bool QColor::isValid() const
|
||||
|
|
@ -884,8 +886,9 @@ QString QColor::name(NameFormat format) const
|
|||
return QString();
|
||||
}
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
/*!
|
||||
\obsolete
|
||||
\deprecated [6.6] Use fromString() instead.
|
||||
|
||||
Sets the RGB value of this QColor to \a name, which may be in one
|
||||
of these formats:
|
||||
|
|
@ -918,7 +921,7 @@ void QColor::setNamedColor(const QString &name)
|
|||
/*!
|
||||
\overload
|
||||
\since 5.10
|
||||
\obsolete
|
||||
\deprecated [6.6] Use fromString() instead.
|
||||
*/
|
||||
|
||||
void QColor::setNamedColor(QStringView name)
|
||||
|
|
@ -929,7 +932,7 @@ void QColor::setNamedColor(QStringView name)
|
|||
/*!
|
||||
\overload
|
||||
\since 5.8
|
||||
\obsolete
|
||||
\deprecated [6.6] Use fromString() instead.
|
||||
*/
|
||||
|
||||
void QColor::setNamedColor(QLatin1String name)
|
||||
|
|
@ -940,7 +943,7 @@ void QColor::setNamedColor(QLatin1String name)
|
|||
/*!
|
||||
\since 4.7
|
||||
|
||||
\obsolete
|
||||
\deprecated [6.6] Use isValidColorName() instead.
|
||||
|
||||
Returns \c true if the \a name is a valid color name and can
|
||||
be used to construct a valid QColor object, otherwise returns
|
||||
|
|
@ -958,7 +961,7 @@ bool QColor::isValidColor(const QString &name)
|
|||
/*!
|
||||
\overload
|
||||
\since 5.10
|
||||
\obsolete
|
||||
\deprecated [6.6] Use isValidColorName() instead.
|
||||
*/
|
||||
bool QColor::isValidColor(QStringView name) noexcept
|
||||
{
|
||||
|
|
@ -968,12 +971,13 @@ bool QColor::isValidColor(QStringView name) noexcept
|
|||
/*!
|
||||
\overload
|
||||
\since 5.8
|
||||
\obsolete
|
||||
\deprecated [6.6] Use isValidColorName() instead.
|
||||
*/
|
||||
bool QColor::isValidColor(QLatin1String name) noexcept
|
||||
{
|
||||
return isValidColorName(name);
|
||||
}
|
||||
#endif // QT_DEPRECATED_SINCE(6, 6)
|
||||
|
||||
/*!
|
||||
\since 6.4
|
||||
|
|
|
|||
|
|
@ -83,10 +83,16 @@ public:
|
|||
0) {}
|
||||
QColor(QRgb rgb) noexcept;
|
||||
QColor(QRgba64 rgba64) noexcept;
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
QT_DEPRECATED_VERSION_X_6_6("Use QColor::fromString() instead.")
|
||||
inline QColor(const QString& name);
|
||||
QT_DEPRECATED_VERSION_X_6_6("Use QColor::fromString() instead.")
|
||||
explicit inline QColor(QStringView name);
|
||||
QT_DEPRECATED_VERSION_X_6_6("Use QColor::fromString() instead.")
|
||||
inline QColor(const char *aname);
|
||||
QT_DEPRECATED_VERSION_X_6_6("Use QColor::fromString() instead.")
|
||||
inline QColor(QLatin1String name);
|
||||
#endif
|
||||
QColor(Spec spec) noexcept;
|
||||
|
||||
static QColor fromString(QAnyStringView name) noexcept;
|
||||
|
|
@ -97,9 +103,14 @@ public:
|
|||
|
||||
QString name(NameFormat format = HexRgb) const;
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
QT_DEPRECATED_VERSION_X_6_6("Use fromString() instead.")
|
||||
void setNamedColor(const QString& name);
|
||||
QT_DEPRECATED_VERSION_X_6_6("Use fromString() instead.")
|
||||
void setNamedColor(QStringView name);
|
||||
QT_DEPRECATED_VERSION_X_6_6("Use fromString() instead.")
|
||||
void setNamedColor(QLatin1String name);
|
||||
#endif
|
||||
|
||||
static QStringList colorNames();
|
||||
|
||||
|
|
@ -223,9 +234,14 @@ public:
|
|||
|
||||
operator QVariant() const;
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
QT_DEPRECATED_VERSION_X_6_6("Use isValidColorName() instead.")
|
||||
static bool isValidColor(const QString &name);
|
||||
QT_DEPRECATED_VERSION_X_6_6("Use isValidColorName() instead.")
|
||||
static bool isValidColor(QStringView) noexcept;
|
||||
QT_DEPRECATED_VERSION_X_6_6("Use isValidColorName() instead.")
|
||||
static bool isValidColor(QLatin1String) noexcept;
|
||||
#endif
|
||||
static bool isValidColorName(QAnyStringView) noexcept;
|
||||
|
||||
private:
|
||||
|
|
@ -296,6 +312,7 @@ public: // can't give friendship to a namespace, so it needs to be public
|
|||
};
|
||||
Q_DECLARE_TYPEINFO(QColor, Q_RELOCATABLE_TYPE);
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
inline QColor::QColor(QLatin1String aname)
|
||||
: QColor(fromString(aname)) {}
|
||||
|
||||
|
|
@ -307,6 +324,7 @@ inline QColor::QColor(const QString& aname)
|
|||
|
||||
inline QColor::QColor(const char *aname)
|
||||
: QColor(fromString(aname)) {}
|
||||
#endif
|
||||
|
||||
inline bool QColor::isValid() const noexcept
|
||||
{ return cspec != Invalid; }
|
||||
|
|
|
|||
|
|
@ -38,6 +38,12 @@
|
|||
#include <private/qdrawingprimitive_sse2_p.h>
|
||||
#include <qrgba64.h>
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
# define DEPRECATED_IN_6_6(...) QT_WARNING_PUSH QT_WARNING_DISABLE_DEPRECATED __VA_ARGS__ QT_WARNING_POP
|
||||
#else
|
||||
# define DEPRECATED_IN_6_6(...)
|
||||
#endif
|
||||
|
||||
class tst_QColor : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
@ -335,7 +341,9 @@ void tst_QColor::namehex()
|
|||
{
|
||||
QFETCH(QString, hexcolor);
|
||||
QFETCH(QColor, color);
|
||||
DEPRECATED_IN_6_6(
|
||||
QCOMPARE(QColor(hexcolor), color);
|
||||
)
|
||||
QCOMPARE(QColor::fromString(hexcolor), color);
|
||||
}
|
||||
|
||||
|
|
@ -724,8 +732,10 @@ static const int rgbTblSize = sizeof(rgbTbl) / sizeof(RGBData);
|
|||
|
||||
void tst_QColor::fromString_data()
|
||||
{
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
QTest::addColumn<QColor>("byCtor");
|
||||
QTest::addColumn<QColor>("bySetNamedColor");
|
||||
#endif
|
||||
QTest::addColumn<QColor>("byFromString");
|
||||
QTest::addColumn<QColor>("expected");
|
||||
|
||||
|
|
@ -735,13 +745,20 @@ void tst_QColor::fromString_data()
|
|||
|
||||
#define ROW(expr) row(expr, #expr)
|
||||
auto row = [&] (auto expr, const char *exprS) {
|
||||
QT_WARNING_PUSH
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
QColor bySetNamedColor;
|
||||
bySetNamedColor.setNamedColor(expr);
|
||||
auto byCtor = QColor(expr);
|
||||
#endif
|
||||
QTest::addRow("%s: %s", e.name, exprS)
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
<< byCtor << bySetNamedColor
|
||||
#endif
|
||||
<< QColor::fromString(expr)
|
||||
<< expected;
|
||||
QT_WARNING_POP
|
||||
};
|
||||
|
||||
const auto l1 = QLatin1String(e.name);
|
||||
|
|
@ -771,21 +788,27 @@ void tst_QColor::fromString_data()
|
|||
|
||||
void tst_QColor::fromString()
|
||||
{
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
QFETCH(QColor, byCtor);
|
||||
QFETCH(QColor, bySetNamedColor);
|
||||
#endif
|
||||
QFETCH(QColor, byFromString);
|
||||
QFETCH(QColor, expected);
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 6)
|
||||
QCOMPARE(byCtor, expected);
|
||||
QCOMPARE(bySetNamedColor, expected);
|
||||
#endif
|
||||
QCOMPARE(byFromString, expected);
|
||||
}
|
||||
|
||||
|
||||
void tst_QColor::constructNamedColorWithSpace()
|
||||
{
|
||||
DEPRECATED_IN_6_6(
|
||||
QColor whiteSmoke("white smoke");
|
||||
QCOMPARE(whiteSmoke, QColor(245, 245, 245));
|
||||
)
|
||||
QCOMPARE(QColor::fromString("white smoke"), QColorConstants::Svg::whitesmoke);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue